1.5. Filesystem Hierarchy#
The Linux filesystem is organized according to the Filesystem Hierarchy Standard (FHS). Understanding this structure is essential for finding files, installing software, and administering systems. Rather than random organization, every directory has a specific purpose.
1.5.1. The Root Directory and Directory Structure#
Everything in Linux starts from / (the root directory). Here’s the standard structure:
/
├── bin/ Essential system programs (binaries)
├── boot/ Boot files and kernel
├── dev/ Device files
├── etc/ System configuration files
├── home/ User home directories
├── lib/, lib64/ System libraries
├── media/ Mount points for removable media
├── mnt/ Mount points for temporary filesystems
├── opt/ Optional software packages
├── proc/ Process information (virtual filesystem)
├── root/ Root user's home directory
├── run/ Runtime data
├── sbin/ System binaries (require root)
├── srv/ Service data
├── sys/ System information (virtual filesystem)
├── tmp/ Temporary files
├── usr/ User programs and data
└── var/ Variable data (logs, caches, databases)
Let’s explore each important directory:
1.5.2. Essential Directories#
1.5.2.1. / (Root)#
The top-level directory containing everything. You can navigate here:
$ cd /
$ ls -la
1.5.2.2. /home — User Home Directories#
Where individual users store their personal files:
/home/
├── alice/ Alice's home directory
├── bob/ Bob's home directory
└── charlie/ Charlie's home directory
Each user gets their own directory. Your home directory is referenced as ~:
$ pwd
/home/alice
$ cd ~ # Same as cd /home/alice
1.5.2.3. /root — Root User’s Home#
The root user (superuser/administrator) has a special home directory:
$ sudo ls /root # Can't access without permissions
Root’s home is /root, not /home/root.
1.5.2.4. /bin and /sbin — System Programs#
bin/ contains essential programs everyone uses:
$ ls /bin | head
bash # Shell
ls # List files
cat # Print files
cp # Copy
rm # Delete
sbin/ contains system programs that require root privileges:
$ ls /sbin | head
ifconfig # Network configuration
reboot # Reboot system
useradd # Add users
You can run programs in these directories without typing the full path because they’re in $PATH:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
1.5.2.5. /etc — Configuration Files#
System-wide configuration files in text format:
$ ls /etc | head
passwd # User account information
shadow # Encrypted passwords
hostname # Computer's name
hosts # IP address to hostname mappings
sudoers # Who can run sudo commands
ssh/ # SSH configuration
These are plain text files you can read (though some require root):
$ cat /etc/hostname # See computer name
$ cat /etc/hosts # See hostname mappings
$ sudo cat /etc/passwd # See user accounts
1.5.2.6. /usr — User Programs and Data#
The largest directory tree, containing most installed software:
/usr/
├── bin/ User programs (like /bin but non-essential)
├── sbin/ User system programs
├── local/ Locally installed software
│ ├── bin/ Your custom programs
│ └── lib/ Libraries for your software
└── share/ Shared data (documentation, icons, etc.)
├── man/ Manual pages
└── doc/ Documentation
When you install software with a package manager, it usually goes here:
$ which python # Find where python is installed
/usr/bin/python3
$ ls /usr/local/bin/ # Locally installed programs
1.5.2.7. /var — Variable Data#
Files that change frequently:
/var/
├── log/ System and program logs
│ ├── syslog System log
│ ├── auth.log Authentication logs
│ └── ...
├── cache/ Cached data
├── tmp/ Temporary files (preserved longer than /tmp)
└── lib/ Database files
Important for troubleshooting:
$ tail /var/log/syslog # View recent system messages
$ tail /var/log/auth.log # View recent login attempts
$ sudo tail /var/log/auth.log
1.5.2.8. /tmp and /var/tmp — Temporary Files#
Temporary storage:
/tmp — Cleared on reboot, used for session files
/var/tmp — May survive reboot, used for process data
$ ls /tmp
$ mkdir /tmp/my_test # Create temporary directory
$ rm -r /tmp/my_test # Clean up when done
1.5.2.9. /dev — Device Files#
Special files representing hardware devices:
$ ls /dev | head
sda # First hard drive
sda1 # First partition of first drive
tty # Terminal devices
null # Null device (discards data)
random # Random number generator
zero # Zeros device
Devices appear as files—you can read/write them:
$ cat /dev/random | head -c 16 | od -A x -t x1z -v
1.5.2.10. /proc — Process Information#
A virtual filesystem showing process information:
$ ls /proc
1 # PID 1 (init process)
2 # PID 2
...
self # Current process
Each directory contains info about a process:
$ cat /proc/self/cmdline # Current command line
$ cat /proc/cpuinfo # CPU information
$ cat /proc/meminfo # Memory information
1.5.2.11. /sys — System Information#
Another virtual filesystem with system details:
$ ls /sys
block/ # Block devices
bus/ # System buses
class/ # Device classes
devices/ # All devices
1.5.3. Important Paths#
1.5.3.1. Absolute vs Relative Paths#
Absolute paths start from root:
$ cd /home/alice/Documents # Absolute path
$ pwd
/home/alice/Documents
Relative paths are relative to current directory:
$ cd Documents # Relative path
$ pwd
/home/alice/Documents
1.5.3.2. Special Path Shortcuts#
Path |
Meaning |
|---|---|
|
Root directory |
|
Your home directory |
|
Current directory |
|
Parent directory |
|
Previous directory |
Examples:
$ cd / # Go to root
$ cd ~ # Go to home
$ cd . # Stay in current (rarely used)
$ cd .. # Go up one level
$ cd - # Go to previous directory
1.5.5. Understanding Directory Permissions#
Directories have special meaning for permissions:
$ ls -ld /home
drwxr-xr-x 5 root root /home
r (read): List contents of directory
w (write): Create/delete files in directory
x (execute): Enter/search the directory
You need x permission to enter a directory, even if you can read its contents!
1.5.6. The Filesystem Hierarchy in Action#
Here’s a practical example—finding your Python installation:
# Find python
$ which python3
/usr/bin/python3
# Check what it is
$ file /usr/bin/python3
/usr/bin/python3: symbolic link to python3.11
# Find the actual binary
$ which python3.11
/usr/bin/python3.11
# Find libraries
$ python3 -c "import sys; print('\n'.join(sys.path))"
/usr/lib/python3.11/
/usr/lib/python3.11/lib-dynload
This shows the filesystem hierarchy in action—programs in /usr/bin, libraries in /usr/lib.
1.5.7. Key Takeaways#
✓ Everything starts from / — Single root directory
✓ /home — User files live here
✓ /usr — Most installed software
✓ /etc — Configuration files
✓ /var/log — System logs for troubleshooting
✓ /tmp — Temporary storage
✓ Absolute paths start with /, relative paths don’t
✓ Use which to find programs, use find to find files
Once you understand the filesystem hierarchy, you’ll know where to look for anything on the system. This knowledge is fundamental to Linux administration and troubleshooting.