This page contains a collection of useful Linux commands. It helps when working on the console (bash), via remote terminal (ssh), or when configuring a Linux system. The overview is kept very brief and does not contain detailed explanations of the individual commands. If more details are needed, a look at the manual (man <command>) or the help output of the command (--help) is often useful.
df -h |
Lists the free disk space of the system. |
du -sh ~/* |
Lists all subdirectories in the user's home directory and shows how much disk space each directory occupies. |
find ~/ -name *.txt |
File search: Searches for all TXT files in the user's home directory. |
tee:ls -l / | tee out.file | grep b |
This example (from Wikipedia) filters the files and directories in the root directory for all those containing a |
top |
Displays a list of the currently running processes on the system (updated every 3 seconds by default). |
wget https://www.andinet.de/andinet.png |
Downloads a file from the internet. |
|
Example script "myprint.sh":
|
The example script "myprint.sh" generates output on the standard output (stdout) and the standard error output (stderr).
|
|
1. Redirect stdout (operator 1> or >):
2. Redirect stderr (operator 2>):
3. Redirect stdout and stderr (operator &>):
No output on the screen. |
In the first example, the standard output is redirected to /dev/null (discarded) and only the standard error output remains on the screen. In the second example it is the other way around: the standard error output is redirected and discarded, and only the standard output remains on the screen. In the third example, both outputs are discarded. Overview of file descriptors: 0 = Standard input (/dev/stdin) |
|
Output forwarding and pipes: 1. stdout from scriptA to stdin of ScriptB:
2. stdout and stderr from ScriptA to stdin of ScriptB:
|
The | operator forwards the standard output of ScriptA to the standard input of ScriptB. Note: the standard error output stderr is normally not forwarded! If stderr should also be forwarded, stderr must first be duplicated to stdout (see example 2). |
| tar -xvzf myfile.tar.gz |
Extracts a .tar.gz file. |
| bunzip2 myfile.tar.bz2 |
Extracts a .tar.bz2 file. |
| zip -r myfile.zip myfolder |
Compresses all files in <myfolder> and creates the file <myfile.zip>. |
Which helpful commands are still missing? Feel free to leave a comment.