Linux Directory Structure Overview - Understanding the Filesystem Hierarchy
"There's cd /etc, then /var/log, all these 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 directory structure together.
1. Introduction: What is a Filesystem?
Documents folder on Linux, just places I've never heard of like /etc and /usr. 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 path in an error message ("ah, this is a system area")
- You stop hesitating about "where should I put what?"
2. The Starting Point: "/" (root)
/ 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. The reason you don't get lost across different distributions is this standard.
3. A Map of the Main Directories
/ <- 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 running processes (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, while /root is the admin-only room. The names look alike, but they are all different: the root directory /, and the admin's room /root. They're easy to confuse, so I'll sort that out later.Remember it in 3 rough 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
/home - Your workspace
A personal directory for each user. For a user named yamada, /home/yamada is assigned, and in the terminal 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, and the passwords themselves are not in it (the actual encrypted passwords are in /etc/shadow). Remember: the contents of /etc are basically "read-only", and 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 (symbolic link) 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. Regular users can't enter it (they get
Permission denied)
5. The Virtual Directories /proc /dev /sys
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's Linux showing you "the current running state" on the spot, 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 |
Kernel and hardware info | A "peek window" into internal settings |
$ cat /proc/cpuinfo # you can see CPU info $ ls /dev/sda* # storage devices
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
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, and 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
Exercise 1: Explore root
Run ls / and check whether the directories that appeared in this article (etc, var, home, etc.) actually exist.
Exercise 2: Go back to your room
Run cd /etc to move into the config warehouse, then check your location with pwd. After that, run cd ~ to go back to your home, and confirm with pwd again.
Exercise 3: See a command's true form
Run which ls and check which directory the ls command binary is in. Was it /usr/bin or /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