brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: rm -I asks once before a big delete instead of for every file

Linux
~/tips/tip-linux-rm-i-capital-prompt-once

rm -I *.log

Get one sanity check before a large or recursive delete, without the endless prompts of rm -i.

rm -i asks about every single file, which is so annoying that most people never use it. GNU rm has a capital -I that asks once, and only when it matters.

rm -I *.log

The help text says it prompts once before removing more than three files, or when removing recursively. So deleting one or two files goes through without a question, while a glob that matches fifty files, or an rm -rI on a folder, gives you one prompt like rm: remove 50 arguments?. Type y to go on and anything else to stop.

That single question has the right moment. It comes exactly when a typo in a glob, or a variable that turned out empty, would do the most damage. I find it less in the way than -i, so it is something you can actually keep using.

If you want it as a habit, an alias works:

alias rm='rm -I'

Put that in your ~/.bashrc. Aliases do not apply in scripts, so your scripts keep working without prompts.

Do not treat it as a safety net. Three files go without any warning, a later -f on the command line overrides it, and once you answer y everything is gone with no trash folder. On another machine without your alias, rm asks nothing at all. It is a speed bump, not a backup.

Further reading: rm(1) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link