[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: undelete



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

and *maybe* it would work.  Remove the 'echo' commands if the output
looks ok.  (Note that it would be best to store options from the command
line to pass along to the inner rm, along with other niceties.)

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.

For backups, I use and would recommend the rsnapshot package, which
uses rsync to efficiently create copies of filesystems.  This might
normally be done to a networked backup server, but can also run on a
single machine.  Lots of other schemes are available, using rsync and
otherwise.

Ken

-- 
Ken Irving, fnkci@uaf.edu



Reply to: