Hey guys! Are you a Linux user? Then here are the Top Linux Commands for beginners: Must-know! I will demonstrate the usage of all the commands on kali-Linux. You can use them on any OS of Linux family.

1. “ls” – list

In Linux, “ls” stand for the list. As the name suggests this command will list all the files, directories, all the stuff present in the current working directory. As shown in the below image, currently we were in the home directory and the “ls” command has listed all the directories present in it.

"ls" - list
“ls” – list

2. “cd” – change directory

This command stands for change directory. It is used when we have to navigate through directories. The usage of this command is shown in the below image. We were currently present in the home directory then using the command “cd Downloads” we have moved to Downloads. Further usage of this command is discussed below.

change directory

3. “pwd” – print working directory

This command is very useful if you are working with a maze of directories. It stands for “print working directory” which means that it will print the directory in which you are currently present. For example – When we have used the command “pwd”, the output comes “/home/researcher/Downloads“.

print working directory

4. “mkdir” – make directory

The command “mkdir” stands for make directory. this command is used to make directory. The syntax of this command is shown below.

mkdir directory_name

For example – We were currently in the “Downloads” directory. Then we have a new directory named as “MusicMix” inside Downloads directory. Using command “ls”, all the files in the Downloads get listed. Then finally we have moved to our new directory “MusicMix”.

make directory

What if we want to make directory in a directory in a directory??

If we use the above procedure for making directories one-by-one, then it will take time. We can use another syntax of mkdir as show :

mkdir -p Directory_name/Directory_name/Directory_name……..

Here “-p” stands for parent. It will tell the terminal that the first directory in our command is a parent directory.

For example – We were currently in the Downloads. Then we have made a directory named “Dir_1” in which another directory named “Dir_2″ in which directory named ” Dir_3″ is present with the help of command “mkdir -p Dir_1/Dir_2/Dir_3”. You can see the current working directory in the command used at last (pwd).

5. “rmdir” – remove directory

This command is used to delete directories that are empty. The syntax of this command is as follows :

rmdir direcitory_name

For example, You can see in the image below, that currently, we are in the Downloads directory. Then we have made new directories as follows: Downloads➡ MusicMix ➡Music ➡Remix and then we moved to Remix directory. Now to move out of the current working directory use command ” cd ..”. Now Remix is an empty directory so we can remove it using the command “rmdir Remix”.

remove directory

I know what you are thinking “Everything is going fine with empty directories, what if directories are not empty, what if they contain some files of stuff, how to remove them? “

5. “rm -r” – remove non-empty directory

To remove non-empty directories along with the files within them use command “rm -r” where rm stands for remove and r stands for recursive. Now we were in our Music directory where we have deleted “Remix” directory using command “rmdir”. Now we have moved 2 directories back using command “cd ..” (2 times). Now we are in Downloads directory where a non-empty directory called MusicMix is present. To remove it, use command “rm -r Music Mix”.

(Note : For non-empty directories we can’t use “rmdir” command as it will show an error “directory not empty”

remove non-empty directory

(Be caution ! : You have to be cautious with this command as it will delete the non-empty directory and the files present in those and there is no undo. So double check the directory you are removing)

5. “touch” – Make new files

This command is used if we want to make new files such as .txt , .html etc. The usage of this command is shown below. We are currently in the Downloads directory where we have created a new file named “Sample.txt” using the command “touch Sample.txt”.

Make new files

6. “ping” – to check connectivity

This command shows our connectivity with the desired server. As shown below, we have checked our connectivity with a re-known server “google.com”.

to check connectivity

7. “alias”

This command is very useful for full time Linux users as well as beginners as with this command we can make short aliases of other commands also the commands listed above. For example, in the image shown below we have created an alias of the command known as “clear” (use to clear out the terminal screen) as “cls”. Now whenever we will use cls it will behave same as “clear”.

alias

A task for you!!

Enter the command to make directories as follows Dir_001/Dir_002/Dir_003/Dir_004/Dir_005/Dir_006 and then make a new file name as “Mathcompt.txt”. Note: use an alias for the command for “making directories”.

Comment the command line

For more noob – friendly Linux tutorials: Stay tuned to MathCompt!

Do follow freshly- made MathCompt’s twitter profile!