Skip to content

Filesystem Navigation


You know what the prompt is telling you and you know how the filesystem tree is organized conceptually. What you don’t have yet is any way to actually move through it. Right now, if you opened a terminal, you’d be sitting in exactly one location with no way to see where that is, look around, or go anywhere else. This chapter fixes that.

Where Am I Right Now?

Every terminal session has a current working directory — the one location in the filesystem tree you’re “standing in” at any given moment. Every command that takes a file or directory as an argument, unless you tell it otherwise, assumes you mean somewhere relative to this location.

To see it, run:

pwd

pwd stands for “print working directory,” and that’s exactly what it does — it prints the full path of wherever you currently are. Right after logging in, this will typically show something like /home/you — your home directory, which is where most shells drop you by default.

Tip

Your prompt already hints at this — remember the ~ in the shell prompt? That symbol is your current location, just abbreviated. ~ always means “home directory,” so a prompt showing ~ and a pwd showing /home/you are telling you the same thing two different ways.

Looking Around: ls

Knowing where you are is only useful if you can see what’s there. That’s ls — short for “list.”

ls

Run with no arguments, ls lists the contents of your current directory. A few flags make it dramatically more useful:

FlagEffect
-lLong format — one entry per line, with permissions, owner, size, and modified date
-aShow hidden files too (anything starting with .)
-hHuman-readable sizes (4.0K instead of 4096) — usually paired with -l
-la or -lahCombine flags, as covered in previous chapters

Try ls -lah on your home directory and you’ll likely notice files you didn’t see with plain ls — things like .bashrc or .profile. Files and directories starting with a dot are considered “hidden” by convention, mostly used for configuration files that clutter a normal listing without adding much value day-to-day. They’re not secret or protected — just tucked out of the way by default.

You can also point ls at somewhere other than your current directory by giving it a path:

ls /etc

This lists /etc’s contents without you having to actually move there first — a useful habit, since checking somewhere doesn’t require leaving where you are.

Going Somewhere: cd

To actually change your current working directory, use cd (“change directory”) followed by where you want to go:

cd /etc

Run pwd again afterward and you’ll see it now reports /etc. A few shortcuts make cd faster to use:

  • cd with no argument at all takes you straight back to your home directory.
  • cd ~ does the same thing explicitly.
  • cd .. moves you up one level — into the parent of your current directory.
  • cd - jumps back to whichever directory you were in before your last cd — handy for bouncing between two locations.

Absolute Paths vs. Relative Paths

This is the one concept in this chapter worth slowing down for, because it explains a lot of confusing behavior later if you skip it.

A path can be written two ways:

Absolute paths start from the root, /, and describe a location no matter where you currently are. /home/you/documents means the same thing regardless of your current working directory.

Relative paths describe a location relative to wherever you currently are. documents means something different depending on whether you’re standing in /home/you or /etc.

    flowchart LR
    subgraph Absolute["Absolute Path: always the same target"]
        A1["/home/you/documents"]
    end
    subgraph Relative["Relative Path: depends on where you start"]
        B1["You in /home/you"] -->|"cd documents"| B2["/home/you/documents"]
        C1["You in /etc"] -->|"cd documents"| C2["Error: no such directory"]
    end
  

Two special relative shorthands come up constantly:

  • . means “this directory” — your current location.
  • .. means “the parent of this directory” — one level up.

You’ll see . used with commands that need “act on the current directory” as an argument, and you already saw .. above with cd ... They chain, too — cd ../.. moves up two levels at once, and cd ../sibling-folder moves up one level, then into a folder next to the one you started in.

Warning

Relative paths are convenient but easy to get wrong when you’ve lost track of where you are. If a command fails with “no such file or directory” and you’re confident the file exists, run pwd before anything else — it’s very often simply that you’re not where you think you are.

Tab Completion

One habit worth building immediately: press Tab while typing a path, and the shell will try to complete it for you. Type cd /et and press Tab, and it’ll fill in the rest to cd /etc/ automatically (assuming nothing else on the system starts with /et). If there’s more than one possibility, pressing Tab twice lists them all.

This isn’t just a convenience — it’s a safety net. If tab completion doesn’t complete a path the way you expect, that’s an immediate, reliable signal that the path is wrong before you’ve even run the command.

What’s Next

You can now see where you are and move anywhere in the tree. The next chapter builds on that directly — creating, copying, moving, and removing files and directories, all of which depend on the navigation you just learned.

Last updated on