#!/bin/sh -

#
# finddup 1.00 - find identical files.
#
# Oleg Kibirev * April 1995 * oleg@gd.cs.CSUFresno.EDU
#
# This code is covered by General Public License, version 2 or any later
# version of your choice. You should recieve file "COPYING" which contains
# text of the license with any distribution of this program; if you don't 
# have it, a copy is available from ftp.gnu.ai.mit.edu.
#


find . -xdev -type f -printf "%p %i\n" |
sort +1 |
uniq -1 |
cut -f 1 -d ' ' |
xargs md5sum |
sort +0 -1 |
(
psum='x'
line=''
many=''
while read sum file; do
  if [ "$sum" != "$psum" ]; then
    if [ ! -z "$many" ]; then
      set x $line
      k="`du $2`"
      shift 2
      echo $k "$@"
    fi
    line="$file"
    psum="$sum"
    many=''
  else
    line="$line $file"
    many=yes
  fi
done 

if [ ! -z "$many" ]; then
  set x $line
  k="`du $2`"
  shift 2
  echo $k "$@"
fi
) | sort +0 -1 -r -n
