Stop Using `rm` in Bash. Use `del`
We’ve all had our fair share of accidentally removing files. Instead of
rm my_file.txt
or rm -rf my_folder
we do del my_file.txt
or del my_folder
where you can define your Bash alias for `del` in ~/.custom_aliases as function del() {
mv $* ~/.Trash
}
which simply moves your files/folders to the trash such that you can recover them easily later.What’s your alternative?
75 comments
[ 15.0 ms ] story [ 2085 ms ] threadIn seriousness tho, if you're ever wondering why such and such thing is not builtin into the kernel read up on separation of policy and mechanism eg:
https://en.m.wikipedia.org/wiki/Separation_of_mechanism_and_...
I'm not sure about the current state, but one needs to test is very carefully before using it.
mv "$@" ~/.Trash/
https://github.com/koalaman/shellcheck/wiki/SC2086
EDIT: See also neighbor comment about appending filenames!
And just a reminder everybody please don't run random scripts you find on the internet.
P.S. you need a semicolon before the close brace :)
Take care when entering commands, if it’s important that you don’t mess up, spend an extra second. Don’t run around shooting rm -rf as super user.
With great powers comes great responsibility.
It's much less hazardous doing this when everything is in source control, though. :)
If you’re the person in charge of making the delete operation the best and safest it can be, you do not have the luxury of yelling at users to just be more careful, because the data shows very plainly that doesn’t work (despite this being the approach most IT people seem to think is acceptable). In this role, with these constraints, the inevitable conclusion is the make a trash can.
It's great for the command line, but for scripting there are much better, cleaner, faster and safer alternatives.
(setq delete-by-moving-to-trash t)
to achieve the same effect.
My alias was for rm itself. I replaced it completely, as the habit of using rm is hard to forget. Today I don’t use an alias anymore.
When I execute rm I mean to delete. When I'm not sure I expyre[1] the path: https://github.com/lonetwin/expyre
[1] shameless plug -- but you did ask ;-)
http://hasseg.org/trash/
Backups too. Nothing replaces backups.
Personally I’m not a fan of shell environment customizations like this because they are often fragile and may vary between systems. I like to know exactly what commands I’m executing.
True. I gave up the practice entirely many years ago for a slightly different reason -- I need to use many different systems on a regular basis, and don't want to get used to using something custom that won't exist on random system X without customizing it, too.
Often, I prefer predictability and stability over convenience.
Also, '\rm', as many distributions insist on aliasing 'rm' by default.
Also, be aware this will silently delete older files with name collisions.
`brew install trash`