The File System

To run an analysis, you must first answer a simple question: Where is the data?

In a Graphical User Interface (GUI), you answer this by double-clicking folders until you see the file you want. You navigate visually. In the CLI, you are blind. You cannot “see” the folders around you; you must know exactly where you are and exactly where you are going. If you understand the file system, you can instantly pinpoint any file among millions. If you do not, you will spend hours staring at a “File Not Found” error.

The Inverted Tree

Some of you are used to Windows, which splits storage into separate islands called drives (e.g., C:, D:). Unix-like systems (Linux and macOS) are different. They act as a single, unified landmass. We structure this landmass as an inverted tree.

  • The Root (/): This is the very top of the hierarchy. Every file, directory, hard drive, and process branches out from this single point.
  • Nodes: Every file or directory is a “node” on this tree.

Root vs. Home

To survive in this environment, you must distinguish between two locations:

  1. The Root (/): Think of this as the lobby of a high-security apartment building. It contains the machinery that keeps the building running (system files). You can look around, but you are generally forbidden from changing anything here.
  2. Home (~): Think of this as your personal apartment (/home/alex or /Users/alex). This is your sanctuary. You have full permission to create, edit, and destroy files here.

Key Idea: The Tilde (~) In the Shell, the tilde symbol (~) is a shorthand for your home directory. If your user path is /home/student, then ~/data is exactly the same as /home/student/data.

Absolute vs. Relative Paths

A Path is simply an address: a string of text that tells the computer how to reach a specific file. There are only two ways to write an address. Understanding the difference is the most critical skill in this chapter.

Absolute Paths

An absolute path is like a GPS coordinate. It always describes the exact same location, no matter where you are currently standing.

  • Rule: It always starts with the Root slash (/).
  • Example: /home/alex/data/dna.fa

Relative Paths

A relative path is like giving turn-by-turn directions. It describes a location relative to where you are standing right now.

  • Rule: It does not start with a slash.
  • Example: data/dna.fa (Translation: “Look in the folder I am currently in, find the ‘data’ folder, and look inside.”)

Example

Imagine you are currently working in your home folder (/home/alex) and you want to list the files in a folder called experiments.

Scenario A: Using the Absolute Path You type: ls /home/alex/experiments

You are giving the computer the full postal address. It ignores where you are standing and goes straight to that specific address.

Scenario B: Using the Relative Path You type: ls experiments

You are saying, “Look right next to me.” Since you are standing in /home/alex, the computer looks for /home/alex/experiments.

If you change directories to /tmp and type ls experiments, the computer will look for /tmp/experiments. The command fails because the relationship has changed.

Caution

The “File Not Found” Error When you see File Not Found, do not panic. It almost always means you provided a Relative Path while standing in the wrong directory.

  1. Check your current location using the pwd (Print Working Directory) command.
  2. Ask yourself: “Is the file actually inside this folder?”

Learning Resources

Software Carpentry: Navigating Files and Directories

Read the entire lesson to practice moving through the tree.

Software Carpentry: Working With Files and Directories

Read the entire lesson to learn how to manipulate the nodes of the tree.

Last updated on