Linux Cheat Sheet: Download PDF for Quick Reference

By | March 18, 2022
Linux Cheat Sheet

Linux is one of the most stable operating systems that are capable of running simply as well as complex applications with great ease. Like the Windows operating system, Linux also has a command prompt (called terminal) that allows the users to execute various commands to carry out either system-related tasks or installing software.

If you are a Linux administrator, then you must be aware of some of the most basic commands that are frequently used in Linux. You can use this cheat sheet to prepare for your upcoming interviews too. Let’s get started.

Linux Cheat Sheet

To make this Linux cheat sheet legible, we have divided it into several sections. So, let’s start from system commands:

1. System-related Commands

1.1 uname -r

If you are new to the Linux system and want to get the details about the available kernel releases, then you can execute the “uname” command along with the “-r” option, where “r” represents the release.

1.2 uptime

If you want to get the details regarding the average system load along with the time for which your system has been running continuously, then you can execute the “uptime” command.

Vamware

1.3 hostname

For getting details regarding the hostname, you can execute the “hostname” command. Yes, it works without passing any parameters.

Vamware

1.4 hostname -i

If you want to get details regarding the ip address of your machine, then you can execute the “hostname” command along with the “-i” option, where “i” represents the IP address.

1.5 last reboot

For getting detailed information regarding the history of the system’s reboot, you can execute the “last reboot” command.

1.6 date

Vamware

This Linux command will provide you with the current date and time of the system.

1.7 timedatectl

There are situations when you want to change the system clock time. For that, you can execute the “timedatectl” command.

1.8 cal

For getting the details of the calendar, you can execute the “cal” command. You will get the output in the calendar format.

2. Hardware-related Commands

2.1 dmesg

For getting the details regarding the bootup messages of the system, you can execute the “dmesg” command.

2.2 cat /proc/cpuinfo

Linux has a file stored on the system that contains the information regarding the CPU. To get the information of that file, you can run the “cat” command for displaying the information on the screen.

2.3 cat /proc/meminfo

Linux has a file stored on the system that contains the information regarding the hardware memory. To get the information of that file, you can run the “cat” command for displaying the information on the screen.

2.4 lshw

Linux stores configurations of the system hardware. For getting the details, you can execute the “lshw” command.

3. Users-related Commands

3.1 Id

If you want to get all the specified details corresponding to all active users, you can execute the “id” command to get the id of the users.

3.2 last

If you want to get the details regarding the last login to the system, you can execute the “last” command.

3.3 who

To get the details regarding the user who is currently using the system, you can execute the “who” command.

3.4 groupadd “admin”

Use this command when you want to add the “admin” for a particular group.

3.5 adduser “Sam”

If you want to add a new user to the system, you can run the “adduser” command followed by the name of the user. Here we are considering “Sam” as a new user.

3.6 userdel “Sam”

If you want to delete a specific user from the system, you can execute the “userdel” command followed by the name of the user. Here we are considering “Sam” as the user to be deleted.

4. File-related Commands

4.1 ls -al-

If you want to get the listing of all the files stored in the present working directory along with all the hidden files, you can use the “ls” command along with the combination of the two options “-al”, where “a” will specify the hidden files and “l” will do the long listing.

4.2 pwd

Use this command when you want to get the details of your current working directory. pwd stands for present working directory.

4.3 mkdir dir_name

If you want to create a new directory in your current directory, then you can run the mkdir command followed by the name of the directory.

4.4 rm file_name

If you want to delete a file from the Linux system that is present in the current working directory, you can run the “rm” command along with the name of the file. It will ask for your confirmation to proceed with the removal of the file.

4.5 rm -f file_name

Unlike the above command, this Linux command will not ask for your confirmation as we have used the “-f” option with the “rm” command, where “f” specifies the forceful removal of the file.

4.6 rm -r directory_name

This command will allow you to delete a non-empty directory that will recursively delete all the contents of that specific directory.

4.7 cp file1 file2

This Linux command will allow you to copy the specific file from the source to the destination.

4.8 touch file_name

If you want to create a new file in the current working directory, then you can run the “touch” command along with the name of the file.

4.9 cat > file_name

This command will allow the user to provide the screen input to the file that results in creating a new file.

5. Process-related Commands

5.1 ps

Within a system, there might be various processes running all the time, and each process is referred to by its process id. If you want to get the details of all the active processes in the system, you can execute the “ps” command.

5.2 pmap

If you want to get the details regarding the memory map for a specific process, you can execute the “pmap” command.

5.3 top

This Linux command is for displaying all the running processes within the system.

5.4 kill pid

Use this command when you want to terminate a process based on its process id.

5.5 killall proc

Suppose you want to terminate all the processes having a particular name, “proc,” then you can execute this command.

5.6 pkill process_name

This command is used for sending a signal to a process based on its process name.

5.7 bg

This Linux command resumes any suspended jobs present in the background.

5.8 fg

If you want to bring all the suspended jobs to the foreground, you can execute this command.

6. Network-related Commands

6.1 ip addr show

If you want to get all the details regarding the IP addresses and interfaces for all the connected networks, then you can execute this command.

6.2 ip address add 192.168.0.1/24 dev eth0

You can assign, for example, the IP address 192.168.0.1 to interface eth0 with the help of this command.

6.3 ifconfig

If you want to get the information regarding all the network interfaces’ IP addresses, you can execute this command.

6.4 ping host

Use this command when you want to send the ICMP echo request for establishing a connection to the server.

6.5 dig domain

For getting the desired information about the domain, such as the DNS information, you can execute this command.

7. Archives-related Commands

7.1 tar -cf home.tar home<:code>

If you are looking to create an archive file called ‘home.tar’ from file ‘home,’ you can execute this command.

7.2 tar -xf files.tar

If you want to extract the archive file ‘files.tar,’ you can execute this command.

7.3 tar -zcvf home.tar.gz source-folder

Use this command to create a zip tar archive file from the available source folder.

7.4 gzip file

If you want to compress a file with the .gz extension, you can execute this command.

8. Package-related Commands

8.1 rpm -i pkg_name.rpm

If you want to install the rpm package, you can execute this command.

8.2 rpm -e pkg_name

Execute this Linux command to remove the rpm package.

8.3 dnf install pkg_name

If you want to install a package with the help of the dnf utility, you can execute this command.

9. Search-related commands

9.1 grep ‘pattern’ files

If you want to search for a specified pattern in files, you can execute this command.

9.2 grep -r pattern dir

Use this Linux command to search for a pattern in a given directory recursively.

9.3 locate file

If you want to find all the instances of the file, you can execute this command.

10. Login-related commands

10.1 ssh user@host

If you want to establish a secure connection to the specified host, you can execute this command.

10.2 ssh -p port_number user@host

If you want to create a secure connection with the host with the help of a specified port, then you can execute this command.

10.3 ssh host

Use this command if you want to establish a secure connection to the system using the SSH default port 22.

11. Disk usage-related commands

11.1 df -h

If you want to get the detailed information regarding the free space on mounted systems, then you can execute this command.

11.2 df -i

If you want to get the detailed information regarding the free inodes on filesystems, then you can execute this command.

11.3 fdisk -l

Use it to get the detailed information regarding the disk partitions, sizes, and types.

11.4 du -sh

If you want to get the detailed information regarding the current directory’s disk usage presented in a human-readable format, you can execute this command.

Conclusion

Well, Linux commands are easy and interesting to work with. You will find commands for every single task, and if you are good with Linux commands, then you can handle your system from the terminal only. You need to practice understanding which command to use in a particular situation and which option to use for getting the specific results.

If you are a beginner and do not know where to start, then you can consider this cheat sheet to start with. You need to practice getting along and master the art of executing commands on a Linux terminal.

People are also reading: 

Author: Maaz Bin Asad

Maaz is a freelance content writer and an engineering undergraduate who is experienced working in the software development industry. He likes solving algorithmic problems and finding new approaches to optimize given problems.

Leave a Reply

Your email address will not be published.