How do you delete all folders and files in a directory and subdirectory?
3 Answers
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>
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.
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
.