Linux Cheat Sheet

Photo of author

By Vijay Singh Khatri

The commands which are present in Linux make it a unique operating system with enhanced capabilities. For a newcomer, the Linux commands may look like a complicated maze initially. However, once the user gets comfortable with these commands, he/she can easily get used to their usage and syntax. In addition to this, a server administrator who is using the bare minimum Linux server package installation can perform any task with the use of Linux commands which can range from 50 commands to even 1000 commands in a single operating system.

So here in this article, we aim to provide both the newcomers of Linux OS and the experts with a list of some of the most useful Linux commands. If you ask a Linux user how many commands they know, the answer you will likely receive is “just a handful”. Well, if you are the one whose answer is the same then by the end of this article, you will learn quite a few commands to take your knowledge about Linux to the next level.

Why Can’t You Learn All the Linux Commands?

It’s a bit difficult to learn all the Linux commands as there are too many of them, and with each command comes their options. You have to memorize most of the commands because they are too random in the first place. Also, Linux being an open-source operating system, with a little bit of tweaking, you can even create your commands to perform any specific task.

To make things easier for you, we have categorized the Linux commands according to their area of working in the operating system. For example, “uname -a” is the basic command used to display the information of the system you are currently using. This command we have categorized in the system information. On the other hand, there are “Chmod” commands used to change the file permission, so we have categorized them in the file permission.

Linux Commands Cheat Sheet

Given below is a list of different command categories along with the commands. You can bookmark this page, so open it anytime and see which command to use when working with Linux OS.

Commonly Used Linux Commands

The commands which are written below are some of the most common commands that you can use randomly anytime when using Linux OS. These commands will help in creating a better experience and give users the flexibility which they are looking for in Linux OS.

Commands Descriptions
IsThis is the Linux basic list command, and when you use it, it will display you all the directories and files which are present in the current directory in which you are working or is opened.
Is -RWhen you use this command, you will go one step further and will have the output of files that are present in the sub-directories of the current directory that is currently opened.
Is -aIn Linux, you can hide a file in any of the directories. This command is used to view hidden files in any current working directory.
Is -alIf you want to have detailed information on the files, such as their size, permission, and ownership. Then you need to use this command, and it will display you all the details.
cd/ cd ~In case you are stuck somewhere when using the terminal and want to return to the home directory of your OS, then all you need to do is type in this command, and the terminal will take you to the main directory.
cd ..To go back to the parent directory of the current directory, you need to use this command.
cdIf you want to move to some other directory from your current directory. Then you need to type in this command and combine it with the target directory where you want to navigate.
cd /This command will take you to the root directory of your operating system. Be careful about the changes you make in the root directory, as the changes can lead to the abnormal working of your Linux OS.
cat > filenameWith the help of this command, you will be able to create a file by the name ‘filename’ in the current directory.

Linux Search Commands

These commands are used to find out the flies, documents, and directories present in the given location of the OS. These commands will not cause any change in the file system as they are only used to look for the files and their content

CommandsDescriptions
grep [pattern] filenameIf you are looking for a specific string of characters in a file, then use this command, and it will output you the line which has the given string.
grep -r [pattern] [directory_name]With the use of this command, you can recursively search for the pattern in the directory which you have entered in the command.
Locate [name]This command is quite simple, but it is quite powerful. This command can be used to find the files and the directories which are related to the particular name that you provided in the command.
find [/folder/location] -name [a]With the help of this command, you will be able to find out the names of files and directories that begin with the character [a] in a specified location of your operating system. [/folder/location]
find [/folder/location] -size [+100M]Find out the files which are larger than the given size [+100M] in a specified folder.
find / -type f ! -perm 777This command can be helpful when you are looking to sort out the files present in the given directory based on the permissions. In this command, when you are using “find/” it represents false for the given permission. Thus, the command will display the files which are present without the 777 permission.
find . -type f ! -perm 777This command is the opposite of the above command, as it will show you all the files which have the 777 permission in the given directory.
find /tmp -type f -emptyWith the use of this command, a user will be able to find out all the files which are empty in the current directory.
find /tmp -type d -emptyWhen you type in this command, you get to see all the directories which are empty in the given path.
find /home -group developerThis command will help a user find all the files which belong to the same group under the home directory. In this command, a developer is a group present in the home directory.

Linux Commands to Transfer and Manage Files

When you are using Linux OS, it is quite common to change file permissions or transfer them from one directory to the other. Well, the commands written below will help you to make changes to the file locations from the command line interface. As a result, you don’t have to rely on the graphical interface to make these changes happen.

Commands Descriptions
Is -a -C -hThis command might seem a little encrypted, but it is used to find all the content which is present in the current directory in which you are using the terminal.
rm -r -fWhen using this command, a user can remove or delete the files or directory instances present in the current path/ location.
locate -iIt is used to track down the files or find the location of the files which are present in your system.
du -sWhen you are using this command, it can provide you with important information regarding the usage of the disk space on your Linux operating system. Moreover, you can use it with the Sudo command to get additional information about your disk space.
file -b -iIn case you are not sure about the file type that you are searching for, then you can use this command to identify the same.
mv -f -iThis command can help move both the files and the directories to a different path or location present within the operating system.
scp file.txt server:/tmpThis command is used to copy the files securely from your local storage to a remote server. In the given command, you can see we have copied the file.txt to the remote server and pasted the file in the temp folder present in the remote location.
rsync -a /samplefolder1 /backups/With the use of this command, you will be able to synchronize the content of two directories. As a result, the content present in the first directory, “samplefolder1”, will be present in the second directory, which is “backups”.
pwdThis command helps print out the current working directory in a hierarchical order, starting from the topmost root directory. The full form of pwd is Print Working Directory.
cat samplefile1To view the contents of the file present in the current directory, you need to use this command. Here “samplefile1” is the file name for whose content will be shown as the output of the command.

File and Directory Commands

The commands written below will allow a user to make changes in the system files and directories.

Commands Descriptions
mkdir [directory_name]When you type in the following command, it will create a directory in the given location by the name which you have provided.
cp filex fileyWith this command, a user will be able to copy the content which is present in the filex to filey without using the copy/paste command. Also, there is no need for two files to be in the same directory. They must be present locally in the machine.
touch [filename]If there is a specific extension that you need a file to have, then you need to use the touch command and create a new file with the specified extension that you need.
more [filename]This command will display the contents of a specified file that is present in the current directory.
head filenameWith the use of this command, you will be able to print out the first ten lines of the file which you have mentioned in the command.
tail filenameThis command will print out the last ten lines of the file that you have written in the command.
gpg -c filenameThe file with which you are using this command will get encrypted.
gpg filename.gpgWhen you use this command on an encrypted file, that file will be decrypted. One thing to note here is that you can only use this command on the files which are encrypted in the first place.
wc filenameThis command will output the number of bytes, lines, and words present in the specified file in the given directory.
less filenameYou can use this command to display the contents of the specific file in the command line so that you can go through the content and get the information that you wanted.

Disk Utilities and Usage

The following commands are used to make connections and interact with the various peripheral components, which can be used to connect with the system that is using Linux as its operating system.

Commands Descriptions
df -hThis command will help a user find out how much space the mounting hardware has; the command can show both the free and the used space in the mounted disk. A mounted disk could be your external hard drive, USB, smartphone storage, etc.
df -iWith the help of this command, users can find out the free inodes present in the mounted disk. The inodes are responsible for holding location data and other types of disk attributes.
du -ahIf you have connected an external disk with your system, this command will display the files and the directories present in the disk and how much disk space each file and directory is consuming.
findmntThis command will show you the target mount point, which is linked with all of your file systems.
mount device_path mount_pointWhen you are mounting a new external drive in your system, you need to use this command.
mkfs -t -VThis command is used to create a new file system in the present directory. One thing to keep in mind is that “-V” here is capital. This command is case-sensitive, and if you use the small v, the command will not work.
pvcreateA user can type in this command in the command line to form a new physical volume in their local system.
IvcreateThis command is used to create a new logical volume in the current directory.
unmount -f -vTo unmount the mounted file system, you can use this command and complete the task straight from the command line.
UnsetThis command will allow a user to get rid of the variable or remove it from the current operating system’s environment.

Conclusion

These were in total more than 30+ Linux commands which you can use to perform the everyday task in your Linux operating system. These commands have several options, and to see those options, you need to use the help command in the command line, and it will display all the commands along with their multiple options.

We hope this Linux cheat sheet will serve as a ready reckoner to essential commands while working on a Linux system. This cheat sheet will give you a better understanding of the commands and how to use them. If there are some commands that you like us to include in this article, feel free to write them down in the comment section, and we will update our cheat sheet.

People are also reading: 

Leave a Comment