Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
I guess you mean "different case" (not "different font size")? –  phunehehe Aug 3 '13 at 13:13
    
Duh, capitalization, I couldn't figure out what he was asking. –  slm Aug 3 '13 at 14:01
    
@gasko-peter are you looking for files with similar names because you're trying to identify the same file with a different names? –  Evan Carroll Aug 5 '13 at 0:44
add comment

3 Answers

up vote 2 down vote accepted

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).

share|improve this answer
    
You probably want sort -f here. Also note that GNU uniq has the same limitation as GNU tr as in it doesn't work for matching case of multi-byte characters. –  Stephane Chazelas Aug 3 '13 at 22:55
    
@StephaneChazelas why do I want sort -f? If uniq can deal with the case, why would I also need to make sort case insensitive? And what do you mean by multi-byte characters? Things like \n,\r etc? How can they have different cases? –  terdon Aug 4 '13 at 0:19
1  
Try export LC_ALL=C; printf '%s\n' a A b B | sort | uniq -di. Some locales sort case-insensitively, some others (like C) don't. uniq needs a sorted input, its duplicate lines must be adjacent. –  Stephane Chazelas Aug 4 '13 at 7:25
    
@StephaneChazelas I see, thanks. –  terdon Aug 4 '13 at 17:48
add comment

Assuming file names don't contain newline characters, you could do something like:

find . | tr '[:upper:]' '[:lower:]' | sort | uniq -d

Note that some tr implementations like GNU tr don't change the case of multi-byte characters.

Also note that the path it reports may not be the paths of any file. For instance, if there's a ./a/b/fOo and a ./A/b/fOo file, it will report ./a/b/foo. If it's not what you want, you may want to refine your requirements.

share|improve this answer
add comment

All of these ideas are bad. Use checksums and be sure the files are the same. Then the task becomes easy.

find . -type f -exec md5sum {} + |
sort |
perl -a -nE'push(@{$db{$F[0]}},$F[1]);END{for(keys%db){say"Dupe detected @{@db{$_}}"if scalar@{$db{$_}}>1}}'

This will sha1sum every file in the directory and all subdirectorys and output all dupes of that file, if there are any. I made the pipeline multiline for readability.

share|improve this answer
    
The OP is not looking for identical files, he's looking for files with the same name, the contents may differ. Sorry, but it is this idea that is bad :). –  terdon Aug 4 '13 at 13:58
    
His first example said different font size, suffice it to assume he doesn't have an idea of what he wants. –  Evan Carroll Aug 4 '13 at 17:25
1  
Suffice it to say that English is not his native language, hardly the OP's fault that. However, the example clearly shows that he is not comparing the files, just looking for files of the same name in a case-insensitive manner. All I'm saying is that you might want to read a question more closely before deciding which ideas are "bad". –  terdon Aug 4 '13 at 17:47
    
Agreed. This doesn't address the OP's concern. I also find it strange that you labeled an answer accepted by the OP as a bad idea because it's not what the OP wants! –  Joseph R. Aug 4 '13 at 17:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.