Hacker News new | ask | show | jobs
by capableweb 1641 days ago
Regarding `rm`, I usually have something like this setup in my bashrc/zshrc:

    rm () {
        mv "$@" ~/.trash
    }
So any time I use rm, it actually just moves it to ~/.trash instead. Not fool-proof nor perfect, but have saved me at least once so found it to be good enough for now.
3 comments

You might want to add a slash at the end of "trash", or add a mkdir before that command. Otherwise, doing this on a system where ~/.trash doesn't exist can still make you lose files after multiple deletions.
I use the `can` command. It does something similar. Personally, I find a separate command to be better so that I treat rm with kid gloves on new systems. https://github.com/joshvoigts/can
I'd be afraid of relying too much on this only to, at some point, be on a server or user that doesn't have this and accidentally deleting something too early.

Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

> Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

But this would defeat the original purpose, i.e. the prevention of someone accidentally using rm.

Not necessarily. If you get used to using `delete` all the time, that is most likely what you would use on the server too. Once you trip over it missing, you are reminded that you are in dangerous territory.
There are many assumptions here. I manage several servers, but many of these are co-managed. Second, it is not foolproof - muscle memory is very strong and for sure sooner or later I'll type rm again. Third, it doesn't prevents the use of rm in scripts.

That said, an accidental removal of files has never been a problem for me (an accidental chmod -R caused me more woes once), and these days with snapshots it's a complete non issue.

If you get used to using a different command, you won't use `rm` accidentally
Sure, but in the context of the present thread I'd have to wait until the history file gets rotated - which will never happen on the systems I manage.
just grep through your history file and delete lines containing `rm` easy fix