rm — delete files and folders
Command to delete files and folders. Safe use of -i, backup cleanup examples and cautions, and execution screen.
💬 "rm command"
- Concept: Short for Remove, it deletes files or folders. Linux has no Recycle Bin, so they disappear immediately.
- Output structure: On success, it prints nothing. With
-v, it shows what was deleted. - Practical recommended output: Make a habit of using
-i, which asks before deleting, rather than-f, which deletes without confirmation, to prevent accidents. - Left column: Not applicable — deletion removes exactly the target you entered.
- Right column: Not applicable — if deletion fails,
No such file or directoryis printed.
Three essential command combinations
rm file— delete a single filerm -r dir— delete a folder and its contentsrm -i file— confirm before deleting
Here are some useful options to know as well.
-fdeletes without confirmation, so be especially careful about path typos- For important files, it is safer to move them to a backup folder with
mvinstead of usingrm
💬 "Show me one way to apply it too"
Scenario: The process of cleaning up temporary files to free up disk space.
Step 1: Check the target
Check the contents of the temporary folder.
ls -al tmp/
Step 2: Delete temporary files
Delete them by selecting with a pattern.
rm -iv tmp/*.tmp
Step 3: Verify the result
Check that the folder is empty.
ls -al tmp/
Actual execution screen
This is an example screen of deleting with confirmation using rm -iv.
!rm command execution result: removed shown after deletion confirmation
Actual production server
Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/rm.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments