Introduction
There are many commands available in the Linux operating system. I will basically write about some of the frequently used commands and as well as important commands for the beginner user in the Linux operating system. It will contain the explanation of command as well as an example and syntax of that command.
Basic Linux Commands |
List of the Linux Commands
mkdir
It is used to make the directory. A directory in Linux means a folder. The syntax for making directory is given below.
- mkdir directory_name
For example, if you want to make a directory named Movie, then the command is
- mkdir Movie
In case if you have the directory name with two words or more, then you should make use of the quotation marks to indicate that it is one name instead of two. You can use either a single(' ') or double(" ") quotation mark. For example, to make My Music directory the command is
- mkdir "My Music"
If you do not use the quotation mark then the system will make the two directories separately instead of one. For instance, if you consider the above directory name, then the two directories name will be My directory and Music directory.
Tips: If you want to create a nested directory, then use the argument -p right after the mkdir command. For example, if you want to create Books/Science/Adventure directory then the command used is
- mkdir -p Books/Science/Adventure
rmdir
This command is used to delete the empty directories only. If the directories are not empty then it will give you an error message. The syntax to delete the empty directory is given below.
- rmdir directory_name
For example, if you want to delete the Movies directory then the command used is
- rmdir Movies
Tips: In case if you have nested empty directories then you can use the argument -p right after rmdir to remove all the nested directories at once. For example, if you have Books/Science/Adventure nested empty directory then the command used is
- rmdir -p Books/Science/Adventure
touch
It is used to change the timestamp of the file. But it is also used to create an empty file. You can give the extension to file as per your requirement. The syntax to create an empty file is given below.
- touch file_name.file_extension
For example, if you want to create the hello.c file then the command used is
- touch hello.c
ls
It is used to list the files and directories available in any location. The syntax to list the files and directories is given below.
- ls loaction_path
For example, in order to list all the files and directories in the current working directory, the command used is
- ls
Tips: In order to list all the hidden files and directory, you can use the -a argument right after the ls command as shown below. Hidden files and directories are those which have a dot(.) at the start of their name.
- ls -a
pwd
It is used to access the location of the present/current working directory. The syntax for checking the present/current working directory is given below.
- pwd
For example, if you are in location /home/user_name/Downloads, now in order to know this location, the command used is
- pwd
It will give you the location /home/user_name/Downloads.
cd
It is used to change the directory location. Basically to navigate from one directory location to another. The syntax to navigate to the new location is
- cd new_location_path
For example, if you want to navigate to /home/user_name/Documents location then the command used is
- cd /home/user_name/Downloads
Tips: In case if you want to navigate to your default user working directory or location then the command used is cd without any arguments.
mv
It is the command used to move the files and directory from one location to another. The syntax to move a file or directory from one location to another is given below.
- mv file_name new_location_path
- mv directory_name new_location_path
For example, if you want to move a file called hello.c from your current location to /home/user_name/Programming location then the command used is
- mv hello.c /home/user_name/Programming
Since there is no separate command to rename the file and directory, we make use of the mv command only. The syntax to rename file is given below.
- mv file_name new_file_name
- mv dir_name new_dir_name
For example, if you want to rename the file called hello.c to hello.java then the command used is
- mv hello.c hello.java
Tips: You can move as well as rename the file in a single command. For example, if you want to rename the file hello.c to java and move to /home/user_name/Programming location then the command used is
- mv hello.c /home/user_name/Programming/hello.java
rm
It is used to delete the file as well as the directory. The syntax to delete the file and directory is given below.
- rm file_name
- rm -r directory_name
For example. if you have the file called hello.c then the command used to delete the file is
- rm hello.c
In case if you have the nested directory with multiple files and subdirectories you can use it to delete it. For example, if you have a directory called Books and the Books directory is having multiple subdirectories and files, you can delete it with the command as follows
- rm -r Books
adduser/useradd
It is used to make the user in the system. In order to make the user, you should be the root user having all the privileges. The syntax for creating a new user in the system is given below.
- sudo adduser user_name
- sudo useradd user_name
For example, if you want to make the user called sam then the command used is
- sudo adduser sam
When you run this command it will ask you to enter the password and then after that it will ask you to give details of the user. So follow the instruction and complete it.
Tips: The user details will be available in the file called passwd file located in /etc directory. You can always check there to see the users available in the system.
passwd
It is used to change the password of the old user. It also needs the root privileges to set or change the password. The syntax to change the password for the user is given below.
- sudo passwd user_name
For example, to change the password for the user-created above, the command is
- sudo passwd sam
First, it will ask the root password of the root user. In case if you have already used the sudo command once in that open terminal it may not ask for the root user password. Then it will ask the password for the created user.
su
It is used to switch between different users in the system. It is read as a substitute user. The syntax to substitute the user is given below.
- su - username
For example, in order to login as sam user that you have created, the command is
- su - sam
It will ask you to enter the password for the user sam.
Tips: You can exit from substitute users using the exit command.
deluser
It is used to delete the user. It needs the root privileges to delete the user. The syntax to delete the user is given below.
- sudo deluser user_name
For example, in order to delete the user called sam that was created above, the command used is
- sudo deluser sam
It will ask you to enter the root user password. Then it will be deleted.
find
It is used to search files and directories in a hierarchical manner in the system. The syntax to search the files and directories is given below.
- find file_name
- find directory_name
For example, in order to find the filled called filed called hello.c the command used is
- find hello.c
It will search the file in its current directories and its subdirectories. It will not search in backward directories. You can give the location if you want to find it in some specific location. For example if you want to search the file called hello.c in /home/user_name/Documents directory then the command used is
- find /home/user_name/Documents hello.c
history
It is used to list the command line history of the user. The command to list the command line history is given below.
- history
Clear
It is used to clear the terminal. The syntax to clear the terminal is given below.
- clear
It will clear the terminal screen.
How to make a normal user into a sudo user?
In order to make a normal user into the sudo user you have to add the user into sudo group file. In order to add the user into sudo group, the current user needs to be the root user having all the privileges. The syntax for adding a normal user into sudo user is given below.
- sudo usermod -aG sudo user_name
For example, in order to add the user sam into the sudo user the command is
- sudo usermod -aG sudo sam
Tips: In order to see the available sudo user in the system, you can open the group file located in the /etc directory. There will be a group name called sudo and all the sudo user will be appended in that group.
Conclusion
It is very important to know the Linux commands if you want to work on the Linux operating system environment. Though it comes with the graphical user interface option, it is more important to know the Linux command line. The usermode command is handy when you get the issue with the root privileges commands. You can make use of this command and make the other user the sudo or root user. Wherever you want to find more usage of the particular command you can use the man command to get more information about a particular command. The syntax is man followed by the command name. If you have any doubts or queries, you can drop the comment in the comment section.