rm: Remove Files
When a file is no longer needed, the rm command (remove) deletes it.
rm old-notes.txt
The file is gone immediately. Run ls to confirm it disappeared.
A serious warning
There is no recycle bin in the terminal. rm does not move files to trash. It
destroys them permanently. There is no "undo".
So before you press Enter, always read your command twice. A good habit is to ls
first and make sure you are deleting exactly what you mean to.
Deleting several files
rm accepts multiple names:
rm log1.txt log2.txt log3.txt
Asking before each delete: rm -i
The -i option (interactive) makes rm ask for confirmation before removing each
file:
rm -i important.txt
rm: remove regular file 'important.txt'?
You type y to confirm or n to cancel. For beginners, rm -i is a safe habit when
deleting anything you are unsure about.
Mission: Purge Junk Data
A routine maintenance scan flagged leftover junk cluttering the station workspace. Before you delete anything, secure the one file that matters. There is no undo for rm.
- Create a
keepfolder and copymission.txtinto it as a safety backup. - Review the workspace before deleting anything.
- Delete the three junk files
junk.txt,temp.logandcache.tmpin a single command.
Expected result
The junk files are gone, mission.txt is still in your home directory, and a safety copy sits in keep.