UNIX: Recursive Delete Directory / Files

How do I delete (remove) a directory called $HOME/foo and its content including all files and sub-directories under Unix like operating systems? What is the best way to completely delete /tmp/foo/ with all it’s content?

You need to use the rm command line utility to remove the files (and directories) specified on the command line. The following command will delete everything including subdires and file from the $HOME/foo directory. So be careful. You will not able to recover files or sub-dirs from the $HOME/foo directory. You have been warned. In order to delete directories, it is necessary to use the -r or -R option. This option recursively removes directories and their contents in the argument list passed to the rm command. The user is normally prompted for removal of any write-protected files in the directories unless the -f option is used by the end user. The syntax is as follows:

rm -rf /path/to/dir
rm -rf $HOME/foo/
rm -rfi $HOME/foo/


  1. -r or -R : Attempt to remove the file hierarchy rooted in $HOME/foo/ i.e. delete all directory’s contents including all files and sub-dirs.
  2. -f : Attempt to remove the files without prompting for confirmation, regardless of the file’s permissions.
  3. -i : Request confirmation before attempting to remove each file, regardless of the file’s permissions
See also

For more information, see the rm command man page by typing the following command:
$ man rm

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts