Home » Why is the root directory denoted by a / sign?

Why is the root directory denoted by a / sign?


The forward slash / is the delimiting character which separates directories in paths in Unix-like operating systems. This character seems to have been chosen sometime in the 1970’s, and according to anecdotal sources, the reasons might be related to that the predecessor to Unix, the Multics operating system, used the > character as path separator, but the designers of Unix had already reserved the characters > and < to signify I/O redirection on the shell command line well before they had a multi-level file system. So when the time came to design the filesystem, they had to find another character to signify pathname element separation.

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 ~ character to represent the home directory originates, the / key is next to the > key:

keyboard layout of the Lear-Siegler ADM-3A terminal

As for why the root directory is denoted by a single /, it is a convention most likely influenced by the fact that the root directory is the top-level directory of the directory hierarchy, and while other directories may be beneath it, there usually isn’t a reason to refer to anything outside the root directory. Similarly the directory entry itself has no name, because it’s the boundary of the visible directory tree.

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 P is the path to a directory and F is the name of a file, then P>F is the syntax for the file called F inside the directory whose path is P.

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, foo is a file in the working directory; foo>bar is a file in the child directory foo of the working directory, and so on. These rules describe relative paths, but a supplementary rule is needed to build absolute paths starting from the root directory. Given that reading a path name from left to right corresponds to moving from the root to the leaves of the tree, the root should be indicated by a special marker at the left of the path name. Since file names are never empty (because that would often be confusing), no relative path name ever starts with the character >, which makes it a convenient marker for absolute path names. Thus >foo is the file called foo in the root directory, >foo>bar is the file called bar in the directory called foo in the root directory, and so on. This leaves the root directory, which could be the empty string; however, it’s often not convenient to use the empty string as a pathname, so instead it gets written >, which has the added benefit that a pathname is absolute if and only if its first character is >.

Unix adopted this design from Multics. Since Unix had already used the character > for output redirection in its command shell, its designers chose a different character / to separate directories in path names.

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:

  • navigate to the root directory, and consume the slash character.
  • if there is more material in the path, then process it it as a relative path, otherwise you’re done.

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 ed editor only display a ? when you do something wrong?) The slash is easy to type, requiring no shift. A path language with only two token types (component and slash) is easy to remember and use.

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:


NEW_PATH="$NEW_HOME$OLD_PATH"  /new/home/old/path

This would not work if we indicated absolute paths in some other way, like a leading dollar sign or whatever else:

OLD_PATH=^old/path  # ^ means absolute path

# now we need more string kung-fu than just catenation

This type of coding is still needed in some cases when dealing with Unix-style paths, but there is less of it.

Related Solutions

Joining bash arguments into single string with spaces

[*] I believe that this does what you want. It will put all the arguments in one string, separated by spaces, with single quotes around all: str="'$*'" $* produces all the scripts arguments separated by the first character of $IFS which, by default, is a space....

AddTransient, AddScoped and AddSingleton Services Differences

TL;DR Transient objects are always different; a new instance is provided to every controller and every service. Scoped objects are the same within a request, but different across different requests. Singleton objects are the same for every object and every...

How to download package not install it with apt-get command?

Use --download-only: sudo apt-get install --download-only pppoe This will download pppoe and any dependencies you need, and place them in /var/cache/apt/archives. That way a subsequent apt-get install pppoe will be able to complete without any extra downloads....

What defines the maximum size for a command single argument?

Answers Definitely not a bug. The parameter which defines the maximum size for one argument is MAX_ARG_STRLEN. There is no documentation for this parameter other than the comments in binfmts.h: /* * These are the maximum length and maximum number of strings...

Bulk rename, change prefix

I'd say the simplest it to just use the rename command which is common on many Linux distributions. There are two common versions of this command so check its man page to find which one you have: ## rename from Perl (common in Debian systems -- Ubuntu, Mint,...

Output from ls has newlines but displays on a single line. Why?

When you pipe the output, ls acts differently. This fact is hidden away in the info documentation: If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is...

mv: Move file only if destination does not exist

mv -vn file1 file2. This command will do what you want. You can skip -v if you want. -v makes it verbose - mv will tell you that it moved file if it moves it(useful, since there is possibility that file will not be moved) -n moves only if file2 does not exist....

Is it possible to store and query JSON in SQLite?

SQLite 3.9 introduced a new extension (JSON1) that allows you to easily work with JSON data . Also, it introduced support for indexes on expressions, which (in my understanding) should allow you to define indexes on your JSON data as well. PostgreSQL has some...

Combining tail && journalctl

You could use: journalctl -u service-name -f -f, --follow Show only the most recent journal entries, and continuously print new entries as they are appended to the journal. Here I've added "service-name" to distinguish this answer from others; you substitute...

how can shellshock be exploited over SSH?

One example where this can be exploited is on servers with an authorized_keys forced command. When adding an entry to ~/.ssh/authorized_keys, you can prefix the line with command="foo" to force foo to be run any time that ssh public key is used. With this...

Why doesn’t the tilde (~) expand inside double quotes?

The reason, because inside double quotes, tilde ~ has no special meaning, it's treated as literal. POSIX defines Double-Quotes as: Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the...

What is GNU Info for?

GNU Info was designed to offer documentation that was comprehensive, hyperlinked, and possible to output to multiple formats. Man pages were available, and they were great at providing printed output. However, they were designed such that each man page had a...

Set systemd service to execute after fstab mount

a CIFS network location is mounted via /etc/fstab to /mnt/ on boot-up. No, it is not. Get this right, and the rest falls into place naturally. The mount is handled by a (generated) systemd mount unit that will be named something like mnt-wibble.mount. You can...

Merge two video clips into one, placing them next to each other

To be honest, using the accepted answer resulted in a lot of dropped frames for me. However, using the hstack filter_complex produced perfectly fluid output: ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4 ffmpeg -i input1.mp4 -i input2.mp4...

How portable are /dev/stdin, /dev/stdout and /dev/stderr?

It's been available on Linux back into its prehistory. It is not POSIX, although many actual shells (including AT&T ksh and bash) will simulate it if it's not present in the OS; note that this simulation only works at the shell level (i.e. redirection or...

How can I increase the number of inodes in an ext4 filesystem?

It seems that you have a lot more files than normal expectation. I don't know whether there is a solution to change the inode table size dynamically. I'm afraid that you need to back-up your data, and create new filesystem, and restore your data. To create new...

Why doesn’t cp have a progress bar like wget?

The tradition in unix tools is to display messages only if something goes wrong. I think this is both for design and practical reasons. The design is intended to make it obvious when something goes wrong: you get an error message, and it's not drowned in...