Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am writing a script for Mac OS X Lion 10.7 and I would like to know how I can search for files based on their SHA1 hashes. I would like to search the whole file system for the file(s) I will be looking for.

For example the SHA1 value 0d882ff2d5edd7d045c1b57320d2e046793868f8 corresponds to the file MacOSXUpdCombo10.7.2.dmg How can I search the hard drive for the file with its SHA1 value without needing to compare the file?

share|improve this question
add comment

2 Answers

You can use the find command:

find / -type f -exec md5 {} \; | grep 0d882ff2d5edd7d045c1b57320d2e046793868f8

However, since you're running this on all files, it may be extremely slow — try limiting the search directory by replacing / with the path to a specific directory you want to search.

share|improve this answer
    
thanks! i was trying to search with shasum -facepalm- –  Bryan Larson Mar 28 '12 at 20:37
    
You'll need to prefix that with sudo if you want the find to reach in to areas of the file system normally off limits to regular users. –  Ian C. Mar 28 '12 at 20:54
1  
@BryanLarson if this answer solved your question you should click the check mark under the vote count on the left there to accept yet. –  Ian C. Mar 29 '12 at 19:56
add comment

You may also want to try using xargs depending on how many files you will be searching through.

find / -type f |
    xargs -I {} openssl sha1 {} | 
    grep 0d882ff2d5edd7d045c1b57320d2e046793868f8
share|improve this answer
    
openssl will still be called once per file thanks to the -I option of xargs, so there won't be any gain. –  patrix Apr 23 '12 at 20:18
    
My apologies, you are correct I have edited my original statement. –  E1Suave Apr 23 '12 at 20:30
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.