Find duplicate files using the terminal

Aug 28, '01 09:13:33PM

Contributed by: robg

[Submitted by victory]

The following will search the current dir (and subdirs) for any files that contain identical content and are of identical size, regardless if they are named differently. Open a terminal shell, and 'cd' to the dir you want to search, then type:

find . -size 20 \! -type d -exec cksum {} \; | sort | tee /tmp/f.tmp | 
cut -f 1,2 -d ' ' | uniq -d | grep -hif - /tmp/f.tmp > dup.txt
[Editor's note: I inserted a carriage return for readability -- type the command on one line when entering it!]

This will produce a list of duplicate files (if any) in dup.txt. True there are some nicely written apps that will do the same thing, but ain't it great that you can do this right from within your OS?

Notes:

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20010828211333805