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.
You can find photos of the Lear-Siegler ADM-3A keyboard on this site.
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 doubt you are going to find as interesting an answer as to the tilde question!
I was not there, but .. is like an ellipsis (...), which makes sense in contexts like cd ../../../there
. Also, and especially looking at ye olde terminal keyboard from the tilde case, there are not many eligible characters for this purpose. You don't need to shift for .
, either. It's perfect.
The fact that a dot prefix is used for hidden files might be another reason. Hidden files are not listed by default by tools such as ls
, so neither are the essentially redundant .
and ..
. Redundant in the sense that there is no point considering them along with other files -- they are certainly useful otherwise.
As it turns out I may have it backwards...from wikipedia:
The notion that filenames preceded by a '.' should be hidden is the
result of a software bug in the early days of Unix. When the special
'.' and '..' directory entries were added to the filesystem, it was
decided that the ls command should not display them. However, the ls
program was mistakenly written to exclude any file whose name started
with a '.', rather than only files named '.' or '..'.
This does turn out to be useful when programming; since the system does include . and .. in response to readdir()
type commands (and shell globs), ignoring them and hidden files can be accomplished the same way.
A different opinion about that use value is in the reference for the wikipedia quote. Of course, the whole story could be apocryphal...it is a little hard to believe that eg, Dennis Ritchie figured just checking for the first character would be okay.
I disagree with the author vis, it would be better to put hidden configuration files in their own directory rather than give them a universal prefix. The prefix is much more flexible, allowing for in-tree directives like .gitignore
and .htaccess
. Witness that files of that sort also appear together when sorted lexicographically -- so perhaps this was on purpose after all.
Best Answer
The earliest mentioning of the dot command that I can find is in the manual for Stephen Bourne's
sh
shell in Unix Release 7 (it may be older, but not evidently present as one of the built-in commands insh
in Release 6).The dot, in quite general terms, seems to have been associated with "here" or "current". The
.
directory is the current directory, and the.
address in theadb
debugger from the same release of Unix had a.
address which was the current address. Likewise, entering a.
followed by newline in theed
editor will re-display the current line of the editing buffer (.
addresses the current line). The dot also means the current node in certain structured query languages for XML, JSON, YAML, etc. (although these are later inventions).It is therefore, I think, not too far fetched to speculate that the
.
command in the shell also means "here" or "current". In particular, "run this script in the current environment."The dot is also quite quick and easy to type, and having a short command for doing a common task (whether it be in
ed
,adb
or in the shell) may have been another reason why another longer name was not used.Note that I don't have a functioning version of
sh
from Release 7 to test things in, and that I can't find the actual implementation of.
in Bourne's shell from that release in the above-mentioned Git repository, so I can't say for sure that it actually did exactly what it does today. But it's likely that it did.