Home / Learn Linux / Lesson 4
The Linux filesystem and paths
What lives in /etc, /var, /home and the rest, and moving around with absolute and relative paths.
- Lesson
- 4 of 30
- Time
- About 40 minutes
On this page
- One tree, starting at /
- What lives where
- Where am I? pwd and ~
- Absolute and relative paths
- Moving around: cd
- Hidden files
- The big picture with tree
- Everything is a file
- Common mistakes
- Practice
- Cheat sheet
One tree, starting at /
Windows gives every disk a letter: C:, D:. Linux doesn't. There's one tree of folders, and it starts at /, called the root of the filesystem. Every file on the system, on every disk, lives somewhere under it. A second disk or a USB stick gets attached to a folder in the tree, which is called mounting (lesson 25).
Linux usually says directory where Windows says folder. They mean the same thing, and this course uses both.
Here's the top of the tree:
$ ls /
bin dev home lost+found mnt proc run snap sys usr
boot etc lib media opt root sbin srv tmp varAdd -l and you'll notice that some of them aren't real directories:
$ ls -l /
total 60
lrwxrwxrwx 1 root root 7 Apr 20 2026 bin -> usr/bin
drwxr-xr-x 5 root root 4096 Oct 21 11:04 boot
drwxr-xr-x 16 root root 4040 Oct 21 11:06 dev
drwxr-xr-x 107 root root 4096 Oct 21 11:06 etc
drwxr-xr-x 3 root root 4096 Oct 21 11:01 home
lrwxrwxrwx 1 root root 7 Apr 20 2026 lib -> usr/lib
drwx------ 2 root root 16384 Jul 20 16:38 lost+found
drwxr-xr-x 2 root root 4096 Jul 20 16:33 media
drwxr-xr-x 3 root root 4096 Oct 21 11:01 mnt
drwxr-xr-x 2 root root 4096 Jul 20 16:33 opt
dr-xr-xr-x 175 root root 0 Oct 21 11:06 proc
drwx------ 3 root root 4096 Oct 21 11:06 root
drwxr-xr-x 32 root root 920 Oct 21 11:06 run
lrwxrwxrwx 1 root root 8 Apr 20 2026 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Oct 21 11:01 snap
drwxr-xr-x 2 root root 4096 Jul 20 16:33 srv
dr-xr-xr-x 13 root root 0 Oct 21 11:06 sys
drwxrwxrwt 12 root root 300 Oct 21 11:06 tmp
drwxr-xr-x 11 root root 4096 Jul 20 16:33 usr
drwxr-xr-x 13 root root 4096 Oct 21 11:01 varbin, sbin and lib are links (the l at the start of the line and the -> arrow) pointing into /usr. Long ago these were separate, and modern Ubuntu keeps the old names working by linking them. Lesson 11 explains links.
Try it
- How many entries does
ls /show on your machine? - Where does
/binreally point?
Answer
- About twenty, though the exact list varies a little between systems.
- To
usr/bin. Runls -l /and look at thebinline:bin -> usr/bin.
What lives where
Linux follows a standard layout, the Filesystem Hierarchy Standard, so once you know it you can find your way around any distro. These are the ones you'll use:
| Directory | What's in it |
|---|---|
/etc | Settings for the whole system, as plain text files. /etc/hostname, /etc/os-release and almost every config file you'll ever edit |
/home | One folder per user, like /home/ubuntu |
/root | Root's home folder. It's not inside /home |
/usr | Installed programs and everything they need. Commands live in /usr/bin, admin commands in /usr/sbin, libraries in /usr/lib, docs and shared data in /usr/share |
/usr/local | Programs you build or install by hand, kept apart from the system's own |
/var | Data that changes while the system runs: logs in /var/log, package caches, databases, and websites in /var/www |
/tmp | Temporary files. Anyone can write here, and it's cleared at every reboot |
/boot | The kernel and the files needed to start the machine |
/dev | Devices, shown as files. /dev/vda is this VM's disk |
/proc, /sys | Live information from the kernel. Nothing here is on disk |
/run | Information about the running system that disappears at shutdown |
/opt | Big add-on software that comes as one package, like some commercial tools |
/srv | Data that a server shares, like files for a web or FTP server |
/mnt, /media | Places to attach extra disks by hand, and where USB sticks appear |
/snap | Snap packages (Ubuntu's other way to install software) |
When something breaks, you'll look in /var/log (what happened) and /etc (how it's set up). Those two are worth remembering above all the rest.
On Ubuntu 26.04, /tmp lives in memory rather than on the disk, which is why it's empty after every reboot:
$ findmnt /tmp
TARGET SOURCE FSTYPE OPTIONS
/tmp tmpfs tmpfs rw,nosuid,nodev,size=1994676k,nr_inodes=1048576,inotmpfs means it's stored in memory. On older systems /tmp was on the disk and cleaned up at boot, which gives the same result.
Try it
- Which directory would you look in for the SSH server's config file?
- A web server is writing errors somewhere. Where would you start looking?
- Is
/proc/uptimea file on the disk?
Answer
/etc. It's/etc/ssh/sshd_config(lesson 19)./var/log. nginx, for example, writes to/var/log/nginx/.- No.
/procis made up by the kernel on the fly.cat /proc/uptimeshows seconds since boot, generated the moment you read it:
$ cat /proc/uptime
23.01 40.11Where am I? pwd and ~
Your shell is always "in" a directory, called the current or working directory. pwd (print working directory) shows it:
$ pwd
/home/ubuntuThat's your home directory, where your own files go. The shell has a shortcut for it: ~ means your home directory, wherever you are. The prompt uses it too, which is why it says ubuntu@linux:~$:
$ echo ~
/home/ubuntuTry it
- What's root's home directory? (Hint:
sudo -ithenpwd.) - What does
echo ~rootprint?
Answer
/root./root.~namemeans that user's home directory.
Absolute and relative paths
A path says where a file or directory is. There are two kinds.
An absolute path starts with / and gives the full route from the top of the tree. It means the same thing no matter where you are: /etc/apt/sources.list is always the same file.
A relative path doesn't start with /. It starts from wherever you are now. If you're in /etc, then apt/sources.list means /etc/apt/sources.list. From /home, the same relative path points somewhere that doesn't exist.
Two special names help with relative paths:
.means the directory you're in...means the directory above it, its parent.
Both of these list the same directory when you're in /etc:
ubuntu@linux:~$ cd /etc ubuntu@linux:/etc$ ls apt apt.conf.d keyrings sources.list trusted.gpg.d auth.conf.d preferences.d sources.list.d ubuntu@linux:/etc$ ls /etc/apt apt.conf.d keyrings sources.list trusted.gpg.d auth.conf.d preferences.d sources.list.d ubuntu@linux:/etc$ ls ./apt apt.conf.d keyrings sources.list trusted.gpg.d auth.conf.d preferences.d sources.list.d ubuntu@linux:/etc$ cd
And .. climbs up:
ubuntu@linux:~$ cd /var/log/apt ubuntu@linux:/var/log/apt$ ls .. README chrony dmesg.1.gz lastlog alternatives.log cloud-init-output.log dmesg.2.gz private apport.log cloud-init.log dpkg.log syslog apt dist-upgrade journal sysstat auth.log dmesg kern.log unattended-upgrades btmp dmesg.0 landscape wtmp ubuntu@linux:/var/log/apt$ ls ../.. backups crash local log opt snap tmp cache lib lock mail run spool ubuntu@linux:/var/log/apt$ cd
From /var/log/apt, ls .. lists /var/log, and ls ../.. climbs twice, to /var.
Use absolute paths in scripts and config files, where you can't be sure what the current directory will be. Use relative paths when you're typing, because they're shorter.
Try it
- You're in
/usr/share. Write the relative path to/usr/bin. - You're in
/var/log. What's the absolute path of../lib?
Answer
../bin/var/lib
Moving around: cd
cd (change directory) moves you. Give it any path, absolute or relative:
ubuntu@linux:~$ cd /var/log ubuntu@linux:/var/log$ pwd /var/log ubuntu@linux:/var/log$ cd .. ubuntu@linux:/var$ pwd /var ubuntu@linux:/var$ cd lib/apt ubuntu@linux:/var/lib/apt$ pwd /var/lib/apt ubuntu@linux:/var/lib/apt$ cd / ubuntu@linux:/$ pwd /
A few shortcuts you'll use every day:
| Command | Goes to |
|---|---|
cd | Your home directory |
cd ~ | Your home directory too |
cd - | The directory you were in before (it prints where) |
cd .. | One level up |
cd ../.. | Two levels up |
cd / | The top of the tree |
cd - is great for jumping between two places:
ubuntu@linux:~$ cd /etc/apt ubuntu@linux:/etc/apt$ cd /var/log ubuntu@linux:/var/log$ cd - /etc/apt ubuntu@linux:/etc/apt$ cd - /var/log ubuntu@linux:/var/log$ cd
And remember Tab. cd /v Tab, l Tab gets you cd /var/log/ in five keys.
Try it
- Go to
/usr/share/doc, then back home, then back to/usr/share/docwithout typing the path again. - From your home directory, go to
/homeusing... - What happens if you
cdinto a file, likecd /etc/hostname?
Answer
ubuntu@linux:~$ cd /usr/share/doc ubuntu@linux:/usr/share/doc$ cd ubuntu@linux:~$ cd - /usr/share/doc ubuntu@linux:/usr/share/doc$ cd .. ubuntu@linux:/usr/share$ cd ~/.. ubuntu@linux:/home$ pwd /home ubuntu@linux:/home$ cd ubuntu@linux:~$ cd /etc/hostname bash: cd: /etc/hostname: Not a directory
cd ~/.. (or cd .. from your home directory) lands in /home. You can't cd into a file, so Bash tells you it isn't a directory.
Hidden files
Names that start with a dot are hidden. ls skips them unless you add -a. Your home directory is full of them, because programs keep their settings there:
$ ls $ ls -a . .. .bash_history .bash_logout .bashrc .cache .profile .ssh
.bashrc is the file you edited in lesson 3. .cache holds things programs can rebuild, like tldr's pages, and .bash_history, once you've logged out at least once, is your saved history. Hidden files aren't secret or protected. The dot only keeps them out of the way.
The big picture with tree
tree (from lesson 1) draws a directory and everything below it. -L limits how deep it goes, and -d shows only directories:
$ tree -d -L 1 /var /var ├── backups ├── cache ├── crash ├── lib ├── local ├── lock -> /run/lock ├── log ├── mail ├── opt ├── run -> /run ├── snap ├── spool └── tmp 14 directories $ tree -L 2 /etc/apt /etc/apt ├── apt.conf.d │ ├── 01-vendor-ubuntu │ ├── 01autoremove │ ├── 10periodic │ ├── 15update-stamp │ ├── 20apt-esm-hook.conf │ ├── 20archive │ ├── 20auto-upgrades │ ├── 20packagekit │ ├── 20snapd.conf │ ├── 50appstream │ ├── 50command-not-found │ ├── 50unattended-upgrades │ ├── 70debconf │ ├── 99needrestart │ └── 99update-notifier ├── auth.conf.d ├── keyrings ├── preferences.d │ ├── ubuntu-pro-esm-apps │ └── ubuntu-pro-esm-infra ├── sources.list ├── sources.list.d │ └── ubuntu.sources └── trusted.gpg.d ├── ubuntu-keyring-2012-cdimage.gpg └── ubuntu-keyring-2018-archive.gpg 7 directories, 21 files
Try it
- Show only the directories directly under
/usr. - How many files and directories are there under
/etc/ssh?
Answer
$ tree -d -L 1 /usr /usr ├── bin ├── games ├── include ├── lib ├── libexec ├── local ├── sbin ├── share └── src 10 directories $ tree /etc/ssh /etc/ssh ... 3 directories, 12 files
The last line of tree always gives the totals.
Everything is a file
Linux shows almost everything as a file: settings, devices, even information about running programs. That's why the same few commands work everywhere. cat reads a config file, and it reads the kernel's live memory statistics just the same:
$ cat /proc/meminfo
MemTotal: 3989348 kB
MemFree: 3176156 kB
MemAvailable: 3568860 kB
.../dev/null is a file that swallows anything written to it. Lesson 8 uses it to throw away output you don't want. And /dev/vda is the VM's whole disk, as one file.
Common mistakes
- **Mixing up
/and~.**/is the top of the whole system, and~is your home directory.cd /andcd ~take you to very different places. - A relative path from the wrong place.
ls aptonly works in/etc. If a command saysNo such file or directory, checkpwdfirst. - Wrong case.
/etc/Hostnameand/etc/hostnameare different files, and only one exists. Tab completion catches this for you. - Spaces in names.
cd My Filestries to go intoMy. Quote it,cd "My Files", or let Tab add a backslash:cd My\ Files. Better still, don't put spaces in file names on a server. - Writing your own files into system directories. Keep your work in your home directory.
/usr/bin,/etcand the rest belong to the system and its package manager.
Practice
- Without changing directory, list the contents of
/var/log/aptusing an absolute path. Then go to/varand list the same directory using a relative path.
Answer
ubuntu@linux:~$ ls /var/log/apt eipp.log.xz history.log term.log ubuntu@linux:~$ cd /var ubuntu@linux:/var$ ls log/apt eipp.log.xz history.log term.log ubuntu@linux:/var$ cd
- Starting in your home directory, use one
cdcommand with..to get to/usr/share.
Answer
ubuntu@linux:~$ cd ../../usr/share ubuntu@linux:/usr/share$ pwd /usr/share ubuntu@linux:/usr/share$ cd
From /home/ubuntu, .. is /home and ../.. is /, then down into usr/share.
- Find the file that sets this machine's name, and print it.
Answer
It's a setting, so it's in /etc:
$ cat /etc/hostname
linux- Show where your shell is, jump to
/etc, then jump back to where you were with the shortest possible command.
Answer
ubuntu@linux:~$ pwd /home/ubuntu ubuntu@linux:~$ cd /etc ubuntu@linux:/etc$ cd - /home/ubuntu
- List every hidden file in your home directory, but not
.and... (Hint: lesson 2'sls --helpshowed an option for that.)
Answer
$ ls -A ~
.bash_history .bash_logout .bashrc .cache .profile .ssh- Use
treeto show the directories under/etc/apt, two levels deep, without any files.
Answer
$ tree -d -L 2 /etc/apt
/etc/apt
├── apt.conf.d
├── auth.conf.d
├── keyrings
├── preferences.d
├── sources.list.d
└── trusted.gpg.d
7 directoriesCheat sheet
| Command or path | What it means |
|---|---|
/ | Top of the filesystem |
~, ~name | Your home directory, someone else's |
., .. | This directory, the one above |
/etc, /var/log | Settings, logs |
/home, /root | Users' homes, root's home |
/usr/bin, /usr/local | Programs, your own installs |
/tmp | Temporary files, gone at reboot |
/dev, /proc | Devices, live kernel information |
pwd | Where am I? |
cd path | Go there |
cd, cd -, cd .. | Home, back, up one level |
ls -a, ls -A | Include hidden files (-A skips . and ..) |
tree -L 2, tree -d | Show two levels, directories only |
findmnt /tmp | What's attached at that directory |
← Terminal speed: Tab, shortcuts, history and sudoListing files: ls, file types and timestamps →