Files, Folders, and Paths
Directories Form a Tree
A filename tells one item apart from its neighbors. To find it on a whole computer you also need to know which directory it sits in. Graphical file managers call directories folders; the two words mean the same thing, and you will see both constantly.
Here is a small project called field-notes. We will use it for the rest of the chapter:
field-notes/
├── README.txt
├── report.py
├── data/
│ ├── observations.csv
│ └── raw/
│ └── monday.txt
└── drafts/
└── outline.txt
The trailing slashes mark field-notes, data, raw, and drafts as directories. Everything else is a file. Indentation shows containment: monday.txt is inside raw, inside data, inside field-notes.
Family words describe positions
Directory trees borrow family words, because they describe the relationships cleanly:
datais the parent ofobservations.csvandraw.observations.csvandraware children ofdata.README.txt,report.py,data, anddraftsare siblings, sharing one parent.field-notesis an ancestor ofmonday.txt, reaching it through other directories.
A directory can hold both files and other directories. A file holds no children at all, which is what makes this a tree rather than a tangle.
One consequence surprises people: two files can have the same name as long as they have different parents. data/monday.txt and drafts/monday.txt are two separate files, and nothing is wrong with that. It is also why “I know it is called monday.txt” is not enough information to find anything.
Using the tree above, which statement is true?
Root and home are different places
Every tree has a top. That is the root.
Windows names a drive root with a letter and a backslash, C:\, and each additional drive gets its own root: D:\, E:\. /, and everything hangs off it.
Your home directory is your personal area inside that larger tree:
Windows: C:\Users\Sam
macOS: /Users/sam
Linux: /home/sam
Home is not another word for root, and mixing them up causes real confusion later. C:\Users\Sam sits below C:\. /home/sam sits below /. Home is a place you own several levels down; root is the top of everything, most of which is not yours and does not want editing.
Read a Unix-style location as a trail down the tree. Every name after / enters the next child directory, so /home/sam means sam inside home, below root.
Put these Linux locations in order, starting at the top of the tree and descending:
Drag the options into order, or use the arrow buttons.
//home/home/sam/home/sam/Documents/field-notes/home/sam/Documents
When a file seems to have vanished
Before assuming deletion, use the tree. Check which parent the file manager is actually showing you. Expand one ancestor at a time rather than searching blindly. Look for a directory with the same name under a different parent, because that is what has usually happened.
Most missing files turn out not to be missing at all. You were looking at the wrong branch of the tree.
The tree tells you where something sits. Next: writing that position down as text, which is how software wants it.