Linux Directory Structure Overview - Understanding the Filesystem Hierarchy

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?

Lina: Linny-senpai, I can't find a Documents folder on Linux, just places I've never heard of like /etc and /usr. I keep getting lost...
Linny-senpai: I totally understand. If you go looking for it like a "C drive" on Windows, you'll get confused. Linux has this structure like one big tree. Let's start by getting the big picture.

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).

Lina: On Windows it was split into "C drive" and "D drive", but Linux is different?
Linny-senpai: Right, that's the big difference. Linux has no drive letters. A USB stick, an external disk, everything connects as "some branch" of one tree that starts from /. 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)

Lina: That / from earlier, is it a folder itself?
Linny-senpai: Exactly. / 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
Lina: Wow, that's a lot. Do I have to memorize all of these...?
Linny-senpai: Relax. You don't need to memorize all of them. At first you only need about 5 or 6. For the rest, just "there's a box like that" is fine. There's actually a rule to this layout, called the FHS (Filesystem Hierarchy Standard), a worldwide convention.

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

Linny-senpai: First, let's look at the overall map. Once this is in your head, you'll never get lost again.
/                  <- 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.)
Lina: home and root look similar. Are they different things?
Linny-senpai: Good catch. /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

Lina: I'd like to know a bit more about each one specifically.
Linny-senpai: Let's go in order of the ones you'll meet most often. Pairing each with "when you use it" makes it stick.

/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  ...
Lina: Does passwd have passwords written in it!?
Linny-senpai: The name is misleading, but /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
Lina: I thought ls was a command, but it's a file?
Linny-senpai: Yes, the true form of a command is a program file placed in /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.

/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

Lina: When I ran ls on /proc, tons of numbered folders showed up and it was creepy...
Linny-senpai: No need to be scared. /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

Lina: I'm starting to understand the structure. But when I'm actually moving around, I feel like I'll still get lost...
Linny-senpai: For times like that, let me teach you the "current-location 3-piece set". With this, you can stay calm wherever you are.

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
Lina: So cd / takes me back to the very top.
Linny-senpai: Right. When lost, 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

Linny-senpai: Alright, let's check whether the map is in your head!

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?

Lina: Done! Even if I go to /etc, I can get back to my room instantly with cd ~, so I'm not scared anymore.
Linny-senpai: That feeling matters. When lost, go back to the root (/) or your room (~). That's the basics of moving between directories.

Recap

Lina: Today I learned the Linux directory structure. / is the starting point, and home, etc, and var branch out from there!
Linny-senpai: Exactly. And "your own stuff is /home", "config is /etc", "logs are /var/log". Just these three will take you far in real-world work.
Lina: Now even when an unfamiliar place shows up, I can guess "ah, this is the system side".
Linny-senpai: Perfect. With the map in your head, you can read a situation just from a path in an error message. Next, let's actually create files and run things!

Three-Line Summary

  1. Linux is one tree starting from / (root). There are no drive letters
  2. The three most important: your own stuff is /home, config is /etc, logs are /var/log
  3. When lost: pwd to check location, cd / for the root, cd ~ for your own room

Once the map of the directory structure is in your head, actually move around and operate so your body learns it.