Shell – How to find file/directory names that are the same, but with different capitalization/case

filenamesfindshell

How can I list the file/directory names in a directory recursively that are the same, but with different capitalization/case? ex.:

INPUT (not the ls command, the directories):

[user@localhost ~/a] ls -R
.:
b

./b:
ize  Ize

./b/ize:

./b/Ize:
[user@localhost ~/a] 

OUTPUT:

/b/ize

Best Answer

If you have GNU uniq, you can sort case insensitively (-i), and use -d to print only duplicate lines:

find . | sort -f | uniq -di

As @StephaneChazelas mentioned in his answer, this might not do what you expect if you can have duplicate paths that only differ in case (like a/b/foo and A/b/foo).

Related Question