Catch Up with Us!

Unix File System

Introduction

The Unix file system is one of the most influential designs in operating systems. It follows a unified philosophy where almost everything is treated as a file, including regular data files, directories, devices, and system resources.

Modern Unix-like systems such as Linux, macOS, and BSD continue to use this design, although implementations have evolved significantly with modern filesystems like ext4, XFS, APFS, and ZFS.

File Types in Unix/Linux

Modern Unix-like systems support several file types:

1. Regular Files

  • Text files, binaries, images, logs, and data files
  • Contain user or application data

2. Directories

A directory is a special file that stores:

  • File names
  • Metadata references (inode pointers)

Directories form a hierarchical tree structure starting from / (root directory).

3. Symbolic Links (Soft Links)

A symbolic link (symlink) is a pointer to another file or directory.

Modern analogy:

  • Similar to shortcuts in Windows
  • Can cross file systems
  • Can break if the target is deleted

Example:

ln -s original.txt link.txt

4. Device Files

Devices are represented as files in /dev.

Types of device files:

  • Character devices: Stream data one character at a time (e.g., keyboards, serial ports)
  • Block devices: Transfer data in blocks (e.g., hard drives, SSDs)

Example:

  • /dev/sda → storage disk
  • /dev/tty → terminal interface

Modern systems use udev (Linux) or equivalent subsystems to manage device files dynamically.

Links in Unix File Systems

Unix supports two types of links:

1. Hard Links

A hard link is another directory entry pointing directly to the same underlying file data (inode).

Key properties:

  • Shares the same inode
  • Cannot cross file systems
  • File remains accessible until all hard links are removed

Modern behavior:

  • Hard links are still widely used in Linux filesystems like ext4 and XFS
  • Less visible to average users but important in backups and system tools

2. Symbolic Links (Soft Links)

A symbolic link stores the path to another file.

Key properties:

  • Works across file systems
  • Can point to directories
  • Can become “dangling” if target is removed

Inodes (Modern View)

An inode (index node) stores metadata about a file:

  • File permissions
  • Ownership (user/group)
  • File size
  • Timestamps
  • Disk block locations
  • Link count

Modern filesystems:

In modern systems, inode concepts still exist but are abstracted by advanced filesystems such as:

  • ext4 (Linux default)
  • XFS (high-performance systems)
  • ZFS (data integrity-focused systems)
  • APFS (Apple systems)

Pipes in Unix/Linux

A pipe is a mechanism for connecting the output of one program to the input of another.

Symbol:

|

Example:

ls | less

Explanation:

  • ls generates output
  • less displays output page by page
  • The pipe (|) connects them

Modern Usage of Pipes

Pipes are fundamental in modern systems for:

  • Log processing
  • Data transformation
  • System monitoring
  • DevOps automation

Example:

cat access.log | grep "ERROR" | sort | uniq

How Pipes Work

  • Managed by the operating system kernel
  • Use anonymous communication channels
  • No intermediate file is created
  • Data flows directly between processes

This is called an anonymous pipe.

Named Pipes (FIFO)

A named pipe (FIFO: First In First Out) allows unrelated processes to communicate using a file-like interface.

Creating a named pipe:

mkfifo mypipe

Using a named pipe:

Terminal 1 (writer):

echo "Hello" > mypipe

Terminal 2 (reader):

cat < mypipe

Modern Usage

Named pipes are still used in:

  • System logging pipelines
  • Inter-process communication (IPC)
  • Lightweight service communication
  • Debugging workflows

However, modern systems also use more advanced IPC mechanisms such as:

  • Unix domain sockets
  • Shared memory
  • Message queues
  • DBus (Linux desktop systems)

Filesystem Philosophy (Modern View)

The Unix file system design is based on simplicity and uniformity:

  • Everything is represented as a file
  • Hardware devices are accessed like files
  • Processes and system information appear as files (/proc, /sys)
  • Tools operate on text streams

Modern Filesystem Features

Modern Unix-like file systems include advanced capabilities:

1. Journaling

Prevents data corruption after crashes (ext4, APFS, XFS)

2. Snapshots

Instant backups of filesystem state (ZFS, Btrfs, APFS)

3. Compression

Transparent file compression (ZFS, Btrfs)

4. Encryption

Built-in filesystem encryption (LUKS, APFS encryption)

5. Copy-on-Write (CoW)

Efficient storage and snapshot management

Modern File System Hierarchy

Modern Linux systems follow the Filesystem Hierarchy Standard (FHS):

  • /home → user data
  • /etc → configuration files
  • /var → logs and variable data
  • /usr → system applications
  • /bin, /sbin → essential commands
  • /dev → device files
  • /proc → process information
  • /sys → kernel and hardware interfaces

Summary

The Unix file system remains one of the most elegant and influential designs in computing. While modern implementations have evolved significantly with advanced features like journaling, snapshots, and encryption, the core philosophy remains unchanged:

Treat everything as a file, and use simple abstractions to build powerful systems.

This design continues to underpin Linux, macOS, cloud systems, containers, and modern distributed computing environments.

Comments