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?
    – kojiro
    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? Jan 4, 2013 at 21:50
  • 5
    Issue a stty iuclc olcuc if you feel like having a case insensitive terminal ;-) Jan 5, 2013 at 17:07
  • 1
    CapsLock + c + d + CapsLock is worse than c + d
    – user137998
    May 7, 2016 at 13:01

8 Answers 8

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
    – fpmurphy
    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.
    – Random832
    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.
    – eppesuig
    Jan 4, 2013 at 11:44
  • 1
    @HussainTamboli There might be commands named cd, CD, cD and Cd each with a unique behavior.
    – scai
    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.
    – kojiro
    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.
    – kojiro
    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.
    – ruohola
    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:)
    – Ajasja
    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)? 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... 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? Apr 18, 2018 at 9:47
  • @ctrl-alt-delor It's just an example: "there are 26^3 (17576) different possibilities in three letters".
    – goldilocks
    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
-2

As a starting point, the reason this question was asked, and the reason you will find much discussion on it if you Google the subject, is that case sensitivity makes it harder for "normal" people to learn and use a programming language or command line interface.

Case sensitivity has its origins in the low power of computers in the past. To make things case insensitive required one additional parsing operation before the command was fed to the interpreter or to a compiler before its execution and early designers were not prepared to waste the computer's power for the convenience of case sensitivity.

I believe there are a number of incorrect assertions in the comments made above. Firstly, psychologists will tell you that humans don't automatically discriminate between a word written in upper or lower case letters or even a combination of the two in terms of the word's meaning. Case is used in normal expressive languages to convey an additional meaning. For example, the use of a capital letter starting a word in a sentence, indicates it is most probably a proper noun. Capital letters are also used to give prose structure. For example, a capital letter, is used to indicate the beginning of a sentence. But "Word" and "word" are viewed by the human mind as meaning the same.

The creators of DOS and of ADA and Pascal, to name a few, appreciated that case sensitivity was an additional burden on the beginner. Later, text editors in "Integrated Development Environments" (IDEs), recognising a reserve word, could recast that word such that it was consistent with style anyway; plus display it in a different colour to make the word stand out. So the argument that case sensitivity makes for more readable code is fallacious. It doesn't to "normal" people. It simply adds an unnecessary and sometimes confusing layer to an already demanding task.

Java is an extreme example of a very poor language from the point of view of ease of use by a beginner. It enforces strict case sensitivity but, stupidly, will allow the programmer to have two functions, both with the same name, but which are actually different functions by virtue of the fact one has a different set of arguments to the other. Indeed, Java is such an abortion of a language that when universities moved from teaching Pascal syntax to students, undertaking non-computer science courses, the pass rate fell from around 70% to 40%.

So, in summary, case sensitivity came about for two reasons. One was lack of computer power. The second was that people who find their way into computer science are often on the autistic spectrum and don't relate well to the needs of "normal" people. As a consequence, these people cannot appreciate that case sensitivity is both unnecessary and an impediment to learning and using a programming language.

4
  • 1
    I would remove the section on Java because it is, imho, opinion-based and besides the point (method overloading has little to do with case-sensitivity) ... method/function overloading is found in other languages as well, such as C++ and pl/sql to name but two. As for your psychology paragraph, I think sources would be nice ... Finally, the last paragraph is, imho, opinion-based as well and offensive and should be removed.
    – thecarpy
    Mar 29, 2018 at 16:11
  • To give you a better understanding of why C and all of the languages that have been spawned from it have done damage to the cause of computer science, please go to;linkedin.com/pulse/… The core of this problem, or should I say kernel :-) , is that programmers are of a personality type not concerned about spreading knowledge but about getting a job done. If you disagree with what has been said in this post then please put forward an argument to substantiate your posits. Opinions count for little. Mar 31, 2018 at 10:26
  • I agree that case sensitivity makes learning harder. But note that almost everything in Unix is lower case, so keep it that way. A major exception is environment variables are conventionally all capitals. May 18, 2018 at 15:05
  • Case should be used consistently, and as said in this answer to convey extra information e.g. environment variable vs normal shell variable. May 18, 2018 at 15:08
-3

Case sensitivity is a silly idea that came about because Unix writers did not understand that ASCII is designed to be readily case insensitive. One simply ignores the leading bits. Ascii is a 7 bit coding with capital A at bit value decimal 65 1000001 and a at bit decimal 97 1100001. with the letters following alphabetically. This generated all sorts of ideas such as all keys in key value pairs should be numeric to avoid Slippers being different to slippers. Pick Multi-Value database realised this from the beginning and is case insensitive.

1
  • 2
    "Silly" is your opinion. There's very little factual in this answer that I can see. Oh, and why restrict yourself to ASCII. There was EBCDIC too. May 22, 2018 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .