Basic Linux Commands: Despite the fact that most of us use Windows in our computer. Still Linux is the first preference of most of the Tech Enthusiast.
There are various advantages of learning Linux. Some of them are, it is free and open source operating system. It is fully customizable and you have the 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 in your computer just ny 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 there are some tasks which can only be performed by using commands in terminal.
So, let’s take a look at some of the Basic Linux Commands that you must know:
1. ls command
ls command is one of the most frequently used command, 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 of the sub-directory.
2. cd command
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 – “Desktop” directory.
Then you can type in “cd Desktop” to use Desktop directory as a current working directory.
3. pwd command
Many time you want to know the location of the directory in which you are working.
With the help of 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 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 cat(concatenate) command, you can create a file, write content to it and view the content of a file in your terminal window.
With cat command, you can concatenate or merge the two files as well.
Lets’s start by creating a file and writing the content to it.
By using “cat” command followed by > sign and the name of 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 cp command, you can copy a file or directory from one location to another using terminal.
The syntax of using 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 mv command.
The only difference between cp and mv command is that with 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 home directory to the Documents directory. The, 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 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 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 mkdir command followed by the name of 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 rmdir command. As 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 man command, you can get the complete documentation or manual of any tool or command in Linux.
The syntax to use man command is as follow:
If you want to get the manual or documentation of mkdir command, then you can do this by using “man mmkdir” 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 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 command in Linux, however most used command as well.
With the help of echo command, you can print the text or string on your terminal screen.
This is 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 normal user.
To perform those tasks, a permission of superuser is needed. Here come the role of sudo command.
Sudo stands for “superuser do”. The sudo command help you in getting the permission of 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 the permission to create a directory.
14. chmod command
You can change the permission of any file you want with the help of 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 following command.
chmod +x main.py
Similarly, you can do various other operation, like changing the reading and writing permission of a file with the help of 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 ps command.
With ps command, you can monitor the current 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 ps command.
For example – using ps -ef will give the complete information about all the running processes in your computer.
16. zip and unzip command
Zip command is used for compressing the file or directory, whereas with unzip command, you can extract the compressed file.
The syntax to use 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 unzip command followed by the name of zip file.
17. Nano, vi, pico command
Nano, vi and pico are the command-line text editor in the 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 the text editor like this.
After you have done, press ctrl+x to exit.
Similarly, there are other text editor in Linux as well. Like – vi and pico. However, the usage of all the text editor is same.
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 “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 command in Linux. With apt-get command, you can perform various operation related to packages, tools or software in Linux.
You can install, update, upgrade or remove a package or tool with the help of apt-get command.
So, if you want to install a package in 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 history command, you will get the complete list of all the recent commands you have used in you Linux terminal.
Hope you understood the essence and use of these Basic Linux Commands.
If you know any other Linux Command which should be in this list or any suggestion, let me know in the comment section below.