How many times rm -i asks
People usually add a safety net for rm with alias rm='rm -i' so rm asks before deleting. On a single file, that
works fine. In a directory with forty logs, rm *.log asks forty times in a row, differing only in the filename:
rm: remove regular file 'app-1.log'? y
rm: remove regular file 'app-10.log'? y
rm: remove regular file 'app-11.log'? y
…
With -r it’s worse: rm -i -r logs asks about every directory (descend into directory 'logs'?) and every file
inside. To avoid hitting y forty times, you end up running rm -f or yes | rm — losing the prompt altogether,
including when a glob matched more than you expected.
What -I does
-I prompts once per command and only for larger deletions: more than three files, or any recursive removal (-r).
The prompt states how many items are matched:
rm -I *.log
# rm: remove 40 arguments?
rm -I -r logs
# rm: remove 1 argument recursively?
If you expected three files and rm asks about forty, the glob caught too much — answer n. One to three files
without -r are deleted without asking: -I won’t catch a typo in a single filename.
Set it up
# ~/.bash_aliases
alias rm='rm -I'
Reload the file with source ~/.bash_aliases (Bash aliases). The full everyday set is in Everyday aliases.
The alias applies only where your file is loaded. In scripts, on another server, or with \rm, there is no prompt.
If it doesn’t work
rm -rf old/ deleted the directory without asking, even though ~/.bash_aliases sets rm -I
- Cause
- Among
-f,-i, and-I, the last flag wins. The alias puts-Ifirst, and your-fcomes after it and cancels the prompt. - Fix
- That’s intended:
-fmeans “don’t ask”. The safety net applies tormandrm -rwithout-f.
rm nginx.conf deleted the file without asking
- Cause
-Idoesn’t prompt for one to three files without-r— that’s the trade-off for one prompt instead of forty.- Fix
- For a file you can’t afford to lose, run
rm -i nginx.conf: the explicit-icomes after-Ifrom the alias and prompts.
How to check
type rm
# rm is aliased to `rm -I'
cd "$(mktemp -d)" && touch 1 2 3 4 && rm 1 2 3 4
# rm: remove 4 arguments?
Answer n — the files stay put.