Nandishwar Singh

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

  1. One tree, starting at /
  2. What lives where
  3. Where am I? pwd and ~
  4. Absolute and relative paths
  5. Moving around: cd
  6. Hidden files
  7. The big picture with tree
  8. Everything is a file
  9. Common mistakes
  10. Practice
  11. 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  var

Add -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 var

bin, 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

  1. How many entries does ls / show on your machine?
  2. Where does /bin really point?
Answer
  1. About twenty, though the exact list varies a little between systems.
  2. To usr/bin. Run ls -l / and look at the bin line: 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:

DirectoryWhat's in it
/etcSettings for the whole system, as plain text files. /etc/hostname, /etc/os-release and almost every config file you'll ever edit
/homeOne folder per user, like /home/ubuntu
/rootRoot's home folder. It's not inside /home
/usrInstalled 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/localPrograms you build or install by hand, kept apart from the system's own
/varData that changes while the system runs: logs in /var/log, package caches, databases, and websites in /var/www
/tmpTemporary files. Anyone can write here, and it's cleared at every reboot
/bootThe kernel and the files needed to start the machine
/devDevices, shown as files. /dev/vda is this VM's disk
/proc, /sysLive information from the kernel. Nothing here is on disk
/runInformation about the running system that disappears at shutdown
/optBig add-on software that comes as one package, like some commercial tools
/srvData that a server shares, like files for a web or FTP server
/mnt, /mediaPlaces to attach extra disks by hand, and where USB sticks appear
/snapSnap 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,ino

tmpfs 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

  1. Which directory would you look in for the SSH server's config file?
  2. A web server is writing errors somewhere. Where would you start looking?
  3. Is /proc/uptime a file on the disk?
Answer
  1. /etc. It's /etc/ssh/sshd_config (lesson 19).
  2. /var/log. nginx, for example, writes to /var/log/nginx/.
  3. No. /proc is made up by the kernel on the fly. cat /proc/uptime shows seconds since boot, generated the moment you read it:
$ cat /proc/uptime
23.01 40.11

Where 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/ubuntu

That'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/ubuntu

Try it

  1. What's root's home directory? (Hint: sudo -i then pwd.)
  2. What does echo ~root print?
Answer
  1. /root.
  2. /root. ~name means 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:

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

  1. You're in /usr/share. Write the relative path to /usr/bin.
  2. You're in /var/log. What's the absolute path of ../lib?
Answer
  1. ../bin
  2. /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:

CommandGoes to
cdYour 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

  1. Go to /usr/share/doc, then back home, then back to /usr/share/doc without typing the path again.
  2. From your home directory, go to /home using ...
  3. What happens if you cd into a file, like cd /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

  1. Show only the directories directly under /usr.
  2. 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

Practice

  1. Without changing directory, list the contents of /var/log/apt using an absolute path. Then go to /var and 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
  1. Starting in your home directory, use one cd command 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.

  1. 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
  1. 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
  1. List every hidden file in your home directory, but not . and ... (Hint: lesson 2's ls --help showed an option for that.)
Answer
$ ls -A ~
.bash_history  .bash_logout  .bashrc  .cache  .profile  .ssh
  1. Use tree to 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 directories

Cheat sheet

Command or pathWhat it means
/Top of the filesystem
~, ~nameYour home directory, someone else's
., ..This directory, the one above
/etc, /var/logSettings, logs
/home, /rootUsers' homes, root's home
/usr/bin, /usr/localPrograms, your own installs
/tmpTemporary files, gone at reboot
/dev, /procDevices, live kernel information
pwdWhere am I?
cd pathGo there
cd, cd -, cd ..Home, back, up one level
ls -a, ls -AInclude hidden files (-A skips . and ..)
tree -L 2, tree -dShow two levels, directories only
findmnt /tmpWhat's attached at that directory