Linux rmdir Not Empty Directories

The rmdir command is used to remove directories. Also, the rm command can be used to remove files and folders too. But the rmdir command should be used only for the empty directories. If the rmdir command is used for the non-empty directories the rmdir: failed to remove 'nmap': Directory not empty error is returned.

Remove Non-Empty Directories

The rmdir: failed to remove 'nmap': Directory not empty error can be solved by using the rm command. The -r option is provided to remove files and directories recursively. The -f option is used to force removal.

$ rm -r -f nmap

Remove Non-Empty Directories Verbosely

While removing the non-empty directories we may want to list removed or deleted directories verbosely. The -v option is provided which lists all removed directories.

$ rm -r -f -v nmap
Linux rmdir Not Empty Directories

Remove Non-Empty Directories Interactively

By default, all directories are removed without any confirmation. If there are some directories we do not want to remove the interactive option -i can be used. The -i option is used to approve every directory and file removal interactively.

$ rm -r -f -i nmap

See also  Delete Non-Empty Directory In Linux - "rmdir directory not empty" Solution

Leave a Comment