Skip to content

Basics of the Linux File System

Introduction

The Linux file system is a hierarchical structure used to organize and manage data efficiently. It follows a tree-like model, with everything originating from the root (/).

What is a file system?

A file system determines how data is stored and accessed. Linux supports multiple file systems, including ext4, XFS, Btrfs, and ZFS, each with unique features.1

The Linux Directory Structure

Essential Directories and Their Purpose

/          # (1) Root directory
/bin       # (2) Essential system programs
/boot      # (3) Bootloader and kernel files
/dev       # (4) Device files (e.g., /dev/sda for hard drives)
/etc       # (5) System configuration files
/home      # (6) User home directories
/lib       # (7) Essential shared libraries
/media     # (8) Mount points for removable devices
/mnt       # (9) Temporary mount points
/opt       # (10) Optional third-party software
/proc      # (11) Virtual filesystem for kernel and process info
/root      # (12) Root user’s home directory
/run       # (13) Temporary process data
/sbin      # (14) System administration commands
/tmp       # (15) Temporary files (cleared on reboot)
/usr       # (16) User applications and utilities
/var       # (17) Variable data like logs and caches

Key Takeaways

  • Avoid modifying /etc unless necessary—critical system settings are stored here.
  • Use /var/log/ for troubleshooting system logs.
  • Mount external drives to /mnt/ or /media/ to prevent conflicts.
  • Device files under /dev/ represent actual hardware (e.g., /dev/sda for disks).

File Permissions & Ownership

Understanding File Permissions

ls -l file.txt
-rwxr--r--  1 user group  1024  Jan 1 12:00 file.txt
- r (read), w (write), x (execute) for owner, group, others.
- chmod 755 file.txt → Owner has full access, others have read/execute.
- chown user:group file.txt → Change file owner and group.

Advanced File Permissions

chmod u+x script.sh  # Give execute permission to the owner
chmod -R 777 /data   # Give full access to all users (not recommended)

Be Careful with Permissions!

Giving full (777) or root (chown root:root) permissions can break security.

Managing File Systems & Partitions

Checking Available File Systems

df -h    # Show disk space usage
du -sh * # Show folder sizes
mount    # List mounted file systems

Mounting & Unmounting Drives

mount /dev/sdb1 /mnt/usb  # Mount a USB drive
umount /mnt/usb           # Unmount the drive

File System Types in Linux

File System Description
ext4 Default Linux FS, journaling, reliable
XFS High-performance, scalable
Btrfs Advanced features, snapshots, self-healing
ZFS RAID support, data integrity, snapshots

Special Linux File System Features

Virtual File Systems

  • /proc → Provides information about running processes (cat /proc/cpuinfo).
  • /sys → Interfaces with hardware components and kernel settings.
  • /dev → Represents hardware devices as files.

Swap Space

free -h         # Check swap usage
swapon -s       # List active swap partitions
sudo mkswap /swapfile  # Create a new swap file
Linux uses swap space when RAM is full, preventing crashes.


Download Cheat Sheet


Conclusion

A strong grasp of the Linux file system enables efficient system management. Mastering navigation, permissions, and file system operations is essential for troubleshooting and automation.

Avoid These Common Mistakes!

  • Deleting critical files in /etc or /bin.
  • Not setting proper permissions (e.g., chmod 777 on sensitive files).
  • Forgetting to unmount (umount) external drives before removal.

  1. Linux file systems like ext4, XFS, Btrfs, and ZFS have unique features suited for different workloads.