Linux Terminal Basic Commands

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

1. pwd command

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 pwd

pwd command
pwd output

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.

pwd command
pwd output

2. ls command

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

ls command
ls output

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 ls command.

ls -l     

(-l means long form) gives all lists in long form including date, size, permissions and other properties.

ls -l command
ls -l command output
ls -a   

(-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.

ls -a command
ls -a command output

Note

  • options are followed by ‘-‘ sign. So write ls -a instead of ls a
  • there should be space between the main command and option.

3. cd command

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.

Usage: cd foldername

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

cd Desktop

Now once again check your present working directory to confirm the above change.

cd command
cd output followed by pwd output

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.

cd with ls command
cd and ls command

As I can see the practice folder in my Desktop using ls command. Now I want to enter in practice folder. So

cd practice 

This time practice has p in lowercase.

and checking with pwd command:

cd ls pwd commands
checking working directory using pwd command

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:

cd ..

So I did that for two times and Now i am back to my /home/bkguru folder

cd command to come back
cd to come back to directory

Lets go back to practice folder directly using direct path.

cd Desktop/practice

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.

cd command with direct path
using cd to long path

Now lets come back using cd ../.. directly to our username folder. first two dots .. take one step back and ../.. takes two step back directly.

cd ../..
cd direct back command
using cd to come back twice in directory

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

 cd ~
cd command to take to home directory
cd command to take back to home directory

4. mkdir command

mkdir command means “make directory”. This command allows us to make a new folder in our present working directory.

Usage:

mkdir new_folder_name

Let’s create a new folder name “my_folder” in Desktop.

First navigate your working directory to Desktop using cd command.

cd Desktop

Now we are in Desktop, lets create a folder using mkdir command

mkdir my_folder

This creates a folder. You can check new folder through your default file browser or check using ls command.

mkdir command
mkdir creates new folder

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'
mkdir command
Two folder created using mkdir command

You can see those two folders in file browser also.

nautilus file explorer
showing two folders

5. rmdir command

rmdir means remove the directory. This command allows us to remove the specified folders of the current working directory.

Usage:

rmdir folderName_to_remove

let’s remove two folders created above using mkdir command

rmdir my_folder
rmdir 'my_folder'
rmdir command
rmdir command to remove directory

This command 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
mkdir with parent option
mkdir with -p option

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 rmdir command.

rmdir to remove non empty folder
rmdir us unable to remove nonempty directory

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.

Share this post:

Leave a Comment

Your email address will not be published. Required fields are marked *