Useful Linux Commands

Update: Saturday, 4. April 2026

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.

Useful Commands in the Linux Bash

df -h

Lists the free disk space of the system.
-h (human readable) provides a clear display of the sizes

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 b . At the same time, a file out.file is created with all files and directories in the root directory.

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.

 

Shell Output Redirections and Pipes

Example script "myprint.sh":

#!/bin/bash
echo "Print on stdout." >&1
echo "Print on stderr." >&2

The example script "myprint.sh" generates output on the standard output (stdout) and the standard error output (stderr).

 

1. Redirect stdout (operator 1> or >):

$> myprint.sh 1> /dev/null

Print on stderr.

2. Redirect stderr (operator 2>):

$> myprint.sh 2> /dev/null

Print on stdout.

3. Redirect stdout and stderr (operator &>):

$> myprint.sh &> /dev/null

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)
1 = Standard output (/dev/stdout)
2 = Standard error output (/dev/stderr)
/dev/null - Null device (data stream is discarded)

Output forwarding and pipes:

1. stdout from scriptA to stdin of ScriptB:

$> ScriptA | ScriptB

2. stdout and stderr from ScriptA to stdin of ScriptB:

$> ScriptA 2>&1 | 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).

 

Compressing and Extracting Files in Linux

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.

Comments 0

 

Write new comment: