I there a way to find all files in a directory with duplicate filenames, regardless of the casing (upper-case and/or lower-case)?
|
If you have GNU utilities (or at least a set that can deal with zero-terminated lines) available, another answer has a great method:
Note: the output will have zero-terminated strings; the tool you use to further process it should be able to handle that. In the absence of tools that deal with zero-terminated lines, or if you want to make sure your code works in environments where such tools are not available, you need a small script:
What is this madness? See this answer for an explanation of the techniques that make this safe for crazy filenames. |
|||||||||||||||
|
|
Sort the list of file names in a case-insensitive way and print duplicates.
Portably, to print all elements in each set of duplicates, assuming that no file name contains a newline:
If you need to accommodate file names containing newlines, go for Perl or Python. Note that you may need to tweak the output, or better do your further processing in the same language, as the sample code below uses newlines to separate names in its own output.
Here's a pure zsh solution. It's a bit verbose, as there's no built-in way to keep the duplicate elements in an array or glob result.
|
|||
|
|
|
There are many complicated answers above, this seems simpler and quicker than all of them:
If you want to find duplicate file names in subdirectories then you need to compare just the file name, not the whole path:
Edit: Shawn J. Goff has pointed out that this will fail if you have filenames with newline characters. If you're using GNU utilities, you can make these work too:
The |
|||||||
|
|
Without GNU
|
|||||||||
|
|
I finally managed it this way:
I used |
|||
|
|