Are bash commands on OSX case insensitive? I type "which TR" and it shows /usr/bin/TR, though there is no such binary there. Same thing for other binaries, when capitalized. Or is Terminal.app maybe doing this translation? How do I turn this off?
5 Answers
This is actually a feature of the filesystem of your disk, not bash or Terminal.app.
HFS+ (the Mac filesystem) is usually configured to be case insensitive but case preserving. This means that the file system will consider foo and FoO to be the same, but when you create a new file it will remember which letters where capitalized and which were not.
When you format a disk with HFS+ you can chose whether the file system should case sensitive or not. If you chose to format with UFS (Unix FileSystem) it is always case sensitive, AFAIK.
To check whether a disk is case sensitive, run:
diskutil info <device>
For example:
diskutil info disk0s2
Look for the Name: line. If it reads something like Mac OS Extended (Case-sensitive, Journaled) it means that it is case-sensitive. If it just reads Mac OS Extended (without the Case-sensitive) then it is only case preserving but not case sensitive.
Since macOS 10.13, the default Apple file system is now APFS which is case-insensitive but case-preserving by default. Like HFS+, it can also be formatted to be case-sensitive. To see which mode is used you now have to use:
diskutil ap list
(diskutil info <device> does not print whether an APFS slice is case-sensitive or not.)
- 3,186
-
HFS+ really is a bit of an oddity, having the ability to both recognise and ignore case at the same time. Your case preserving note was missing from my answer, and is important for a Unix based OS which would normally be expected to be case sensitive where Foo and FOO are 2 different files. I suspect the behaviour came about between Mac OS 9 HFS and Mac OS X HFS+ and the requirement to be understood by both classic and new apps etc. – stuffe Aug 17 '11 at 16:49
-
7Outside of Unix, the case preserving nature isn't so unusual. For example, NTFS is the similar: not case sensitive by default, but you can format it so it is. I also think that the case insensitive is default came via Mac OS 9, but the fact that a lot of Mac and Windows developers are lazy in this respect and don't care about correct casing makes it almost impossible to switch to case sensitive as default, it breaks lots of apps. Coming from Unix, I found it very strange at first as well. – DarkDust Aug 17 '11 at 16:57
-
I haven't gone back and looked, but I'm pretty sure Mac OS has used case-preserving (but not case-sensitive) filesystems since the original 1984 Mac (which used MFS -- Macintosh File System -- to format its 400k floppy disks) – Gordon Davisson Aug 17 '11 at 17:03
-
1I have to admit I never used Classic Mac OS, so was guessing. Either way, this is the answer, and DarkDust put it better than me so this one should be accepted I think. – stuffe Aug 17 '11 at 17:11
-
7Every version of Mac OS has been case-insensitive-but-preserving, for usability reasons. While UNIX favours precision (byte-by-byte comparisons of filenames), it can be a usability nightmare for end users who accidentally save 'Resume' and 'REsume' and then get confused when they open the wrong version and all their changes are gone. – Dan Udey Aug 17 '11 at 17:30
-
Thanks for the explanation DarkDust, very informative. Funny, I've been using OSX for years and never noticed, until yesterday I accidentally typed 'LS' and to my surprise received output I expected from 'ls'. – verboze Aug 19 '11 at 01:02
-
2On the other hand, it can also be a "usability nightmare" when typing "HEAD" at the command-line results in the program /usr/bin/head (show first lines of a file) being executed instead of /usr/local/bin/HEAD (from LWP: make an HTTP 'HEAD' request). – TML Apr 23 '13 at 17:12
-
5Thinking that for every uppercase character there is one lowercase equivalent and vice versa is typical of English speaking programmers, and is not locale-independent. I don't know what solution has been adopted for Turkish, where there is the dotted lowercase
icorresponding to the DOTTED uppercaseİ, while the dotless uppercaseIcorresponds to the DOTLESS lowercaseı, but ANY solution will be bad. And what about the Germanß, often capitalized with 2Ss? And accents that are often left out when capitalizing? And... Case sensitivity does away with all of these headaches. – Walter Tross Jun 19 '15 at 16:42 -
Just a side note. Since macOS 10.13 (High Sierra) was introduced in 2017, mac has shifted from HFS+ to Apple File System (APFS). – aafulei Jul 23 '19 at 06:56
I managed to fix this with one line by following http://blog.nickburwell.com/blog/2008/11/mac-os-x-terminal-case-insensitive-auto
echo "set completion-ignore-case On" >> ~/.inputrc
- 100,768
- 191
-
This appears to be the only answer that answers the "how can I turn this off" portion of the OP. – Chaim Eliyah Dec 15 '19 at 00:39
-
Take a look at your filesystem, as there are both case sensitive and case insensitive variations on HFS. The default is case insensitive, in which case it's not so much a case of BASH, but the underlying filesystem. You can test this by formatting a spare USB stick with the case sensitive option, and copying files over ato repeat your test, etc.
- 25,668
It's your file system thing.
I'm using APFS, it's also case insensitive but case-preserving. This post provides a good explanation about H(ierarchical)FS and APFS.
#include <sys/stat.h>
#include <iostream>
int main(int argc, char **argv) {
struct stat sb;
int ret = stat(argv[0], &sb);
std::cout << ret << std::endl;
}
output of this program using stat:
$ ./a.out ./test_dir/cat.png
0
$ ./a.out ./test_dir/caT.png
0
a simple bash test
$ cp cat.png caT.png
cp: caT.png and cat.png are identical (not copied).
As for bash, I believe it's also case insensitive on Mac OS if you are using the default HFS or APFS since command executable is also a file and when you type a command name, the name is used search through search PATH to find that file to be executed.
$ echo x X
x X
$ eChO x X
x X
- 100,768
- 245
Bash is definitely case sensitive.
I just typed whoami into terminal and the caps lock button was on.
I got a completely different response from WHOAMI.
I can see there is a WHOAMI command with which but I can't find it with ls.
- 147
- 11
-
8This isn't the shell being case sensitive, it's the
whoamiprogram itself. It's actually the same program asid, but it checks which name it was run as, and uses a different output (equivalent toid -un) if run under the name "whoami". That check is case sensitive. Compare the output ofid,WHOAMI,WhOaMi,WhoAmI, etc. Also, compare the output ofls -li /usr/bin/whoamivsls -li /usr/bin/WHOAMI, and note that the inode number (the first thing listed in the output) is the same -- they're two different ways of specifying the exact same file. – Gordon Davisson Apr 21 '17 at 16:57
localeand completion-ignore-case / nocaseglob – bmike Aug 17 '11 at 16:11http://article.gmane.org/gmane.linux.kernel/1853266
http://www.itworld.com/article/2868393/linus-torvalds-apples-hfs-is-probably-the-worst-file-system-ever.html January 2015
Although fixed in Git, this is an exploit waiting to happen, for Mac users who have ever installed software from some other UNIX-like case-sensitive system.
For that matter, it is probably a potential security hole for code ported from case sensitive iOS to Mac OS X.
– Krazy Glew Oct 09 '15 at 02:52