Monday, June 18, 2007

Speaking of backing up before editing...

This is my favorite new shell script. I wrote it myself, but after reading many people's suggestions and documentation. I use it when I am going to edit configuration files. I have a directory called "setting-backup" that I store the copies in. Each file is given its original name plus the date and time, all the way down to the second. That way, if you can make several changes in a minute, you can save a copy between each change. For most people this would probably be more useful for documents. The script:
#!/bin/bash
# script=bk
#parameter $1 is the existing file name
#dt=`date +%y%m%d`
#mv $1 $1$dt
cp $1 ~/computer/setting-backup/
`basename $1`-`date +%Y-%m-%d_%H.%M.%S`

#usage: bk.sh myfile
#must be run from directory of original file
#produces myfile070602

No comments: