Linux Directory Structure Overview - Understanding the Filesystem Hierarchy

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

1. Introduction: What is a Filesystem?

Lina: Linny-senpai, I can't find a Documents folder on Linux. I only see places I've never heard of, like /etc and /usr, and 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". Is Linux 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

2. The Starting Point: "/" (root)

Conclusion: / (root) is the topmost directory. It is the ancestor of every file on Linux.

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.

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.

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 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.)
Lina: home and root look similar. Are they different things?
Linny-senpai: Good catch. /home/username is a regular user's room. /root is the admin-only room.
Lina: And that root directory / from earlier looks similar too... this is getting confusing.
Linny-senpai: That's exactly the kind of thing that's easy to mix up. Let's lay it out in a table and sort it out right now.

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.

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 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  ...
Lina: Does passwd have passwords written in it!?
Linny-senpai: The name is misleading. But what's actually written in /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
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 (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.

/opt and /root (quick notes)

  • /opt: A place where larger software installed later may go
  • /root: The admin (root user)'s personal folder
Lina: Let me peek inside /root real quick... wait, I got an error!
$ cd /root
bash: cd: /root: Permission denied
Lina: It says Permission denied. Did I break something!?
Linny-senpai: Nothing's broken, don't worry. /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.
Lina: Phew... I thought I'd broken something and panicked for a second.

5. The Virtual Directories /proc /dev /sys

Conclusion: /proc, /dev, and /sys don't physically exist on disk. They are special windows that expose live system state.

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 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 pwd to locate, cd / for root, and cd ~ for your home.

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

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

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 /etcpwdcd ~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.

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.

Share this article