Basic Command Memo

Debian GNU/Linux systems have all the graphical applications needed to perform your daily tasks, so why to use the command line?

the ultimate command: man.



Browse directories

command action
pwd Print Working Directory
cd rep Change Directory to rep
cd Change Directory to /home/$USER or ~/
cd .. move up to the parent directory
ls rep List information about file(s) in rep
ls -a ls with hidden files displayed
ls -l ls with size and rights

Action on files or directories

command action
mv source target move source file to target
cp source target copy source file to target
cp -R source target copy source directory to target recursively
ln source link create a hard link from source to link
ln -s source link create a symbolic link from source to link
touch file create a file or update its modification time
mkdir rep create the repertory rep
mkdir -p rep/rep2 mkdir with creation of parent directory if needed
rm file delete the file
rm -f file delete write-protected file
rmdir rep delete an empty directory
rm -R rep delete a non-empty directory
du -h file or rep display size of file or rep

View/Compare files

command action
wc file Prints byte, word and line counts of file
cat file displays the contents of a file
more file display file page by page. 'Space'=next page, 'Enter'=next line, 'u'=up
less file display file with fine navigation Left/Right/Up/Down/PageUp/PageDown
head -n x file displays the 'x' first lines of file
tail -n x file displays the 'x' last lines of file
tail -f file dynamicaly displays last line of file
diff file1 file2 Displays differences between two text files
diff -u file1 file2 Displays differences between file1 and file2 with patch syntax
comp file1 file2 compares two binary files
comp file1 file2 n N compares two files, file1 from the octet n, and file2 from the octet N

Users & groups

command action
whoami Print the current user id and name
who Print all usernames currently logged in
id Print user and group id's uid, gid
id user Print user and group id's (root only)
finger user Print informations about user
write user Print a message on user's terminal
tty Print the current terminal's name
su -, sudo Switch to administrator mode, superuser
passwd Change the password of the current user
adduser add a user
deluser remove a user
addgroup add a group
delgroup remove a group

Process

command action
ps Process Status. Lists running process
ps ax Print all running processes
ps aux Print all process identified by users
pstree Print all process in a tree
top List processes running on the system in a semi-graphical table
kill signal pid kill a process using its pid
pkill signal nom kill a process using its name

signals used by kill/pkill

signal action
-1 (HUP) Reload the process configuration file
-2 (INT) Interrupt the process
-3 (QUIT) Quit the process
-9 (KILL) Kill the process (to avoid, try '-15' first)
-15 (TERM) Complete the process properly
-18 (STOP) Freeze the process
-20 (CONT) Resume execution of a frozen process

Hardware

command action
lsusb Lists connected USB devices
lspci Lists connected PCI devices
cat /proc/cpuinfo Displays processor information
cat /proc/partitions Displays mounted partitions

examples:

command action
lspci | egrep "3D|Display|VGA" Display the graphics card model
lspci | grep -i "net" | cut -d: -f3 Show the Wifi card model
lspci | grep -i audio | cut -d: -f3 Show the soundcard model

(sources linuxtrack)

Network

command action
hostname Print or set system name
ping machine Send a ping to a machine on the network
traceroute machine Displays a traceroute through a machine
netstat Displays the use of the network by the processes
netstat -a netstat with the display of the server processes
lsof Detailed list of file and network usage
ip a Displays the config of the interfaces
route Displays the routing table
curl ifconfig.me Displays public IP

example: displays its locap IP on wireless wlp3s0:

ip address show wlp3s0 | grep "inet " | tr -s " " ":" | cut -d: -f3

Search

command/option action
locate pattern Search for file with a pattern name
updatedb Update locate database
find path options Search for file corresponding to options in path
find -name pattern search for file with a pattern name. ex: find -name '*.html'
find -type f/d/l search by filetype with f=file, d=directory and l=link
find -exec cmd execute cmd on found files

Example: search for all png files in the ‘Images’ directory, then copy all files to tmp directory (‘{}’ stands for found files):

find $HOME/Images -name "*.png" -exec cp {} $HOME/tmp/ \;

Archives

format compress extract
.tar.bz2, .tbz2 tar -cvjf archive.tar.bz2 directory tar xvjf
.tar.gz, .tgz tar -cvzf archive.tar.gz directory tar xvzf
.bz2 bzip2 files bunzip2
.rar - unrar x
.gz gzip files gunzip
.tar tar -cvf archive.tar files tar xvf
.zip zip -r archive.zip files unzip
.Z compress files uncompress
.7z 7z a files 7z x
.xz xz -z directory unxz

Kernel

command description
cat /proc/version Version of the Linux kernel used, its name, the version of the compiler used.
uname -r Version of the Linux kernel used.
dpkg -l | egrep "linux-(header|image)" List all kernels installed on your machine.

Debian package management

the following commands are preceded by "$" (for $USER) or "#" (for #ROOT)

command description
# apt update updates the list of packages in the repositories
# apt upgrade update installed packages, without removal
# apt full-upgrade same as 'upgrade' but with removal of packages if necessary
# apt install package(s) install the package(s) passed as argument
# apt remove package(s) uninstall the package(s) passed in argument
# apt autoremove uninstall unnecessary packages
# apt purge package(s) uninstall package(s) + configuration files
# apt edit-sources edit the file containing Debian repository addresses
$ apt show package displays package informations
$ apt search pattern perform a pattern search in the package list

Various orders

some very practical daily commands (wip):

Specific commands on nakeDeb

nakeDeb integrates nakedtools, small scripts to make the geek's life easier ...
nakeDeb also integrates a .bashrc filled with aliases and functions.
here is the list of commands available on your nakeDeb:

nakedtools options description
dotcleaner trash, securetrash, cache, thumbnails, history, all, secureall trash, cache, previews & recent document cleanup. display a selection menu if launched without arguments. secure option uses shred
nakedquit - keyboard shutdown menu
nakedhelp - command to open the wiki in your default browser
nakedwelcome - launches the nakeDeb greeting
nakedwalls $DIR menu which allows you to define a random wallpaper from the $DIR indicated in argument or from the folders specified in the script if started without argument, to choose one or to view them.
nakedlocate $DIR searches from the root or in the directory given as argument. opens the parent folder once the search is validated
popmenu [0-8] launches a minimal menu in the lower left corner powered by rofi and based on .desktops. the position can be determined as an argument (cf man popmenu)

aliases & functions in your ~/.bashrc:

alias/functions description
gm, gc, :q, oust, comeback cd /media or ~/.config, exit, shutdown, reboot
ports list the applications using the network
debin package sudo apt install --no-install-recommends package
debrm package sudo apt autoremove --purge package
debup sudo apt update && sudo apt full-upgrade
debsh package apt search package
debvs package apt-cache policy package
genpass 12 characters random password
getweb url capture the content of a website
nospace renames by removing spaces in the names of files in the current folder
ff pattern find pattern in the current directory then lists results
space calculates the occupied space and lists the folders in order
extract archive extract the archive in the current folder
mktar, mktgz, mktbz, mktxz dir/file create a tar, tar.gz, tar.bz2, tar.xz archive from the dir/file
invertcolors completely inverts the screen colors (negative view)