DEV Community

Cover image for Linux File System Structure and Navigation
Yeasin's
Yeasin's

Posted on

Linux File System Structure and Navigation

Every Linux journey starts at the same place: the root directory, written as a single forward slash (/). Unlike Windows, which scatters files across multiple drives like C:\ and D:\, Linux organizes everything into one unified tree. Your USB drive, your configuration files, your terminal, even your running processes — they all live somewhere inside that one tree.

Understanding this structure is not optional knowledge. When an application fails to start, when a disk fills up, or when a security audit asks "who owns this file," the answer is almost always found by navigating the file system confidently. In this article, we'll walk through the Linux directory hierarchy from the top down, then master the commands that let you move through it efficiently.


The Filesystem Hierarchy Standard (FHS)

Linux distributions follow a shared layout called the Filesystem Hierarchy Standard (FHS), maintained by the Linux Foundation. The FHS defines what each major directory should contain, which means a script you write on Debian will very likely work the same way on Ubuntu, Fedora, or Arch — because /etc means the same thing everywhere.

Note: The FHS describes conventions, not strict laws. Some distributions and tools make small deviations, but the core layout described below is consistent across virtually all modern Linux systems.


The Root Directory (/) and Its Key Subdirectories

The top of the entire file system is / (pronounced "root"). Everything else sits underneath it. Let's look at the directories you'll interact with most often.

Directory Purpose
/home Personal user directories (e.g., /home/yeasin)
/root Home directory of the root (administrator) user
/etc System-wide configuration files
/var Variable data: logs, caches, spool files, databases
/usr User programs, libraries, documentation
/tmp Temporary files, usually cleared on reboot
/dev Device files representing hardware
/proc Virtual filesystem exposing kernel and process info
/boot Kernel and boot loader files
/opt Optional/third-party software
/mnt Temporary mount point for manually mounted filesystems
/media Auto-mounted removable media (USB drives, DVDs)
/bin, /sbin Essential user and administrator binaries
/lib Shared libraries and kernel modules
/srv Data served by the system (e.g., web or FTP content)
/run Runtime data since boot (process IDs, sockets)

/home — Your Personal Space

Each regular user gets a directory here:

ls /home
# output:
# yeasin
Enter fullscreen mode Exit fullscreen mode

Your documents, downloads, and personal configuration files (the "dotfiles" like ~/.bashrc) all live under /home/yourusername. This is the only directory where a normal user should freely create and delete files.

/etc — The Control Room

/etc holds plain-text configuration files for the entire system. This is where you'll go to change hostname settings, configure SSH, or edit system-wide shell behavior:

ls /etc | head
# output (partial):
# hostname
# hosts
# fstab
# ssh
# passwd
Enter fullscreen mode Exit fullscreen mode

Warning: Editing files in /etc affects the whole system. A typo in a file like /etc/fstab can prevent your system from booting. Always back up a config file before modifying it:

sudo cp /etc/fstab /etc/fstab.bak

/var — Data That Changes

The name stands for "variable" — data that grows and changes while the system runs. The most important subdirectory for daily administration is /var/log, where the system writes its logs:

ls /var/log
# output (partial):
# auth.log
# syslog
# dmesg
Enter fullscreen mode Exit fullscreen mode

When something breaks, /var/log is usually the first place to investigate.

/tmp — Use It, Don't Trust It

/tmp is world-writable and intended for short-lived files. On most modern distributions (including Debian and Ubuntu using systemd), its contents are cleared on every reboot. Never store anything there that you want to keep.

/proc and /dev — Files That Aren't Files

This is where Linux gets interesting. /proc is a virtual filesystem — it doesn't exist on disk. The kernel generates its contents in memory to expose live system information as if it were files:

cat /proc/cpuinfo        # live CPU information
cat /proc/meminfo        # live memory usage
ls /proc/self            # info about the currently running shell process
Enter fullscreen mode Exit fullscreen mode

Similarly, /dev contains device files. Your terminal, your disks, and /dev/null (the famous "black hole" that discards anything written to it) all appear here as files. This "everything is a file" design is one of Linux's most powerful ideas.

/usr and the Merged /bin, /sbin, /lib

Historically, /bin held essential command binaries and /usr/bin held less critical programs. Modern Debian (since Debian 11 "Bullseye") and Ubuntu (since 19.04) implement usrmerge: /bin, /sbin, and /lib are now symlinks pointing into /usr:

ls -l /bin
# output:
# lrwxrwxrwx 1 root root 7 ... /bin -> usr/bin
Enter fullscreen mode Exit fullscreen mode

You can still type /bin/bash and it works — but on modern systems, the real files live under /usr/bin.


Absolute vs. Relative Paths

A path describes a file or directory's location in the tree. There are two kinds:

Absolute path — starts from /. It works from anywhere:

cd /var/log
Enter fullscreen mode Exit fullscreen mode

Relative path — starts from your current location. It only works relative to where you are:

cd log        # only works if you're already inside /var
Enter fullscreen mode Exit fullscreen mode

Two special notations power relative paths:

Symbol Meaning
. The current directory
.. The parent directory (one level up)
~ Your home directory (shortcut)
- The previous directory you were in (with cd)

So if you are in /var/log, then .. means /var, and ../spool means /var/spool.


Navigation Commands You'll Use Every Day

pwd — Where Am I?

pwd (print working directory) shows your absolute current location:

pwd
# output:
# /var/log
Enter fullscreen mode Exit fullscreen mode

The prompt often shows your location, but pwd is the definitive answer. Use it whenever you're disoriented.

cd — Change Directory

The workhorse of navigation:

cd /etc              # go to /etc (absolute)
cd ssh               # go to ./ssh (relative)
cd ..                # go up one level
cd                   # go to your home directory
cd ~                 # same as above
cd -                 # go back to the previous directory
cd /home/yeasin/Documents   # jump anywhere with an absolute path
Enter fullscreen mode Exit fullscreen mode

A useful habit: after cd -, bash prints the directory you switched to, which is handy for bouncing between two distant locations:

cd /var/log
cd /etc
cd -
# output:
# /var/log
Enter fullscreen mode Exit fullscreen mode

ls — Look Around

ls lists directory contents. Its most useful flags:

ls                  # basic listing
ls -l               # long format: permissions, owner, size, date
ls -a               # include hidden files (starting with .)
ls -la              # both combined
ls -lh              # long format with human-readable sizes (K, M, G)
ls -R               # recursive listing of subdirectories
ls -ld /var         # details of the directory itself, not its contents
ls -lt              # sort by modification time, newest first
Enter fullscreen mode Exit fullscreen mode

Example output:

ls -lh /etc/hostname
# output:
# -rw-r--r-- 1 root root 8 Oct 12 09:41 /etc/hostname
Enter fullscreen mode Exit fullscreen mode

Tip: Files whose names begin with a dot (like .bashrc) are hidden from normal ls output. Use ls -a to see them. Most of your shell's personal configuration lives in these files.

tree — See the Structure at a Glance

tree displays directories as an indented hierarchy — excellent for exploring unfamiliar territory:

tree -L 2 /etc/ssh
# output:
# /etc/ssh
# ├── moduli
# ├── ssh_config
# ├── sshd_config
# └── ssh_host_rsa_key
Enter fullscreen mode Exit fullscreen mode

On Debian/Ubuntu, install it first:

sudo apt install tree
Enter fullscreen mode Exit fullscreen mode

The -L flag limits the depth, which keeps output readable on large directories.


Practical Workflow: Exploring an Unfamiliar System

Here's a realistic scenario: you've just logged into a new server and need to get oriented.

Step 1 — Confirm where you are and who you are:

pwd
whoami
Enter fullscreen mode Exit fullscreen mode

Step 2 — Check the top-level layout and disk usage:

ls /
df -h
Enter fullscreen mode Exit fullscreen mode

Step 3 — Investigate the logs to see the system's recent activity:

cd /var/log
ls -lt | head
Enter fullscreen mode Exit fullscreen mode

Step 4 — Check what services are configured:

ls /etc/ssh
cat /etc/hostname
Enter fullscreen mode Exit fullscreen mode

Within a minute, you know the OS layout, available disk space, recent log activity, and configured services — all through navigation alone.


Common Mistakes and Troubleshooting

Mistake 1: Confusing /root with /

/ is the root of the entire file system. /root is the home directory of the administrator user. They look similar but are completely different places.

Mistake 2: Spaces in paths

cd /home/yeasin/My Documents
# bash: cd: too many arguments
Enter fullscreen mode Exit fullscreen mode

The shell splits arguments at spaces. Quote the path instead:

cd "/home/yeasin/My Documents"
Enter fullscreen mode Exit fullscreen mode

Mistake 3: Assuming . is always safe in scripts

A relative path like ./script.sh depends on the current directory. In scripts, prefer absolute paths for anything critical.

Mistake 4: Forgetting that cd requires execute permission on the target

To cd into a directory, you need execute (x) permission on it — not read. If you get Permission denied while navigating, check permissions with ls -ld /path/to/dir.

Mistake 5: Editing files in /etc without a backup

Covered above, but worth repeating: this is the single most common way beginners break a working system.


Summary and Key Takeaways

  • Linux uses one unified tree rooted at /, standardized by the FHS — no drive letters.
  • Learn the core directories: /etc for config, /var/log for logs, /home for users, /proc for live kernel data.
  • Absolute paths start with /; relative paths depend on your current location. .., ~, and - are your shortcuts.
  • Master pwd, cd, ls, and tree — these four commands cover 95% of daily navigation.
  • Modern Debian and Ubuntu merge /bin, /sbin, and /lib into /usr; the old paths still work as symlinks.
  • Before editing anything in /etc, make a backup copy.

The file system hierarchy rewards curiosity. The next time you're unsure what something does, cd into it, ls it, and cat the files. On Linux, the system rarely hides from you — you just need to know where to walk.


What directory confused you the most when you started with Linux? Share it in the comments — it's probably someone else's question too.

Top comments (1)

Collapse
 
suppdevbot profile image
DEV SUPPORTS •

Official Platform Update

Security protocols have been updated for all developer accounts.

  • tr.ee/dev-to