MacOS – Search file duplicates in OSX by hash

filemacossearchspotlight

I am looking for a way to search for a determinate file in OSX (Maverick but more generally OSX).
In particular I would like to do the following:
given a File_001 I'd like to search if in the filesystem exists a copy of this file.
Not just with the same name, I would like the comparison method to be an hashing algorithm like MD5, SHA etc..

Most of the "duplicate file finder" I have tried just search for all the duplicates in a drive/system. I would, instead, be interested in submitting one file and search for its duplicates.

Does anyone know if such a program exists? Maybe some obscure function of Spotlight?

Best Answer

You might also use fdupes. It doesn't have an option to search for duplicates of a specific file, but you can just grep the output for the filename:

fdupes -r1 .|grep filename

-r recurses into directories and -1 prints each group of duplicate files on a single line.

Other useful examples:

fdupes -r . finds all duplicate files under the current directory;

fdupes -r . -dN deletes all except the first duplicate from each group of duplicates;

fdupes -r dir1 dir2|grep dir1/|xargs rm removes duplicates in dir1.

You can install fdupes with brew install fdupes.