On Tue, Jan 23, 2007 at 11:25:21AM -0900, Ken Irving wrote: > On Tue, Jan 23, 2007 at 11:32:31AM -0800, Andrew Sackville-West wrote: > > On Tue, Jan 23, 2007 at 02:06:02PM -0500, Tony Heal wrote: > > > OK, how about some preventative stuff. If there is not real way to > > > 'undelete' files. How about adding a script named 'rm' that passes the > > > same > > > switches to from the script to /bin/rm but moves the files to tmp before > > > deleting them. > > > > I don't have one, but it would be trivial to write a bash script that > > takes an rm <arglist> <target> and turns it into a mv <target> > > /tmp/trash. simply alias rm to that script in bashrc et al. or, if you > > wanted system-wide "Trashing" you could mv the rm binary out of the > > way and symlink to your script. the implications of that could be huge > > though. > > Something like this *might* work, but is off-the-cuff, not tested: > > $ cat ~/bin/rm2trash > #!/bin/sh > TRASH=~/.trash > for f in $*; do > echo TEST of $0: > echo cp -pf "$f" "$TRASH/$f" > echo rm "$f" > done > ... make it executable, alias the rm command to run it, e.g., > > $ chmod +x ~/bin/rm2trash > $ alias rm=rm2trash
sorta works but bombs if .trash doesn't exist, or if rm switches are used (eg. -rf). hows this [EMAIL PROTECTED]:~$ cat rm2trash #!/bin/bash TRASH=~/.trash if [ ! -e $TRASH ]; then mkdir $TRASH fi for f in $*; do if [ -e $f ]; then cp -pf "$f" "$TRASH/$f" rm "$f" else echo $f does not exist, skipping. fi done > > A real danger in using this sort of crutch is that you'll get nailed if > you rely on it, assume it's there, and then end up using the native rm > without knowing it. The same goes for alias rm='rm -i'. > > IMHO the best approach is to realize the nature of the system you're > working with, learn to use the native commands, and set up a decent > backup system. you are correct sir! A
signature.asc
Description: Digital signature