Deletion deserves more care than creation or copying. Graphical desktops often use a trash folder, while command-line rm normally has no equivalent recovery step. Check the current directory, target path, and filename first.
Remove files with rm
rm notes.txt removes a regular file and normally prints nothing on success. You can specify multiple targets, but larger scope deserves an ls check first. rm -i notes.txt prompts before deletion and is a useful learning habit.
rm file Remove one regular file.
rm -i file Prompt before removing each target.
rmdir empty-dir Remove an empty directory; refuse a non-empty one.
rm -r directory Recursively remove a directory and all its contents.
Empty directories and recursive deletion
rmdir old-folder only removes an empty directory, preventing an unexpected tree deletion. A non-empty directory needs rm -r old-project; -r descends into files and subdirectories.
Why rm -rf should not be your default
-f means force and reduces prompts and some errors. It appears in automation, but a wrong path can cause extensive damage. Absolute paths still need checking; inspect the same target with ls first.
Wildcards widen the scope
rm *.log removes every matching log in the current directory. A wrong directory or broader-than-expected match can delete the wrong data. Preview the match first.
Deletion safety line: confirm location → preview the same target with ls → inspect wildcard scope → prefer interactive confirmation → verify backups.
Preview Before Deleting
Simulated terminal ready. Run commands and watch the filesystem on the right.
/homealicearchivebackupcachedataindex.bin
DocumentsDownloadsemptyPicturesprojectsrcREADME.md
.bashrc.profileaccess.logapp.logdraft.txterror.lognotes.txt
varlogsyslog
Quick buttons fill the prompt; run the command or press Enter to change terminal and filesystem state.KNOWLEDGE QUIZ
KNOWLEDGE QUIZ
Plan a Cache Cleanup
You are in /home/alice/app. Remove the entire tmp/ tree, the empty old/ directory, and all *.log files here. Write a “check first, delete second” sequence without -f.
- Confirm location with pwd and preview all three targets separately.
- Use interactive confirmation for logs and the more restrictive command for the empty directory.