undo rm -rf *
Bill Davidsen
davidsen at tmr.com
Sat Mar 30 03:02:39 UTC 2013
Celik wrote:
>
>
> On Tue, Mar 26, 2013 at 11:57 PM, jarmo <oh1mrr at nic.fi <mailto:oh1mrr at nic.fi>>
> wrote:
>
> Tue, 26 Mar 2013 22:23:29 +1100
> Celik <celik.n.00 at gmail.com <mailto:celik.n.00 at gmail.com>> kirjoitti:
>
> > Hi,
> >
> > Had a logic error in my bash script and did "rm -rf *" on my current
> > working directory. Any tips for undoing such an error?
> >
> > Regards,
> > C
>
> Just try to find your BACKUP :))
>
>
> Very funny :))) Didn't have a backup... :))) ohh dear laughing at lost work...:)))
> Seems like I need pickup new skills on making "proper/better" backups
>
> Thanks for making me laugh...much appreciated :)))
>
Actually better skills at scripting might be job one, use of "rm -rf" is ALWAYS
dangerous, I suggest putting temporary stuff in a subdir using the process id,
and deleting that at the end. If you miss you don't delete anything.
MyWk=joe-$$-$RANDOM
mkdir ${MyWk} || exit 2
# do stuff
rm -rf ${MyWk}
I would qualify that as "less unsafe" rather than idiot proof, but using both
the process id and a random number does avoid reusing a name. Note that if the
mkdir fails the script bails out immediately. Belt and suspenders programming.
--
Bill Davidsen <davidsen at tmr.com>
"We have more to fear from the bungling of the incompetent than from
the machinations of the wicked." - from Slashdot
More information about the users
mailing list