Recently I was made aware of a little gotcha in the Mac file system. And that is file names on a Mac OS are case preserving, yet case insensitive.
What this means is that the cases are preserved in the file name, but when accessing the file, the name you use to identify the file is not case sensitive.
For example if you have a file named MyFile.txt. The cases in that file name is preserved. However when you want to access the file, you can call the filename as MyFile.txt or MYFILE.txt or Myfile.txt and in the mac, it will all reference the same file.
So you can do something like this.
$ echo "Hello World" > MyFile.txt $ cat MyFile.txt Hello World $ cat Myfile.txt Hello World $ echo "Hello Again" >> myfile.txt $ cat MyFile.txt Hello World Hello Again $ ls MyFile.txt
So Where’s the Gotcha?
The gotcha lies mainly when you use the file in two different file systems and one of them uses case sensitive file names.
For example if you are writing Java code in a Mac but your build server run on Linux. You might be working on a file called MyClass.java but when you initially created the file, it was called Myclass.java. However because MyClass.java would reference the same file as Myclass.java, you weren’t aware of it until the class gets compiled on Linux.
Another example is you might have a script which executes another script or make references to other files. The file naming case sensitively on the Mac might bite you when you try to run that same script on a different operating system.
How do I work around this?
From what I have read, the case insensitive file system is actually a good thing on the Mac as for those who decided to reformat their hard drives to have a case insensitive file system, they seem to be complaining about a whole bunch of problems, mainly from programs not running as they can’t find files. You could also argue that it’s a bad thing as it resulted in programs being written with complete disregard for case sensitivity in the file name.
So it seems like the best way to work around this is to use caution when creating files when working on a Mac. And I guess if you have a build server running on Linux, as long as you have good tests, that will help you verify that your program/scripts will work in a case-insensitive file system.