Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

In a terminal you can do with this command:

rm -R <directory>

or

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

or

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.

share|improve this answer

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.

share|improve this answer
    
-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

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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