Finding file-names that differ only by case under Unix

harry.pottash's picture

On occasion it is necessary to export a project to a file system that is not case sensitive.

In this situation if you export using SVN, the entire export (which, if from a remote server and on a large project, can often take hours) will halt and produce an error. The error will let you know which file(s) had the matching name, and the official advice is use the command "SVN mv" to rename the file, and try again.

Though this basic approach works, it's much more practical to find _all_ of the names that differ only by case first, fix them, and then run the export. The best way I have found to search for names that differ only by case is to go to the root directory of your project and run the following command:

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

Let's break that down for a little enlightenment:

"find ." invokes the find command, telling it to start in the current directory, and find _everything_, printing it out as a full path.

"|" called a "pipe" is a way of telling Unix (bash actually) to send the output of one command to the command that follows.

"tr '[:upper:]' '[:lower:]'" translates all of the upper case characters to lower case ones.

"sort", not so shockingly sorts the lines alphabetically and is necessary for the next command to work.

Switchback Caravan logo

Caravan is a powerful and full-featured membership management system, designed specifically for membership- driven organizations.

Caravan Member Managment

Switchback Trailhead logo

Trailhead is a Drupal-based system, built with the features smaller businesses need, bundled together into a ready-to-launch package.

Trailhead CMS Packages

On the Trail Blog