Beginner · Linux and the shell · topic 2 of 57 · 30 min
The filesystem hierarchy and paths
Explanation
One tree, not drive letters
Windows shows disks as C:, D: and so on. Linux has a single tree of directories (folders) that starts at / , called the root directory. Every disk, USB stick or network share is attached somewhere inside this tree; attaching it is called mounting. So /home might live on one disk and /var on another, but you see one tree.
The important directories
| Directory | What lives there |
|---|---|
| /etc | System settings (config files): /etc/passwd, /etc/fstab, /etc/ssh/sshd_config |
| /var | Data that changes: logs in /var/log, web pages in /var/www, databases in /var/lib |
| /home | Home directories of normal users, like /home/asha |
| /root | Home directory of the root (admin) user. Not the same as / |
| /usr | Installed programs and libraries: /usr/bin, /usr/lib, /usr/share |
| /bin, /sbin, /lib | On RHEL these are links into /usr (for example /bin points to /usr/bin) |
| /tmp | Temporary files any user can write; cleaned up regularly |
| /boot | The kernel, the initramfs and the GRUB boot loader files |
| /dev | Device files: disks such as /dev/sda or /dev/vda, and /dev/null |
| /proc, /sys | Virtual files the kernel creates to show live information |
| /run | Runtime data that disappears at reboot (PID files, sockets) |
| /opt, /srv | Optional third-party software; data served by this system |
This layout comes from the Filesystem Hierarchy Standard (FHS). The man page hier(7) describes it on your own machine: run man hier.
Absolute and relative paths
A path is the address of a file. An absolute path starts with / and works from anywhere: /etc/hosts. A relative path does not start with / and is read from your current working directory (the folder you are in now). If you are in /etc, the relative path ssh/sshd_config means /etc/ssh/sshd_config.
- . (one dot) means "this directory".
- .. (two dots) means "the parent directory", one level up.
- ~ (tilde) means your home directory, for example /home/asha.
- - with cd means "the directory I was in before".
$ pwd
/home/asha
$ cd /etc/ssh
$ pwd
/etc/ssh
$ cd ../sysconfig
$ pwd
/etc/sysconfig
$ cd ~
$ pwd
/home/ashaEverything is a file
Linux shows many things as files: disks (/dev/sda), the random number source (/dev/urandom), and live kernel data (/proc/cpuinfo). That is why you can read the CPU details with cat /proc/cpuinfo, or throw unwanted output into /dev/null, a file that swallows everything written to it.
Common mistakes
- Mixing up / (the root of the tree) and /root (the root user's home folder).
- Using a relative path in a script or cron job. The script may run from a different directory, so the file is not found. Use absolute paths in scripts.
- Typing C:\ style paths or backslashes. Linux uses forward slashes, and names are case-sensitive: Report.txt and report.txt are two different files.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
The filesystem hierarchy and paths · 1/7
Linux has one tree of folders, starting at slash, the root directory.
Prefer a video by a teacher? Find free videos on “linux filesystem hierarchy explained etc var usr” on YouTube ↗
In real life: Finding logs on a college lab server
A college in Pune runs its exam portal on a RHEL server. During the exam the portal is slow. The lab assistant does not know the app, but she knows the hierarchy: settings are in /etc, logs are in /var/log, and the web content is in /var/www. In two minutes she finds /var/log/httpd/error_log full of "too many open files" lines and calls the right person.
$ ls /var/log/httpd/
access_log error_log
$ tail -n 2 /var/log/httpd/error_log
[Mon Oct 19 10:02:11 2026] [error] (24)Too many open files: AH00169: ...
[Mon Oct 19 10:02:12 2026] [error] (24)Too many open files: AH00169: ...Practice (0/3 done)
Where would you look first for the settings file of the SSH server?
Write resolve(cwd, path) that returns the absolute path the shell would use. cwd is an absolute directory like "/etc". If path starts with "/" it is already absolute. Otherwise join it to cwd. Then handle "." (stay) and ".." (go up one, but never above "/"). Return "/" for the root. Do not use the os module; split on "/".
On your lab VM, explore the tree and write one line about what you found in each of: /etc, /var/log, /home, /boot, /dev, /proc.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Shell basics and getting helpLinux and the shell · same module
- Working with files: ls, cp, mv, rm, links and findLinux and the shell · same module
- The Linux filesystem and everyday commandsDevOps: Git, Docker, Kubernetes and CI/CD · Linux for DevOps
- Links: connecting pagesFrontend Web Development · HTML basics
- Linux security basicsCyber Security: from zero to SOC analyst · Systems and cryptography
- Positioning and stackingFrontend Web Development · CSS layout and responsive design
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which directory holds log files?
Answer: /var/log
Changing data such as logs lives under /var; logs are in /var/log.
You are in /etc. Which absolute path does the relative path ../home/asha mean?
Answer: /home/asha
.. takes you from /etc up to /, then into home/asha.
What is /root?
Answer: The home directory of the root user
The top of the tree is /. /root is root's home directory.
Which path is absolute?
Answer: /etc/hosts
Only paths that start with / are absolute.
Why use absolute paths in scripts?
Answer: The script may run from a different working directory
A relative path depends on the current directory, which may be different when cron or another user runs the script.
Which folder holds log files on a typical Linux server?Related
Answer: /var/log
/var/log holds system and many application logs.
Which attribute holds the address of a link?Related
Answer: href
href (hypertext reference) is where the link goes. src is used by images and media.
Which file holds Linux password hashes?Related
Answer: /etc/shadow
/etc/shadow holds the hashes and is readable only by root (and the shadow group).
An absolute badge flies to the corner of the whole page. What is missing?Related
Answer: position: relative on the card
Without a positioned ancestor, absolute elements use the page as their reference.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Linux and the shell” before its exam: Shell basics and getting help, Working with files: ls, cp, mv, rm, links and find, Reading text: grep, less, pipes and redirection, Editing files with vim.
- Module 1 exam: Linux and the shell · 13 questions · 20 min, without help. 6 topics of this module still to finish first.
- Then the next module, Permissions, users and sudo. 57 topics left in the course before the final exam.