1 #!/bin/sh 2 #create by lizr 2016-01-15 3 #脚本功能 4 #覆盖文件前先备份 5 cfsuffix=$(date +%Y-%m-%d); #备份文件后缀 6 if [ $# -lt 2 ]; then #输入参数说明 7 echo "error...need args" 8 echo "eg:path1 path2" 9 echo "path1 files backup and copy to path2" 10 exit 1 11 else 12 path1=$1; 13 path2=$2; 14 if [ [ -d "$path1" ] && [ -d "$path2" ] ]; then 15 ls $path1 | awk -F‘[ ]‘ ‘{print $1}‘ | while read filename 16 do 17 if [ -f $filename ]; then 18 sfile = $path1‘/‘$filename; #源文件 19 pfile = $path2‘/‘$filename; #需备份文件 20 cfile = $path2‘/‘$filename‘.‘$cfsuffix; #备份后文件 21 if [ -f $pfile ]; then 22 cp pfile cfile && a=1 || a=0; 23 if [ $a -eq 1 ]; then 24 echo $filename "backup success!"; 25 cp $sfile $path2; 26 else 27 echo $filename "backup error!" 28 fi 29 else 30 echo $pfile "not find"; 31 cp $sfile $path2; 32 fi 33 fi 34 done 35 else 36 echo "error...args path not find!"; 37 fi 38 fi
原文:http://www.cnblogs.com/lzr-rr/p/5132765.html