使用Shell脚本检查相同文件名的文件比较文件内容的一致性

该shell脚本定义了一个getdir函数,用于遍历两个指定目录$root_dir和$comm_dir中的文件和子目录。它使用find命令找到所有文件,然后对每个文件对执行Linux的diff工具进行比较。根据diff的返回值,脚本判断文件是否相同、不同或存在错误。
摘要由CSDN通过智能技术生成

compare是自定义的比较工具,可以更换成Linux操作系统自带的diff工具
Shell脚本如下

#!/bin/bash
 
function getdir()
{
	for element1 in `find $1`  
	do  
		for element2 in `find $2`
		do
			#首先判断对象是目录还是文件
			if [ -d $element1 ]||[ -d $element2 ];
			then
				#是目录
				echo "Is a Directory!"
			else
				#是文件
				echo $element1
				echo $element2
				./compare $element1 $element2
				RESULT=$?
				if [ "$RESULT" == 3 ];
				then
					echo "file is different"
				elif [ "$RESULT" == 2 ];
				then 
					echo "file is same"
				elif [ "$RESULT" == 255 ];
				then
					echo "has something wrong"
				fi
			fi
	    done
    done
}
root_dir="/home/zzl/compareFile-main/hello"
comm_dir="/home/zzl/compareFile-main/bye"
getdir $root_dir $comm_dir #函数传参
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值