16

When I do - CD .. instead of cd ..
it gives me error saying -

CD: command not found

Why is the terminal case sensitive when it comes to linux commands? I mean you should be able to execute the command either with "all uppercase" or "all lowercase" characters.

I know it is due to some reason, but I am just curious.

4
  • 10
    I almost feel like this question should be re-titled Why are things case-sensitive? Commented Jan 4, 2013 at 17:02
  • 16
    "I mean you should be able to execute the command either with "all uppercase" or "all lowercase" characters." Really? Why? Commented Jan 4, 2013 at 21:50
  • 5
    Issue a stty iuclc olcuc if you feel like having a case insensitive terminal ;-) Commented Jan 5, 2013 at 17:07
  • 1
    CapsLock + c + d + CapsLock is worse than c + d Commented May 7, 2016 at 13:01

6 Answers 6

45

Ultimately, it was an arbitrary choice made by the creators of Unix over four decades ago now. They could have chosen to make things case-insensitive like the creators of MS-DOS did a decade later, but that has its disadvantages, too.

It's too deeply embedded in *ix culture to change now. The case sensitive filesystem issue brought up by eppesuig is only part of it. macOS systems — which are Unix-based — typically have case-insensitive (but case-preserving) file systems, so on such systems commands external to the shell are in fact treated case-insensitively. But, builtins like cd remain case-sensitive.

Even with a case-insensitive filesystem, the history of things conspires against your wishes, Hussain. If I type ls on my Mac, I get a colorized directory listing. If I type LS instead, /bin/ls still runs, but the listing isn't colorized because the alias that adds the -C flag is case-sensitive.

Best just get used to it. If you can, learn to like it.

2
  • 1
    Actually Windows filenames can be case-sensitive. They are in the POSIX subsystem for example and see msdn.microsoft.com/en-us/library/ee681827%28v=vs.85%29.aspx Commented Jan 4, 2013 at 13:45
  • 4
    It's actually surprising since some common terminals available at the time were in uppercase only and they had to implement a workaround (put a backslash before a letter if you want it to be really uppercase - enabled if you typed your username in all uppercase when you logged in) in the line discipline driver. Commented Jan 4, 2013 at 14:06
9

This is not a "terminal" problem, it is a file system feature. How should the shell look for your commands on the (always case sensitive) file system?

10
  • 1
    The only option that may help you a little bit is a bash option called cdspell: it try to find the correct file name even if you tiped it wrong, but it is only working for command arguments. Commented Jan 4, 2013 at 11:44
  • 1
    @HussainTamboli There might be commands named cd, CD, cD and Cd each with a unique behavior. Commented Jan 4, 2013 at 12:04
  • 8
    It's not really a file system feature or a terminal feature – it's a shell feature. Shell builtins will be case-sensitive on a case insensitive filesystem. Also, most shells hash commands, so commands are never really files, they're actually drawn from a hash. Try hash -p /bin/hostname HOSTNAME and now HOSTNAME is the command for /bin/hostname. Commented Jan 4, 2013 at 16:57
  • 2
    Oh, I should also mention you can tell most shells to be less case-sensitive. For bash, you can bind set completion-ignore-case on. Commented Jan 4, 2013 at 17:06
  • 1
    What an earth are you on about? For example macOS's filesystem is case insenstive, but the built-in bash it still case sensitive on it. Commented Mar 28, 2020 at 12:59
6

The technical systems that I use and respect are almost exclusively case-sensitive: be it OS or programming language or anything else.

The exceptions I could think of right now is the HTML tags and some implementations of SQL, and the Ada programming language.

Even in those cases, I think there are strong tendencies to actually write HTML tags in lowercase, and the SQL query semantics in uppercase (and parameters capitalized). (Correct me if I'm wrong.) As for Ada, the Emacs mode will correct you if you for example type a lowercase procedure name, although that won't matter when compiling. So, even when there is case-insensitiveness, it seems people agree it's a bad idea.

The reason is that you get much more expressive power with case-sensitiveness. Not only quantitatively - CD is one, but CD, Cd, cD, and cd are four - but more importantly, you can express purpose, emphasis, etc. using upper- and lowercase sensibly; also, when programming, you'll enhance readability.

Intuitively, it is clear that you don't read hi and HI the same way!

But, to give you a computer world example, in the programming language Ada (from the 1980s), the first line of a procedure code block could look like this:

procedure body P(SCB : in out Semaphore_Control_Block) is

as you see, the procedure and parameter names are capitalized, as are datatypes, everything else is lowercase. Also note that the "all uppercase" parameter name tells us that it is an acronym. Now, compare this to

procedure body p(scb : in out semaphore_control_block) is

This is possible, as Ada is case-insensitive (or, to be exact, the compiler will change it to the way in my first example, but of course won't change your code). Or, how about:

PROCedure body P(Scb : IN Out semaphore_CONTROL_BLOCK) iS

That one is a bit ridiculous, I know; but someone would be stupid enough to write it that way (well, perhaps not). Point is, a case sensitive system will not only force people to be consistent, they will also be helped by it (readability) and use it to their advantage (the acronym example above).

3
  • 2
    Pascal and Delphi are also case insensitive. Also, having for example two variables length and Length is usually a bad idea:) Commented Jan 4, 2013 at 16:27
  • @Ajasja: That's interesting, because Ada is a lot like Pascal. Well, I guess if you counted them all, there would be tons of such languages, because there are so many programming languages. As for length, of course - but you could possibly think of some such case: what about Max (a person), and max (a function that takes a list of reals, and returns the biggest)? Commented Jan 4, 2013 at 17:16
  • Regarding your last example, you might be interested to know that the QL's SuperBasic interpreter capitalised keywords in exactly that way: DEFine PROCedure Hello, for example. You only had to type the capitalised bits, but the full word appeared in program listings. This applied to REMark, too, and wasn't that annoying... Commented Apr 26, 2014 at 20:34
4

It's no more or less strange than the fact that we have an upper and lower case alphabet to start with. If you look in /usr/bin, you'll notice a (very) few executables exploit capitalization.

A case sensitive namespace is not just twice as big as an insensitive one -- the difference grows exponentially with word length. Eg, using 26 characters, there are 26^3 (17576) different possibilities in three letters; using 52 (2 * 26) characters there are 52^3=140608. An open namespace is a good thing ;)

2
  • Where did you get the 3 from? Commented Apr 18, 2018 at 9:47
  • @ctrl-alt-delor It's just an example: "there are 26^3 (17576) different possibilities in three letters". Commented Apr 18, 2018 at 13:39
2

The concept of "upper/lower" case can be (and is indeed) a locale specific thing, which, as any other design complication should be pushed as close to the usage point as possible in the application stack, not be a part of the core.

Having case sensitive environment allows to wrap it into case insensitive environment, but not other way around.

1

It is not the terminal, it is the file-system. Or in the case of cd (cd is a shell built in) the shell, that is case sensitive.

It could have been possible (at least with ASCII), to make is case insensitive. This is harder with the now used unicode (whether two characters are the same, may depend on local).

What to do about it

  • Live with it.
  • Try these shell options. They give a compromise, and make things easier, without introducing all of the problems of case insensitivity.
    • shopt -s nocaseglob #this is in my ~/.bashrc
    • shopt -s nocasematch #this would also be in ~/.bashrc
    • set completion-ignore-case on #this is in my ~/.inputrc

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.