What is a File System?#

A file system organizes data on storage devices into a hierarchy of files and directories. It manages how data is stored, retrieved, and updated on disk.

flowchart TD
    Root["/"]
    Root --> etc["/etc (config)"]
    Root --> home["/home (users)"]
    Root --> var["/var (variable data)"]
    Root --> usr["/usr (programs)"]
    Root --> tmp["/tmp (temporary)"]
    
    home --> alice["/home/alice"]
    var --> log["/var/log"]

Linux Directory Structure#

PathPurpose
/Root — everything starts here
/binEssential binaries (ls, cp, cat)
/etcSystem configuration files
/homeUser home directories
/varVariable data (logs, databases, mail)
/tmpTemporary files (cleared on reboot)
/usrUser programs and libraries
/optOptional/third-party software
/procVirtual filesystem — process info
/devDevice files (disks, terminals)
/mnt, /mediaMount points for external storage

File System Types#

FSOSFeaturesUse Case
ext4LinuxJournaling, mature, reliableDefault Linux FS
XFSLinuxHigh performance, large filesEnterprise, databases
BtrfsLinuxSnapshots, compression, RAIDAdvanced Linux
NTFSWindowsACLs, encryption, journalingWindows default
APFSmacOSSnapshots, encryption, SSD-optimizedmacOS/iOS
FAT32Cross-platformSimple, universalUSB drives, boot partitions
ZFSLinux/BSDChecksums, snapshots, RAID-ZStorage servers

Key Concepts#

Inodes#

Every file has an inode — metadata about the file (NOT the filename):

Inode ContainsNOT in Inode
File sizeFilename
PermissionsFile content
Owner/group—
Timestamps (created, modified, accessed)—
Pointers to data blocks—

The directory is just a table mapping filenames → inode numbers.

TypeWhat It IsCrosses FS?Target Deleted?
Hard linkAnother name for same inodeNoFile still accessible
SymlinkPointer to a path (like shortcut)YesBroken link (dangling)
ln file.txt hardlink.txt       # hard link
ln -s file.txt symlink.txt     # symbolic link

Journaling#

A journal records changes before applying them — if the system crashes mid-write, the journal enables recovery:

1. Write intent to journal
2. Apply changes to file system
3. Mark journal entry complete

Without journaling: crash during write → corrupted file system.


Mounting#

In Linux, storage devices are “mounted” into the directory tree:

# Mount a device
mount /dev/sdb1 /mnt/usb

# View mounted filesystems
df -h                    # disk usage
mount | column -t        # all mounts
lsblk                   # block devices

# Unmount
umount /mnt/usb

/etc/fstab — Persistent Mounts#

# device          mount-point    type    options         dump  pass
/dev/sda1         /              ext4    defaults        0     1
/dev/sda2         /home          ext4    defaults        0     2
UUID=abc-123      /data          xfs     defaults,noatime 0    2

Disk Usage and Management#

# Check disk space
df -h                    # filesystem usage
du -sh /var/log          # directory size
du -sh * | sort -rh      # largest items in current dir

# Find large files
find / -type f -size +100M -exec ls -lh {} \;

# Check inode usage (can run out of inodes before disk space!)
df -i

Key Takeaways#

  1. Everything in Linux is a file — devices, processes, sockets
  2. Inodes store metadata, directories map names to inodes
  3. Journaling prevents corruption on crash (ext4, XFS)
  4. df -h for disk space, du -sh for directory sizes
  5. Mount points attach storage into the directory tree
  6. You can run out of inodes before running out of disk space