Navigating the File System
Use pwd, ls and cd to move around, tell absolute from relative paths, and learn what lives in /etc, /home, /var and the other standard directories.
Welcome back!
Step 1 of 14Learn
One tree, starting at /
Windows gives each drive its own letter: C:\, D:\. Linux has a single tree. Everything, including extra disks and USB sticks, hangs somewhere below one top directory called the root directory, written as a single slash: /.
Directories (folders) are separated by forward slashes. The path /home/lena/projects/report.txt reads: start at the root, go into home, then lena, then projects, and there is the file report.txt.
Three commands do most of the moving around:
pwd(print working directory) shows where you are right now.lslists what is in the current directory, or in a directory you name:ls /etc.cd(change directory) moves you:cd /var/log.
Useful ls options: -l for a long listing with permissions, owner, size and date; -a to show hidden files, whose names start with a dot, such as .bashrc; -h for human-readable sizes; -t to sort by modification time, newest first. ls -lht is a quick way to see what changed most recently in a directory.
A Linux file name can contain almost any character, and file extensions like .txt are a convention for humans, not a rule the system enforces.
Step 2 of 14Practice · Diagram
One tree, starting at /
A small part of a typical Linux file system. Tap a directory to see what lives there.
Tap the directory that holds the system log files.
Tap the shape that answers the question, then press Check.
- /
The root directory. Every path starts here.
- home
One directory per regular user.
- lena
/home/lena, Lena's home directory (~ for her).
- projects
- etc
System-wide configuration files, mostly plain text.
- var
Data that changes: logs, caches, often websites.
- log
/var/log, the first place to look when something breaks.
- usr
Installed software.
- bin
/usr/bin holds most programs, such as ls and grep.
- tmp
Temporary files, often wiped at reboot.
Step 3 of 14Learn
Absolute and relative paths
There are two ways to name any location.
An absolute path starts with / and spells out the full route from the root. /home/lena/projects means the same place no matter where you currently are. Scripts and configuration files should use absolute paths for this reason.
A relative path does not start with /. It is read starting from your current directory. If you are in /home/lena, then cd projects takes you to /home/lena/projects. Run the same command from /tmp and it fails, because there is no /tmp/projects.
Special names make relative paths powerful:
| Shortcut | Meaning |
|---|---|
. | the current directory |
.. | the parent directory, one level up |
~ | your home directory |
- | (with cd) the previous directory you were in |
Examples from /home/lena/projects: cd .. goes to /home/lena; cd ../.. goes to /home; cd ~ or plain cd goes home; cd - jumps back to wherever you were before. ls ../photos lists a sibling directory without moving.
The most common beginner mistake is forgetting the leading slash: cd etc looks for a directory called etc inside the current one, while cd /etc goes to the system directory.
Step 4 of 14Diagram
How the shell reads cd ../photos
Start in /home/lena/projects. A relative path is followed one piece at a time from where you are.
Tap a shape with to see more.
- Start: /home/lena/projects
- .. means one level up
The parent of projects is /home/lena.
- Now at /home/lena
- photos: go into it
A name without a slash is looked up inside the current directory.
- End: /home/lena/photos
Step 5 of 14Practice · Sort into groups
You are currently in /home/sam. Sort each command by whether it uses an absolute or a relative path.
Tap an item, then tap its group (or drag it there).
Step 6 of 14Practice · Work it out
You are in /var/www/html/images. You run cd ../../logs. How many levels below the root directory / is your new directory? (For example, /var is 1 level below the root.)
Step 7 of 14Learn
What lives where
Linux distributions follow a shared layout called the Filesystem Hierarchy Standard. Once you know it, you can find your way around almost any Linux machine.
/homeholds one directory per regular user, such as/home/lena. Your files, settings and downloads live here./rootis the home directory of the root user, kept separate from/home./etcholds system-wide configuration files, almost all plain text:/etc/hostname,/etc/ssh/sshd_config,/etc/passwd./varholds variable data that grows and changes: logs in/var/log, mail, caches, and often website files in/var/www./usrholds installed software: programs in/usr/bin, libraries in/usr/lib, shared data in/usr/share./binand/sbinhold essential commands; on modern systems they usually point into/usr./tmpis for temporary files and is often wiped at reboot./devexposes hardware devices as files,/procexposes running processes and kernel information as files, and/mntor/mediaare where extra disks and USB drives are attached (mounted).
When something breaks, two places come first: the logs in /var/log to see what happened, and the configuration in /etc to see how the service is set up.
Step 8 of 14Practice · Match the pairs
Match each directory to what you would expect to find there.
Tap an answer, then tap the place where it belongs (or drag it there).
- /etc
- /var/log
- /home
- /usr/bin
- /tmp
- /dev
Step 9 of 14Flashcards
More directories worth knowing
Tap a card to flip it.
Step 10 of 14Note
Step 11 of 14Note
Step 12 of 14Practice · Put in order
Starting in /home/lena, put these commands in the order needed to view the system log directory and then return home.
Drag the items, or use the arrow buttons, to put them in order.
- cd ~
- cd log
- pwd (shows /var/log)
- ls -lt
- cd /var
Step 13 of 14Practice · What would you do?
What would you do?
Priya runs ls in her home directory and sees only Documents and Downloads. A tutorial tells her to edit ~/.bashrc, but she insists the file "doesn't exist". What is going on?
Step 14 of 14Practice · Choose one
You are in /home/lena/projects/site. Which command takes you to /home/lena/photos?
Lesson complete!