How to Force Remove a Directory in Linux (rm -rf Examples)

Updated Sep 2026 · originally published Jan 2021 · Tested on Linux, Unix, macOS

Advertisement

To force remove a directory in Linux, including one that is not empty, use rm -rf:

rm -rf /path/to/directory

The -r flag removes the directory and everything inside it recursively. The -f flag forces the removal without prompting for confirmation. That single command is what most people are looking for. The rest of this page explains what it does, the safer variations, and when to reach for rmdir instead.

rmdir vs rm -rf

There are two commands for removing directories, and they do different jobs.

rmdir removes empty directories only. If the directory has any file or subdirectory inside it, rmdir refuses and reports “Directory not empty.”

rm -rf removes a directory and all of its contents. This is what you need for a directory that is not empty.

rmdir emptydir          # works only if emptydir is empty
rm -rf fulldir          # removes fulldir and everything in it

What the flags mean

rm on its own only removes files, and it will not touch a directory. The flags change that:

  • -r (recursive) lets rm descend into a directory and remove it along with all its subdirectories and files. This is required to remove any directory, even an empty one.
  • -f (force) skips the confirmation prompts and ignores “no such file” errors. Without it, rm may ask you to confirm each deletion.

Combined as rm -rf, they force-remove a directory and its entire contents in one step, no prompts.

Examples

Remove a directory and everything under it, including the directory itself:

rm -rf /home/james/logs

Empty a directory but keep the directory itself:

rm -rf /home/james/logs/*

Remove several directories at once:

rm -rf dir1 dir2 dir3

Do it safely

On Linux and Unix, rm does not move files to a trash or recycle bin. A deleted file is gone and can only be restored from a backup. A few habits prevent disaster:

  • Check the path before you press Enter, especially with wildcards. rm -rf /home/james /logs (note the stray space) is very different from rm -rf /home/james/logs.
  • Use -i when unsure. rm -ri dirname prompts before each deletion, which is a useful safety net on important paths.
  • Use -v to see what is happening. The verbose flag prints each file as it is removed, so you can confirm you are deleting the right thing.
rm -rvf /home/james/logs     # force-remove, but print everything it deletes

Quick reference

CommandWhat it does
rmdir dirRemove dir only if it is empty
rm -rf dirForce-remove dir and all its contents
rm -rf dir/*Empty dir but keep the directory
rm -ri dirRecursively remove, prompting for each item
rm -rvf dirForce-remove and print what is deleted
Advertisement