Beginner · 7 min · practise every command in the built-in terminal

rm — Remove Files

⚠️ Warning: Linux has no Recycle Bin. Deleted files are gone permanently!

Delete a file

rm file.txt

Delete multiple files

rm file1.txt file2.txt file3.txt
rm *.txt                              # Delete all .txt files

Delete a directory

rmdir emptydirectory/       # Only works on EMPTY directories
rm -r directory/            # Delete directory and all contents

Safety flags

rm -i file.txt              # Interactive: confirm each deletion
rm -I *.txt                 # Prompt once before deleting 3+ files
rm -v file.txt              # Verbose: show what's being deleted

The dangerous command

rm -rf /     # NEVER run this — deletes everything!

-f means force (no prompts), -r means recursive.

Better practice

Before deleting, use ls to confirm what you're about to delete:

ls *.txt          # See what files match
rm *.txt          # Then delete them

Practice tasks

  1. Create a test file called deleteme.txt, then delete it
  2. Create a directory called temp, then remove it
  3. Create two files and delete them both in one command
  4. Create a directory with a file inside it, then delete the whole thing recursively

Commands in this lesson

Files & Directories