I have done some research about this on Google, but the results were cloudy. Why is the
/ sign used to denote the root directory. Are there any solid reasons behind it?
|show 1 more comment|
The forward slash
A thing to note here is that in the Lear-Siegler ADM-3A terminal in common use during the 1970's, from which amongst other things the practice of using the
As for why the root directory is denoted by a single
|show 2 more comments|
The first hierarchical file system as we know it today was designed for Multics. The design is described in “A General-Purpose File System For Secondary Storage” by R.C. Daley and P.G. Neumann. A salient characteristic of this filesystem is that a directory is a file which can be contained in a directory like any other file. The file structure forms a tree, in which all of the non-leaf nodes are directories. The root of the tree is always a directory. Each file has a name (the entry name) which is unique within its parent directory. The root directory doesn't have a name since it isn't contained in another directory.
In order to designate a file, you need to describe the path from the root of the tree. Multics adopted a natural syntax for path names where if
For those times when you don't want to burden yourself with directories, Multics had a notion of working directory. A bare file name with no directory indication is interpreted as a file in the working directory.
Combining these rules,
Unix adopted this design from Multics. Since Unix had already used the character
In path name components on Unix, only two characters may not be used: the null character, which terminates strings in C (the language of the kernel) and the slash, which is reserved as the path separator. Furthermore, path components cannot be empty strings.
So, in a path name, we have only two kinds of tokens: a slash, and a component.
Suppose that, without adding any new tokens, we would like to support support two types of paths, relative and absolute. Furthermore, we would like to be able to refer to the root directory, which has no name (it has no parent which would give it a name).
How can we represent relative paths, absolute paths, and refer to the root directory, using only the slash?
The most obvious way to extend a language (other than introduction of new token) is to create new syntax: give new meaning to combinations of tokens that are invalid syntax.
Paths which begin with a slash do not make sense, so why not use a leading slash as a marker which indicates "this path is absolute, rather than relative".
A path which contains nothing but a slash is also invalid, so why not assign it the meaning "the root directory".
These two meanings tie together because an absolute path begins searching at the root directory. In other words a leading slash can be regarded as having the meaning:
Then, we might as well throw in a trailing slash, which can mean "this path asserts that the last path component is the name of a directory rather than a regular file or any other type of object: that trailing slash denotes that directory similarly to the way the leading slash denotes the root directory."
With all this above syntax, we still have syntax with an unassigned meaning: double slashes, triple slashes, and so forth.
Why not just introduce another token and do it differently. This is probably because the designers took minimalistic approaches in general. (Why does the
Another important consideration is that easy manipulations of paths are possible using only string representations. For instance, we can "re-root" absolute paths to a new parent directory quite easily:
This would not work if we indicated absolute paths in some other way, like a leading dollar sign or whatever else:
This type of coding is still needed in some cases when dealing with Unix-style paths, but there is less of it.