4 ms·
> I bet you've never accidentally rm -rf'ed your home directory or your email archives either. If this is a concern to mitigate, consider adding the following
by AdieuToLogic 1y ago
> I bet you've never accidentally rm -rf'ed your home directory or your email archives either.
If this is a concern to mitigate, consider adding the following alias to your preferred shell profile:
alias rm='/bin/rm -I'
This will not conflict with scripts using PATH-relative 'rm' invocations, yet will provide the desired protection from erroneous interactive use of "rm -rf".
See here[0] for details regarding the '-I' flag.
0 - https://linux.die.net/man/1/rm https://linux.die.net/man/1/rm
- porridgeraisin 1y agoI alias rm='rm -i', and then check that I'm deleting the right thing. And then redo the command with `yes | rm -r whatever`. This ends up giving me an "audit log" of what was deleted.
- kragen 1y agoThis would have helped when I `rm -rf`ed my home directory, but I was on Ultrix, whose `rm` didn't have the `-I` flag. In fact, I don't think even GNU `rm` had `-I` yet. I was in /tmp/something where I'd unpacked some software package I'd downloaded and decided was of no use, and I wanted to read netnews, so I typed rm -rf * & cd; trn Several hours later, around 3 AM, I was done reading netnews, so I exited trn. Then I remembered that there was one newsgroup I had forgotten to read, so I typed ↑↵ to run trn again, which had the effect of again running rm -rf * & cd; trn but this time in my home directory. And of course my frantic ^C^C^C had no effect on the `rm`, which was safely in the background. Fortunately the computer center kept nightly backups.