Skip to main content

The Linux Filesystem: Structure and Navigation

·1130 words·6 mins
Linux Learning Lab
Author
Linux Learning Lab
Writing about code, tools, and workflows.
linux-beginner - This article is part of a series.
Part 1: This Article

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
#

DirectoryPurpose
/Root — the top of the filesystem tree
/binEssential user commands (ls, cp, cat)
/sbinEssential system commands (mount, reboot, iptables)
/etcSystem configuration files
/homeUser home directories (/home/mike, /home/alice)
/rootHome directory for the root user
/tmpTemporary files (cleared on reboot)
/varVariable data — logs, caches, mail, spool files
/usrUser programs and data (most installed software lives here)
/libShared libraries needed by /bin and /sbin
/optOptional/third-party software
/devDevice files (disks, terminals, USB devices)
/procVirtual filesystem exposing kernel and process info
/sysVirtual filesystem exposing hardware and driver info
/mntTemporary mount point for manual mounts
/mediaAuto-mounted removable media (USB drives, CDs)
/bootBoot loader files and kernel images
/srvData 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 information

Paths: Absolute vs Relative
#

Absolute paths start from root (/):

/home/mike/Documents/notes.txt
/etc/ssh/sshd_config

Relative 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
#

SymbolMeaning
/Root directory
.Current directory
..Parent directory (one level up)
~Home directory of the current user
~mikeHome directory of user “mike”
-Previous directory (used with cd)

Essential Navigation Commands
#

pwd — Print Working Directory
#

Shows where you are:

pwd
# /home/mike/projects

cd — 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 directory

ls — 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 too

Reading 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
FieldMeaning
d or -Directory or regular file
rwxr-xr-xPermissions (owner/group/others)
5Number of hard links
mike mikeOwner and group
4096Size in bytes
Jun 9 10:30Last modified date
DocumentsFilename

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 directory

Note: 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 RGBA

stat — 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 deep

df — Filesystem Disk Space
#

df -h                # Show all mounted filesystems with human-readable sizes
df -h /              # Show space for a specific mount point

Finding 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" -delete

which — Find Command Location
#

which python3
# /usr/bin/python3

which git
# /usr/bin/git

locate — Fast Filename Search#

locate sshd_config
# /etc/ssh/sshd_config

locate 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  Downloads

Common hidden files in your home directory:

FilePurpose
~/.bashrcShell configuration
~/.ssh/SSH keys and config
~/.config/Application configurations (XDG standard)
~/.local/User-specific data and binaries
~/.gitconfigGit configuration

Best Practices
#

  • Use cd - to toggle between two directories you’re working in
  • Use tab completion — press Tab to auto-complete paths and filenames
  • Use ls -la as 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 /proc or /sys unless you know exactly what you’re doing
  • Use /tmp for scratch files — it’s cleaned automatically, so nothing important should live there
  • Keep personal scripts in ~/.local/bin and add it to your PATH
linux-beginner - This article is part of a series.
Part 1: This Article