Linux Cheat Sheet: Download PDF for Quick Reference

Posted in /  

Linux Cheat Sheet: Download PDF for Quick Reference
maazbinasad

Maaz Bin Asad
Last updated on November 21, 2024

    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. 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.

    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.

    3. hostname

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

    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.

    5. last reboot

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

    6. date

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

    7. timedatectl

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

    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

    1. dmesg

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

    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.

    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.

    4. lshw

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

    3. Users-related Commands

    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.

    2. last

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

    3. who

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

    4. groupadd "admin"

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

    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.

    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

    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.

    2. pwd

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

    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. 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.

    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.

    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.

    7. cp file1 file2

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

    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.

    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

    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.

    2. pmap

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

    3. top

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

    4. kill pid

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

    5. killall proc

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

    6. pkill process_name

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

    7. bg

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

    8. fg

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

    6. Network-related Commands

    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.

    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.

    3. ifconfig

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

    4. ping host

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

    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

    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.

    2. tar -xf files.tar

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

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

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

    4. gzip file

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

    8. Package-related Commands

    1. rpm -i pkg_name.rpm

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

    2. rpm -e pkg_name

    Execute this Linux command to remove the rpm package.

    3. dnf install pkg_name

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

    9. Search-related commands

    1. grep 'pattern' files

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

    2. grep -r pattern dir

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

    3. locate file

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

    10. Login-related commands

    1. ssh user@host

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

    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.

    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

    1. df -h

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

    2. df -i

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

    3. fdisk -l

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

    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:

    Leave a Comment on this Post

    0 Comments