Directory Commands in Linux

Directory Commands in Linux

Table of Contents

  1. mkdir
  2. cd
  3. rmdir
  4. rm -r

In this article, I'll be presenting several Linux directory commands designed for directory operations.

I have a user named tux, although it might be different for you, the concepts remain the same. Let's look into tux's home folder.

Home directory of tux.
Figure 1. Home directory of tux.

1. mkdir

To begin with, the mkdir command in Linux allows you to make a directory. As illustrated in Figure 1, let's create a new directory called Notes:

$ mkdir Notes

Easy right?

Consequently, Figure 1 now appears as follows:

mkdir example

2. cd

Secondly, the cd command in Linux is used to change directories. Now, utilize the cd command to navigate or to work with the Notes directory.

$ cd Notes

3. rmdir

Furthermore, the rmdir command removes/deletes a directory.

In the meantime, I have created several directories and files within the Notes directory. For simplicity, let's attempt to remove the directory called drafts.

$ rmdir drafts

rmdir: failed to remove 'drafts/': Directory not empty

Removing this directory fails because it is not empty. Therefore, rmdir without any flags only works with an empty directory.

Nevertheless, you will be able to delete draft-2 directory:

$ rmdir draft-2

4. rm -r

Finally, rm -r directory command removes folders and their contents recursively (-r). With the -r flag, you can now remove the drafts folder, 1.txt, and 2.txt.

$ rm -r drafts

Articles recommended by the author

Leave a Reply

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


© 2024 A. Maharjan