How to find duplicate filenames (recursively) in a given directory? BASH

前端 未结 7 788
执念已碎
执念已碎 2021-02-04 08:06

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

7条回答
  •  终归单人心
    2021-02-04 08:28

    One "find" command only:

    lst=$( find . -type f )
    echo "$lst" | rev | cut -f 1 -d/ | rev | sort -f | uniq -i | while read f; do
       names=$( echo "$lst" | grep -i -- "/$f$" )
       n=$( echo "$names" | wc -l )
       [ $n -gt 1 ] && echo -e "Duplicates found ($n):\n$names"
    done
    

提交回复
热议问题