Basic Linux Commands: Although most of us use Windows on our computer. Still, Linux is the first preference of most of the Tech-Enthusiast, and Linux vs Windows is still a hot topic.
There are various advantages to learning Linux. Some of them are, it is a free and open-source operating system. It is fully customizable and you have complete control over your computer.
The first step towards learning Linux is to start using the basic Linux Commands.
With the help of these commands, you can perform all the operations on your computer just by using your terminal.
Learning these Linux Terminal Commands can be very resourceful and helpful for you, as it will help you in using your computer more efficiently.
There are many good Linux Distributions available, based on your priority or preference.
However, the Linux Commands we about to discuss are common for all Linux Distribution.
If want to use any of the Linux Distribution then you must know the use of these commands, as some tasks can only be performed by using commands in a terminal.
So, let’s take a look at some of the Basic Linux Commands that you must know:
Table of Contents
1. ls command
ls command is one of the most frequently used commands, as this command helps in listing the names of all the files in the directory in alphabetical order.
By just typing “ls” in your terminal, you will get the names of all the files and folders in the current working directory.
However, if you want to get names as well as other detail of files in the directory, then you can use the “ls -l” command.
The commands we discussed above are only for listing non-hidden files. However, if you want to list the details of hidden files as well, then you should use “ls -a” or “ls -al”.
By using “ls -R”, you will get the name of files of the directory as well as the sub-directory.
2. cd command
The cd command is used for changing the current working directory.
So, if you are in the home directory and you want to navigate to the other director, for example – the “Desktop” directory.
Then you can type in “cd Desktop” to use the Desktop directory as a current working directory.
3. pwd command
Many times you want to know the location of the directory in which you are working.
With the help of the pwd command, you will get the absolute location of your current working directory.
As in the above example, you can see that by typing “pwd” in the terminal, we get the absolute location of our working directory.
4. touch command
With the help of the touch command, you can create multiple empty files of any type.
For example, if you want to create a single empty text file in the current working directory, then you can type in “touch hello.txt” in your terminal.
However, to create two or more empty files in the directory, you can type in “touch name.txt address.txt program.c” in your terminal.
5. cat command
With the help of the cat(concatenate) command, you can create a file, write content to it and view the content of a file in your terminal window.
With the cat command, you can concatenate or merge the two files as well.
Let’s start by creating a file and writing the content to it.
By using the “cat” command followed by > sign and the name of a file, you can create a file in which you can write content to it. To exit the file, press ctrl+D.
However, if you just want to view the content of any file. You can type in “cat FILENAME”.
For merging or concatenating the two files, you can use the command “cat FILE1 FILE 2 > NEWFILE”.
6. cp command
With the cp command, you can copy a file or directory from one location to another location using a terminal.
The syntax of using the cp command is as follow:
cp SOURCE DESTINATION
So, if you are in a home directory and you want to copy a file named “hello.txt” to the destination directory named “Documents”.
Then you can type in “cp hello.txt Document” in the terminal and the file will get copied from the home directory to the Documents directory.
7. mv command
Similarly, you can move a file from source to destination by using the mv command.
The only difference between cp and mv command is that with the mv command, the source directory will no longer have the file which has been moved.
You just have to use mv instead of cp. The syntax of using mv is:
mv SOURCE DESTINATION
So, if you want to move a file named “hello.txt” from the home directory to the Documents directory. Then, you can type in the following command:
mv hello.txt Documents
8. rm command
If you want to delete any file or non-empty directory, you can do it by using the rm command.
The command to delete a file is “rm FILENAME”. However, for deleting a non-empty directory. the command is “rm -r DIRECTORY”.
For example – if you want to delete a file named “hello.txt” from the home directory, then you can type in “rm hello.txt” and the hello.txt file will get removed from the current working directory.
To delete a non-empty directory named “NewDirectory”, you have to use the command “rm -r NewDirectory” for that.
9. mkdir command
By using this command, you can create a directory inside the current working directory.
You just have to type in the mkdir command followed by the name of the new directory you want to create.
So, if you want to create a new directory named “record”, then you can use the command “mkdir record”.
10. rmdir command
This command is used to delete an empty directory.
Make sure that you cannot delete a non-empty directory with the rmdir command. This command is used for deleting non-empty directory only.
So, if you want to delete a non-empty file named “student” from the current working directory. You can use the following command:
11. man command
By using the man command, you can get the complete documentation or manual of any tool or command in Linux.
The syntax to use the man command is as follow:
If you want to get the manual or documentation of the mkdir command, then you can do this by using the “man mkdir” command and you will get the following manual on your terminal screen.
However, if you want to go to the 2nd or 3rd page of the manual, then you can do so by using the man command, followed by page_number and the name of command or tool.
man 2 mkdir
12. echo command
This is one of the most basic commands in Linux, however the most used command as well.
With the help of the echo command, you can print the text or string on your terminal screen.
This is a very useful command in scripting as it helps in printing the output to the screen.
The syntax of the echo command is:
for example, you can print the string “The CoderPedia” in your terminal by using this command.
echo “The CoderPedia”
13. sudo command
There are some tasks or operations in Linux, which cannot be performed by a normal user.
To perform those tasks, the permission of the superuser is needed. Here comes the role of the sudo command.
Sudo stands for “superuser do”. The sudo command helps you in getting the permission of the root user or superuser.
For example, if you try to create a directory in the etc directory of your system. Then you will get a “Permission denied” message on your screen.
However, for getting superuser permission, you have to type in sudo before the command you want to run. Like – “sudo mkdir NewDirectory”.
Now, you just have to type in the root user password and you will get permission to create a directory.
14. chmod command
You can change the permission of any file you want with the help of the chmod command.
For example – if you want to make a Python file executable so that you can directly run your python code with just the name of the file.
Then you can do so by using the following command.
chmod +x main.py
Similarly, you can do various other operations, like changing the reading and writing permission of a file with the help of the chmod command.
15. ps command
If you are a Windows user, then you must have used Task Manager, in which you can monitor all the running process and other details.
However, In Linux, the same task can be performed by using the ps command.
With the ps command, you can monitor the currently running process of your computer.
To get the most out of the ps command, you have to use the various option or arguments available with the ps command.
For example – using ps -ef will give complete information about all the running processes on your computer.
16. zip and unzip command
Zip command is used for compressing the file or directory, whereas, with the unzip command, you can extract the compressed file.
The syntax to use the zip command is
zip filename.zip source_file
So, if you want to compress a file named “hello.txt”, then you can do so by the following command.
zip file.zip hello.txt
To unzip this or any other compressed file, you just have to use the unzip command followed by the name of a zip file.
17. nano, vi, pico command
Nano, vi, and pico are the command-line text editor in Linux.
Let’s first take a look at the syntax and usage of the nano command. To use the nano text editor, you just have to type in,
In the next window, you will get a text editor like this.
After you have done, press ctrl+x to exit.
18. passwd command
This command is used to change the password of the user account in Linux.
So, if you want to change the password of the current running account, then you just have to type in the “passwd” command.
However, if you are a root user (superuser) and you want to change the password of another user. Then the command for that is “sudo passwd username”.
19. apt-get command
This is one of the most useful commands in Linux. With the apt-get command, you can perform various operations related to packages, tools, or software in Linux.
You can install, update, upgrade, or remove a package or tool with the help of the apt-get command.
So, if you want to install a package on your computer, then the command for that is
apt-get install PACKAGE_NAME
For example, to install a python package in your Linux system, you have to type in
apt-get install python
Similarly, you can update, upgrade, or remove any package in Linux.
To update a package, use “apt-get update PACKAGE_NAME”.
To upgrade a package, use “apt-get upgrade PACKAGE_NAME”.
To remove a package, use “apt-get remove PACKAGE_NAME”.
20. history command
If you want to get the list of all the commands you have recently used in your terminal, then you just have to type in “history” in your terminal.
With the help of the history command, you will get the complete list of all the recent commands you have used in your Linux terminal.