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?
mv "$@" ~/.Trash/
alias del="mv -t ~/.Trash/" alias del="mv -t ~/.Trash/ ; find ~/.Trash/ -mtime +30 -exec rm {} \;" trash-put my_file.txt
[1] https://github.com/andreafrancia/trash-cliI'm not sure about the current state, but one needs to test is very carefully before using it.
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.
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.
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.
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 ;-)
garbage-io has some features that scratch my own itches:
- Trash files with the same name without clashing - Delete things from trash directory base on deletion time and file size - Hide the deleted files/directories before moving them, in case moving them takes a long time (I later think this was a bit over the top...) - The smart deletion can also be used for e.g. ~/Downloads
I do feel that a better approach would be something that works alongside the trash functionality instead of replacing it, though.
Also, '\rm', as many distributions insist on aliasing 'rm' by default.
(setq delete-by-moving-to-trash t)
to achieve the same effect.
Backups too. Nothing replaces backups.
alias rm='rm -i'
has worked for me. $ ls -l /usr/local/bin/del
lrwxrwxrwx 1 root root 13 Mar 18 12:46 /usr/local/bin/del -> /usr/games/slMy 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.
function del() {
mv “$@“ ~/.Trash
}
instead. Thanks @floatingatoll!Also, be aware this will silently delete older files with name collisions.
`brew install trash`
In 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_...
It's great for the command line, but for scripting there are much better, cleaner, faster and safer alternatives.