When you are in Linux OS, you might want to use the terminal to do your work, as the terminal is the command line interface of Linux OS having the powerful features. The terminal can achieve anything if and only if commands are given correctly. The commands at first seem intimidating but I will help you with commands dividing into basic, intermediate, and advanced.
So, This post will help you to write some basic commands, and in the end, anyone can write those commands easily and can move to intermediate commands.
To open up a terminal Press
Ctrl + Shift + T
pwd command meaning is “present working directory”. It means our current location in the Linux file system. Whenever we open our terminal, using Ctrl + Shift + T, the Linux file system takes us to the user folder. let’s try our first command
so my output says “/home/bkguru“. your output might show your username instead of my username “bkguru“. This says, we are inside “bkguru” folder so, any other commands that do certain tasks will be done in this “bkguru” folder.
To try more, I will open terminal inside any folder I have, and open up terminal using right mouse key. then same command
pwd will have different output, as it will show exact location of our folder.
ls command means list that means this commands list out all the files and folder inside our current working folder.
So simply type the command
ls and see its output, as soon as, you open up the terminal using
Ctrl + Shift + T
The output shows all the files and folders inside my current working folder (username folder).
But with the
ls command, we can provide options too. you can check all the options available for
ls command using command
man (for manual), typing
man ls. This command
man works for all commands help. Here is few options to work with
-l means long form) gives all lists in long form including date, size, permissions and other properties.
-a for all) gives the list of all files and folders including hidden system files as well. Be sure you are doing nothing that put system as risk. The files with ‘.’ dot sign front are the hidden files.
- options are followed by ‘-‘ sign. So write
ls -ainstead of
- there should be space between the main command and option.
cd command meaning is change directory. If we want to change our working folder then we have to use this command. This command can be used to change our directory back and forth in the LINUX file system.
Now I am in my /home/bkguru/ directory, if I use
ls command then, I can see so many other folders inside my bkguru folder. Now I want to work on Desktop folder. That means I have to change the directory from bkguru to Desktop. So I have to type
Now once again check your present working directory to confirm the above change.
As you can see in the above output,
ls shows the Desktop folder with other folders and
cd Desktop takes us to Desktop folder, which is confirmed by
pwd output: “/home/bkguru/Desktop“
NOTE: Desktop has capital D at first, so
cd desktop won’t work.
Now, let’s list out the folders available in Desktop using
ls command again.
As I can see the practice folder in my Desktop using
ls command. Now I want to enter in practice folder. So
This time practice has p in lowercase.
and checking with
It says /home/bkguru/Desktop/practice
Till now, we only used
cd command to move ahead with folders but how to get back with
cd command, let’s learn that as well.
For that we have to type:
So I did that for two times and Now i am back to my /home/bkguru folder
Lets go back to practice folder directly using direct path.
This takes us directly to the practice folder in one step. So, we can use the long path as well if we know the path exactly.
Now lets come back using
cd ../.. directly to our username folder. first two dots .. take one step back and
../.. takes two step back directly.
Now suppose we are in a different directory than our usual directory which is /home/bkguru. In that case, we have a direct command to come back to the initial directory using
mkdir command means “make directory”. This command allows us to make a new folder in our present working directory.
Let’s create a new folder name “my_folder” in Desktop.
First navigate your working directory to Desktop using cd command.
Now we are in Desktop, lets create a folder using
This creates a folder. You can check new folder through your default file browser or check using
But why do we write my_folder instead of my folder?
We cannot give space in the folder name in terminal similar to the variable name in any programming languages. If we really want folder name with space, we can give using single quotes (‘ ‘)
mkdir 'other folder'
You can see those two folders in file browser also.
rmdir means remove the directory. This command allows us to remove the specified folders of the current working directory.
let’s remove two folders created above using
rmdir my_folder rmdir 'my_folder'
rmdir works fine with the empty folder, but it cannot remove the folder which is not empty. for eg.
I will first create a folder using
mkdir command with
-p option. The option -p allows us to create a folder, inside folder like a path.
mkdir -p new/more
The above command creates ‘new‘ folder at first then creates ‘more‘ folder inside that ‘new’ folder. It means the folder ‘new’ is not empty. Now let’s try to remove ‘new‘ folder using
It says failed to remove ‘new’ : Directory not empty.
In such case, we can use
rm -r command. Don’t worry for now, just type command:
rm -r new
This deletes ‘new‘ folder with everything inside it.
We will talk about
rm command after some other commands.
Remaining commands will be posted soon. Stay Tuned.