Table of Contents
- mkdir
- cd
- rmdir
- 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.
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:
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
- There are several interesting topics for you to explore, such as absolute path", relative path, or the rules for creating file names in Linux, among others. I highly recommend checking out an article titled Linux Directory Structure ↗ by New Mexico State University.
- This post is part of the series called A Linux Crash Course for Absolute Beginners