Navigation
3 min read
Core idea
A Linux system organises every file into a single hierarchical tree that starts at the root directory, written /. Every disk, every USB stick, every network share is grafted onto a branch of that tree — there are no C: or D: drive letters. To work from the shell you need three primitives: a way to ask "where am I" (pwd), a way to look around (ls), and a way to move (cd). With those three commands and one mental picture — you are standing inside the tree, with a parent directory above you and possibly children below — you can reach any file the system contains.
The other half of navigation is pathnames: the address you give cd (or any other command) to point at a place in the tree. Pathnames come in two flavours. An absolute pathname starts at / and lists every branch down to the target. A relative pathname starts wherever you currently are. Both reach the same place; the right choice is the one that takes less typing.
Why it matters
Mental model
The tree, upside down
Most computer science draws the filesystem with the root at the top and directories descending like branches. You are always inside exactly one node. From that node you can see its contents, you can step down into a child directory, or you can step up to the parent (which is what .. refers to).
Absolute vs relative addresses
Suppose you are standing in /home/jay/Documents. To reach /usr/bin you can use either form:
| You are at | You want to go to | Absolute | Relative |
|---|---|---|---|
| /home/jay/Documents | /usr/bin | cd /usr/bin | cd ../../../usr/bin |
| /home/jay/Documents | /home/jay | cd /home/jay | cd .. |
| /home/jay/Documents | /home/jay/Music | cd /home/jay/Music | cd ../Music |
Relative paths win for short hops; absolute paths win when you have no idea where you currently are. Two notations make relative paths fluent:
.— the current directory...— the parent directory.
You can chain them: ../../foo means "up two levels, then into foo".
Useful cd shortcuts
| Shortcut | What happens |
|---|---|
| cd | Go home ($HOME). |
| cd - | Toggle back to the previous directory. |
| cd ~ | Same as cd — ~ expands to your home directory. |
| cd ~bob | Go to user bob's home. |
Practical application
The three navigation commands
-
Where am I?
pwd(print working directory) prints the absolute path of your current location. -
What's here?
lslists files and directories in the current location.ls /etclists a different directory without leaving yours. -
Take me there.
cd /path/to/somewherechanges the working directory. Runpwdafter to confirm.
Hidden files
When your account is created, several files starting with . are placed in your home directory — things like .bashrc, .profile, and .ssh/. They are configuration data, deliberately hidden so a normal ls does not clutter your view. To see them:
ls -a # show all files, including dotfiles
ls -A # like -a but skip . and ..
Naming files sensibly
Linux lets you put almost anything in a filename. That permission is not an invitation. Stick to letters, digits, hyphens, underscores, and periods — and never embed spaces. A file called my report.pdf must be quoted ("my report.pdf") or escaped (my\ report.pdf) every time you reference it, and globbing patterns get confused by it.
Example
You log in to a fresh laptop and want to find out where your downloads end up. Starting from the home directory:
$ pwd
/home/jay
$ ls
Desktop Documents Downloads Music Pictures Videos
$ cd Downloads
$ pwd
/home/jay/Downloads
$ ls -la
total 8
drwxr-xr-x 2 jay jay 4096 May 26 09:15 .
drwxr-xr-x 8 jay jay 4096 May 26 09:14 ..
The directory is empty (only . and .. show up). You jump back home with a single keystroke pair:
$ cd
$ pwd
/home/jay
Then jump to the system-wide programs directory, look around, and jump back where you were a moment earlier:
$ cd /usr/bin
$ ls | head -3
[
addr2line
apropos
$ cd -
/home/jay
That last cd - is the toggle: it returns to your previous directory and prints its name. Once you internalise this loop — pwd, ls, cd, cd - — you can rummage through an unfamiliar system without ever getting lost.
Related lessons
Related concepts
- Filesystemlinked concept
- Command Linelinked concept