The Linux Filesystem
On Windows every drive has a letter: C:, D:, E:. Linux has no drive letters at all. Everything, from your documents to your USB stick to the settings of the web server, lives in a single tree of folders that starts at one place, called root and written as /.
In this lesson you will learn what the main folders in that tree are for, how to write paths that point into it, and why Linux says "everything is a file". Knowing the map makes every later lesson easier, because you will know where to look.
One tree, starting at /
A directory is the Linux word for a folder. At the very top is the root directory /. Every other directory hangs below it, and other disks are attached somewhere inside the tree (this is called mounting, covered in Disks & Storage).
ls /bin dev home lib64 media opt root sbin srv tmp var boot etc lib lost+found mnt proc run snap sys usr
Your list may contain a few extra entries, but these names are the same on nearly every distribution. They follow the Filesystem Hierarchy Standard (FHS), a shared agreement about what goes where.
What each directory is for
| Directory | What it holds |
|---|---|
/home | One folder per normal user, such as /home/priya. Your files go here |
/root | The home folder of the root user (not the same as /) |
/etc | System-wide configuration files: users, network, SSH, web server settings |
/var | Data that changes while the system runs: /var/log (logs), /var/www (websites), /var/lib (databases, package data) |
/tmp | Temporary files; cleared on reboot. Anyone can write here |
/usr | Installed programs and their files: /usr/bin (commands), /usr/lib (libraries), /usr/share (docs, icons) |
/usr/local | Software you install by hand, kept apart from the distro's packages |
/opt | Large third-party applications installed as one folder |
/boot | The kernel and the files needed to start the computer |
/dev | Devices shown as files, such as disks (/dev/sda) and the "black hole" /dev/null |
/proc, /sys | Virtual files that show live kernel information; nothing here is stored on disk |
/run | Runtime data for running services; cleared on reboot |
/mnt, /media | Places to attach extra disks; USB drives appear under /media |
/srv | Data served by this machine, used on some servers |
Three directories deserve special attention. /etc is where you change how the system behaves: almost every file in it is plain text. /var/log is where you look when something goes wrong. /home is where your own work lives, and it is usually the only place a normal user can write (apart from /tmp).
Where did /bin go?
Older Unix systems kept essential commands in /bin and /sbin, and everything else in /usr/bin and /usr/sbin. Modern distributions, including Ubuntu, have merged them: /bin is now just a symbolic link (a shortcut) to /usr/bin.
ls -ld /bin /sbin /liblrwxrwxrwx 1 root root 7 Apr 23 09:12 /bin -> usr/bin lrwxrwxrwx 1 root root 8 Apr 23 09:12 /sbin -> usr/sbin lrwxrwxrwx 1 root root 7 Apr 23 09:12 /lib -> usr/lib
The l at the start and the arrow show that each one is a link. So /bin/bash and /usr/bin/bash are the same file. You will still see #!/bin/bash in scripts, and it still works.
Absolute and relative paths
A path is the address of a file or directory. There are two kinds:
- An absolute path starts with
/and gives the full route from the root:/home/priya/Documents/marks.txt. It works from anywhere. - A relative path does not start with
/. It is read from your current directory (the folder you are "in"). If you are in/home/priya, thenDocuments/marks.txtmeans the same file.
Three short names help you write paths:
| Name | Meaning | Example |
|---|---|---|
. | The current directory | ./backup.sh runs a script in this folder |
.. | The parent directory, one level up | From /home/priya/Documents, ../Downloads is /home/priya/Downloads |
~ | Your home directory | ~/notes is /home/priya/notes for Priya |
Linux uses forward slashes / between names. A backslash \ means something else in the shell, so Windows-style paths do not work.
Hidden files
A file or directory whose name starts with a dot is hidden: plain ls does not show it. Hidden files are usually settings, such as ~/.bashrc (your shell settings) and ~/.ssh (your SSH keys). Add -a to see them:
ls -a ~. .bash_history .bashrc .profile Documents notes projects .. .bash_logout .cache .ssh Downloads orders.csv
Here you can also see . and .. themselves listed as entries.
Everything is a file
Linux represents almost everything as a file: documents, directories, hardware devices, even information about running programs. This means the same few tools (cat, ls, grep) work on all of them. The file command tells you what something really is, whatever its name:
file /etc/hostname /var/log /bin
head -n 3 /proc/meminfo/etc/hostname: ASCII text /var/log: directory /bin: symbolic link to usr/bin MemTotal: 4010456 kB MemFree: 2311488 kB MemAvailable: 3290412 kB
/proc/meminfo is not stored on any disk. The kernel creates its contents at the moment you read it, so the numbers are always live.
Common mistakes
- Confusing
/rootwith/./is the top of the whole tree;/rootis only the root user's home folder. - Forgetting the leading slash.
etc/ssh(relative) is not/etc/ssh(absolute). If a path "does not exist", check where you are. - Saving your work in
/tmp. It is emptied on reboot. Keep anything you care about in your home folder. - Using backslashes or wrong capital letters.
/Home/Priyadoes not exist;/home/priyadoes.
Key points
- Linux has one directory tree starting at
/; there are no drive letters. /homeholds user files,/etcholds configuration,/var/logholds logs and/usr/binholds commands.- Absolute paths start with
/; relative paths start from the current directory. .is the current directory,..the parent and~your home.- Names starting with a dot are hidden;
ls -ashows them.
Exercise
Priya is in /home/priya/projects. Write the absolute path and one relative path for each of these: her Downloads folder, the SSH configuration folder /etc/ssh, and a file todo.txt inside her notes folder. Then, on your own system, use file to check what /etc/os-release is.
Show solution
| Target | Absolute path | Relative path from /home/priya/projects |
|---|---|---|
| Downloads | /home/priya/Downloads | ../Downloads |
| SSH settings | /etc/ssh | ../../../etc/ssh |
| todo.txt | /home/priya/notes/todo.txt | ../notes/todo.txt |
file /etc/os-release/etc/os-release: symbolic link to ../usr/lib/os-release
For /etc/ssh the absolute path is far simpler than climbing up three levels, which is why absolute paths are used for system files. On Ubuntu, /etc/os-release is a link to the real file in /usr/lib.
Quick Quiz
1. Which directory holds system-wide configuration files?
Configuration lives in /etc, mostly as plain text files.
2. Which of these is an absolute path?
Absolute paths always start with /, the root directory.
3. Where should you look first for log files?
Logs are changing data, so they live under /var, in /var/log.
4. What does .. mean in a path?
.. moves one level up; ~ is home and / is root.
Learn Linux with a mentor
Free lessons get you started. Our Ethical Hacking & Cyber Security training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
