How to use the rmdir Command to Remove Directory In Linux
In this section, we will explore the detailed steps to remove the directory in Linux by using the rmdir inbuilt command.
Syntax:
rmdir [options] [directory name]
The rmdir
command includes the following options:
--ignore-fail-on-non-empty
: Doesn’t show an error message when trying to remove a non-empty directory.-p
: Removes the directory along with its parent in the hierarchy.-v
: Provides a verbose output.--help
: Displays help text.--version
: Displays the command version.
Step 1: Firstly, open your Linux system and open the terminal. You will see an interface like this, as shown in the image below.
hostnamectl
Step 2: After that Before establishing a new directory, use the pwd command to determine where you are in the filesystem.
pwd
Step 3: Now, before going to delete any directory on the Linux system, we first have to create a new directory to perform the task using the below command. Check its options and available parameters.
mkdir --help
Step 4: Now we have to use the above command and create the one directory name as ‘w3wiki‘ then we see how to delete it.
mkdir w3wiki
Step 5: To check if the directory w3wiki was created on your system or not, use the ls command and check it.
ls
We will navigate to the w3wiki directory and view its contents.
cd w3wiki
ls
Step 6: Remove the Directory to remove the directory and its contents, use the rmdir command.
rmdir w3wiki
How to Remove Directory in Linux
In Linux, a Directory is a container for files and other directories, forming a hierarchical structure. so, before deep diving into the directory, let’s learn about the Linux Directory. A directory is a structure that plays an important role in the file system, offering users a systematic way to navigate and structure their data. In the Linux System Directories are essential for maintaining order and providing a clear path for accessing files. Directories enable users to categorize related files, making it easier to locate and manage them. The directory structure follows a tree-like hierarchy, with the root directory at the top, branching into subdirectories, and further dividing into files. Users can traverse through directories using commands like “cd” (change directory) in the Linux terminal.
How to Remove Directory in Linux?
- Method 1: Using the rmdir Command to Remove Directory
- Method 2: Using the rm Command to Remove Directory