#! /bin/sh # Script to create backup copies of specified files. # by Chuck Anderson, Colorado State University, January 2005. # Example: # > backup *.cpp # Created the following BACKUP files: # BACKUP/arr2.cpp.2005-01-25-14-51-36 # BACKUP/arr.cpp.2005-01-25-14-51-36 # BACKUP now contains 2 files ## Create subdirectory BACKUP if it does not exist yet. if [ ! -d BACKUP ]; then echo " Creating BACKUP directory." mkdir BACKUP chmod go-rwx BACKUP fi ## For each file specified as command line arguments... echo " Created the following BACKUP files:" for file in "$@" do if [ -f $file ] then ## ...copy into BACKUP dir with same filename appended by date and time newname=$file.`date +"%F-%H-%M-%S"` cp $file BACKUP/$newname chmod go-rwx BACKUP/$newname ls BACKUP/$newname fi done echo " BACKUP now contains " `ls -1 BACKUP | wc -l` " files"