How to use the rm Command to Remove Directory In Linux
The rm command in Linux is a powerful tool for deleting files and directories. When it comes to removing a directory, the -r (recursive) option is crucial. This ensures that the directory and its contents are deleted.
Syntax:
rm [options] [file or directory name]
The different rm
command options include:
- –
f
: Forces the removal of all files or directories. -i
: Prompts for confirmation before removing.-I
: Prompts once before removing more than three files or when removing recursively.-r
: Removes directories and their content recursively.-d
: Removes empty directories.-v
: Provides a verbose output.--help
: Displays the 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.
Step 2: Navigate to the Parent Directory Use the cd command to navigate to the parent directory containing the target directory.
cd /home/kali/Documents/
Step 3: Remove the Directory To remove the directory and its contents, use the rm command with the -r (recursive) option.
rm -r w3wiki
Step 4: Confirm Removal If you want to confirm each deletion, you can add the -i option to prompt for confirmation.
rm -ri directory_name
So using the rmdir command, we can delete the directory of our system. As you can see in the image, initially, when we created the directory, it was in our system. However, after the deletion, it was not shown in our file directories, and the file was successfully deleted.
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
Contact Us