合并脚本文件:mergedir.sh
调用:mergedir.sh dir1 dir2 (将dir1合并到dir2里边)
说明:dir2里边已经有的文件或文件夹直接跳过,不会覆盖
#!/bin/bash
source_dir=$1
dist_dir=$2
function read_dir() {
for file in `ls $1`
do
filepath=$1/$file
if test -d $filepath
then
dirname=$dist_dir/${filepath#*/}
if [ ! -e $dirname ]; then
mkdir $dirname
fi
read_dir $filepath
else
filename=$dist_dir/${filepath#*/}
if [ ! -e $filename ]; then
cp -f $filepath $filename
fi
echo $filepath
fi
done
}
read_dir $source_dir