How do you delete all folders and files in a directory and subdirectory?


This command will remove directory and sub-directories

  rm -r directory_name

This command will remove forcely

  rm -rf directory_name

This command will remove the empty directory

  rmdir directory_name

In a terminal you can do with this command:

rm -R <directory>


sudo rm -R <directory> (if you need root privileges for that directory)

where <directory> is the directory that you want to delete.

For more specifications about rm command run:

man rm


rm --help

Otherwise, in Nautilus file manager - the default file manager in Ubuntu - select the directory that you want to delete and press Delete (to move it into Trash) or Shift+Delete (to permanently delete). Also, you can see How do I start Nautilus as root? if you need root privileges for delete that directory.


rm -r /path/to/directory

Be very careful with this command as if it is used incorrectly (with out directory argument) it can destroy your entire linux system. Be especially careful when using this command as root or with sudo. Another note, this is not completely secure and the file can be recovered with data reconstruction. If you would like to overwrite the file after it is unlinked use shred.

  • -f option is not necessary. – Radu Rădeanu May 21 '13 at 23:59
  • Ok I just looked that up, you're right. Thanks for the correction. – Qwintus May 22 '13 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.