The ultimate Linux commands cheat sheet

Here it is! This is all you need. Every necessary Linux commands all in one place. FOSS Linux presents you with the ultimate Linux commands cheat sheet.

Knock, knock!

Who’s there?

FOSSLinux

FOSSLinux who?

FOSSLinux with a Cool Linux Commands Cheat Sheet!

The world of Linux is uniquely structured by its maze of commands that continue to make it more than just an ordinary operating system. A typical Linux desktop user might relate to several hundreds of these commands. On the other hand, a server administrator used to bare-bone Linux server’s packages installation and management can count over 1000 differing commands.

So the real question this article piece is asking you is this, how many Linux commands are you familiar with? If we took a survey on all FossLinux readers, the majority answer would be ‘only a handful.’ This response is what this article is here to fix. There is more to using Linux commands on your Operating System terminal than just updating your system and navigating to user and system directories. If you are a Linux user, then you must flexibly adapt to the usage of as many Linux commands as possible.

The reason for memorizing most of the Linux commands is not because they are too many but because they are too random for you to categorically relate to the scenarios that best apply to each of them. FossLinux is here to fix this problem. We want to map each Linux command to where they belong categorically.

This approach’s expected long-term effect is that you continuously reference this Linux command cheat sheet based on the category of each specified command you seek. And because practice remains the initiator of perfection, you won’t have to remember or reference this article within no time. It will be your muscle memory doing all the work as you perfectly key-in the commands of your choice with complete adherence to their syntax rules.

Linux commands cheat sheet

Time to key-in these categorical Linux commands.

Commonly Used Linux Commands

You will most probably find yourself randomly needing to use these Linux command sets to improve your user experience and flexibly meet any set OS objectives.

Command Description
lsIt is a list command and will display the directories and files visible under the present working directory
ls -RGoes a step further to display or list files in sub-directories of the present working directory
ls -aThe argument -a in this list command helps list all the hidden files in the present working directory
ls -alThe argument -al in this list command gives a detailed list of the displayed files and directories with extra information such as size, permission, owner, etc.
cd or cd ~Takes you to the Home directory of your Linux operating system
cd ..navigates you backwards to the parent directory of the current directory you are under.
cdcombine it with a target directory under the present working directory to navigate to it e.g cd Downloads
cd /Takes you to the root directory of your Linux operating system
cat > filename It will create a file called filename
cat filenameIt will display the contents of a file called filename
cat file_1 file_2 > file_3Joins the content of file_1 and file_2 and copies the result to a newly created file_3
mv file_random "defined file path"It will move the file called file_random to the target file path or destination you will define.
mv file_name new_filenameIt will rename the file called file_name to a new file name called new_filename
sudoA command used by sudoer users to execute privileged commands applicable to a root user or superuser.
rm filenameIt will delete a file called filename
manUse it with a Linux command you do not understand to get help on how to use it. E.g man sudo
historyIt will display a list of the previous Linux terminal commands you have executed under that specific session.
clearIt will clear your command-line interface if you feel it is too crowded.
mkdir directory_nameit will create a director called directory_name
rmdir my_directoryIt will delete a directory called my_directory
mvYou can use it to rename a directory or a file
pr -xIt will divide or split a file to x defined columns.
pr -hUse it to add a header to a target file.
pr -nUses Line numbers to denote a target user file.
lp -nc, lpr cIt is a printing function and in this case it will print c copies of a target file.
lp -d lp -PHelps you identify the name of the printer you are using.
apt or apt-getA Debian distro package command for installing system updates and package applications
mail -s 'mail_subject' -c 'cc-mail_address' -b 'bcc-mail_address' 'to-mail_address'Use this command to send an email from the terminal.
mail -s "mail_subject" to-mail_address < attachment_filenameUse this command to also send an email from the terminal but this time with an attachment.

Linux Commands for System Information

You will find these commands useful when you want to query specific information about your Linux system.

Command Description
uname -aDisplays basic system information like machine name and the supported operating system architecture.
uname -rOutputs the kernel release information like the kernel version.
lsb_release -aIf you are using any Linux distro, this command displays its Distributor ID, Description, Release, and Codename.
uptimeOutputs how long your Linux system has been active together with the load average of this duration.
hostnameOutputs your system's hostname or the name you have given your Linux machine
hostname -IOutputs the assigned IP address your system is currently using depending on the network connection it is under.
last rebootA useful command for you to gauge how many times your system restarted.
dateUseful in displaying the current date and time.
calOutputs the present month's calendar.
wLets you know who or which systems are online especially if you are in a large network.
whoamiOutputs the name of the current user using the Linux system

Linux Commands for File Permissions

File permissions in Linux relate to Read (r), Write (w), and Execute (x) privileges. They employ changes associated with directory and file ownership. This ownership privilege can apply to a specific user, a user group, or other user levels defined within the Linux system.

CommandDescription
ls -lOutputs the file type and the file permissions needed to access the target file.
chown root /uIn this command, the ownership of /u is transferred to the root user.
chown user:group file_nameThe user and group privileges linked to file_name are changed.
chmod 777 [file_name]Everyone access the file called file_name will have read, write, and execute permissions.
chmod 755 [file_name]The owner of the file called file_name will have read, write, and execute permissions while other users will only have read and execute permissions.
chmod 766 [file_name]The owner of the file called file_name has complete access to it while group and other users can only read and execute.
chown [user] [file_name]The ownership of the file called file_name is assigned or changed to a new owner called user.
chmod -c -RAssign a file the read, write, and execute permissions.
touch -a -tUseful in creating or modifying a file timestamp.
chown -c -RUseful in changing the ownership of an assigned or owned file.
chgrp -c -RUseful in changing the group permission of a file.

Linux Commands for Networking

Under a Linux operating system, it is almost impossible not to cross paths with network-related tasks. The following commands will be useful along the way.

Command Description
SSH username@ip_address or hostnameEnables SSH login or sign-in to a remote Linux machine by specifying the machine's username and IP address.
ping hostname Useful in analyzing the responsiveness of a hostname connected to a network.
dirHelps you view files under a remote computer's active directory.
cd "dir_name"Access a directory called dir_name on a remote computer.
put filenameIt will upload a file called filename from your local computer to a target remote computer.
get filenameIt will download a file called filename from a specified remote computer to your local machine.
quitLogout from a remote connection.
ping -c hostnameIt will print a routing packet trace associated with the targeted hostname or IP address
ssh -iGrants user access to openSSH client.
tcpdumpUsed to dump network traffic.
telnetGrants access to the TELNET protocol's user interface.
netstat -r -vPrints network routing, information, and connections.
ip addr showOutputs network interfaces and their related IP addresses.
ip address add [IP_address]Used under interface eth0 to assign an IP address.
ifconfigOutputs configured network interfaces' IP addresses.
netstat -pnltuA netstat command for revealing active or listening ports on a network.
netstat -nutlpA netstat command for displaying udp and tcp ports.
whois [domain_name]Reveals more information regarding an active domain name on the internet.
dig [domain_name]Reveals DNS information and configuration regarding an active domain name.
dig -x hostIt is applicable when dealing with DNS and will reverse lookup an active domain.
dig -x [IP_address]It is also applicable when dealing with DNS and will reverse lookup an active IP address.
host domain_nameIt will lookup the IP address of an active domain
host -I hostnameIt will output the local IP address of the specified hostname with other additional useful information.
wget [file_name]Useful in downloading a file from a specified domain name storage directory.
ifconfig -aOutputs all the network interface details of a system with inclusion to the IP address.
ifconfig eth0Outputs eth0 configuration and address details.
ethtool eth0Used to manage hardware and network drivers query and control settings

Linux Commands for Archives and File Compression

You will never fail to come across file archives or files in a compressed state within the Linux operating system environment. The following commands will be useful.

CommandDescription
tar xvfzUsed for creating or extracting files with .tar or .tgz extensions.
gzip, gunzip, zcat filenameUsed in creating, extracting. or viewing files with .gz extension
uuencode, uudecodeUsed in creating or extracting files with .Z extension.
zip, unzip -vUsed in creating or extracting files with .Zip extension.
rpmUsed in creating or extracting files with .rpm extension.
bzip2, bunzip2Used in creating or extracting files with .bz2 extension.
rarUsed in creating or extracting files with .rar extension.
tar cf [compressed_filename.tar] [file_name]This command creates an tar archive called compressed_filename for the file_name file.
tar xf [compressed_filename.tar]This command extracts the tar archive called compressed_filename.
tar czf [compressed_filename.tar.gz] This command compresses a tar file into a gzip archive.
tar cf my_archive.tar directoryThis command creates a tar archive called my_archive with a directory in it.
tar xzf my_archive.tar.gzThis command extracts a compressed tar file inside a gzip archive
tar cjf archive.tar.bz2 directorThis command compresses a tar file inside a bz2 archive.
tar xjf archive.tar.bz2This command extracts a tar file compressed inside a bz2 archive.

Linux Commands for Installing Packages

Since you will be using the Linux terminal to install most of your packages from various repositories, you will need to memorize the following commands.

CommandDescription
yum search [keyword]Trace a package installation based on specific keywords.
yum install package.rpmThe use of a YUM package manager to install and configure a package.
yum info packageThe use of the YUM package manager to find more information about a package before optionally proceeding with its installation.
rpm -i package.rpmUsing the RPM package manager to install a downloaded package.
yum remove packageUsing the YUM package manager to uninstall or remove a package from your system.
tar zxvf sourcecode.tar.gz
cd sourcecode
./configure
make
make install
Command sequence to install a package software that comes as a source code.
dnf install package.rpmUsing the DNF package manager to install a package software.
apt install packageUsing the APT package manager to install a package software.
rpm -e package.rpmUsing the RPM package manager to remove or uninstall an rpm package

Linux Search Commands

The commands in this category effectively deal with file patterns, sizes, and even their naming conventions.

CommandDescription
grep [pattern] [file]Employs a specific pattern to search the contents of a file.
grep -r [pattern] [directory_name]Recursively or repeatedly searches within a specified directory for a defined pattern match.
locate [name]It will track and locate directories and files based on a name identity.
find [/path/to/folder/location] -name [a]Traces a specific system directory location then queries the names of its files and folders based on a character match. In this case [a]
find [/path/to/folder/location] -size [+100M]It will trace a system directory location and list the files within it that are bigger than 100 M in size.
find /home/FossLinux -name 'prefix*'Traces a specified system path for files with a matching prefix.

Linux Commands for SSH Logins

SSH logins are useful when you want access to remote computers or servers. These commands give you undisputed flexibility in file access, management, and manipulation.

CommandDescription
ssh username@hostnameConnects you to a remote machine or server based on a valid username and hostname or IP address.
ssh hostConnects you to a specified host through the default port 22.
ssh -p [port] username@hostnameConnects you to a remote machine or server through a specified port.
telnet hostnameUses telnet's default port 23 to connect you to a target hostname, remote machine, or server.

Linux Commands for File Transfers and Management

It is very rare to log-in to a Linux operating system environment and not feel the urge to transfer a file, directory, or folder from one system path to another. These file management commands ensure that you won’t have to be switching from the command-line interface to the desktop graphical interface each time you feel like making a file or directory change or query.

CommandDescription
findThis command is useful when you need to find a specific file
ls -a -C -hLists or displays the content of an active directory.
rm -r -fUsed to remove or delete active files and directories instances.
locate -iUses updateddb(8) to track and find files on your system.
cp -a -R -iUsed to copy directories or files from an active directory instance.
du -sGive important information regarding the disk usage (storage space) on your Linux system. It is efficient when combined with the Sudo command.
file -b -iHelps identify the type of file on your system.
mv -f -iUsed for moving directories or files to a different system path or location.
grep, egrep, fgrep -i -vUseful in printing lines with a matching pattern.
scp file.txt server:/tmp Uses secure copy command to copy file to a remote server. In this case the tmp folder
scp server:/var/www/*.html /tmpUses secure copy command to copy files from a remote server to a directory on a local machine. In this case it will copy all files with the .html extension.
scp -r server:/var/www /tmpIt will recursively copy all the files and directories on a remote server's active directory to a target machine directory. In this case the tmp directory
rsync -a /home /backups/Synchronizes the content of two directories (/home and /backups) on the same machine.
rsync -avz /home server:/backups/It synchronizes the content of an active director on a local machine with the content of an active directory on a remote server.

Linux File and Directory Commands

It would help if you also had flexibility in dealing with your user and system files and directories.

CommandDescription
lsIt will list the files and directories under an active director path.
ls -aLists only active files, but in a long and detailed list.
pwdreveals the present directory you are working under.
mkdir [dir_name]It will create a directory with the specified name.
rm [filename]It will delete a file with the specified name.
rm -r [directory_name]It will delete a directory with the specified name.
rm -rf [directory_name]It will recursively and forcefully delete a directory with the specified name.
cp filename1 filename2It will copy the contents of filename1 to filename2
cp -r [directory1] [directory2]It will recursively copy the content of directory1 to directory2
mv filename1 filename2It will rename filename1 to filename2
ln -s /path/to/[file_name] [link_name]Use this command to create a symbolic link (link_name) to a specified file name (file_name).
touch [filename]Used to create a new file with a specified extension.
more [filename]It will open and display the contents of a specified file.
cat [filename]It will also open and display the contents of a specified file.
cat filename1 >> filename2It appends or adds the content of filename1 at the bottom of filename2.
head filenameOutputs the first ten lines of a specified file name.
tail filenameOutputs the last ten lines of a specified file name.
gpg -c filenameUsed to encrypt a specified file.
gpg filename.gpgUsed to decrypt a specified file with a .gpg extension.
wc filenameOutputs number of bytes, lines, and words of a specified file name.
less filenameThis command enables a user to browse through the content of a text file
tail -f filenameNot only outputs the last 10 lines of a specified file but also follows the growth progress of this file when more content is added to it.
cdTakes you to the Home directory of our Linux system
cd ..Takes you to the previous active directory or one level up.
cd /target/directoryNavigate to the location of a specific directory name.

Linux Commands for Disk Utilities and Usage

It is also important to know how to interact with the various hardware components that connect with your Linux system.

CommandDescription
df -hWorks with mounted systems to reveal their free and used space.
df -iWorks with mounted systems to reveal their free inodes. These inodes hold disk block location data an other attributes.
fdisk -lReveals disk information like types, sizes, and partitions.
du -ahOutputs files and directories disk usage.
du -shOutputs your currently active directory's disk usage.
findmntOutputs the target mount point associated with all your file system.
mount device_path mount_pointUse this command syntax to mount a device.
mkfs -t -VUse this command to create a new file system.
resize2fsUsed for updating a file system, especially after lvextend*
fsck -A -NUsed to check and repair a file system.
pvcreateUsed for creating a physical volume.
mount -a -tUsed for mounting a file system.
lvcreateUsed for creating a logical volume.
unmount -f -vUsed for unmounting a mounted file system.

Linux Commands for Environment Variables

An environment variable describes the environment behavior of your operating system. The usage and description of the following commands make more sense to this definition.

Command Description
echo $Variable_nameOutputs the value of a defined variable on the terminal.
envOutputs data related to all environment variables.
variable_name = variable_valueUse this command syntax to assign a variable name with a variable value.
UnsetUsed to remove or get rid of a variable.
export Variable = valueUsed to assign an environment variable a new value.

Linux Commands for System Processes Management

If you are looking for an internal grip or understanding of how your Linux operating system relays its functions and operations, then the following commands will be useful.

CommandDescription
bgSends a running process to execute in the background.
fgSends a stopped or halted process to keep executing on the foreground.
topOutputs all active processes details.
htopIt is an interactive process viewer command.
psOutputs a running process's status to a system user.
ps -efOutputs all active or executing processes on the Linux system.
ps -ef | grep process_nameOutputs the running process information for a specified process name.
ps PIDOutputs a running processes's status in reference to its process ID.
pidofReveals the process ID of a specified process.
kill PIDKills a running process based on its process ID.
niceGrants execution rights to a process with an assigned priority.
reniceChanges or alters the execution priority of an already running system process.
dfOutputs free and used storage information regarding the system's hard disks.
freeOutputs information about the system RAM's and swap's free and used memory.
free -mAlso outputs information about the system RAM's and swap's free and used memory.
killallStops all the actively executing processes by their process names.
killall process_nameWill stop a running process based on the process name.
sensorsOutputs the Linux system's CPU temperature.
topOutputs actively running processes and provides an interface for real-time monitoring of these processes.
kill -1 -9Used to send a signal to a running process.
service [start|stop|restart]Used for managing system services through an executable sysV init script. You can start, stop, or restart the specified system service.
ps auxOutputs a snapshot of the current running processes.
dmesg -kOutputs system messages. Helps in troubleshooting the health status of your Linux system.
program &Executes a program in the system background.
fg nMoves a running job n to the system's foreground.

Linux Commands for VI Editing

The command sequences related to the VI editor let you manage your files from the terminal without seeking a text editing app with a graphical interface. VIM is an improved version of this editor with additional features. The VIM editor absorbs all the implementation of the VI editor’s commands.

CommandDescription
vilaunch the VIM editor.
:q!quit the editor without saving the implemented changes.
:wqquit the editor and also make changes to the open file.
iTakes the editor to insert mode and initiates a cursor.
aAn insert mode that enables the system user to write their input after a cursor.
AAn insert mode for writing at the end of the line.
ESC keyUsed to exit the insert mode.
uUndo Vim command for the last change.
UUndo Vim command for an entire line.
oInsert mode for opening a new line.
ddVim command to delete a line.
3ddVim command to delete three lines.
DVim command to delete line content(s) that follow or succeed the cursor.
CVim command to delete line content(s) that follow or succeed the cursor and additionally allows the system user to insert new text.
dwVim command to delete a word.
4dwVim command to delete four words.
cwVim command to change a word.
xVim command for character deletion at the cursor.
rVim command to replace a character.
RWith this command, all the characters succeeding the cursor are overwritten.
sCommand to substitute a single character under cursor and then continues to insert mode.
SCommand to substitute an entire line and then initiate insert mode at the beginning of that same line.
~Vim command to change the case (upper or lower) of individual characters.

Linux Commands for File Editors

You can use the following Linux command shortcuts to access your favorite file editor without the need to navigate to the Graphical User Interface to launch them

CommandDescription
exLaunches a basic editor.
viLaunches visual editor.
nanoLaunches the GNU nano editor.
viewLaunches an editor in view or read-only mode.
emacsLaunches emacs, an extensible and customizable system editor.
sublimeLaunches sublime text editor.
sedlaunches stream editor.
picolaunches pico, a simple editor.

Linux Commands for File Utilities

There is more to how you can interact with files on a Linux operating system. These Linux commands paint a clearer picture.

CommandDescription
tr -dCommand for translating or deleting a character.
uniq -c -uCommand for reporting or omitting repeated lines.
split -lCommand for splitting a file into segments.
wc -wThis command prints the number of bytes, words, and newlines on a specified file.
head -nOutputs the first few contents of a specified file.
cut -sremoves or deletes a file's section.
diff -qCommand to compare files line by line.
join -iGiven that two files have a common field, this command will join the lines of these files.
more, lessEnables a system user to view the contents of a file, a single file page view at a time.
sort -nCommand to sort the lines within a text file.
comm -3After two files are sorted, this command can be used to sort them line by line.
cat -sCommand to concatenate or link files to a specific standard output.
tail -fCommand to output the last portion of a file.

Linux Commands for Scripting

Once your skillset on using the Linux operating system improves with time, you might be inspired to scribble some scripts from your OS environment. These commands apply both to the scripting languages you might be familiar with and the scripting environment setup to make your Linux OS life as comfortable as possible.

[table “49” not found /]

Linux Commands for Hardware Information

What if you want to know how your hardware is performing under a Linux operating system environment? Consider the use of the following commands.

CommandDescription
dmesgOutputs the kernel ring buffer messages.
cat /proc/cpuinfoOutputs CPU information of your machine.
cat /proc/meminfoOutputs Memory information of your machine.
free -hOutputs both free and used machine memory info.
lshwOutputs the system's hardware configuration information.
lsblkOutputs the system's block devices information.
lspci -tvOutputs the system's PCI devices.
lsusb -tvOutputs the system's USB devices.
dmidecodeOutputs the system's hardware information on DMI/SMBIOS related to the BIOS.
hdparm -i /dev/diskOutputs a specified disk data information.
hdparm -tT /dev/[device]Used with a specified system disk to output its read speed test performance.
badblocks -s /dev/[device]Used to reveal and test unreadable blocks on a specified disk sda.

Linux Commands for Performance Monitoring and Statistics

It helps to statistically assess how the Linux OS is adapting to its hardware environment.

CommandDescription
mpstat 1Outputs processor-related statistics.
vmstat 1Outputs statistical data related to the system's virtual memory.
iostat 1Outputs I/O (Input/Output) statistics.
lsofOutputs all the system's open files.
lsof -u userOutputs a list of all the files opened by a system user.
watch df -hA command to output periodic system updates.
tail 100 /var/log/messagesCommand to output the most recent 100 syslog messages. The Debian systems equivalent of this command is /var/log/syslog
tcpdump -i eth0An interface eth0-related command for outputting captured packets.
tcpdump -i eth0 'port 80'Command for monitoring traffic through port 80

Linux Commands As Keyboard Shortcuts

To be good at these commands, you only need to master a few keyboard strokes.

CommandDescription
Ctrl + CCommand to kill a running process.
Ctrl + ZCommand to stop a currently active process.
Ctrl + WCommand to cut a single word preceding the cursor.
Ctrl + UCommand to cut a line fragment preceding the cursor.
Ctrl + KCommand to cut a line fragment succeeding the cursor.
Ctrl + YCommand to paste from clipboard.
Ctrl + RCommand to recall the last used command.
Ctrl + OCommand to execute the previously recalled command.
Ctrl + GCommand to exit command history.
!!Command to execute a previously executed command.
exitCommand to sign off from an active session.

Linux Misc Commands

These are miscellaneous commands that are also useful in further improving your Linux operating system’s user experience.

CommandDescription
date -dCommand to print formatted date.
'[command_name]A backquote to execute a specified command.
exportA command for assigning or removing an environment variable.
calCommand to print a calendar.
exprA command used to evaluate an expression.
bcLaunches a high-precision calculator shell.
pwd -PReveals the current system directory you are under.

Final Note

The Linux Command Cheat Sheet exists to make the life of individuals pursuing a comfortable Linux life easy. You can comfortably adapt to these commands to make your Linux OS usage more efficient. As you have noticed, the categorical grouping of these commands has a few duplicated commands in other command categories. It just shows how flexible and adaptable a Linux command can be instead of being restricted to a single system function. Good luck in mastering and implementing these Linux Command Cheat Sheet categories.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

22,858FansLike
443FollowersFollow
16SubscribersSubscribe

Latest Articles

Suggested

How to set up and login as root user in MySQL

A root account is a superuser account that offers a wide array of privileges throughout the databases of MySQL. By default, the initial password for the root account is ‘empty/blank,’ thus allowing access to the MySQL server as root to anyone.

Featured

More Articles Like This