File System Hierarchy
Order is very important to a computer; just as we need maps and roads to lead us to a destination, a computer needs the same things. By storing things in a hierarchal manner, the computer can know how to search for things and store them more efficiently.
For any particular file system, there is a starting point. From the starting point, we can locate files and/or directories (folders). The directories themselves can also contain more directories and files. This system of directories and files is known as a file tree. In nature, trees begin with a root and grow to leaves. In the computing world, this is the same.
Tree Vocabulary
- A tree is a widely used abstract data type that represents a hierarchical tree structure with a set of connected nodes.1
- The root of a file tree is the beginning of the file system, and all other nodes trace back to it. The only difference is that the root starts at the top and grows down from the root in a file system. In the image, the node labeled “A” is the root of the system.
- Nodes can, but are not required to, have child nodes (a node connected below another node). Above, nodes B, C and D are all child nodes of A.
- Nodes that have child nodes are known as parent nodes. A is the parent node of B, C, and D.
- Leaf nodes are nodes which have no children. C is a leaf node.
File Systems
Now that we have a generic idea of the tree data structure, let’s see how it’s applied to a file system.
To understand what a ‘home directory’ is, let’s have a look at how the file system as a whole is organized. Let’s assume that there is someone with the username nelle
inside Users
.
The filesystem looks like an upside down tree. The topmost directory is the root directory that holds everything else. We refer to it using a slash character, /
, on its own; this character is the leading slash in /Users/nelle
.
Inside the directory /
are several other directories: bin
(which is where some built-in programs are stored), data
(for miscellaneous data files), Users
(where users’ personal directories are located), tmp
(for temporary files that don’t need to be stored long-term), and so on.
Important: Notice that there are two meanings for the /
character. When it appears at the front of a file or directory name, it refers to the root directory. When it appears inside a path, it’s just a separator.
Example 2
Note that we have directories etc
, bin
, dev
, users
, and under users
we have more directories for raj
, tom
, and lester
. Some of these directories are parents to more directories or files. Files are leaf nodes.
- See Wikipedia ↩︎
- Image and following text referenced from: SW Carpentry ↩︎
- Reference Pressbooks ↩︎