Remove directory or delete directory using rmdir command.

 

Remove directory or delete directory using rmdir command.

 

Using the rmdir command to delete empty directory or remove empty directory from the Linux system.

 

Remove directory.

 

The rmdir command usually use to delete or remove empty directory in the Linux system, there is several program or command that have the ability to remove or delete directory form Linux system.  This article show the step by step using 'rmdir' command to remove or delete empty directory from the Linux Fedora Core system.

 

Remove or delete empty directory.

 

The rmdir without any options can be use to delete only a empty directory. Step shown below remove empty directory from the system

 

1.  Before we can delete or remove a directory we need to create the directory first, or we can use the available directory in the system (not recommended).  To be save, create empty directory name 'directory_example' directory with 'mkdir' command.

 

[melinda@fedora ~]$ mkdir directory_example

 

2. Verify directory creation using ls command.

 

[melinda@fedora ~]$ ls -l

total 4

drwxr-xr-x 2 melinda melinda 4096 Apr 7 05:15 directory_example

[melinda@fedora ~]$

 

3. Using the rmdir command to delete the empty directory.

 

[melinda@fedora ~]$ rmdir directory_example/

[melinda@fedora ~]$

 

or using the rmdir with option -v for verbose output.

 

[melinda@fedora ~]$ rmdir -v directory_example

rmdir: removing directory, directory_example

[melinda@fedora ~]$

 

Delete the empty directory tree.

 

You can use the rmdir command to delete list of empty directory include with their parents directory.

 

1. Create empty directory using mkdir command with option -p.

 

[melinda@fedora ~]$ mkdir -p list/of/empty/directory

 

2. Verify the empty directory list using 'tree' command.

 

[melinda@fedora ~]$ tree list

list

`-- of

    `-- empty

        `-- directory

 

3 directories, 0 files

[melinda@fedora ~]$

 

3.  Test using the rmdir command to delete the 'list' directory.

 

[melinda@fedora ~]$ rmdir -p list

rmdir: list: Directory not empty

[melinda@fedora ~]$

 

Note: The execution of rmdir fail because the 'list' directory contain other directory ( directory 'of', 'empty' and 'directory').

 

4.  Now using the same command above; but now try using the 'tab' key for command completion till you get the same command shown in the example below.

 

[melinda@fedora ~]$ rmdir -p list/of/empty/directory/

[melinda@fedora ~]$

 

or using the 'rmdir' with -pv option.

 

[melinda@fedora ~]$ rmdir -pv list/of/empty/directory/

rmdir: removing directory, list/of/empty/directory/

rmdir: removing directory, list/of/empty

rmdir: removing directory, list/of

rmdir: removing directory, list

[melinda@fedora ~]$

 

Getting help on 'rmdir' command:

[melinda@fedora ~]$ info rmdir

[melinda@fedora ~]$ rmdir --help

[melinda@fedora ~]$ man rmdir

 

Related:

Using rm command to remove file and directory.

Make new directory with mkdir command.

 

Keywords: remove directory, delete directory, rmdir, rmdir command, delete empty directory, remove empty directory, linux rmdir command.

 

aaaaaaaaaaa