Linux Commands
This article lists the most common commands and options for navigating and administering Linux distributions via the Command Line Interface (CLI) - usually called Terminal or Shell in the Linux environment.
Command Syntax
Linux commands are structured according to the following syntax
command [-options <parameter>] [<arguments>]
or
command [--option_long <parameter>] [<arguments>]
The command part calls a program that fulfils one or more functions. The ls command, for example, lists the contents of the folder in which the user is currently located.
As a rule, options can be used to give the program additional information on how it should behave. This can be the type or length of the output, but also the behavior in the event of errors or similar.
Both the command and the options can require additional parameters for the output. For example, if you want to move a folder, both the source and destination folders must be specified.
Example
We will look at the command:
ping -c 3 localhost
This command is structured as follows:
| Command Part | Syntax | Description |
|---|---|---|
ping
|
command name | The Ping package is called up |
-c
|
option | The number of ping processes is specified |
3
|
option parameter | 3 ping processes are specified |
localhost
|
command parameter | Destination address to be pinged |
Auxiliary commands
Linux offers several ways to get help on commands and their options.
| Command | Description |
|---|---|
man |
Stands for Manual and calls up the Manpage of a command |
whatis |
Also uses the man pages, but only gives a short summary of the command |
info |
Starts a utility program for displaying instructions for a command |
apropos |
To search for keywords within all manuals |
Standard options
Linux programs also use some standard options that all packages listed there understand.
| Option | Description |
|---|---|
-h, --help |
Displays all available options of the command and ends the process. |
--version |
Displays the version of the package and ends the process. |
-- |
Limits the options. Options specified after a -- are interpreted as command parameters. The sort -- -r command would attempt to sort the -r file.
|
Commands
Listed here and organised by category are the most important commands for administering server systems. The tables also indicate whether the respective programs are included in a minimal installation of Debian Linux.
System
The following packages provide system information or allow certain system parameters to be manipulated.
| Debian Standard | Command | Description | Important options | Option parameters | Option description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | uname | Call up the name and information of the running kernel | -a, --all
|
Show all information | unix name | ||
-r, --kernel-release
|
Output release number of the kernel | ||||||
-v, --kernel-version
|
Output version of the kernel | ||||||
| ✔ | hostname | Retrieve or set the host name of the system | -I, --all-ip-adresses
|
Shows all network addresses of the host | |||
-f, --fqdn, --long
|
Displays the Fully Qualified Domain Name (FQDN) | ||||||
-s, --short
|
Displays the short name of the host | ||||||
| ✔ | uptime(siehe auch w) | Display the runtime (uptime) of the system (and logged-in users and utilization data) | -p, --pretty
|
Shortens the display to the pure uptime | |||
| ✔ | lscpu | Display information about the processor architecture | -a, --all
|
Displays all online and offline CPUs. May only be used together with -e or -p
|
list cpu | ||
-e, --extended
|
=listelement1,listelement2,... (possible list elements: CPU, CORE, SOCKET, BOOK, NODE, CACHE, ADDRESS, ONLINE, CONFIGURED, POLARIZATION)
|
Displays the list in human-readable format | |||||
-p, --parse
|
=listelement1,listelement2,...(possible list elements as above) | Makes the output machine-readable | |||||
| ✔ | lsblk | Displays information on selected or all block devices | -a, --all
|
Displays all devices | list block | ||
-f, --fs
|
Displays the file system | ||||||
-t, --tree
|
Displays the devices in a tree | ||||||
| ✔ | lsmod | List loaded kernel modules | list modules | ||||
| ✔ | lsusb | List devices that are connected to the Universal Serial Bus (USB) | -v, --verbose
|
Show detailed information | list usb | ||
-t, --tree
|
Display output as a directory tree | ||||||
| ✔ | free | Display free and occupied memory | -h, --human
|
Makes the output human-readable. To do this, it is scaled to the smallest unit with three digits | |||
-s, --seconds
|
Indicates the free memory continuously after the specified time interval | ||||||
-c, --count
|
Specifies the number of time intervals after which the process is to be terminated | ||||||
| ✔ | df | Display hard disk usage | -h, --human-readable
|
Makes the output human-readable | disk free | ||
-t, --type
|
=TYPE | Lists only the specified file systems | |||||
-T, --print-type
|
Outputs a column specifying the file system | ||||||
| ✔ | du | Displays the hard disk usage of files | -h, --human-readable
|
Makes the output human-readable | disk usage | ||
-c, --total
|
Create grand total | ||||||
| ✔ | modinfo | Shows information about specific Linux kernel modules | <modulname>
|
module information | |||
| ✔ | grep | Searches for patterns in files or system output and displays them | -f, -file=
|
<filename>
|
Searches a specific file for search patterns | global regular expression print | |
-e,--regexp=
|
<Pattern>
|
Searches for a specific pattern | |||||
-r,-recursive
|
Searches below each directory recursively |
Process Management
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | top | Show all running processes | table of processes | ||||
| ✔ | kill | Terminates a process | -L
|
Lists all signals that can be sent to a process | <Process ID (PID)>
|
||
| ✔ | pkill | Sends a SIGTERM signal to the named process
|
<Process Name>
|
process kill | |||
| ✔ | killall | Terminates all processes by name | <Process Name>
|
||||
| ✔ | ps | Reports on the process status | -e
|
Selects all processes | process status | ||
-f
|
Displays the listing in full format | ||||||
| ✘ | bg | Commands jobs to be executed in the background1 | <Job Title>
|
background | |||
| ✘ | fg | Commands jobs to be executed in the foreground | <Job Title>
|
foreground | |||
| ✔ | nice | Determines the priority of a command when allocating processor time | <Process Name>
|
nice | |||
| ✔ | renice | Changes the nice value of running processes
|
<nice value (-20[high] bis +19[low])> <Process-ID>
|
1 If you want to start a job and have it run in the background, you can also add an & to the end of the command, e.g. ping 8.8.8.8 > pinglog &.
Directory Structure
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | mkdir | Creates new directories | -m, --mode
|
=MODE | Set access rights (see chmod)
|
<directory,directory,...>
|
make directory |
| ✔ | cd | Changes the current working directory | <directory>
|
change directory | |||
| ✔ | pwd | Outputs the current working directory | print working directory | ||||
| ✔ | ls | Lists the contents of a directory | -l
|
Long list format | list | ||
-h, --human-readable
|
Human-readable format (bytes in KB, MB, GB) | ||||||
-a
|
Also lists hidden directories (directories beginning with .)
|
File Management
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | rm | Remove files and directories | -r
|
Recursive: Also deletes subdirectories | <file-/directoryname>
|
remove | |
-f
|
Force: Forces deletion without user query | ||||||
| ✔ | touch | Change timestamp of files - Creates files if argument does not exist | <filename>
|
||||
| ✔ | cp | Copying files and directories | <sourcefile/-directory> <targetfile/-directory>
|
copy | |||
| ✔ | mv | Moving files and directories | <sourcefile/-directory> <targetfile/-directory>
|
move | |||
| ✔ | cat | Displaying and merging files | <filename>
|
concatenate | |||
| ✔ | head | Displaying the first lines of a file | <filename>
|
||||
| ✔ | tail | Displaying the last lines of a file | <filename>
|
||||
| ✔ | ln | Creating links between files | <filename>
|
link | |||
| ✔ | find | Finding files within a directory hierarchy | <filename>
|
||||
| ✔ | wc | Output bytes, words or lines of files | -l
|
Returns the number of lines in a file | <File>
|
word count |
User and Group Administration
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | whoami | Output ID of the logged-in user | |||||
| ✔ | who | Output ID of all logged in users | |||||
| ✘ | finger | Outputs information on all logged-in users | |||||
| ✔ | last | Display list of recently logged in users | |||||
| ✔ | adduser | Adds a new user | |||||
| ✔ | deluser | Deletes a user | |||||
| ✔ | passwd | Allows the password to be changed | Password | ||||
| ✔ | usermod | Change user accounts | user modification | ||||
| ✔ | w | Displays information on all logged in users |
Rights Management
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | chmod | Changes the mode of files | change mode | ||||
| ✔ | chown | Changes the user and group rights | change owner | ||||
| ✔ | chgrp | Changes the group membership of files | change group | ||||
| ✘ | umask | Display or set the date mode mask | -S
|
Symbolic output | unix mask | ||
-p
|
Output in such a way that it can be reused as input |
File Compression and Archiving
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | tar | Archiving tool | Tape Archive | ||||
| ✔ | gzip | Data compression tool | GNU zip | ||||
| ✘ | bzip2 | Data compression tool | zipper | ||||
| ✘ | xz | Data compression tool | x zip |
I/O Redirection
| Debian Standard | Command | Description | Important Options | Option Parameters | Option Description | Arguments | Origin |
|---|---|---|---|---|---|---|---|
| ✔ | < | Instead of a manual input, the content of a file is used as an argument (stdin) |
grep -nw < /etc/protocols 'ipv6'
|
||||
| ✔ | > | The standard output ( stdout) is redirected to a file
|
echo "Hello World!" > text
|
||||
| ✔ | >> | The standard output (stdout) is appended to a file
|
echo "Hello World!" >> text
|
||||
| ✔ | 2> | The error output ( stderr ) is redirected to a file
|
find /usr admin 2> error-file
|
||||
| ✔ | 2>> | The error output (stderr) is appended to a file
|
find /usr games 2>> error-file
|
||||
| ✔ | &> | Redirects the standard output (stdout) and error output (stderr) to a file
|
find /usr admin &> searchfile
|
||||
| ✔ | &>> | Appends the standard output (stdout) and error output (stderr) to a file
|
find /usr games &>> searchfile
|
||||
| ✔ | | | The pipe links two commands together | cat /etc/protocols | grep 'ipv6'
|
||||
| ✔ | 2>&1 | Outputs the error output as standard output | cat notafile > file 2>&1[1]
|
Miscellaneous and useful information
| Command | Options | Arguments | Description |
|---|---|---|---|
which
|
<Command>
|
Find a command | |
cat
|
/proc/cpuinfo |
Display information about the processors in the system | |
cat |
/proc/meminfo |
Display information on the system's working memory | |
free |
-h --si |
Display information on the system's memory usage (-h for better readability with adapted units; h: human readable; --si: display in powers of 1000)
| |
df |
-H |
Display of information on the system's data carrier allocations (-H for better readability with adapted units in powers of 1000)
|
Further information
Article on Linux kernel modules: How to display list of modules or device drivers in the Linux Kernel
References
- ↑ Understand Shell Script's idiom: 2>&1 (www.brianstorti.com, 28.06.2024)
|
Author: Stefan Bohn Stefan Bohn has been employed at Thomas-Krenn.AG since 2020. Originally based in PreSales as a consultant for IT solutions, he moved to Product Management in 2022. There he dedicates himself to knowledge transfer and also drives the Thomas-Krenn Wiki. |

