How to compare parts of files by hash?
Solution 1:
Creating hashes to compare files makes sense if you compare one file against many, or when comparing many files against each other.
It does not make sense when comparing two files only once: The effort to compute the hashes is at least as high as walking over the files and comparing them directly.
An efficient file comparison tool is cmp
:
cmp --bytes $((100 * 1024 * 1024)) file1 file2 && echo "File fragments are identical"
You can also combine it with dd
to compare arbitrary parts (not necessarily from the beginning) of two files, e.g.:
cmp \
<(dd if=file1 bs=100M count=1 skip=1 2>/dev/null) \
<(dd if=file2 bs=100M count=1 skip=1 2>/dev/null) \
&& echo "File fragments are identical"
Solution 2:
I am sorry I can't exactly try that, but this way will work
dd if=yourfile.zip of=first100mb1.dat bs=100M count=1
dd if=yourotherfile.zip of=first100mb2.dat bs=100M count=1
This will get you the first 100 Megabyte of both files.
Now get the hashes:
sha256sum first100mb1.dat && sha256sum first100mb2.dat
You can also run it directly:
dd if=yourfile.zip bs=100M count=1 | sha256sum
dd if=yourotherfile.zip bs=100M count=1 | sha256sum