Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 3 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"
  fi
done
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.