5 ms·
Review my idea: Preventing accidental usage /bin/rm
The problem of accidentally deleting files using rm seems to common, dangerous and painful. Like here: http://news.ycombinator.com/item?id=2661209.
I'm thinking of writing a 'replacement' utility of sorts for /bin/rm. I'll rename the existing rm command to say rmx or something and use my version of /bin/rm instead. When you type rm at the prompt, my replacement utility will actually move the files to a "Trash Can" in the file system, instead of deleting it it. And when you type, say 'rm --rm' it will by pass the Trash can and delete the file. And something like 'rm --restore [filename]' will restore the file to its original location.
This way accidental deletions are prevented. Does a utility like this exist already, so that I don't re-invent the wheel?
- lv_ 15y agoNot a bad idea. Surprised this hasn't been implements in cPanel's jailshell to be 'customer-proof'
- tmhedberg 15y agoThere is libtrash (http://pages.stern.nyu.edu/~marriaga/software/libtrash/ http://pages.stern.nyu.edu/~marriaga/software/libtrash/), which does something very similar. It adds a library to your LD_PRELOAD variable which intercepts unlink syscalls and moves deleted files to $HOME/Trash instead of actually deleting them. The nice thing about this is that it works transparently, and not just for /bin/rm, but for anything that deletes files. That's not to say it couldn't be improved upon, though.
- fagatini 15y agoOr you could just be responsible with your rm commands. Also keep good backups. As soon as I read the article it reminded me to plug in my 2tb drive and run timemachine.
- fexl 15y agoI do this sort of thing a lot, not as a formalized utility but as a practice. For example I'll often do something like this: mv data ~/tmp/ cd ~/tmp/ rm -rf data At least when I'm in the tmp directory I can see that clearly on the command line so I'm more comfortable issuing dangerous commands. I suppose there might be room for a formal utility, but sometimes you just have to be careful. Take for example my "build" script for Fexl (at https://github.com/chkoreff/Fexl/blob/master/src/build https://github.com/chkoreff/Fexl/blob/master/src/build). There you will see these lines: # I don't use $obj and $bin here because that would be dangerous if I made # a mistake setting them above. rm -rf ../obj rm -rf ../bin If I were not being so careful, I could simply say: rm -rf $obj rm -rf $bin Because after, all, the $obj and $bin variables are "guaranteed" to point to safely disposable directories. Heh. Famous last words. Redundancy is key to reliability.