The rm -i command stands for interactive removal.
Normally, when you run rm, Linux deletes the file immediately without saying a word. The -i flag adds a safety layer by asking for your permission before the deletion happens.
How it works:
- You type the command:
rm -i filename.txt - The terminal will pause and display a prompt like:
rm: remove regular empty file 'filename.txt'? - You must provide an answer:
- Type
y(for yes) and press Enter: The file is deleted. - Type
n(for no) and press Enter: The file is not deleted.
- Type
Why use it?
- Prevent Accidental Deletion: It gives you one last second to think, "Wait, is this the right file?"
- Safeguard Wildcards: If you use it with a wildcard (like
rm -i *.txt), it will ask you about every single file one by one. This is very helpful if you want to delete most files in a folder but keep a specific few.
In short, rm -i is the "Are you sure?" button for the Linux command line!