知道两个二进制文件是否相同(除了时间戳)最简单的方法是什么(在Ubuntu Linux上使用图形工具或命令行)?我不需要提取差值。我只需要知道它们是否相同。
当前回答
为了寻找闪存缺陷,我不得不写这个脚本,它显示所有包含差异的1K块(不仅仅是cmp -b所做的第一个)
#!/bin/sh
f1=testinput.dat
f2=testoutput.dat
size=$(stat -c%s $f1)
i=0
while [ $i -lt $size ]; do
if ! r="`cmp -n 1024 -i $i -b $f1 $f2`"; then
printf "%8x: %s\n" $i "$r"
fi
i=$(expr $i + 1024)
done
输出:
2d400: testinput.dat testoutput.dat differ: byte 3, line 1 is 200 M-^@ 240 M-
2dc00: testinput.dat testoutput.dat differ: byte 8, line 1 is 327 M-W 127 W
4d000: testinput.dat testoutput.dat differ: byte 37, line 1 is 270 M-8 260 M-0
4d400: testinput.dat testoutput.dat differ: byte 19, line 1 is 46 & 44 $
免责声明:我在5分钟内破解了脚本。它不支持命令行参数,也不支持文件名中的空格
其他回答
我最喜欢的使用xxd十六进制转储从vim包:
1)使用vimdiff (vim的一部分)
#!/bin/bash
FILE1="$1"
FILE2="$2"
vimdiff <( xxd "$FILE1" ) <( xxd "$FILE2" )
2)使用diff
#!/bin/bash
FILE1=$1
FILE2=$2
diff -W 140 -y <( xxd $FILE1 ) <( xxd $FILE2 ) | colordiff | less -R -p ' \| '
有一种相对简单的方法来检查两个二进制文件是否相同。
如果你在编程语言中使用文件输入/输出;您可以将这两个二进制文件的每一位存储到它们自己的数组中。
在这一点上,检查非常简单:
if(file1 != file2){
//do this
}else{
/do that
}
我发现Visual Binary Diff是我正在寻找的,可用的:
Ubuntu: Sudo apt安装vbindiff Arch Linux: sudo pacman -S vbindiff Mac OS X通过MacPorts: 端口安装vbindiff Mac OS X通过Homebrew: 酿造安装vbindiff
我最终使用hexdump将二进制文件转换为十六进制表示,然后在meld / kompare /任何其他diff工具中打开它们。我不像你,我要找的是文件中的差异。
hexdump tmp/Circle_24.png > tmp/hex1.txt
hexdump /tmp/Circle_24.png > tmp/hex2.txt
meld tmp/hex1.txt tmp/hex2.txt
为了寻找闪存缺陷,我不得不写这个脚本,它显示所有包含差异的1K块(不仅仅是cmp -b所做的第一个)
#!/bin/sh
f1=testinput.dat
f2=testoutput.dat
size=$(stat -c%s $f1)
i=0
while [ $i -lt $size ]; do
if ! r="`cmp -n 1024 -i $i -b $f1 $f2`"; then
printf "%8x: %s\n" $i "$r"
fi
i=$(expr $i + 1024)
done
输出:
2d400: testinput.dat testoutput.dat differ: byte 3, line 1 is 200 M-^@ 240 M-
2dc00: testinput.dat testoutput.dat differ: byte 8, line 1 is 327 M-W 127 W
4d000: testinput.dat testoutput.dat differ: byte 37, line 1 is 270 M-8 260 M-0
4d400: testinput.dat testoutput.dat differ: byte 19, line 1 is 46 & 44 $
免责声明:我在5分钟内破解了脚本。它不支持命令行参数,也不支持文件名中的空格