3

I have an image file, and I know there's another copy of it somewhere in a directory or one of its ancestors, but it has a different, unknown file name, and there are thousands of images in this directory.

How can I find the file name of the image that's the same as the one I do know?

2 Answers 2

5

First, find all files with the exact same file size, then do a binary compare.

s=$(stat -c "%s" $file)    #File size in bytes
for i in $(find $dir -size "${s}c"); do    #by default, find expects sizes in blocks
  if cmp "$i" "$file"; then
    echo "$file and $i identical"
  fi
done
3

Use bgrep. Open the known image in a hex editor and copy some arbitrary chunk in the middle. Suppose that chunk is "21310441125161320581C113F071B122". Then use bgrep to search the directory for that chunk:

bgrep 21310441125161320581C113F071B122 images_directory

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .