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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33160790/article/details/76040027
#!/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的文件夹存放文件

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页