The Linux file system follows a logical, hierarchical structure that might seem confusing at first, especially if you're coming from Windows. However, once you understand the principles behind this organization, you'll appreciate its consistency and logic.
Linux follows the Filesystem Hierarchy Standard (FHS), which defines the directory structure and contents for Unix-like operating systems. This standard ensures consistency across different Linux distributions.
- Everything starts from the root directory (/
)
/
) as path separators.
)The root directory is the top-level directory in the Linux filesystem hierarchy. Every file and directory stems from here.
ls -la /
Let's explore each major directory and its purpose:
Contains essential command-line utilities that need to be available in single-user mode and for all users.
ls /bin
# Common contents: bash, cat, chmod, cp, date, echo, grep, ls, mkdir, mv, rm, sh
Examples:
which ls # Usually /bin/ls
which bash # Usually /bin/bash
which cat # Usually /bin/cat
Purpose:
Contains essential system administration binaries, typically used by the root user.
ls /sbin | head -10
# Common contents: fsck, init, mount, reboot, shutdown, iptables
Examples:
which mount # Usually /sbin/mount
which iptables # Usually /sbin/iptables
which fsck # Usually /sbin/fsck
Purpose:
The largest directory in most systems, containing user-space programs and data.
Non-essential user commands and applications.
ls /usr/bin | wc -l # Often thousands of files
# Contents: gcc, python3, vim, firefox, git, npm, etc.
System administration programs that are not critical for basic system operation.
Shared libraries and internal binaries not meant to be executed directly by users.
Software installed locally by the system administrator, separate from distribution packages.
# Typical structure:
/usr/local/bin/ # Local binaries
/usr/local/lib/ # Local libraries
/usr/local/share/ # Local data files
/usr/local/src/ # Local source code
Shared data files, documentation, and resources.
ls /usr/share
# Contents: doc, man, icons, fonts, applications, locale
Shared library files needed by programs in /bin
and /sbin
.
ls /lib/x86_64-linux-gnu/ | head -10
# Contents: libc.so.6, libpthread.so.0, libdl.so.2
Purpose:
System-wide configuration files and shell scripts used during boot.
ls /etc | head -20
# Important files and directories we'll explore:
/etc/passwd
- User account information
head -5 /etc/passwd
# Format: username:password:UID:GID:info:home_directory:shell
/etc/shadow
- Encrypted passwords
sudo head -3 /etc/shadow
# Format: username:encrypted_password:last_change:min:max:warn:inactive:expire
/etc/group
- Group information
head -5 /etc/group
# Format: group_name:password:GID:user_list
/etc/fstab
- Filesystem mount information
cat /etc/fstab
# Defines which filesystems are mounted at boot
/etc/hosts
- Static hostname to IP mappings
cat /etc/hosts
# Local hostname resolution
/etc/sudoers
- Sudo configuration
sudo cat /etc/sudoers
# Defines sudo access permissions
/etc/cron.d/
- Cron job configurations
/etc/ssh/
- SSH server configuration
/etc/ssl/
- SSL certificates and keys
/etc/systemd/
- Systemd service configurations
/etc/network/
- Network configuration (Debian/Ubuntu)
Files that are expected to grow or change during normal system operation.
System and application log files.
ls /var/log
# Common logs: syslog, auth.log, kern.log, dpkg.log, apt/
Important log files:
sudo tail -f /var/log/syslog # System messages
sudo tail -f /var/log/auth.log # Authentication logs
sudo tail -f /var/log/kern.log # Kernel messages
dmesg # Kernel ring buffer
ls /var/cache
# Contents: apt, man, fontconfig
Persistent data modified by programs as they run.
ls /var/lib
# Contents: dpkg, systemd, mysql, docker, snapd
Temporary files waiting to be processed.
ls /var/spool
# Contents: mail, cron, cups (printing)
Temporary files that should persist between reboots.
Temporary files that are typically cleared on reboot.
ls -la /tmp
# Usually cleared automatically or on reboot
Characteristics:
drwxrwxrwt
)Personal directories for each user account.
ls -la /home
# Each user has a subdirectory: /home/username
ls -la ~/
# Hidden configuration files (.bashrc, .profile, .ssh)
# User data directories (Documents, Downloads, Pictures)
Important hidden directories:
~/.ssh/
- SSH keys and configuration~/.config/
- Application configurations~/.local/
- User-specific data and binaries~/.cache/
- User-specific cache filesHome directory for the root user (system administrator).
sudo ls -la /root
# Similar structure to user homes but for root
Files needed to boot the system, including the kernel and initial ramdisk.
ls -la /boot
# Contents: vmlinuz (kernel), initrd.img, grub/
Key files:
vmlinuz-*
- Linux kernelinitrd.img-*
- Initial RAM diskgrub/
- GRUB bootloader configurationSpecial files representing hardware devices and virtual devices.
ls -la /dev | head -20
# Everything is a file in Linux, including devices
Important device files:
ls -la /dev/sd* # Hard drives (sda, sdb, etc.)
ls -la /dev/tty* # Terminal devices
ls -la /dev/null # Null device (discards all data)
ls -la /dev/zero # Zero device (produces infinite zeros)
ls -la /dev/random # Random number generator
Virtual filesystem providing information about running processes and kernel parameters.
ls /proc | head -20
# Numbered directories are process IDs (PIDs)
Useful /proc
files:
cat /proc/cpuinfo # CPU information
cat /proc/meminfo # Memory information
cat /proc/version # Kernel version
cat /proc/uptime # System uptime
cat /proc/loadavg # System load average
cat /proc/mounts # Currently mounted filesystems
Process-specific information:
ls /proc/$$ # Information about current shell process
cat /proc/$$/cmdline # Command line of current process
cat /proc/$$/environ # Environment variables
Virtual filesystem for kernel and hardware information.
ls /sys
# Contents: block, bus, class, dev, devices, firmware, fs, kernel, module, power
Examples:
cat /sys/class/power_supply/BAT0/capacity # Battery level (laptops)
cat /sys/class/thermal/thermal_zone0/temp # CPU temperature
ls /sys/class/net/ # Network interfaces
Temporary mount points for filesystems.
- /mnt
- Temporary mount point for system administrators
/media
- Mount point for removable media (automatic mounting)ls /mnt
ls /media
mount | grep /media # Show mounted removable media
Add-on application software packages.
ls /opt
# Often contains: google, mozilla, proprietary software
Typical usage:
Runtime variable data since last boot.
ls /run
# Contents: systemd, user, lock, udev
Data for services provided by the system.
ls /srv
# Often contains: www, ftp, git
Start from the root directory (/
).
/home/username/Documents/file.txt
/etc/passwd
/var/log/syslog
Relative to the current working directory.
Documents/file.txt # If in /home/username
../etc/passwd # If in /root
./script.sh # In current directory
. # Current directory
.. # Parent directory
~ # Home directory
~username # Another user's home directory
- # Previous directory (with cd)
pwd # Print working directory
cd /path/to/directory # Change directory
ls -la # List files with details
tree /path # Visual directory tree
find /path -name "pattern" # Find files
locate filename # Quick file search
du -h /path # Directory sizes
df -h # Filesystem usage
ncdu /path # Interactive disk usage analyzer
mount # Show mounted filesystems
lsblk # List block devices
fdisk -l # List disk partitions
file /path/to/file # Determine file type
stat /path/to/file # Detailed file information
# Check system logs
sudo tail -f /var/log/syslog
sudo journalctl -u ssh.service
# Find large log files
find /var/log -name "*.log" -size +100M
# Archive old logs
sudo gzip /var/log/oldfile.log
# Backup configuration before changes
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
# Find configuration files
find /etc -name "*.conf" | head -10
# Compare configurations
diff /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
# Check user information
getent passwd username
getent group groupname
# User home directory exploration
ls -la /home/username
du -sh /home/*
# Typical development setup
mkdir -p ~/projects/myapp/{src,tests,docs,config}
cd ~/projects/myapp
# System-wide installations
ls /usr/local/bin # Local binaries
ls /usr/local/lib # Local libraries
# Find library files
ldconfig -p | grep libname
# Check library dependencies
ldd /usr/bin/program
# Locate header files
find /usr/include -name "*.h" | grep pattern
# Check filesystem types
df -T
# Common types:
# ext4 - Standard Linux filesystem
# xfs - High-performance filesystem
# btrfs - Advanced filesystem with snapshots
# tmpfs - Temporary filesystem in RAM
# proc - Process information
# sysfs - System information
# devpts - Pseudo-terminal devices
# Manual mounting
sudo mount /dev/sdb1 /mnt/usb
sudo mount -t ext4 /dev/sdb1 /mnt/external
# Unmounting
sudo umount /mnt/usb
# Check what's mounted
mount | column -t
# Critical system directories
ls -ld /etc /bin /sbin /usr/bin
# Should be owned by root with appropriate permissions
# Check for unusual permissions
find /usr/bin -perm -o+w # World-writable binaries (dangerous)
find /etc -perm -o+w # World-writable configs (dangerous)
# Files that should be protected
ls -la /etc/shadow # Password hashes
ls -la /etc/sudoers # Sudo configuration
ls -la ~/.ssh/id_rsa # Private SSH keys
# Find large files and directories
du -h / 2>/dev/null | sort -hr | head -20
find / -size +100M 2>/dev/null
# Check ownership and permissions
ls -la /path/to/problem/file
namei -l /path/to/problem/file # Show permissions for entire path
# Search for files
find / -name "filename" 2>/dev/null
locate filename
which command_name
# Organize your home directory
mkdir -p ~/projects/{personal,work,learning}
mkdir -p ~/scripts/{backup,automation,utilities}
mkdir -p ~/documents/{references,notes,archives}
# Keep configuration files organized
mkdir ~/dotfiles
ln -s ~/dotfiles/.bashrc ~/.bashrc
ln -s ~/dotfiles/.vimrc ~/.vimrc
# Create symbolic links
ln -s /very/long/path/to/file shortcut
ln -s /opt/myapp/bin/myapp /usr/local/bin/myapp
# Check where a link points
readlink /usr/bin/python3
ls -la /usr/bin/python3
# Extended attributes (on supported filesystems)
lsattr filename # List attributes
chattr +i filename # Make file immutable
chattr -i filename # Remove immutable attribute
/ Root directory
├── bin Essential user binaries
├── sbin System binaries
├── etc Configuration files
├── var Variable data (logs, caches)
├── usr User programs and data
├── home User home directories
├── root Root user home
├── tmp Temporary files
├── boot Boot loader files
├── dev Device files
├── proc Process information (virtual)
├── sys System information (virtual)
├── lib Essential libraries
├── mnt Temporary mount points
├── media Removable media mount points
├── opt Optional software
├── srv Service data
└── run Runtime data
pwd # Current directory
cd /path # Change directory
ls -la # List files
tree # Directory tree
du -h # Directory sizes
df -h # Disk usage
mount # Mounted filesystems
find /path -name pat # Find files
locate filename # Quick search
which command # Find command location
~/.bashrc # User shell configuration
~/.ssh/ # SSH keys and config
/etc/passwd # User accounts
/etc/group # Group definitions
/var/log/ # System logs
/proc/cpuinfo # CPU information
/sys/class/ # Hardware information
- The Linux filesystem hierarchy is logical and consistent across distributions
/
)/etc
, logs in /var/log
, user data in /home
/proc
, /sys
) provide system informationMastering the Linux file system hierarchy is fundamental to becoming proficient with Linux. This knowledge forms the foundation for system administration, software development, and general Linux usage. Take time to explore these directories on your system and observe how different applications organize their files within this structure.
---
This is Part 3 of our comprehensive Linux mastery series.
Previous: Terminal Commands - Master essential command-line navigation
Next: File Management - Learn to create, copy, move, and organize files efficiently
Beginner Foundation:
Ready for File Operations? Continue with file management to learn practical file manipulation techniques!
---
Congratulations! You've completed the foundational Linux topics. With these skills, you're ready to explore more advanced topics like shell scripting, system administration, networking, and server management.