[TAG] deleted file recovery
Ben Okopnik
ben at linuxgazette.net
Fri Oct 17 02:52:27 MSD 2008
On Thu, Oct 16, 2008 at 10:17:31PM +0200, Karl-Heinz Herrmann wrote:
>
> Hm... there is also the CLI version:
> ``
> alias rm="rm -i"
> ''
That would be the scripted version of "if you're not sure you should
delete it, then don't." Frankly, I have a certain stubborn mindset when
it comes to this: if you don't practice good data hygiene (i.e., backing
it up, *really* thinking about whether you're ever likely to need that
file ever again - not that I'm perfect at it myself...), then you
_deserve_ to suffer an occasional sharp pain for not doing so.
``
Be wary of systems that degrade gracefully, for unless they inflict some
pain in an attempt to right their hurt, they will tend to always operate
in a degraded state.
-- Kent Borg
''
> or as also stated in:
> http://forums.macosxhints.com/archive/index.php/t-9123.html
>
> ``
> del () { /bin/mv -i ${*} ~/.Trash; }
> ''
>
> and use del (reason why this can't be achieved with alias in bash is
> also given in the url).
Even if we ignore my first point, above, there are still significant
problems with this approach. It does not (easily) handle identical
filenames - in fact, it will give a highly-confusing message in that
case; it also allows ostensibly deleted files to keep taking up disk
space forever. It would take a bit more than just a simple function to
handle that.
Here's something that should address both issues (I have not done any
significant testing on this, and would certainly welcome comments):
``
#!/bin/bash
# Created by Ben Okopnik on Thu Oct 16 18:17:50 EDT 2008
[ -z "$1" ] && { printf "Usage: ${0##*/} <file_to_safely_delete>\n"; exit; }
################ User-defined variables ###########################
savedir=${HOME}/.Trash # Directory in which files are backed up #
keeptime=30 # Delete backups after this many days #
###################################################################
# Create $savedir if it doesn't exist
[ -d "$savedir" ] || mkdir "$savedir"
# Generate unique, time-stamped filename
savename="${1##*/}:`/bin/date '+%s%N'`"
# Delete file *only* if hardlink creation succeeded
/bin/ln "$1" "$savedir/$savename" && /bin/rm "$1"
# Delete any files in $savedir that are older than $keeptime
/usr/bin/find $savedir -mtime +$keeptime -delete
''
--
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
More information about the TAG
mailing list