rm: remove files and directories

Updated November 2026

rm removes files. There is no recycle bin: once a file is removed, it is gone unless you have a backup. Read this page before you use rm -r.

rm [options] file ... rmdir directory ...

Common options

OptionMeaning
-iAsk before each removal
-IAsk once before removing more than three files or recursing (GNU)
-r, -RRemove directories and everything in them
-fForce: never ask, ignore missing files
-vShow what is removed
-dRemove empty directories (like rmdir)

Examples

rm old.txt                    # remove a file
rm -i *.bak                   # ask about each .bak file
rm -r build/                  # remove a directory tree
rmdir empty-dir               # remove an empty directory (fails if not empty: a safe check)
rm -- -oops.txt               # a name starting with "-"
rm ./-oops.txt                # the same, another way
rm "file with spaces.txt"

Be careful with rm -rf

rm -rf does not ask and cannot be undone

A space in the wrong place can be disastrous: rm -rf /tmp/build /* instead of rm -rf /tmp/build/* removes the build directory and then everything on the system. GNU rm refuses to remove / itself, but nothing stops /*.

Removing files by age, size or name across a tree

Use find, and look at the list before deleting:

find /var/tmp/app -type f -mtime +30 -print     # list files older than 30 days
find /var/tmp/app -type f -mtime +30 -delete    # then delete them

Removed but the disk is still full?

If a running program still has a file open, the space is not freed until the program closes it. Find such files with lsof +L1 (or lsof | grep deleted) and restart the program. To empty a big log file that a program is writing, truncate it instead of removing it: : > /var/log/app.log or truncate -s 0 /var/log/app.log.

Safer alternatives

On desktops, gio trash file (GNOME) or the trash-cli package moves files to the desktop's trash instead of deleting them. On servers, the real safety net is a backup and file system snapshots (btrfs, ZFS, LVM).