[NBLUG/talk] Finding duplicate files

Lincoln Peters lincoln_peters at hotmail.com
Sun Jul 6 23:01:01 PDT 2003


Is there an easy way to do a recursive search for duplicate files, 
preferably from the shell?  The best I've come up with is:

#!/bin/sh
for file1 in *
do
	for file2 in *
	do
                if [ "$file1" != "$file2" ] && [ ! -d "$file1" ] && \
		   [ ! -d "$file2" ] && [ "$file1" != - ] && [ "$file2" != - ]
                then
                        cmp -- "$file1" "$file2" &> /dev/null && \
                                echo "$file1 and $file2 are identical" && \
                                # do what must be done...
                fi
        done
done

Of course, this doesn't work recursively (I tried using `find`, but it 
didn't handle filenames with spaces properly), and it ends up performing 
every comparison twice.  Is there a more efficient way I could do this?



Lincoln

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.  
http://join.msn.com/?page=features/virus




More information about the talk mailing list