Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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"
share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.