判断两个文件在Unix/Linux中是否具有相同内容的最快方法? [英] Fastest way to tell if two files have the same contents in Unix/Linux?

查看:327
本文介绍了判断两个文件在Unix/Linux中是否具有相同内容的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Shell脚本,在其中需要检查两个文件是否包含相同的数据.我对大量文件执行此操作,并且在我的脚本中,diff命令似乎是性能瓶颈.

I have a shell script in which I need to check whether two files contain the same data or not. I do this a for a lot of files, and in my script the diff command seems to be the performance bottleneck.

以下是这行:

diff -q $dst $new > /dev/null

if ($status) then ...

是否可以有一种比较快速的方法来比较文件,也许是自定义算法而不是默认的diff?

Could there be a faster way to compare the files, maybe a custom algorithm instead of the default diff?

推荐答案

我相信cmp会在第一个字节差处停止:

I believe cmp will stop at the first byte difference:

cmp --silent $old $new || echo "files are different"

这篇关于判断两个文件在Unix/Linux中是否具有相同内容的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆