Unix remove directory recursively command

I am on Unix and I need to remove directory recursively. I try the rmdir command but failed to remove directory recursively on Unix. Please tell me command.

1 Like

You need to use the rm command. It will remove given directory and all its contents, including any subdirectories and files. Pass the -r option to the rm. It is called the recursive option.

Unix remove directory or folder recursively

rm -r dir
rm -r /path/to/dir/

We use the rmdir to remove an empty directory. For example:

rmdir dirNameHere
rmdir foo

Any directories and files that are removed with the rmdir/rm command cannot be recovered. Hence be careful with these two commands.


you can use this command carefully to force recursive remove directory

rm -rf /dir/path/


why -f needed ?

The -f option to the rm forces to remove given dirs or files. Always read man pages to get help futher:

rm --help
man rm
man rmdir
1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki