rm (remove) deletes files:
rm downloads/setup.tmpThere's no bin on the command line. Once rm has removed a file, it's gone. That's the whole reason for the habits below.
Directories
rmdir removes a directory, but only an empty one, which makes it the safe choice for tidying up:
rmdir empty-folderTo delete a directory and everything inside it, use rm -r (recursive):
rm -r old-projectYou'll often see rm -rf: -f (force) skips the errors and questions. Combined with a wrong name or a stray space it can delete far more than you meant, so leave -f off until you have a reason for it.
Safe habits
- Run
lswith the same name or pattern first, to see exactly what will go. - Prefer specific names to patterns, and patterns to whole directories.
- Keep a copy (
cp) of anything you can't get back.
In this practice terminal, Reset brings everything back. On a real computer, nothing does.