拷贝两个文件夹中不同的内容到一个文件夹

时间:2022-09-24 21:38:46
#!/bin/sh
ls $1;ls $2
num1=0;num2=0
for d1 in `ls $1`
do
num1=`expr $num1 + 1`
done
echo $1:$num1
for d2 in `ls $2`
do
num2=`expr $num2 + 1`
done
echo $2:$num2
mkdir new
#echo file in dir1 not in dir2
for f1 in `ls $1`
do
#echo $f1
i=0
for f2 in `ls $2`
do
if [ $f1 = $f2 ]
then
break 1
fi
i=`expr $i + 1`
if [ $i -eq $num2 ]
then
echo $f1
cp $1/$f1 new/$f1
fi
done
done
#echo file in dir2 not in dir1
for f2 in `ls $2`
do
#echo $f2
i=0
for f1 in `ls $1`
do
if [ $f2 = $f1 ]
then
break 1
fi
i=`expr $i + 1`
if [ $i -eq $num1 ]
then
echo $f2
cp $2/$f2 new/$f2
fi
done
done

用法:

./first.sh 文件夹1 文件夹2

会生成一个名为new的文件夹存放文件