LinuxGetting StartedFile System

Linux File System

Understanding the Linux file system hierarchy, file types, permissions, and management.

Linux File System

The Linux file system is a hierarchical structure that organizes files and directories in a tree-like format. This guide explains the key concepts and components of the Linux file system.

File System Hierarchy

The Linux file system follows the Filesystem Hierarchy Standard (FHS), with the root directory (/) at the top:

/
├── /bin    # Essential command binaries
├── /boot   # Boot loader files
├── /dev    # Device files
├── /etc    # System configuration files
├── /home   # User home directories
├── /lib    # Shared library files
├── /media  # Mount points for removable media
├── /mnt    # Mount points for temporary mounts
├── /opt    # Optional application software
├── /proc   # Process information
├── /root   # Root user's home directory
├── /sbin   # System binary files
├── /tmp    # Temporary files
├── /usr    # User programs and data
└── /var    # Variable data files

File Types

Linux recognizes several types of files:

  1. Regular Files

    • Text files
    • Binary files
    • Data files
  2. Directories

    • Special files that contain other files
    • Used for organizing the file system
  3. Device Files

    • Represent hardware devices
    • Located in /dev
    • Block devices (e.g., hard drives)
    • Character devices (e.g., terminals)
  4. Symbolic Links

    • Pointers to other files
    • Created using ln -s
  5. Named Pipes

    • Used for inter-process communication
    • Created using mkfifo

File Permissions

Linux uses a permission system with three levels:

  1. User (Owner)

    • Permissions for the file owner
    • First set of permissions
  2. Group

    • Permissions for the group owner
    • Second set of permissions
  3. Others

    • Permissions for all other users
    • Third set of permissions

Permission Types

  • r (read): 4
  • w (write): 2
  • x (execute): 1

Example: rwxr-xr-- (754)

  • Owner: read, write, execute (7)
  • Group: read, execute (5)
  • Others: read only (4)

File System Management

Mounting and Unmounting

mount   # Mount a file system
umount  # Unmount a file system

Disk Management

df      # Show disk space usage
du      # Show directory space usage
fdisk   # Partition table manipulator

File System Types

Common Linux file systems:

  • ext4 (Extended File System 4)
  • XFS (X File System)
  • Btrfs (B-tree File System)
  • ZFS (Zettabyte File System)

File System Operations

Creating and Managing Files

touch   # Create empty files
mkdir   # Create directories
rm      # Remove files
rmdir   # Remove empty directories

File Attributes

chmod   # Change file permissions
chown   # Change file owner
chgrp   # Change file group

Best Practices

  1. Regular Backups

    • Maintain regular backups of important data
    • Use appropriate backup tools
  2. Disk Space Management

    • Monitor disk usage
    • Clean up unnecessary files
    • Use disk quotas when needed
  3. File Organization

    • Follow a logical directory structure
    • Use meaningful file names
    • Keep related files together
  4. Security

    • Set appropriate permissions
    • Use ACLs when needed
    • Regular security audits

Next Steps

Continue learning about:

  • Advanced file system features
  • RAID configurations
  • Logical Volume Management (LVM)
  • File system optimization
  • Backup and recovery procedures