I need to find every duplicate filenames in a given dir tree. I dont know, what dir tree user will give as a script argument, so I dont know the directory hierarchy. I tried thi
#!/bin/bash
file=`mktemp /tmp/duplicates.XXXXX` || { echo "Error creating tmp file"; exit 1; }
find $1 -type f |sort > $file
awk -F/ '{print tolower($NF)}' $file |
uniq -c|
awk '$1>1 { sub(/^[[:space:]]+[[:digit:]]+[[:space:]]+/,""); print }'|
while read line;
do grep -i "$line" $file;
done
rm $file
And it also work with spaces in filenames. Here's a simple test (the first argument is the directory):
./duplicates.sh ./test
./test/2/INC 255286
./test/INC 255286