开发者

How to compare first N bytes of binary files in Linux

I have two binary files with different sizes. I need to compare first N bytes of these files in Linux. I expect that the result is either "yes" (the same) o开发者_开发知识库r "no" (not the same), not byte-to-byte comparing. The N may vary from KBs to GBs.

Currently I'm using the following approach:

head -c N input1.dat | rdiff signature >1.sig
head -c N input2.dat | rdiff signature >2.sig
diff 1.sig 2.sig

But I'm wondering if there is another approach, more simple. Thanks.


Try cmp:

cmp -n <bytes> file1 file2

From the man page: exit status is 0 if inputs are the same, 1 if different, 2 if trouble.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜