Skip to content

rm command

Delete files and directories.

On this page

Syntax

rm [options] file…

Provided by the coreutils package. Run man rm for the full manual.

Common options

OptionWhat it does
-rRemove directories and their contents
-fForce: no prompts, ignore missing files
-iAsk before every removal
-IAsk once before removing more than 3 files
-vPrint each file removed
-dRemove empty directories
--preserve-rootRefuse to remove / (default)

Examples

  1. Delete a file

    rm file.txt
  2. Delete several files

    rm a.txt b.txt
  3. Delete all .log files here

    rm *.log
  4. Delete a directory and everything in it

    rm -r old-project/
  5. Delete without prompts

    rm -rf build/
  6. Ask before each file

    rm -i *.conf
  7. Delete a file whose name starts with a dash

    rm -- -file.txt
  8. Too many files for one command line

    find . -name "*.tmp" -delete

Tips

  • There is no recycle bin: check paths before rm -rf.
  • Run ls with the same pattern first to see what will be deleted.

rm guides

← All Linux commands · Suggest a fix

Back to top