File Tree and Pathnames
A file system stores your files in a hierarchical structure, like a tree. In nature, trees begin with a root and grow to leaves. In the computing world, this is the same (drawn upside down from the root).
In Unix-like operating systems, the “top level” directory (aka folder) in which everything is called the root of the file system tree. Within the root directory, there are usually other directories, subdirectories, sub-subdirectories, and/or files.
Note about the upside-down trees: Our language reflects this thinking: when we move a file, we move it “down” into a subdirectory, or “up” into a directory “above” the current one.
Tree Vocabulary

- A tree consists of nodes and edges. In this example, A through M are nodes. The lines between nodes are edges, like the edge between (A,C).
- In the image, the node labeled “A” is the root of the system.
- Nodes may have child nodes (a node connected below another node). Above, nodes B, C and D are all child nodes of A.
- Parent nodes: Nodes that have child nodes. A is the parent node of B, C, and D.
- Leaf nodes are nodes which have no children. C is a leaf node.
Pathnames

A pathname is the unique location of a file or directory within the file tree. Pathnames allow you to specify where you want to put files and help you find your location on the file tree. We refer to the root using a slash character, /, on its own. In this example, the root contains several other directories: bin, data, Users, tmp.
On UNIX, every user normally has a home directory, serving as a personal storage locker for files and directories. Let’s assume that there is someone with the username nelle inside Users. Then nelle’s home directory is /Users/nelle. We use the / character to show the path, or edges, that we follow for a given pathname. If you start with the leading forward slash for writing a path, you are indicating that the path starts at the root folder /.
On UNIX or Mac, within a terminal window, try running echo $HOME to see the absolute path to your own home directory. ~/ Tilde-slash is a shortcut to your home directory.
Absolute Pathnames
Each file and directory in the file system has an absolute path to locate it, starting with the root folder / and listing each directory on the way to the file. A slash / between each level in the path name separates each directory name from the previous level. Note: 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.
Windows, rather than using /, uses names like C:. On a Windows operating system, other drives (e.g., CD-ROMs, network drives) would get their own “root” directory with names like D: and E: (with the main hard drive usually having the name C:). On Unix-based operating systems, there is only ever one file system hierarchy, and the top level is always /. Special devices like CD-ROM drives and network drives are mounted somewhere in the file system. It may be that the directory /media remains empty, for example, but when a CD-ROM is inserted, a new directory may appear inside that directory, perhaps with the absolute path /media/cdrom0, and the files on the CD-ROM will appear there.
Relative Pathnames
Rather than specifying the full, absolute path to locate a file or directory, we can use a relative path. A relative path locates a file or directory relative to the present working directory.

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.
UNIX/Linux systems recognize some special character combinations known as relative pathnames. For example, in the file tree above, if we are in /users/raj/work, then the relative path to report is ../report. Use these relative pathnames as shortcuts to save time while accessing files and directories. Even though you are in that directory, some commands require you to use ./ as a security measure.
../ Dot-dot-slash refers to the directory above your current working directory (the parent directory). | |
./ Dot-slash refers to the current working directory. Instead of typing the long (absolute) pathname, you can use dot. This is useful when working with files in your current working directory. |
Think of an absolute pathname like a physical, named address, such as 2610 Cates Ave, Raleigh, NC 27606 (Talley Student Union). A relative path for the same location would be something like: if I’m at Withers Hall, then cross the railroad tracks and turn right to get to Talley. The absolute path would tell me where to go from any other location, but the relative path will only work if I’m at Withers.
Linux File Names
- Should not include spaces (follows the special characters rule). To separate words, it is advised to use an underscore (_), like_this
- Up to 256 characters long
- No special characters: | { } [ ] ( ) ! & * ? \ ^ % @ # ” ‘ `<>
- FYI: If you must use a special character, precede it with a backslash (‘\’). For example, to name a file “some!file”, you may have to name it “some\!file” for it to function correctly
- Cannot include the forward slash (‘/’)
References
- Image and following text referenced from: SW Carpentry ↩︎
- Reference Pressbooks ↩︎
