Like most modern operating systems, Linux also provides you with a shell, which you can use to control your system using command line commands. All of the settings that you set via the graphical user interface (GUI) can also be made via the shell. We show you the most important Linux commands and explain their function and ap­plic­a­tion.

Cheap domain names – buy yours now
  • Free website pro­tec­tion with SSL Wildcard included
  • Free private re­gis­tra­tion for greater privacy
  • Free Domain Connect for easy DNS setup

List of the 50 most important Linux commands

Command De­scrip­tion
sudo Run programs with the rights of another user
ls List directory contents
cd Nav­ig­a­tion in the directory tree
touch Create new file
mkdir Create new directory
rm Delete file
rmdir Delete directory
mv Move file or directory
cp Copy file or directory
pwd Print current position in directory tree
zip Write files to zip archives
unzip Extract files from zip archives
ln Create symbolic link
cat Combine file contents
grep Search text files
diff Find dif­fer­ences between text files
cmp Align files at byte-level
tar Write and extract files to tar archives
echo Output string to the standard spe­cific­a­tion
clear Clear terminal
ssh Connect to another computer via a secure shell
wget Download file directly from the internet
ping Request server and measure latency
ftp, sftp Transfer files via (S)FTP
ip query and configure network in­ter­faces
apt/pacman/yum Download and manage software packages
netstat Display network interface status
traceroute Track data packets
route Display and edit IP routing tables
dig Request DNS in­form­a­tion
mount/unmount Integrate file systems (set up/mount)
dd Copy files, par­ti­tions or data carriers to the exact bit
chmod Manage access rights
chown Manage ownership rights
adduser Add/modify user account
passwd Create/edit passwords for user accounts
groupadd Create user groups
chattr Manage file at­trib­utes
lsattr Display file at­trib­utes
chgrp Manage group af­fil­i­ations for files and dir­ect­or­ies
man Call up user manual
shutdown, reboot Shut down/reboot the system
top Dynamic process overview
lscpu Display processor in­form­a­tion
lshw Output hardware in­form­a­tion
kill Stop and terminate process via PID
killall Stop and terminate processes via name
nice Define process pri­or­it­ies
pgrep Identify PID via search term
ps Display list of all running processes

sudo command in Linux

The Linux sudo command(sub­sti­tute user do) can set the program call to run with the rights of another user. As a rule, entering a password is required for this. The sudo command always asks for the password of the user account being called up.

If the command is entered without a username, then the superuser root is set as the target user.

sudo -u USERNAME PROGRAM CALL
bash

ls command in Linux

The Linux ls command line directive ls stands for list and is used to display the content of a directory (the names of all files and folders found in the given directory).

The syntax of the command reads:

ls [OPTIONS] DIRECTORY
bash

If ls is used without a directory entry, then the command lists the content of the current directory. With the help of ad­di­tion­al options, you can define which in­form­a­tion is shown and how it’s displayed.

cd command in Linux

The Linux cd command directive stands for change directory, and is used for nav­ig­a­tion in the directory tree.

The syntax of the command reads:

cd [OPTION] DIRECTORY
bash

If no target directory is given, then cd auto­mat­ic­ally switches to the user’s home directory. If cd is used with a minus symbol after it (-), it changes back to the previous directory.

touch command in Linux

The Linux touch command line directive can be used to modify access and al­ter­a­tion time stamps for files. If touch is applied to a file that doesn’t exist yet, then it is auto­mat­ic­ally created, meaning that the command is also good for creating empty files. Use touch according to the following pattern:

touch [OPTIONS] FILE
bash

To set the time stamp for a file to the desired date, use the OPTION -t along with the time in­form­a­tion in the forms [YY]MMDDhhmm[.ss].

Example:

touch -t 1703231037 file.txt
bash

Access and al­ter­a­tion time stamps are now set to March 23, 2017, 10:37. The modi­fic­a­tion can be re­stric­ted to access or time stamps with the options -a and -m. If the touch command is used without option -t, then it uses the current time stamp.

mkdir command in Linux

The Linux mkdir command stands for make directory, and allows Linux users to make new dir­ect­or­ies. Use the following syntax to create a new directory in the current directory:

mkdir [OPTION] DIRECTORY NAME
bash

If a directory is supposed to be created in a par­tic­u­lar target directory, then specify the absolute or relative path to the directory.

rm command in Linux

The Linux rm command (remove) per­man­ently deletes files or entire dir­ect­or­ies. The program call is based on the following syntax:

rm [OPTIONS] FILE/DIRECTORY
bash

If a directory is to be deleted along with all its sub­dir­ect­or­ies, then use rm plus the option -R (–recursive).

rmdir command in Linux

If you want to delete a par­tic­u­lar directory, use the command line directive rmdir (remove directory) according to the following syntax:

rmdir [OPTION] DIRECTORY
bash

You can only delete empty dir­ect­or­ies with rmdir. To delete a directory along with all of its contained files and sub­folders, use the command rm (remove) with the option –r.

In other articles you will find ad­di­tion­al ways to delete a Linux file or delete a Linux directory.

mv command in Linux

The Linux mv command (move) copies a file or directory and deletes the original element. If it’s used within the same directory, then mv can be used to rename files.

The program call is based on the following syntax:

mv [OPTIONS] SOURCE TARGET
bash

cp command in Linux

The Linux cp command (copy) is used to copy files and dir­ect­or­ies. The basic syntax of the command reads:

cp [OPTIONS] SOURCE TARGET
bash

The SOURCE is the element that is intended to be copied. Either a file or a directory is then defined as the TARGET of the copying process. If you define an existing file as the target file, its contents are over­writ­ten with the source file. You also have the option to create a new file with whatever name you choose as the target file.

pwd command in Linux

Use the Linux pwd command (short for print working directory) to output the name of the current working directory.

The syntax of the command reads:

pwd [OPTIONS]
bash

zip command in Linux

Use the zip command to compress several files into a zip archive. The syntax of the command is:

zip DESTINATION FILES
bash

The DES­TIN­A­TION is the name or path of the resulting zip file. FILES refers to the file names or paths of the files to be com­pressed (separated by spaces).

unzip command in Linux

You can use unzip to extract files from zip archives. The syntax is:

unzip FILE.zip -d DESTINATION
bash

Here FILE refers to the zip archives where the files are to be extracted from. Op­tion­ally, you can use the -d TARGET option to specify a target directory where the resulting files are to be stored. Otherwise the files are stored in the current directory.

ln command in Linux

The Linux ln command (short for link) generates a shortcut to a file or a directory. This creates another directory entry for this file, which allows you to access the re­spect­ive file via another file path. The call for ln has to always contain at least the path to the source file.

ln [OPTIONS] path/to/sourcefile
bash

In this case, a shortcut will be created in the current work directory under the same name. You can also enter a target path and then name the shortcut whatever you want:

ln [OPTIONS] path/to/sourcefile path/to/shortcut
bash

cat command in Linux

The Linux cat command (short for con­cat­en­ate) was developed as a tool for the com­bin­a­tion of file content and can be used as a pager for the display of file content in the terminal.

Use cat with the following syntax in the terminal to read a file and output it to stdout (the standard output):

cat OPTIONS FILE
bash

Multiple files can be separated by spaces:

cat OPTIONS FILE1 FILE2
bash

grep command in Linux

With the Linux grep command, you can search through text files. Any character strings or regular ex­pres­sions can be used as a search pattern. Use grep according to the following syntax:

grep [OPTIONS] SEARCH PATTERN [FILE(S)]
bash

If grep en­coun­ters a string that cor­res­ponds to the search pattern, then the line number along with the file name is output to the terminal. In general, grep is used on all files in the current directory. The option -r enables a recursive search into the sub­dir­ect­or­ies.

diff command in Linux

The command line program diff serves to compare two files. You can also use diff to determine if two dir­ect­or­ies contain the same files.

Call up the program in the terminal using the following syntax:

diff [OPTIONS] FILE1 FILE2
bash

cmp command in Linux

cmp is part of the diff package and is used to compare file contents. As opposed to diff, the alignment is done at the byte level and so is par­tic­u­larly suitable for binary files. Use cmp according to the following syntax:

cmp [OPTIONS] FILE1 FILE2
bash

If cmp finds dif­fer­ences, the command line program outputs the byte and line number of the first deviation in the terminal.

tar command in Linux

The command tar allows you to write various files and dir­ect­or­ies se­quen­tially into a tar file and use it as a backup for recovery if needed. Unlike the zip format common in Windows, all user rights of the archived file are retained even after unpacking. Use the following syntax:

tar [OPTIONS] FILES
bash

If you want to create a new archive, use tar with the options -c (create new archive) and -f (write archive to a given file or read from it). Find out more in our article on tar backups and how to create archives under Linux.

echo command in Linux

Use the Linux echo command to output strings line-by-line on the standard output (usually the terminal).

The general command syntax reads:

echo [OPTIONS] STRING
bash

clear command in Linux

Use the command line directive clear to clear the screen content.

clear
bash

You’ll receive a blank terminal with a prompt. Older entries remain in the scroll­back buffer. Instead of using this command, you can also clear the terminal with the key com­bin­a­tion [Ctrl] + [L].

ssh command in Linux

You can use ssh to connect your computer to an external computer via the SSH protocol, which means you are then in the shell of the other computer. The syntax is as follows:

ssh USERNAME@HOSTNAME
bash

Here, USERNAME and HOSTNAME denote the username under which you wish to log in and the address of the external computer.

wget command in Linux

You can use the Linux wget command to download files from the internet. Use the following syntax for this:

wget [OPTION] LINK
bash

Here LINK denotes the URL where the file can be found. You can op­tion­ally use the optional argument -c to continue a download that has been in­ter­rup­ted.

ping command in Linux

Use the Linux ping command to test the ac­cess­ib­il­ity of other computers in the network. The command is based on the following syntax:

ping [OPTIONS] TARGET
bash

Together with the round-trip time (RTT) – the time span between sending the data package and receiving an answer – ping also writes the IP address of the target system in the terminal. You can use optional arguments to set the number of packets or seconds after which ping ter­min­ates itself.

ftp or sftp command in Linux

This gives you the pos­sib­il­ity to exchange files between the local system and another computer in the network. Use FTP (File Transfer Protocol) according to the following syntax to establish a con­nec­tion to the FTP server of the target computer:

ftp [OPTIONS] [HOST[PORT]]
bash

The ad­dress­ing takes place via host name or IP address. Spe­cify­ing a port number is optional. Only use FTP in networks that you trust, as this protocol is not secure. For security reasons, it is almost always advisable to use SFTP (SSH File Transfer Protocol). The command line program sftp functions like ftp to transfer data in the network, but here the transfer is encrypted. SFTP uses Secure Shell (SSH) as standard, i.e. also its au­then­tic­a­tion methods. We explain how to use SSH keys for your network con­nec­tion in another article.

ip command in Linux

The command line program ip is part of the program col­lec­tion iproute2, with which network in­ter­faces are requested and con­figured via the terminal. The general syntax of the command reads:

ip [OPTIONS] OBJECT [COMMAND [ARGUMENT]]
bash

Which action is carried out by ip is defined with the help of objects, sub­com­mands, and their arguments.

The program supports various objects, such as address (IP address), link (network interface), route (entry in the routing table), or tunnel, to which sub­com­mands such as add, change, del, list, or show can be added.

For example, if you would like to access the IP address of a par­tic­u­lar network interface (i.e. eth0), use the command ip in com­bin­a­tion with the object address, the command show, and the argument dev eth0:

ip address show dev eth0
bash

We will show you how to display an IP address in Linux in more detail in another article.

apt, pacman and yum command in Linux

Every Linux dis­tri­bu­tion has a Packet Manager with which you can download and manage software packages. The syntax for app in­stall­a­tion is as follows:

apt install [PACKET] # Debian-based distributions such as Ubuntu
pacman -S [PACKET] # Arch-based distributions
yum install [PACKET] # Red Hat-based distributions
bash

[PACKET] is the name of the package or program you want to install. In most cases, these commands must be executed via sudo in root mode. For other dis­tri­bu­tions that use other package managers, the commands may differ. Each manager also has commands to remove packages, update the package list and update all installed packages, among others. On Ubuntu, these commands are as follows.

apt remove [PACKET] # remove package
apt update # update package list
apt upgrade # upgrade packages
bash

netstat command in Linux

The command line program netstat is used to query the status of network in­ter­faces. The general syntax of the command reads:

netstat [OPTIONS]
bash

Use netstat without option to output all open sockets in the terminal. You can also use the following options to see the routing table (-r), interface stat­ist­ics (-i), masked con­nec­tions (-M), or network link messages (-N). Find out more in our in­tro­duc­tion to netstat.

traceroute command in Linux

To trace the transport route of an IP data packet between your system and a target computer, you can use the command traceroute. Use the following pattern.

traceroute [OPTIONS] HOSTNAME
bash

Via traceroute you can identify which router and internet nodes an IP package passes on its way to the target computer – for example, to in­vest­ig­ate the cause of a delay.

route command in Linux

With the command line program route, the IP routing table of the core can be requested and edited. The command is based on the following syntax:

route [OPTIONS] [add|del] [-net|-host] TARGET
bash

Use the command without options to display the complete routing table of the core:

route
bash

If you want to set a route to a network, use the sub­com­mand add.

route add -net 10.0.0.0
bash

dig command in Linux

dig is a lookup tool that can be used to request in­form­a­tion from the DNS server and output it in the terminal. The command line program is generally used according to the following syntax to request the IP address and other DNS in­form­a­tion on a given domain name:

dig [@SERVER] [DOMAIN] [TYPE]
bash

SERVER is the DNS server that should be searched for the desired in­form­a­tion. If no server is given, dig iden­ti­fies the standard DNS server from the file /etc/resolv.conf. DOMAIN stands for the domain name from which the DNS in­form­a­tion should be iden­ti­fied. TYPE is used to specify the type of query, i.e. ANY (all entries), A (IPv4 record of a host), or AAAA (IPv6 record of a host). The standard request type is defined as A.

mount and unmount command in Linux

If a file system is to be in­teg­rated in the directory structure of the operating system via the directory structure, then the command line program mount is used under Linux. The general syntax of the command reads:

mount [OPTIONS] DEVICE MOUNTPOINT
bash

DEVICE = Path to the device file of the storage device that you want to mount as the partition.

MOUN­T­POINT = The location in the directory structure of your operating system where you want to mount the partition. The moun­t­point is usually specified as an absolute path.

Example:

mount /dev/sdd /media/usb
bash

The device sdd is mounted in the directory /media/usb.

dd command in Linux

The command line program dd enables a copying process in which data is read out bit for bit from an input file (if) and written into an output file (of). The program call is based on the following syntax:

dd if=Source of=Target [OPTIONS]
bash

As the source and target, you can specify in­di­vidu­al files as well as entire par­ti­tions (i.e. /dev/sda1) or a complete storage device (i.e. /dev/sda).

dd if=/dev/sda5 of=/dev/sdb1
bash

chmod command in Linux

The command line program chmod (short for change mode) is used to assign rights in unix-like file systems (i.e. ext2, ext3, ext4, reiser, xfs). The general syntax of the command reads:

chmod [OPTIONS] MODE FILE
bash

or

chmod [OPTIONS] MODE DIRECTORY
bash

The MODE place­hold­er stands for the ap­plic­able rights mask. You can find out more about how to create a system like this and what to pay attention to in our guide on access rights with chmod. With the help of the -R option, rights can be assigned re­curs­ively to sub­folders and files contained in a directory.

chown command in Linux

The Linux chown command stands for change owner and allows you to modify the owner per­mis­sions.

chown [OPTIONS] [USER][:[GROUP]] FILE
bash

or

chown [OPTIONS] [USER][:[GROUP]] DIRECTORY
bash

To set owner rights for a user or group, there are four possible com­bin­a­tions available. Owner and group are reset according to the input:

chown [OPTIONS] owner_name:group_name file.txt
bash
# The group is reset according to the input, the user remains unchanged:
chown [OPTIONS] :group_name file.txt
# The owner is reset according to the input, the group remains unchanged:
chown [OPTIONS] owner_name file.txt
# The user is reset according to the input. The group is set to the default group for the logged-in user:
chown [OPTIONS] owner_name: file.txt
# The changes are recursively extended to subdirectories with the help of OPTION `-R`.
bash

adduser command in Linux

The simplest option for creating a user account is by using the command line program adduser. This is a Perl script based on the Linux useradd command and offers the same functions in a user-friendly way. The adduser command requires root priv­ileges and is used according to the following syntax:

adduser [OPTIONS] USERNAME
bash

Use adduser without options to auto­mat­ic­ally create a user ID, home directory, and user group with the same name, in addition to the new user account.

adduser test
bash

This is followed by an in­ter­act­ive dialog in which you can define the password and other user in­form­a­tion (real name, office number, telephone number, etc.).

passwd command in Linux

Use the Linux passwd command to change the password of a user or define, check, and change intervals. The command is based on the following syntax:

passwd [OPTIONS] USERNAME
bash

If you want to change the password of another user, then you need root per­mis­sions. Use the passwd command without a username to change your own password. If the password is supposed to be blocked, use the command passwd with the option -l (–lock). Other options give you the op­por­tun­ity to define a duration for the ex­pir­a­tion of passwords (-x) as well as warning (-w) and check intervals (-i).

groupadd command in Linux

The command line program groupadd is used to create user groups. Use groupadd with root per­mis­sions according to the following syntax:

sudo groupadd [OPTIONS] GROUPS
bash

Each newly-created group contains its own group ID (GID). Group IDs between 0 and 99 are reserved for system groups. If you want to define the GID for a new user group for yourself, use the command line directive groupadd with the option -g (GID). If you want to create a system group, use the option -r (root).

chattr command in Linux

The command line program chattr (short for change attribute) allows you to view files or dir­ect­or­ies with at­trib­utes. Use chattr according to the following syntax to set an attribute:

chattr [OPTIONS] +ATTRIBUTE FILE
bash

Replace the plus sign with a minus sign to remove at­trib­utes again. For example, set the attribute -i to prevent changes (deletions or modi­fic­a­tions) to a file or directory. For other at­trib­utes and possible options, refer to the chattr program manual.

lsattr command in Linux

If you would like to display which at­trib­utes are set for a file or directory, use the command line directive lsattr (short for list at­trib­utes) according to the following syntax:

lsattr [OPTIONS] FILE/DIRECTORY
bash

chgrp command in Linux

The command chgrp stands for change group and is used for the man­age­ment of group af­fil­i­ations for files and dir­ect­or­ies. To be able to use chgrp on a chosen file or directory, you have to have owner or root per­mis­sions. These are the only groups to which you can belong. chgrp is used according to the following syntax:

chgrp [OPTIONS] GROUP FILE
bash

or

chgrp [OPTIONS] GROUP DIRECTORY
bash

The option -R refers to sub­folders and files contained in a directory.

man command in Linux

The man command opens the manual pages (man-pages) of your Linux dis­tri­bu­tion directly in the terminal. Use the following scheme to call the manual pages:

man [OPTION] TOPIC
bash

The Linux man-pages are divided into 10 topic areas: User commands, system calls, functions of the pro­gram­ming language C, file formats, con­fig­ur­a­tion files, games, mis­cel­laneous, system ad­min­is­tra­tion commands, core functions, new commands.

shutdown command in Linux

The Linux shutdown command can be used by the root user to shut down the system. The command is based on the following syntax:

shutdown [OPTIONS] [TIME] [MESSAGE]
bash

If you want to induce a shutdown, you have the option to define a time that the system should be turned off. For this, use either a concrete time input (hh:mm) or a countdown (+m). Other users on the system will get a shutdown message. This can be ac­com­pan­ied by a personal message, if needed. If the command shutdown is used with the option -r, the shutdown of the system is followed by a reboot.

top command in Linux

The command top calls a dynamic overview of all running processes. The call is based on the following pattern:

top [OPTIONS]
bash

The output of the process in­form­a­tion can be adjusted using various options. The top process overview (among others) supports the following hotkeys to sort through the outputs:

  • [P] = Sorts the output according to CPU load
  • [M] = Sorts the output according to storage re­quire­ments
  • [N] = Sorts the output nu­mer­ic­ally by PID
  • [A] = Sorts the output by age
  • [T] = Sorts the output by time
  • [U USERNAME or UID] = Filters the output by re­spect­ive user

Use the hotkey [H] to display a help page, or [Q] to close the process overview.

lscpu command in Linux

Use lscpu (short for list cpu) according to the following pattern to output in­form­a­tion about the CPU ar­chi­tec­ture in the terminal.

lscpu [OPTIONS]
bash

For possible options, refer to your operating system’s manual.

lshw command in Linux

The command lshw stands for list hardware and outputs in­form­a­tion about the hardware com­pon­ents in the terminal. Use lshw according to the following syntax:

lshw [OPTIONS]
bash

The command supports various options for cus­tom­ising the output format (-html, -xml, -short, -businfo) as well as the range of in­form­a­tion (i.e. –sanitize to hide sensitive in­form­a­tion).

kill command in Linux

kill is a command line program with which processes can be stopped and finished. The command is passed on according to the following pattern with a desired signal and the ID of the chosen process.

kill [OPTIONS] [-SIGNAL] PID
bash

Common signals are:

  1. TERM: Causes a process to end itself (standard)
  2. KILL: Forces the end of a process (through the system)
  3. STOP: Stops a process
  4. CONT: Allows a stopped process to continue

killall command in Linux

Use the Linux killall command in com­bin­a­tion with a par­tic­u­lar search term to only end the processes whose names coincide (the first 15 char­ac­ters are used to match).

killall [OPTIONS] [-SIGNAL] [PROCESS NAME]
bash

The option -e (–exact) allows you to extend the match to all char­ac­ters of the process name.

nice command in Linux

The command line directive nice indicates a process value between -20 and +19 at the start of a process in integer steps, after which the available computing power of the system is dis­trib­uted. The range of -20 to +19 cor­res­ponds to the Linux priority levels 100 to 139. A process with a nice value of -20 has a higher priority than a process with a nice value of 19. The solo syntax reads:

nice [OPTION] [COMMAND]
bash

Without ad­di­tion­al spe­cific­a­tion, every process starts with a nice value of 0- Use the option -n to define the process priority. It should be noted that negative pri­or­it­ies can only be assigned with root per­mis­sions.

pgrep command in Linux

The command line program pgrep matches the list of running processes with a search term and outputs the re­spect­ive PIDs if there are matches. The general syntax reads:

pgrep [OPTIONS] Search term
bash

By default, pgrep outputs the PIDs of all processes that contain the search term. If the search is to be limited to only exact matches, then use the command along with the option -x. If you would like to obtain the PID in addition to the process name, use pgrep with the option -l. Similarly to grep, pgrep supports search terms based on regular ex­pres­sions.

ps command in Linux

The Linux ps command outputs a list of all running processes in the terminal.

ps [OPTIONS]
bash

If you need a detailed output, use ps with the options -f (detailed) or -F (very detailed). For ad­di­tion­al options, refer to your operating system’s manual.

Ad­di­tion­al Linux commands at a glance

Basic commands

In the basic commands category, you’ll find the Linux basic commands that are used to control the terminal. Learn how to clear the terminal’s vis­ib­il­ity, retrieve previous terminal entries from the history, or exit the terminal session.

1. exit

The command line directive exit ends the current session and closes the terminal.

exit
bash

Instead of this, you can use the key com­bin­a­tion [Ctrl] + [D].

2. help

Use the help command to see a list of all in­teg­rated shell commands (built-in commands). Call up help in com­bin­a­tion with a shell command to retrieve a short de­scrip­tion of the demand in question.

help COMMAND
bash

3. history

In Bash, the last 500 commands entered in the command line are saved in the history. This function serves as entry as­sist­ance, and allows you to look through the list of previous commands using the arrow keys and execute them again.

The history can be searched using keywords with the key com­bin­a­tion [Ctrl] + [R]. You also have the option to view the complete list, numbered in the terminal. Use the command history without options and arguments.

history
bash

If you want to filter the results, combine history via Linux Pipe with the command line program grep (see search options) and a search term.

history | grep SEARCH TERM
bash

Help pages

Are you stuck on what to do? No worries. Under Linux, there are various help and doc­u­ment­a­tion pages available directly via the terminal, such as the Unix man-pages and GNU info pages. These contain a detailed de­scrip­tion of all command line programs, system calls, con­fig­ur­a­tion files, file formats, and core functions. With the Linux whatis command and apropos, you can find command line programs in the help pages category, which allow you to search the manual pages of your operating system for keywords.

1. apropos

Use apropos to search the page titles and de­scrip­tions of your operating system’s manual by keywords. Refer to the following scheme:

apropos [OPTIONS] SEARCH TERM
bash

The command supports different options. Use the -e option to limit the search to exact matches, or use wildcards (-w '*SEARCH TERM') and regular ex­pres­sions (-r).

2. info

Via the info command, you can retrieve the GNU info pages for a specific topic. In most cases, these pages cor­res­pond to the manual pages that can be accessed via man, but as opposed to these, they have links that make the nav­ig­at­ors in the manual simpler to read. Use the following syntax:

info [OPTION] TOPIC
bash

A call without an option or topic leads you to the main menu of the GNU info page.

3. pinfo

With pinfo, you have a variant of the command line program info, which is based on the command line browser Lynx and issues in­form­a­tion pages with high­lighted links. Use pinfo the same way as the info command:

pinfo [OPTIONS] TOPIC
bash

4. whatis

The command line program whatis serves as a keyword search in the manual pages. Call this program with a popular keyword to search your operating system’s manual for exact matches. If there is a match, whatis gives a brief de­scrip­tion in the terminal.

whatis [OPTIONS] SEARCH TERM
bash

whatis (-w '\*SEARCH TERM') also supports place­hold­ers and regular ex­pres­sions (-r).

Directory op­er­a­tions

You’ll use Linux commands for directory op­er­a­tions to create, delete, and manage dir­ect­or­ies on your system through the terminal, as well as navigate the directory tree. The most important command line dir­ect­ives in this category are cd, ls, mkdir, and rmdir.

1. chroot

The chroot command (short for change root) is used to execute a command in a different root directory. For example, chroot is used to isolate critical programs from the rest of the file system. Calling the program requires root priv­ileges, and is based on the following formula:

chroot DIRECTORY COMMAND
bash

2. mkdirhier

With mkdirhier you can create entire directory hier­arch­ies with a single command line directive:

mkdirhier [OPTION] /home/user/directory1/directory2/directory3
bash

If directory1 and directory2 already exist, mkdirhier only creates directory3. Otherwise, all three dir­ect­or­ies are created.

3. tree

While ls only lists the content of a directory, the command line directive tree can be used to output the entire directory hierarchy re­curs­ively as a tree structure. The command uses the following syntax:

tree [OPTIONS] [DIRECTORY]
bash

File op­er­a­tions

The Linux commands in this chart allow you to carry out various file op­er­a­tions from the terminal. Use the Linux basic commands like cp, mv, and rm to copy, move, rename, or delete files on your system.

1. basename

A file path is passed to the command line directive basename, which simply returns the file name without a default path. The syntax of the command reads:

basename [OPTIONS] path/to/files [SUFFIX]
bash

The command can be expanded to multiple files using options.

2. comm

Use the command line program comm to compare sorted files (i.e. via sort) line by line. The program call is based on the following syntax:

comm [OPTIONS] FILE1 FILE2
bash

The program supports three options:

  • -1: suppress unique lines from FILE1
  • -2: suppress unique lines from FILE2
  • -3: suppress all lines contained in both files

3. cut

The cut command allows you to extract the contents of a file from the text line of a file (i.e. log or CSV files). The syntax of the command reads:

cut [OPTIONS] FILE
bash

The exact position of an extracted section is defined via the options -b (byte position), -c (character position), -d (delimiter), and -f (field).

4. dirname

dirname is the coun­ter­part to basename. The command line directive allows you to extract the path portion from a file path and output it in the terminal without file names. The syntax of the command reads:

dirname [OPTIONS] path/to/file
bash

5. file

With the command line directive file you can output in­form­a­tion about the file type of a file. The call is based on the following syntax:

file [OPTIONS] FILE
bash

6. lsof

The Linux lsof command stands for list open files, a tool that gives you in­form­a­tion about open files in the terminal, sorted by PID (process ID). Call the program to the terminal using the following syntax:

lsof [OPTIONS]
bash

Since unix-like systems such as Linux generally follow the policy that ‘Everything is a file’, the list outputted by the lsof command is ac­cord­ingly long. As a rule, the options are used to limit this output.

7. md5sum

The command line directive md5sum helps you calculate and check MD5 checksums for files.

8. paste

Similar to cat, the command line program paste also enables the output of file contents to the standard output. But while cat merely combines content, paste joins column by column. The basic syntax of the command reads:

paste [OPTIONS] FILE1 FILE2 …
bash

You can customise which separator is used by paste with the option -d. Tabs are used as the default separator. A second mode can be activated using the -s option (serial). With this, all lines of the first input file are trans­ferred to the first line of the output. The data for all other input files follows in separate output lines, so each line of the output contains the contents of only one input file.

9. rename

The command line program rename enables the renaming of files and folders with the help of regular ex­pres­sions (regex). As opposed to mv, the rename function is suitable for file op­er­a­tions where the names of several files are supposed to be either partially or com­pletely adapted. Use rename according to the following syntax:

rename [OPTIONS] 'REGULAR_EXPRESSION' FILE
bash

Regular ex­pres­sions cor­res­pond to the following syntax for re­place­ments:

s/SEARCHPATTERN/REPLACEMENT/MODIFIER
bash

10. shred

shred is a command line program that enables safe deletion of files. Chosen elements are over­writ­ten in the course of the deletion process and so can’t be restored by forensic means. The overall syntax of the command reads:

shred [OPTIONS] FILE
bash

11. sort

Use the command line directive sort to sort file lists and program output nu­mer­ic­ally, al­pha­bet­ic­ally, and by row. The overall syntax of the command reads:

sort [OPTIONS] FILE
bash

The sorting method can be cus­tom­ised using options. For example, numerical (-n), random (-R), or in reverse order (-r).

12. split

The command line directive split is used to divide files. The un­der­ly­ing syntax reads:

split [OPTIONS] [INPUT [PREFIX]]
bash

The place­hold­er INPUT cor­res­ponds to the file that is to be split. The PREFIX acts for the names of the par­ti­cip­at­ing files. Their name is based on the following pattern:

PREFIXaa, PREFIXab, PREFIXac …
bash

If no prefix is defined, split uses the default prefix x. The -b (bytes) option can be used to specify the size of the partial files. This can be specified either in bytes (b), kilobytes (k) or megabytes (m).

Example:

split -b 95m archive.tgz split-archive.tgz.
bash

13. stat

The command line directive stat (status) outputs access and al­ter­a­tion time stamps for selected files and dir­ect­or­ies. The general syntax of the command reads:

stat [OPTIONS] FILE
bash

The output format can be cus­tom­ised with the use of options.

14. uniq

The command line directive uniq is usually used in com­bin­a­tion with sort to clean sorted files from duplicate lines. In the following example, the sort command is linked by a pipe (|) to the uniq command to first sort a file and then output it without duplicate lines.

sort file.txt | uniq
bash

Search options

Linux offers various command line dir­ect­ives for searching through the system directly from the terminal.

1. find

Using find helps you to search through a Linux file. This is based on the following syntax:

find [OPTIONS] [DIRECTORY] [SEARCHCONDITION] [ACTIONS]
bash

The specified directory is the starting directory of the search. The command then searches the starting directory and its sub­dir­ect­or­ies. If no directory is entered, then find starts the search from the current working directory.

Options allow you to define search criteria and actions. The default action is preset at -print: The output of the complete file names of all search results to the standard output (usually the terminal). Further options make it possible to filter by file name, file size, time of access, etc. These are listed on the cor­res­pond­ing man-page.

2. locate

The command line program locate also allows you to search for files through the terminal. But as opposed to find, instead of searching through the file directory, it searches a specially created and regularly updated database. As a result, locate provides results must quicker than find. To search the database for a par­tic­u­lar file, locate is used according to the following syntax:

locate SEARCHPATTERN
bash

The search pattern can contain meta-char­ac­ters as place­hold­ers (*). Put these in quotation marks to prevent in­ter­pret­a­tion by the shell.

3. tre-agrep

tre-agrep also is used to search for strings in text files based on search patterns. But unlike grep, it’s not only exact matches that are output, but vague results are also allowed, such as those with trans­posed letters or missing char­ac­ters. The program is based on the TRE library and makes it available in the command line. The syntax of tre-agrep matches that of the grep command:

tre-agrep [OPTIONS] SEARCHPATTERN FILE(S)
bash

Using options, you can define a maximum error allowance. In the following example, a maximum of one deviation is tolerated.

tre-agrep -1 'Linux' test .txt
bash

4. updatedb

A locate search only functions properly if the /var/lib/locatedb file is con­tinu­ously kept up to date. The updatedb command allows you to manually update the database. Note that you need root per­mis­sions to do this:

updatedb
bash

5. whereis

With the whereis command, you can locate the binary code, source code, or manual files of the selected program. The general syntax of the command reads:

whereis [OPTIONS] PROGRAM
bash

Options can be used to limit the search to specific file types or dir­ect­or­ies.

6. which

If you would like to identify the binary files of a program, use the command which with the following syntax to output the path in the terminal.

which [OPTIONS] PROGRAM
bash

In the default mode, which outputs the first file it finds. Use the option -a to show all files that fulfill the search criteria.

User in­form­a­tion

Use the command line programs for the following cat­egor­ies to access detailed in­form­a­tion on the re­gistered users in the system as well as their groups and processes.

1. finger

The command line program finger serves to access user in­form­a­tion. Use the command in com­bin­a­tion with the desired username:

finger [options] [USERNAME]
bash

Use finger without a username to obtain in­form­a­tion about your own account.

2. groups

The command groups lists the group af­fil­i­ations of a selected user account. Use groups without a username to list all groups to which your user account belongs.

Use the command line directive according to this pattern:

groups [OPTIONS] [USERNAME]
bash

3. id

The command line directive id outputs user and group iden­ti­fi­ers of the selected user accounts. If you want to identify your own IDs, use the command without a username.

id [OPTIONS] [USERNAME]
bash

The range of the output can be limited using options.

4. last

Use the command last according to the following pattern to view a list of recently logged-in users, including login and logout times.

last [OPTIONS] [USERNAME]
bash

The cor­res­pond­ing in­form­a­tion is obtained from the wtmp file under /var/log/wtmp. If you only want to request in­form­a­tion about a par­tic­u­lar account, then enter the command line directive with the desired username.

5. w

The command w outputs a list of all re­gistered users including all processes that they’ve executed. Use w in com­bin­a­tion with a username to limit the command to just this user account:

w [OPTIONS] [USERNAME]
bash

Range and format of the output can be cus­tom­ised using options.

6. who

The command who outputs detailed in­form­a­tion about users re­gistered on the system. The general syntax of the command reads:

who [OPTION] [SOURCEFILE]
bash

By default, who refers to data about currently registers users from the /var/run/utmp file. You have the option to specify one of the following files as the source of the in­form­a­tion.

7. whoami

Use the command whoami to obtain your own username.

whoami [OPTIONS]
bash

User account man­age­ment

Linux provides you with a series of programs with which you can create, delete, and manage user accounts and groups directly from the terminal. An overview of the important Linux commands for user account man­age­ment is put together for you here. You’ll also find Linux terminal commands in this category that enable you to access code with other user rights, including the super-user root.

1. chfn

The command line directive chfn (short for change finger) allows you to customise ad­di­tion­al in­form­a­tion on a user account, such as the real name, office number, and private or work telephone numbers. The general syntax reads:

chfn [OPTION "NEW VALUE"] [USERNAME]
bash

Which user in­form­a­tion will receive a new value is defined with the help of the option -f (real name), -r (office number), -w (work phone), and -h (private phone).

2. chsh

The command line directive chsh (short for change shell) changes the login shell of a chosen user. Use the following pattern as a guide when entering the data:

chsh [OPTIONS] USERNAME
bash

You can use the -s option to change the login shell of a user account.

3. deluser

The command line program deluser deletes all entries for a selected user account from the system account files. Calling deluser requires root per­mis­sions and uses the following syntax:

deluser [OPTIONS] USERNAME
bash

If you would also like to delete all files from the home directory of the user, then use the command with the options --remove-home. If you want to delete all user files from the system, use the options --remove-all-files.

4. delgroup

The command line directive delgroup (short for delete group) deletes an existing user group. To execute the command, root per­mis­sions are required. The general syntax of delgroup is:

delgroup [OPTIONS] GROUP
bash

5. groupmod

Names and group IDs (GID) of existing user groups can be cus­tom­ised via groupmod. The command line directive is used with root per­mis­sions according to the following syntax:

groupmod OPTIONS GROUP
bash

Use groupmod with the option -g to customise the GID. Call the command with the option -n to overwrite the group name.

6. newgrp

The command newgrp (short for new group) allows re­gistered users to change their current group ID without having to log out and back in. The general syntax of the command reads:

newgrp [-] [GROUP]
bash

If the newgrp command is used with the optional parameter [-], then the group change causes a restart of the user en­vir­on­ment – as if the user had logged in again. Those who use newgrp without group spe­cific­a­tion change to the default group specified under /etc/passwd.

7. su

The command su also allows for a temporary user change to run a program call with the rights of a target user. As opposed to sudo, the command is not directly executed. Instead, a change of identity occurs. Instead of asking for the password of the calling user, the target user password is requested. The general syntax of the command reads:

su [OPTIONS] [USERNAME]
bash

A call without a USERNAME selects root as the target user.

8. usermod

The command line directive usermod gives you the option to edit pre­vi­ously created user accounts. Use usermod with root per­mis­sions according to the following syntax:

usermod [OPTIONS] USERNAME
bash

Which modi­fic­a­tions are intended can be defined with the help of options. For example, you can change the username with the -l NEW_NAME option. Further options can be found on the cor­res­pond­ing man-page.

System commands

In the system commands category, you’ll find the basic Linux commands for system control. Use the following commands to restart and shut down the system from the terminal – and control them with a timer, if desired.

1. logger

Use logger according to the following pattern:

logger "YOUR MESSAGE"
bash

Find the system log under /var/log/syslog.

2. reboot

The command line directive reboot causes a restart of the system. To trigger a restart, the command has to be executed with root per­mis­sions.

reboot [OPTIONS]
bash

3. rtcwake

The command line directive rtcwake allows you to start and shut down the system according to a timer. The command is based on the following syntax:

rtcwake [OPTIONS] [MODE] [Time]
bash

Choose a par­tic­u­lar mode (-m MODE) for the system to move to at a par­tic­u­lar time in seconds (-s TIME IN SECONDS). You also have the option to wake up your system at a precisely defined time (-t UNIXTIME).

System in­form­a­tion

In the system in­form­a­tion category, we’ve collected command line programs with which you can obtain in­form­a­tion and status reports, giving you a com­pre­hens­ive overview of the state of your system.

1. date

The command date outputs the system time including the date.

date [OPTIONS] [OUTPUTFORMAT]
bash

If you want to work with a par­tic­u­lar time in the context of a program call (see rtcwake), define this with the help of the option -d 'DATE'. In addition, various options are supported that can transfer date and time in­form­a­tion to a desired format.

2. df

Use the command df (disk free) according to the following pattern.

df [OPTIONS] [FILE]
bash

If the command is used in com­bin­a­tion with a par­tic­u­lar file, the system only specifies the free space on the partition where the file is located. Otherwise, the free hard disk space of mounted par­ti­tions is displayed. The option -l (local) restricts df to the local file system. It also supports options that let you customise the output format.

3. dmesg

The program dmesg (short for display message) outputs core circular buffer messages in the terminal and allows you to localise hardware and driver failures. Use dmesg according to the following pattern:

dmesg [OPTIONS]
bash

The dmesg output contains all messages of the boot routine, and is ac­cord­ingly long. The command line program is often used in com­bin­a­tion with a pager, like more, less, or tail.

4. free

The command free outputs the memory usage. The general syntax reads:

free [OPTIONS]
bash

As output, you’ll get two spe­cific­a­tions: Mem (Memory) and Swap. Free also supports the option -h for out­put­ting the memory usage in a human-readable format.

5. hostname

Use the command hostname according to the following pattern to display the DNS names of the system.

hostname [OPTIONS]
bash

6. uname

The command line directive uname stands for unix name and is used to access system in­form­a­tion from the core. The command supports various options with which the output can be filtered according to the desired in­form­a­tion. These can be found in the cor­res­pond­ing man entry.

uname [OPTIONS]
bash

7. uptime

If you want to determine how long the system has been running since the last reboot, use the command line directive uptime according to the following pattern:

uptime
bash

8. vmstat

With the help of the mon­it­or­ing tool vmstat, you can access in­form­a­tion about virtual memory, reading and writing pro­ced­ures on the disc, and CPU activity. Call vmstat according to the following syntax to output the average values since the last system start.

vmstat [OPTIONS]
bash

vmstat also offers a con­tinu­ous mon­it­or­ing mode that accesses system values as often as requested in a desired time interval in seconds.

vmstat [Options] [INTERVAL [REPETITIONS]]
bash

Hardware in­form­a­tion

Linux commands in this category deliver detailed in­form­a­tion about the hardware com­pon­ents that form the found­a­tion of your system.

1. lspci

Use lspci (short for list pci) according to the following pattern to output detailed in­form­a­tion about PCI devices.

lspci [OPTIONS]
bash

For possible options, refer to your operating system’s manual.

2. lsusb

Use lsusb (short for list usb) to output detailed in­form­a­tion about USB devices in the terminal.

lsusb [OPTIONS]
bash

For possible options, refer to your operating system’s manual.

Process man­age­ment

On Linux, the instance of a running program is called a process. The following terminal commands are part of the standard rep­er­toire of the process man­age­ment, and allow you to supervise all processes on your system easily from the terminal and control as necessary.

1. chrt

The command line program chrt deals with con­tinu­ous process controls and makes it possible to identify and customise the real-time at­trib­utes (schedul­ing reg­u­la­tion and priority) of running processes, or execute commands and their arguments with specified real-time at­trib­utes. The general syntax of the command reads:

chrt [OPTIONS] [PRIOTITY] PID/COMMAND [ARGUMENT]
bash

Use chrt without entering a priority and with the option -p to identify the real-time at­trib­utes of chosen processes.

chrt also offers the pos­sib­il­ity to set or define the schedul­ing reg­u­la­tion of running or newly started processes with the help of options. Further in­form­a­tion on this can be found in the cor­res­pond­ing man entry.

2. ionice

The command line directive ionice is used to influence the priority of a process that uses the I/O interface of the core. The general syntax of the command reads:

ionice [OPTIONS] COMMAND
bash

To be able to execute ionice, you need root per­mis­sions. The command dis­tin­guishes between three schedul­ing classes that are passed on using the -c class option. Possible values are 1, 2, and 3.

  • 1 = Real time: The I/O action is executed im­me­di­ately.
  • 2 = Best effort: The I/O action is executed as quickly as possible.
  • 3 = Idle: The I/O action is only executed when no other process is taking I/O time.

3. nohup

Normally, all of a user’s dependent processes are auto­mat­ic­ally ended as soon as the terminal session is closed (i.e. via exit). The Linux nohup command (short for no hangup) deletes a command from the current session and allows you to keep it running even when you log out of the system.

nohup COMMAND
bash

4. pidof

The command line program pidof outputs the process iden­ti­fic­a­tion numbers (PIDs) of all of a program’s processes. Identify PIDs via pidof according to the following pattern:

pidof [OPTIONS] PROGRAM
bash

If you would like to output only the first process ID, use pidof in com­bin­a­tion with the option -s (short for single shot).

5. pidkill

Like kill, the command pkill also sends a signal to a chosen process. The ad­dress­ing isn’t done by PID, though. Instead, a search term is given that matches the name of the running process. This can also be for­mu­lated as a regular ex­pres­sion. pkill forwards the standard signal TERM, as long as no other signals are defined. The general syntax of the command reads:

pkill [OPTIONS] [-SIGNAL] [SEARCHTERM]
bash

Ad­di­tion­al options can be used to limit the command to the processes of a par­tic­u­lar user (-U UID), the sub-processes of a par­tic­u­lar parent process (-P PID), or the newest (-n) or oldest (-o) processes.

6. pstree

Use pstree to display all running processes in a tree structure. The general syntax of the command reads:

pstree [OPTIONS]
bash

The format and range of the output can be cus­tom­ised using various options.

7. renice

The command line directive renice allows you to customise the priority of a running process. The general syntax reads:

renice PRIORITY [OPTIONS]
bash

8. sleep

The Linux sleep command allows you to disrupt the current terminal session for a given time. The general syntax of the command reads:

sleep NUMBER[SUFFIX]
bash

If you use sleep without a suffix, the given number will be in­ter­preted as time in seconds (s). You also have the option to disrupt the terminal session for minutes (m), hours (h), or days (d).

9. taskset

The command line directive taskset is used for advanced process control, which is used in mul­ti­pro­cessor systems to assign processes or commands to specific pro­cessors. The command requires root per­mis­sions and uses one of the following patterns:

taskset [OPTIONS] MASK COMMAND
taskset [OPTIONS] -p PID
bash

Assigning a process or command to a processor happens using a hexa­decim­al bitmask. Since assigning via bitmask like this isn’t very intuitive, taskset is generally used with the option -c (–cpu-list) to enable a numerical as­sign­ment of pro­cessors (i.e. 0, 5 7, 9-11).

Pager

Do you want to use your overview to keep track of multi-page file content? With a command line program from the pager category, you can select which sections are displayed in the terminal and scroll through the file in in­ter­act­ive mode if necessary.

1. head

The Linux head command is used to output the first part of a file. The general syntax of the command reads:

head [OPTIONS] File
bash

Use the option -n NUMBER_LINES to define how many lines are to be output, starting at the beginning.

2. less

The command line program less enables the display of the content of a text file in the terminal. The general syntax reads:

less [OPTIONS] FILE
bash

The output is auto­mat­ic­ally in in­ter­act­ive mode. This allows you to scroll through the selected document or search by keyword. The [Q] key ends the in­ter­act­ive reading mode. Other control keys and available options can be found in the program’s manual.

3. tail

While head displays the first 10 lines of a chosen file by default, the Linux tail command outputs the last 10. Both pagers are used according to the same pattern (refer to head).

Editors

Under Linux, you don’t need a graphical text editing program to customise con­fig­ur­a­tion files, edit code snippets, or draft short notes. Simple text editors can be easily called up in the terminal without time delays. Here we present three programs that you should know.

1. emacs

Emacs is a cross-platform text editor, which can be expanded as desired by a pro­gram­ming interface. By default, Emacs starts with a graphical user interface, but can also be opened in the terminal using the option --no-window-system.

emacs --no-window-system
bash

Emacs has an available in­teg­rated tutorial that you can call up with the key com­bin­a­tion [CTRL] + [H], [T].

2. nano

Nano is a terminal-based text editor. Nano offers a smaller range of functions than com­par­able editors (i.e. Vim), but is char­ac­ter­ised by a par­tic­u­larly user-friendly operation. The general syntax of the program call reads:

nano [OPTIONS] FILE
bash

The program opens the given file in an editing window in the terminal. If you call Nano without file names, a new text file can be created that’s stored in the currently selected directory.

3. vim

Vim (short for Vi Improved) is a further de­vel­op­ment of the text editor Vi that stands out due to numerous ex­ten­sions such as syntax high­light­ing, a com­pre­hens­ive help system, native scripting, automatic code com­ple­tion, and visual text selection.

The open-source program offers various modes of operation for editing pure text files, and can be used either in the terminal or as a stand-alone ap­plic­a­tion with a graphical user interface (GVim). A central ap­plic­a­tion area of the program is the editing of program code.

If you start Vim in the console, the operation is done via keyboard. Generally, the program is called together with a text file according to the following pattern:

vim [OPTIONS] FILE
bash

Vim offers the program vimtutor as a com­pre­hens­ive in­tro­duc­tion, which is also started from the command line. Our basics article on the Linux Editor Vim also offers ad­di­tion­al in­form­a­tion on the in­stall­a­tion and various operating modes of the program.

Network man­age­ment

Network man­age­ment is also managed easily from the terminal in Linux. Whether you want to test the con­nec­tion, request DNS in­form­a­tion, configure the interface, or transfer files to another computer in the network, with the following programs a single command is suf­fi­cient to put your project into motion.

1. arp

The command line program arp allows you to access and ma­nip­u­late your operating system’s ARP cache. Use arp without a modifier to output the content of the ARP table in the terminal.

arp [OPTION]
bash

Al­tern­at­ively, you can limit the output with options or create or delete entries:

  • -a HOSTNAME = Limit output to entries for specific host names (al­tern­at­ive to an IP address)
  • -s HOSTNAME MAC_ADDRESS = Create ARP entry with specified host name and MAC address
  • -d HOSTNAME = Delete APR entry

2. iw

The command line program iw is used for the con­fig­ur­a­tion of WLAN in­ter­faces and is es­tab­lished as a current al­tern­at­ive to iwconfig. The call is based on similar syntax to that of the ip command:

iw [OPTIONS] OBJECT [COMMAND]
bash

Possible objects are:

  • dev NAME_OF_INTERFACE = Network interface
  • phy NAME_OF_DEVICE = WLAN device (by name)
  • phy#INDEX_OF_DEVICE = WLAN device (by index)
  • reg = Reg­u­lat­ory agent for the con­fig­ur­a­tion of regional and country settings

An overview of the possible commands and options can be found in the cor­res­pond­ing man entry.

3. nslookup

Like dig, nslookup is also a name res­ol­u­tion service. The command line program is available in two modes: in­ter­act­ive and non-in­ter­act­ive. If you want to use nslookup in non-in­ter­act­ive mode, call the program in com­bin­a­tion with a host name or an IP address.

nslookup [OPTIONS] [HOST/IP]
bash

To start in­ter­act­ive mode, enter the command nslookup in the terminal without any ad­di­tion­al in­form­a­tion and then enter host names or IP addresses to display the as­so­ci­ated IP addresses or host names.

Since the program is of­fi­cially outdated, users are en­cour­aged to use dig instead.

4. rsync

The command line program rsync enables you to syn­chron­ise files locally or over a network. For this purpose, the size and modi­fic­a­tion time of the concerned files are compared. The syntax of the call reads:

rsync [OPTIONS] SOURCE(S) TARGET
bash

The command rsync is generally performed with the option -a, which ensures that all sub­dir­ect­or­ies and symbolic links are copied and all user rights take effect.

5. scp

With the Linux scp command (short for secure copy), another program for secure data transfer in the network is available directly via the terminal. scp copies data from one computer to another and uses the network protocol SSH. The client program functions in the same way as the file option cp, but is used system-wide according to the following syntax:

scp [OPTIONS] FILE [[user@]remote_host:]PATH
bash

When spe­cify­ing the path of the remote computer, the username and the re­spect­ive hostname are placed in front. Local files are ex­pli­citly addressed using relative or absolute paths.

Example:

scp/home/max/images/image.jpg max@example.com:/home/max/archive
bash

Ad­di­tion­al options allow you to make ad­just­ments to the transfer mode and the en­cryp­tion settings.

6. tty

The command line directive tty outputs the file names of the terminal that are defined as the standard input. The general syntax of the command reads:

tty [OPTIONS]
bash

Archive and compress

Linux offers various tech­no­lo­gies with which files can be packed and com­pressed in archives. It should be noted that not every archive contains a com­pres­sion. So tar – a program for the archiving of files – is usually combined with a com­pres­sion program like gzip, bzip2, or xz.

1. gzip

gzip is a program with which you can easily compress or de­com­press files via the command line. The general syntax of the command reads:

gzip [OPTIONS] FILE(S)
bash

Note that by default, gzip deletes the original file as part of the packing process. Prevent this by using the option -k. The program can be used for multiple files at the same time, if necessary. Each output file is converted into a separate gz file. If you want to write several files in a single com­pressed archive, use gzip in com­bin­a­tion with the archiving program tar.

If you want to de­com­press a gz file, use the gzip command with the -d option.

2. bzip2

A popular al­tern­at­ive to gzip is the command line program bzip2. This uses the same syntax as gzip, but is based on a three-stage com­pres­sion process which allows for a sig­ni­fic­antly higher com­pres­sion ratio. Files that are com­pressed with bzip2 use the file ending .bz2. Use bzip according to the following pattern to compress files:

bzip2 [OPTIONS] FILE(S)
bash

bzip2 can also be applied to tar archives. The de­com­pres­sion is analog with gzip and runs with the help of option -d.

3. xz

The command line program xz converts files in the same-named data com­pres­sion format xz. The program call uses the same pattern as gzip and bzip2.

xz [OPTIONS] FILE(S)
bash

Files that are com­pressed with xz use the file ending .xz. The de­com­pres­sion functions as with gzip and bzip with the option -d. The command unxz can also be used.

Like gz and bz2 files, xz files are also not archive files. If you would like to write multiple files into the same com­pressed xz file, you will also have to use the archiving tool tar with this com­pres­sion program.

4. cpio

The archiving program cpio (short for copy in, copy out) allows you to write data in an archive file (.cpio) and extract data from it.

Partition man­age­ment

If you want to access a file system on another partition in Linux, you first have to integrate it into the directory structure of your operating system. This is called ‘mounting’ a partition. If necessary, this can happen via the graphical user interface. Command line programs like lsblk, blkid, and mount also offer the ability to request in­form­a­tion about connected block storage devices and to mount or unmount them when necessary.

1. lsblk

Use the command lsblk (short for list block devices) to represent all connected block storage devices and par­ti­tions as a tree structure. These don’t ne­ces­sar­ily have to be involved. The call is based on the following syntax:

lsblk [OPTIONS]
bash

If necessary, the output and a list of desired at­trib­utes can be in­di­vidu­ally modified using the -o (–output) option to retrieve ad­di­tion­al in­form­a­tion, like the iden­ti­fic­a­tion number (UUID), file system (FSTYPE), or the state (STATE).

In the standard settings, empty storage devices are bypassed. If you also want to include these in the overview, use lsblk in com­bin­a­tion with the option -a (–all). If you only want to request in­form­a­tion on a par­tic­u­lar device, use lsblk according to the following pattern:

lsblk [OPTIONS] DEVICE
bash

2. blkid

Similar to lsblk, blkid also outputs in­form­a­tion on connected block storage devices. Use blkid according to the following pattern to obtain the iden­ti­fic­a­tion number (UUID) and file system type (TYPE) of all connected block storage devices.

blkid [OPTIONS]
bash

For tabular output, use the -o option in com­bin­a­tion with the value list. You can also limit blkid to a chosen device:

blkid [OPTIONS] DEVICE
bash

Mis­cel­laneous

The following list contains ad­di­tion­al Linux basic commands that don’t belong to any of the previous cat­egor­ies.

1. alias

In­ter­ac­tion with the shell is usually via commands that can be used to call up command line programs of the same name. You use a program call for every action you want to perform via the terminal. The Linux alias command allows you to define short names for program calls. Use alias according to the following pattern:

alias NICKNAME= 'COMMAND'
bash

Replace the place­hold­er COMMAND with any command line directive, including options. This will link the inserted string for the place­hold­er NICKNAME.

2. at

Call the command line program at according to the following pattern to run a time-con­trolled command.

at TIME
bash

Then enter the command and close the in­ter­act­ive mode with [CTRL] + [D].

3. cal

Use cal according to the following pattern to output a calendar in the terminal.

cal [OPTIONS] [[MONTH] Year]
bash

4. pr

Use the command line program pr to prepare text files for printing. The general syntax of the command reads:

pr [OPTIONS] File
bash

In the standard settings, pr generates a page header that contains the file name, current date, and page number.

5. script

The command line program script allows you to record a terminal session in the file typescript. If there’s already a recording of a previous session in typescript, then it’s over­writ­ten. The recording auto­mat­ic­ally starts with the program call:

script
bash

Use the key com­bin­a­tion [CTRL] + [D] to end the recording. If you would like to save the recording in another file instead of in typescript, call script in com­bin­a­tion with a file name or path.

6. seq

Use the command seq to output a numerical series in the standard output. Define a start value, an end value, and an increment (optional).

seq [OPTIONS] STARTVALUE INCREMENT ENDVALUE
bash

7. tasksel

The command line program tasksel serves as in­stall­a­tion help for standard ap­plic­a­tions (mail server, DNS server, OpenSSH server, LAMP server, etc.). Use the tool to auto­mat­ic­ally install all packages and programs required for a task in the correct order. Call tasksel with the option --list-tasks to output a list of all available standard ap­plic­a­tions.

tasksel --list-tasks
bash

If you want to access more in­form­a­tion about a standard ap­plic­a­tion on the list, use tasksel with the option --task-desc and the cor­res­pond­ing task. If you want to list all packages that belong to the ‘mail-server’ task, use tasksel in com­bin­a­tion with the option --task-packages.

To install all packages of a standard ap­plic­a­tion, use the sub­com­mand install. This requires root per­mis­sions.

8. tee

The Linux tee command is used to double the output of a program. One output is passed to the standard output, and another is written to the file given with the tee command.

tee [OPTIONS] FILE
bash

tee is usually used in com­bin­a­tion with the re­dir­ec­tion operator Pipe (|).

ls | tee example.txt
bash

9. time

Use the command time according to the following pattern to identify the runtime of programs that you’ve started over the terminal.

time [OPTIONS] Command [ARGUMENTS]
bash

10. tr

Use tr to delete a desired character set or replace it with another. To do this, tr reads the data stream of the standard input (e.g. a file) and writes it to the standard output according to the desired modi­fic­a­tion. If a character set is to be replaced by another, then tr is used with two arguments.

tr OPTION CHARACTERSET1 CHARACTERSET2
bash

The second argument (CHAR­AC­TER­SET2) replaces the first (CHAR­AC­TER­SET1). If you want to delete a character sequence, use tr with the option -d and enter the set to be deleted as the argument.

tr -d CHARACTERSET
bash

The command line program is usually used in com­bin­a­tion with re­dir­ec­tion operators (< and >) to make modi­fic­a­tions to files.

tr 'a-z' 'A-Z' < example1.txt > example2.txt
bash

tr reads out the content of the example1.txt file, replaces the lower-case letters a through z with upper-case letters, and writes the output in the example2.txt file.

11. wall

The command line program wall allows you to send a message to all users re­gistered on a system. To send a com­mu­nic­a­tion, start the program with the following call:

wall
bash

Confirm the program call with [Enter] and enter your message. Then confirm again with [Enter] and send with the key com­bin­a­tion [CTRL] + [D]. All users re­gistered on the system receive your message as a broadcast in the terminal. It is worth noting that in order to be able to receive com­mu­nic­a­tions, you have to provide other users with a write access to your terminal. For this, use the command mesg:

If you want to send file content to all re­gistered users, use wall in com­bin­a­tion with an input re­dir­ec­tion and the re­spect­ive file name:

wall < FILENAME
bash

12. watch

The command line program watch allows you to set a command to run at regular intervals. The program call is based on the following syntax:

watch [OPTIONS] COMMAND
bash

The time interval at which the command given in watch will be run is defined with the option -n SECONDS. End watch with the key com­bin­a­tion [CTRL] + [C].

13. wc

The Linux wc command (short for word count) outputs the number or lines, words, letters, char­ac­ters, and/or bytes of a text file, by request. The overall syntax of the command reads:

wc [OPTIONS] FILE
bash

If wc is called without options, the output cor­res­ponds to the LINES WORDS CHARACTERS FILE pattern. For a filtered output, the command line program supports the options: -l (lines), -c (bytes), -m (char­ac­ters), -L (length of the longest line), and -w (words).

14. xargs

The Linux xargs command allows you to transfer the output of a previous command to a new command as an argument. Generally, this is used with the Pipe (|) as a diversion operator. Use xargs according to the following syntax:

COMMAND1 | xargs [OPTIONS] COMMAND2
bash

xargs can be used in com­bin­a­tion with the command find, for example. In the following example, find iden­ti­fies all files in the current directory that fit the search term *.tmp, and outputs their names to the standard output. There, the file names of xargs are accepted and passed as arguments to the command rm.

find . -name '*.tmp' | xargs rm
bash

The overview presented here doesn’t claim to be complete, but includes basic Linux commands with selected ap­plic­a­tion examples for everyday work with unix-like operating systems. A com­pre­hens­ive de­scrip­tion of the command line programs presented here, as well as all other commands, can be found in your operating system’s manual. An online version of these help-and-doc­u­ment­a­tion pages are available via the Linux man-pages project by Michael Kerrisk.

Go to Main Menu