[olug] Unix Tip: SAVE A COPY
Unix Guru Universe
listserv at ugu.com
Sun Jul 13 16:36:37 UTC 2003
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2020 - July 13, 2003
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SAVE A COPY
Ever edited a file, then wished
you'd saved a copy first?
This script will save it for you.
It even handles multiple files,
and multiple edits of the same file.
############### Cut here ##########
#!/bin/ksh
# My vi : Save a backup of the file(s) to edit
for file in $* ; do
if [[ -a $file ]] ; then
basefile=`basename $file`
cp $file ~/bak/${basefile}.`date +%C%y%m%d%H%M%S`
fi
done
/usr/bin/vi $*
############### Cut here ##########
You'll need to create a directory
called 'bak' in your $HOME directory,
and it would be a good idea to set up
a cron job to clear out old copies
periodically.
This tip generously supported by:
gordon.morrison at vf.vodafone.co.uk
--------------------------------------------------------------------------
To Subscribe: http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe: http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today
==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU ADVISES THAT
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.
Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
==========================================================================
More information about the OLUG
mailing list