The Linux Filesystem#
Everything in Linux is a file. Directories are files. Devices are files. Processes expose themselves as files. This single organizing principle means that once you understand the filesystem, you understand how to interact with nearly everything on the system.
The filesystem starts at a single root directory, /, and branches downward. There are no drive letters like C:\ or D:\ — everything lives under one tree.
/
├── bin
├── etc
├── home
├── tmp
├── usr
├── var
└── ...The Filesystem Hierarchy Standard (FHS)#
The FHS defines where files should live on a Linux system. Every major distribution follows it, so the layout is consistent whether you’re on Ubuntu, Fedora, Arch, or a server running RHEL.
Top-Level Directories#
| Directory | Purpose |
|---|---|
/ | Root — the top of the filesystem tree |
/bin | Essential user commands (ls, cp, cat) |
/sbin | Essential system commands (mount, reboot, iptables) |
/etc | System configuration files |
/home | User home directories (/home/mike, /home/alice) |
/root | Home directory for the root user |
/tmp | Temporary files (cleared on reboot) |
/var | Variable data — logs, caches, mail, spool files |
/usr | User programs and data (most installed software lives here) |
/lib | Shared libraries needed by /bin and /sbin |
/opt | Optional/third-party software |
/dev | Device files (disks, terminals, USB devices) |
/proc | Virtual filesystem exposing kernel and process info |
/sys | Virtual filesystem exposing hardware and driver info |
/mnt | Temporary mount point for manual mounts |
/media | Auto-mounted removable media (USB drives, CDs) |
/boot | Boot loader files and kernel images |
/srv | Data served by the system (web, FTP) |
Key Directories in Detail#
/etc — Configuration#
Almost every system and application configuration lives here:
/etc/hostname # System hostname
/etc/hosts # Local DNS overrides
/etc/fstab # Filesystem mount table
/etc/ssh/sshd_config # SSH server configuration
/etc/passwd # User account information
/etc/group # Group definitions
/etc/resolv.conf # DNS resolver configuration/var — Variable Data#
Data that changes during system operation:
/var/log/ # System and application logs
/var/log/syslog # General system log
/var/log/auth.log # Authentication events
/var/cache/ # Application caches
/var/tmp/ # Temporary files that persist across reboots
/var/lib/ # State information for applications/usr — User Programs#
Most installed software ends up here:
/usr/bin/ # Non-essential user commands
/usr/sbin/ # Non-essential system commands
/usr/lib/ # Libraries for /usr/bin and /usr/sbin
/usr/local/ # Locally compiled software (kept separate from package manager)
/usr/share/ # Architecture-independent data (docs, icons, man pages)/proc and /sys — Virtual Filesystems#
These don’t exist on disk — the kernel generates them on the fly:
/proc/cpuinfo # CPU information
/proc/meminfo # Memory usage
/proc/1234/ # Information about process 1234
/sys/class/net/ # Network interface information
/sys/block/ # Block device informationPaths: Absolute vs Relative#
Absolute paths start from root (/):
/home/mike/Documents/notes.txt
/etc/ssh/sshd_configRelative paths start from your current directory:
Documents/notes.txt # relative to where you are
../config/settings.toml # one level up, then into config/Special Path Symbols#
| Symbol | Meaning |
|---|---|
/ | Root directory |
. | Current directory |
.. | Parent directory (one level up) |
~ | Home directory of the current user |
~mike | Home directory of user “mike” |
- | Previous directory (used with cd) |
Essential Navigation Commands#
pwd — Print Working Directory#
Shows where you are:
pwd
# /home/mike/projectscd — Change Directory#
cd /etc # Go to /etc (absolute)
cd Documents # Go to Documents (relative)
cd .. # Go up one level
cd ~ # Go to your home directory
cd # Also goes to your home directory
cd - # Go back to the previous directoryls — List Directory Contents#
ls # List current directory
ls /var/log # List a specific directory
ls -l # Long format (permissions, owner, size, date)
ls -a # Show hidden files (starting with .)
ls -la # Long format + hidden files
ls -lh # Long format with human-readable sizes
ls -lt # Long format sorted by modification time
ls -R # Recursive — list subdirectories tooReading ls -l output:
drwxr-xr-x 5 mike mike 4096 Jun 9 10:30 Documents
-rw-r--r-- 1 mike mike 842 Jun 9 09:15 notes.txt| Field | Meaning |
|---|---|
d or - | Directory or regular file |
rwxr-xr-x | Permissions (owner/group/others) |
5 | Number of hard links |
mike mike | Owner and group |
4096 | Size in bytes |
Jun 9 10:30 | Last modified date |
Documents | Filename |
tree — Visual Directory Structure#
tree # Tree view of current directory
tree -L 2 # Limit to 2 levels deep
tree -d # Directories only
tree /etc/ssh # Tree view of a specific directoryNote: tree may not be installed by default — install it with your package manager.
file — Identify File Type#
file document.pdf
# document.pdf: PDF document, version 1.4
file /bin/ls
# /bin/ls: ELF 64-bit LSB pie executable
file image.png
# image.png: PNG image data, 1920 x 1080, 8-bit/color RGBAstat — Detailed File Information#
stat notes.txt
# Shows: size, blocks, inode, permissions, timestamps (access, modify, change)du — Disk Usage#
du -h Documents/ # Size of each subdirectory (human-readable)
du -sh Documents/ # Summary total only
du -sh */ # Size of each directory in current location
du -h --max-depth=1 # One level deepdf — Filesystem Disk Space#
df -h # Show all mounted filesystems with human-readable sizes
df -h / # Show space for a specific mount pointFinding Files#
find — Search by Attributes#
# Find by name
find /home -name "*.txt"
# Find by name (case-insensitive)
find /home -iname "*.jpg"
# Find directories only
find /var -type d -name "log"
# Find files modified in the last 24 hours
find /etc -mtime -1
# Find files larger than 100MB
find / -size +100M
# Find and act on results
find /tmp -name "*.tmp" -deletewhich — Find Command Location#
which python3
# /usr/bin/python3
which git
# /usr/bin/gitlocate — Fast Filename Search#
locate sshd_config
# /etc/ssh/sshd_configlocate uses a pre-built database — run sudo updatedb to refresh it.
Hidden Files#
Files and directories starting with . are hidden by default:
ls -a ~
# .bashrc .config .ssh Documents DownloadsCommon hidden files in your home directory:
| File | Purpose |
|---|---|
~/.bashrc | Shell configuration |
~/.ssh/ | SSH keys and config |
~/.config/ | Application configurations (XDG standard) |
~/.local/ | User-specific data and binaries |
~/.gitconfig | Git configuration |
Best Practices#
- Use
cd -to toggle between two directories you’re working in - Use tab completion — press
Tabto auto-complete paths and filenames - Use
ls -laas your default — hidden files and permissions are usually relevant - Learn the FHS layout — when something goes wrong, knowing where logs, configs, and binaries live saves time
- Never modify files in
/procor/sysunless you know exactly what you’re doing - Use
/tmpfor scratch files — it’s cleaned automatically, so nothing important should live there - Keep personal scripts in
~/.local/binand add it to yourPATH

