How to delete files and folders

Overview

Terminal deletion normally bypasses the desktop Trash. rm removes files, while rmdir removes empty directories.

Examples

rm old-note.txt
rm -i *.tmp
rmdir empty-folder
rm -r old-project

Options

  • -i asks before each removal
  • -I asks once before a large or recursive removal
  • -r descends through a directory tree
  • -f forces removal and suppresses many warnings
  • -- ends options before a name beginning with a dash

Critical safety

Do not use rm -rf casually. It combines recursive deletion with forced, non-interactive behavior and can erase a mistyped path immediately.

Check pwd, preview with ls, use exact names, and avoid sudo rm -rf. Keep backups of important data.