#!/bin/sh
#parameter check
# $1 is regarded as the original folder
# $2 is regarded as the latest folder
# $3 is regraded as the patch file
if [ $# -lt 3 ];then
echo "usage:$0 original_dir dest_dir patch_file"
exit -1;
fi
#variable declare
ori_dir=$1
new_dir=$2
patch_file=$3
#remove the old patch file
if [ -f ${patch_file} ];then
rm ${patch_file}
fi
#find out all the files, except symbol link
ori_files=`cd ${ori_dir}; find ./ -type f ! -type l`
for file in ${ori_files};do
if [ -f ${ori_dir}/${file} ];then
if [ -f ${new_dir}/${file} ];then
#remove the "./" symbol from the file string.
file=`echo ${file} | sed s/"./"//`
diff -uNr ${ori_dir}/${file} ${new_dir}/${file} >> ${patch_file}
fi
fi
done
2. 另外一种方法:
(1)查找某个目录下的所有符号链接文件,重定向到一个文件
(2)由于符号链接文件中包含了路径"/",所以在每一行的头和尾加上引号"
(3)使用diff命令制作patch文件,用其X参数排除符号链接文件
这样制作出来的patch文件也是不包含原始目录下symbolic link文件
PS:patch文件的使用(以下命令中的x代表去掉patch文件中的第几个"/",0代表不去掉,1代表去掉第一个"/",以此类推)