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

前端 未结 7 773
执念已碎
执念已碎 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:32

    #!/bin/sh
    dirname=/path/to/check
    find $dirname -type f | 
    while read vo
    do
      echo `basename "$vo"`
    done | awk '{arr[$0]++; next} END{for (i in arr){if(arr[i]>1){print i}}}  
    

提交回复
热议问题