Linux Directory Structure Overview - Understanding the Filesystem Hierarchy
What you'll be able to do
- Explain what the main directories (/, /home, /etc, …) are for
- Guess where a file you need is likely to live
Prerequisites (read these first)
"There's cd /etc, then /var/log. So many different places keep showing up. What are they all?" This is a question everyone hits when they start using Linux. In this article, through a dialogue between Linny-senpai and Lina, let's build a mental map of the Linux directoryA container that organizes files. Same idea as a "folder" on Windows or macOS. structure together.
What You'll Learn
- That the Linux filesystem is one tree branching from
/(rootThe special administrator account allowed to do anything on the system.) - The roles of key directories like
/etc,/var,/home, and/bin - The FHS (Filesystem Hierarchy Standard), a worldwide convention
- What virtual directories like
/proc,/dev, and/sysreally are - How to check your location so you never get lost
1. Introduction: What is a Filesystem?
Documents folder on Linux. I only see places I've never heard of, like /etc and /usr, and I keep getting lost...What is a filesystem?
On Linux, every file and folder (directory) branches out from a single starting point, forming a "tree"-like structure. This starting point is called the root directory, written as / (a single slash).
/. Remember this and everything else gets much easier.Why knowing the structure pays off
- You can predict where config files live (usually inside
/etc) - You know where logs live (usually
/var/log) - You can make an educated guess from a pathA string that describes the location of a file or directory. in an error message ("ah, this is a system area")
- You stop hesitating about "where should I put what?"
2. The Starting Point: "/" (root)
Conclusion:
/(root) is the topmost directory. It is the ancestor of every file on Linux.
/ from earlier, is it a folder itself?/ is the topmost directory, the ancestor of every file. Let's take a look inside.$ ls / bin dev home lib mnt proc run srv tmp var boot etc lib64 media opt root sbin sys usr
FHS (Filesystem Hierarchy Standard)
A standard specification that decides what goes in which directory. Thanks to it, on Ubuntu or CentOS alike, "config is in /etc" and "logs are in /var/log" are in almost the same place.
By the way, a "packaged set of Linux" like Ubuntu or CentOS is called a distribution (or "distro" for short). The reason you don't get lost across different distros is this standard.
3. A Map of the Main Directories
Conclusion: Group the main directories into people, system, and changing-data sets.
/ <- the starting point of everything (root) ├── bin <- basic commands (ls, cp, etc.) ├── boot <- files needed to boot ├── dev <- devices (disks, USB, etc.) ├── etc <- system-wide config files ├── home <- per-user personal folders │ └── yamada <- yamada's "own room" ├── lib <- shared libraries (program parts) ├── opt <- extra software you added ├── proc <- info on processes (running programs) (virtual) ├── root <- the admin (root) user's personal folder ├── tmp <- temporary files (cleared on reboot) ├── usr <- where apps and command binaries live └── var <- changing data (logs, etc.)
home and root look similar. Are they different things?/home/username is a regular user's room. /root is the admin-only room./ from earlier looks similar too... this is getting confusing.Telling apart the three things called "root"
| Written as | Called | What it refers to |
|---|---|---|
/ |
The root directory | The topmost directory. The starting point of everything |
/root |
The admin's home | The personal folder of the admin (root user) |
root |
The root user | The name of the admin account. Refers to a person |
The same word "root" splits into three different things. / is the top of the location hierarchy, /root is the admin's room, and root is the name of the admin, a person. Keep these three separate and you won't get confused.
Remember it in 3 groups
| Group | Directories | In one phrase |
|---|---|---|
| Belongs to people | /home, /root |
Personal file storage |
| Belongs to the system | /etc, /bin, /usr, /lib |
Config and program binaries |
| Changes while running | /var, /tmp, /proc, /dev |
Logs, temp, live info |
4. A Closer Look at Common Directories
Conclusion: Your stuff is
/home, config is/etc, logs/var/log, binaries/usr/bin.
/home - Your workspace
A personal directory for each user. For a user named yamada, /home/yamada is assigned, and in the terminalAn interactive program that reads the commands you type and runs them. you can write it as ~ (tilde).
$ cd ~ $ pwd /home/yamada
Almost all of your everyday file creating and editing happens inside here. Just remember: your own stuff goes under /home and you're safe.
/etc - The config file warehouse
The place where system-wide config files gather.
$ ls /etc hostname hosts passwd ssh network ...
passwd have passwords written in it!?/etc/passwd is user account info. The passwords themselves are not in it (the real encrypted passwords are in /etc/shadow). Remember: the contents of /etc are basically "read-only". Editing many of them requires admin privileges./var - Constantly changing data
Short for "variable". Data that grows and shrinks lives here. The thing beginners rely on most is logs.
$ ls /var/log syslog auth.log dpkg.log ...
The first place to look when troubleshooting is /var/log. "Something's wrong, so check the logs here" is a basic move even in real-world operations.
/bin and /usr/bin - The command binaries
The "real bodies" of the commands you type, like ls and cp, live here.
$ which ls /usr/bin/ls
ls was a command. But it's a file?/usr/bin and similar. You can check its location with which command-name. On recent distributions, /bin is often a shortcut (a symbolic link, a kind of "pointer" to the real file) to /usr/bin./tmp - Temporary storage
A place for temporary files. The contents are often cleared on reboot, so never put important files here.
/tmp is "only for things that can disappear". Saving important work-in-progress data here, then rebooting and losing it, is a classic beginner accident. Always use somewhere under /home to save things.
/opt and /root (quick notes)
- /opt: A place where larger software installed later may go
- /root: The admin (root user)'s personal folder
/root real quick... wait, I got an error!$ cd /root bash: cd: /root: Permission denied
Permission denied. Did I break something!?/root is the admin-only room. You, as a regular user, don't have a key to that room. This error just means "you can't come in", nothing more.5. The Virtual Directories /proc /dev /sys
Conclusion:
/proc,/dev, and/sysdon't physically exist on disk. They are special windows that expose live system state.
ls on /proc, tons of numbered folders showed up and it was creepy.../proc is a directory that doesn't physically exist on disk. It shows the info of processes (programs currently running), live, right there, like an information desk.| Directory | Contents | Image |
|---|---|---|
/proc |
Info on running processes | The system's "health-check desk" |
/dev |
Devices (disks, USB, etc.) | The "connection ports" to hardware |
/sys |
Info on the kernelThe core program of an OS. It bridges hardware and software. (the core of Linux) and hardware | A "peek window" into internal settings |
$ cat /proc/cpuinfo # you can see CPU info $ ls /dev/sda* # storage devices
What you see here will differ from computer to computer. It's fine if you can't read it yet — for now, just remember that "a window like this exists".
These are "information pretending to be files". You don't need to fully understand the mechanism yet. Just knowing "there are special boxes with no real substance" is enough.
6. Tips for Never Getting Lost
Conclusion: When lost, use
pwdto locate,cd /for root, andcd ~for your home.
The current-location 3-piece set
$ pwd # where am I now? (shows the absolute path) $ ls # what's here? $ cd / # go back to root and start over
cd / takes me back to the very top.cd / takes you back to root. From there you follow the branches one by one with ls, and you'll always reach your destination. It's the feeling of returning to the root of the tree. And cd ~ takes you straight back to your own room (home).Absolute paths vs relative paths
| Type | Example | Meaning |
|---|---|---|
| Absolute path | /var/log/syslog |
A full address written from / |
| Relative path | log/syslog |
Directions from where you are now |
When in doubt, use an absolute path (one starting from /) to be certain. The strength of an absolute path is that "it points to the same place no matter where you are".
Mini Exercises
Conclusion: Three exercises to check, with your own hands, "what's inside root," "how to get back to your own room," and "where a command's binary lives." Try typing it yourself before peeking at the answer.
Exercise 1: Explore root. Check whether the directories that appeared in this article (etc, var, home, etc.) actually exist
Hint 1 (Direction) — click to reveal
Look at what's directly under /. There's a command for listing directory contents that you used back in Chapter 2.
Hint 2 (Command) — click to reveal
Run ls /.
Show Answer
$ ls / bin dev home lib mnt proc run srv tmp var boot etc lib64 media opt root sbin sys usr
etc, var, and home are all there.
Exercise 2: Take a detour to the config warehouse, then find your way back to your own room
Hint 1 (Direction) — click to reveal
First move into /etc and check your location. Then use the symbol that takes you straight back to your own room.
Hint 2 (Command) — click to reveal
Run cd /etc → pwd → cd ~ → pwd, in that order.
Show Answer
$ cd /etc $ pwd /etc $ cd ~ $ pwd /home/yamada
cd ~ took you straight back to your own home.
Exercise 3: See a command's true form
Hint 1 (Direction) — click to reveal
There's a dedicated command for checking which file on disk is the actual body of a command like ls.
Hint 2 (Command) — click to reveal
Run which ls.
Show Answer
$ which ls /usr/bin/ls
The binary lives inside /usr/bin.
/etc, I can get back to my room instantly with cd ~, so I'm not scared anymore./) or your room (~). That's the basics of moving between directories.Recap
/ is the starting point, and home, etc, and var branch out from there!/home", "config is /etc", "logs are /var/log". Just these three will take you far in real-world work.Three-Line Summary
- Linux is one tree starting from
/(root). There are no drive letters - The three most important: your own stuff is
/home, config is/etc, logs are/var/log - When lost:
pwdto check location,cd /for the root,cd ~for your own room