Working with Directories in Ubuntu

In this article, we would discuss basic command-line utilities like cd, pwd and mkdir. These three command-line utilities do make our life easier while working with Directories in Ubuntu.

Here, we will just scratch the surface. In-detailed explanations for cd, pwd and mkdir in coming articles.

So, we start with cd

I. cd command-line utility – It is shell built-in command. It is used to change working directories. For instance,

if we want to move to root directory, use the following command –

cd /

or, if we want to move one level up –

cd ..

That means, if we were in /home/xyz directory. Then, above command will get us to /home directory.

If we would like to move back to the previous directory –

cd -

If we moved to /home directory in earlier example. Now, we want to move back to /home/xyz directory then, use the above command.

To navigate between directories, for instance – if we want to move to /media/xyz/test then, directly use –

cd /media/xyz/test

II. pwd – It basically prints the name of the current working directory. Continuing with the previous example, if we have moved to /media/xyz/test then using pwd command-line utility prints the name of the directory.


This will get us the output –


III. mkdir – The utility is used to make directories. So, if you would like to make a directory in current working directory then,

mkdir directory1

This will make a directory1/

Now, let’s say we want to make nested directories then, use -p option. For instance,

mkdir -p 2/3/4

This will make a directory 2/ in the current directory then, inside the directory 2/ it will make directory 3/. Similarly, things move ahead with 4/ directory and so on. As we can see, the command can make nested directories in no time.

In conclusion, we got aware of where we are at present in the hierarchy structure through pwd. We can create directories using mkdir. And, navigate through them using cd command-line utility.

Additional Info –

We discussed above how to make directories. But, what if we want to remove one then, use rmdir. For instance,

Continuing with the above example. If we want to remove 2/3/4 directory. Then,

rmdir 2/3/4

This will remove 4/ directory.

What if we want to remove all the three directories 2/3/4 then,

rmdir -p 2/3/4

This will remove all three directories.

Word of Caution – When removing directories, just make sure the directory is not useful to you anymore. Also, there are directories which are required by our Ubuntu distribution. Deleting those directories would harm our distribution’s configuration.

Similar Posts