If you want a customized rm
, don't call it rm
but a name of yours, myrm
, delete
or whatever.
The rm='rm -i'
alias is an horror because after a while using it, you will expect rm
to prompt you by default before removing files. Of course, one day you'll run it with an account that hasn't that alias set and before you understand what's going on, it is too late.
In any case, a good way to be prepared for file loss or corruption is doing backups.
A fast alternative that will protect you against accidental file deletion or overwriting is using a file system that support unlimited snapshots like ZFS. If frequent snapshots are done automatically, you can recover the files at the state they were during the last snapshot before the incident.
7Not that I don't have sympathy, but I don't think
rm
is a dangerous command requiring an alias for safety. By using ther
andf
options, you're telling the shell I know this is dangerous, and I've thought carefully about it, and it's really what I want to do. If you don't use those options, you can't delete your entire home folder with it. – user26512 – 2012-01-25T17:40:51.830Does this question cover the same information as http://stackoverflow.com/questions/373156/what-is-the-safest-way-to-empty-a-directory-in-nix?
– David Harris – 2012-01-25T17:43:44.170@grossvogel it happened to me once in 5+ years in which I use Linux and the terminal every day. – None – 2012-01-25T17:47:31.713
@puller: Sorry, I wasn't trying to say you're a bad linux user. Just that the design of
rm
is already quite good, in that it already has safety checks, and only becomes overly destructive when you disable them. – user26512 – 2012-01-25T17:52:29.2231@grossvogel no offense taken :)! However, aliasing this command is a common practice. A lot of people use the -f option to avoid confirming each deletion. – None – 2012-01-25T17:58:46.793
24Note that if you use an alias for
rm
you will get used to that alias. Then one day, you'll be on a system where the alias doesn't exist, and you'll do the wrong thing when you are least expecting it. And it probably won't be your system. – Stefan Lasiewski – 2012-01-25T19:41:02.790Good times if it's not your system. Assuming you can outrun them. – Sirex – 2012-01-27T10:34:40.797
2@puller Only on systems like RHEL that stupidly alias
rm
torm -i
. – Daniel Beck – 2013-07-21T09:03:34.107