2

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

3 Answers 3

2

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
0

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.

0

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .