Why was '~' chosen to represent the home directory?

  • I have often wondered why the ~ (tilde) represents the home directory of a user. Is there a reason behind this, or is it just some infrequently used character?

    WARNING! Never do this `mkdir '~'` because you *will* forget escaping this `rm -rf ~` (worst day ever)!

    That is why you should use `rmdir`.

  • pbm

    pbm Correct answer

    9 years ago

    Quoting Wikipedia:

    On Unix-like operating systems (including BSD, GNU/Linux and Mac OS X), tilde often indicates the current user's home directory: for example, if the current user's home directory is /home/bloggsj, then cd, cd ~, cd /home/bloggsj or cd $HOME are equivalent. This practice derives from the Lear-Siegler ADM-3A terminal in common use during the 1970s, which happened to have the tilde symbol and the word "Home" (for moving the cursor to the upper left) on the same key.

    layout of the ADM-3A keyboard

    You can find photos of the Lear-Siegler ADM-3A keyboard on this site.

    image of an ADM-3A keyboard

    This terminal is also the source of the movement commands used in the vi editor: h, j, k, l for left, down, up, right.

    I have also read this is why `Esc` is used to switch modes in `vi`, since the key is easy to reach on this type of keyboard.

    Reading this answer, I just realised why GMail's shortcuts also use 'J' and 'K' for move to previous email and move to next email, respectively!

    How neat would it be to have a keyboard like this!

    @ThomasAhle if your keyboard uses Cherry-MX keys then you can do this quite easily. See also this reddit thread on cherry-mx-vim-keyboard setups.

    Incidentally, what is the `HERE IS` key for?

    I'm not sure if it is relevant: `Some teleprinters had a "Here is" key, which transmitted a fixed sequence 20 or 22 characters [...] This was commonly used to identify a station; the operator could press the key to send the station identifier to the other end`. Source: http://en.wikipedia.org/wiki/Teleprinter#.22Here_is.22_key

    That's exactly what the "HERE IS" key is for; it would be useful when many terminals share a serial line to the computer. On the ADM-3A, it was an optional addon board for the RAM to store the identification in. Source: http://vt100.net/lsi/adm3a-om/adm3a-om.pdf

    The next question is why the home key selected to have tilde on it. :)

    And you could really edit fast in Vi on an adm3a. Vim users, it's where it all cameo from....

    @JustinEthier: like many vim users, I always tweak my settings in order to make "CapsLock" behave like "ESC" ("ScrollLock" is a good candidate for the "CapsLock" funcions).

    The "resting point" and "I-know-where-I-am-without-looking-at-the-keyboard point" for my index finger of the right is the `j` key. This is probably why this moving scheme has always been such a pain to learn for me.

    another interresting tidbit: hjkl : look at the shape of those letters: 'j' has a bit going underneath the line ("goes down"), 'k' has a bit going above the line ("goes up"), and 'l' (L) has a big going to the right. Easy way to remember each letter's respective direction. And then "h" is the symetrical of "l" around the "hj" axis... [it does help to remember the motions, trust me ^^]. I believe that's why those letters were used for the "left,down,up,right" directions.

    Is this also the reason why in RegEx, "^" is the start of a string?

    @olivier, that is post-facto reasoning. You can't see these features on the keyboard's capital letters anyway. They are the four adjacent home-row letters under the right hand, that's why the arrows are there. Other "classic" keyboards like the VT52 used them this way as well, iirc. (Of course, using I/K for Up/Down, and J/L for right/left, as many console games did, is ergonomically far more convenient.)

    @alexis, How would you know it's not pre-facto?

    @Pacerier, because the QWERTY keyboard layout is about a hundred years older than CRT screens and arrow keys!

    @jogloran Yeah, 'Here is' was unusual to see. But have you seen 'RUB' & 'REPEAT' at the bottom? What is 'RUB'?

    @AlexStragies RUB is short for RUBOUT, which was what the Delete key was called on many keyboards of the time.

    @JustinEthier according to image on Wikipedia Esc was where nowadays Tab usually is. (I'm considering remapping this in my Vim...)

    If you happened to notice a strange influx of upvotes today, it's because you've been featured on Hacker News for the third time: https://hn.algolia.com/?query=why%20was%20chosen%20home%20directory&;sort=byPopularity&prefix&page=0&dateRange=all&type=story

    Where is the 'any' key? :-)

    @alexis yes no one in there right mind would invent something as poorly optimised as querty for a CRT (or LCD/OLED/etc) display. Now that we don't have mechanical linkages between keys and printer, there is no need for it. (`',.pyf`)

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM