Skip to content
Tutorials
Esc
  • Type at least two characters.
Browse Tutorials

History: Understanding the Linux Filesystem

Import from Docusaurus (tutorial/Linux/02 - Filesystem.mdx) (first version)

Back to history
Added: # Understanding the Linux Filesystem
Added:
Added: The Linux filesystem is a crucial component of the operating system, defining how data is stored, managed, and accessed. Unlike Windows, where filesystems are identified with drive letters (e.g., `C:\`, `D:\`), Linux organizes everything under a single root directory (`/`).
Added:
Added: ## The Hierarchical Structure of the Linux Filesystem
Added:
Added: Linux follows a tree-like structure where directories branch out from the root (`/`). Each directory serves a specific purpose in managing system files, user data, and configurations.
Added:
Added: ### Key Directories in Linux
Added:
Added: | Directory | Description |
Added: | --------- | ---------------------------------------------------------------------------------------- |
Added: | `/` | The root directory, which contains all other directories and files. |
Added: | `/bin` | Essential binary executables (e.g., `ls`, `cp`, `mv`). |
Added: | `/boot` | Contains bootloader files, kernel images, and startup configuration files. |
Added: | `/dev` | Stores device files representing hardware components (e.g., `/dev/sda` for hard drives). |
Added: | `/etc` | System-wide configuration files and scripts. |
Added: | `/home` | User home directories (`/home/user1`, `/home/user2`). |
Added: | `/lib` | Shared library files required by system binaries. |
Added: | `/media` | Mount point for removable media (USB, CD/DVD). |
Added: | `/mnt` | Temporary mount point for manually mounted filesystems. |
Added: | `/opt` | Third-party software installations. |
Added: | `/proc` | Virtual filesystem for process and system information. |
Added: | `/root` | Home directory for the root user. |
Added: | `/run` | Runtime data for processes since the last boot. |
Added: | `/sbin` | System binaries required for system administration. |
Added: | `/srv` | Data for system services such as web servers. |
Added: | `/sys` | Kernel-related system information. |
Added: | `/tmp` | Temporary files, often cleared on reboot. |
Added: | `/usr` | User utilities and applications (e.g., `/usr/bin`, `/usr/lib`). |
Added: | `/var` | Variable data such as logs, caches, and temporary files. |
Added:
Added: ## Linux Filesystem Types
Added:
Added: Linux supports multiple filesystems, each with its strengths and specific use cases. Below are some commonly used Filesystems.
Added:
Added: ### 1. **ext4 (Fourth Extended Filesystem)**
Added:
Added: - **Overview**: ext4 is the default filesystem for most Linux distributions. It is an improved version of ext3 with better performance and reliability.
Added: - **How It Works**: It uses journaling to keep track of changes, reducing the risk of data corruption. ext4 supports large file sizes and partitions.
Added: - **Pros**:
Added: - Efficient space management.
Added: - Faster file system checking.
Added: - Backward compatibility with ext3.
Added: - **Cons**:
Added: - Lacks built-in data deduplication.
Added: - No snapshot functionality.
Added:
Added: ### 2. **XFS**
Added:
Added: - **Overview**: A high-performance journaling filesystem designed for large-scale storage systems.
Added: - **How It Works**: Uses metadata journaling for data consistency and scalability.
Added: - **Pros**:
Added: - Excellent parallel processing capability.
Added: - Suitable for large files and high-performance computing.
Added: - **Cons**:
Added: - Slower performance for small files.
Added: - More complex to manage than ext4.
Added:
Added: ### 3. **Btrfs (B-Tree Filesystem)**
Added:
Added: - **Overview**: A modern filesystem developed by Oracle, designed for scalability, reliability, and advanced features.
Added: - **How It Works**: Uses copy-on-write (CoW) to prevent data loss and supports snapshots and compression.
Added: - **Pros**:
Added: - Built-in RAID, snapshot, and cloning support.
Added: - Self-healing mechanisms to prevent data corruption.
Added: - **Cons**:
Added: - Higher system resource usage.
Added: - Not as stable as ext4 in some scenarios.
Added:
Added: ### 4. **ZFS**
Added:
Added: - **Overview**: Originally developed by Sun Microsystems, ZFS is known for high data integrity and scalability.
Added: - **How It Works**: Utilizes checksums to prevent data corruption and supports automatic data healing.
Added: - **Pros**:
Added: - Strong error correction and self-healing.
Added: - Supports massive storage capacities.
Added: - **Cons**:
Added: - High memory consumption.
Added: - More complex setup and management.
Added:
Added: ### 5. **F2FS (Flash-Friendly File System)**
Added:
Added: - **Overview**: Developed by Samsung, F2FS is optimized for NAND flash storage like SSDs and SD cards.
Added: - **How It Works**: Uses log-based structures to reduce write amplification, improving longevity and performance.
Added: - **Pros**:
Added: - High performance on flash storage.
Added: - Reduces write cycles to extend SSD lifespan.
Added: - **Cons**:
Added: - Not suitable for traditional HDDs.
Added: - Limited adoption outside flash-based devices.
Added:
Added: ### 6. **tmpfs (Temporary Filesystem)**
Added:
Added: - **Overview**: A volatile filesystem that stores files in RAM instead of disk.
Added: - **How It Works**: tmpfs is created at runtime and disappears upon reboot.
Added: - **Pros**:
Added: - Extremely fast read/write speeds.
Added: - Reduces disk wear by avoiding unnecessary writes.
Added: - **Cons**:
Added: - Data loss on reboot.
Added: - Limited by available system RAM.
Added:
Added: ## File Permissions and Ownership
Added:
Added: Linux follows a strict permission system to manage file access and security.
Added:
Added: ### Understanding File Permissions
Added:
Added: Each file and directory in Linux has three permission types:
Added:
Added: - **Read (`r`)**: Allows viewing file contents.
Added: - **Write (`w`)**: Permits modifying file contents.
Added: - **Execute (`x`)**: Allows running files as programs or scripts.
Added:
Added: Permissions are categorized into three groups:
Added:
Added: - **User (Owner)**: The creator of the file.
Added: - **Group**: Users belonging to the same group.
Added: - **Others**: All other users.
Added:
Added: Permissions are represented using:
Added:
Added: - Symbolic notation: `rwxr-xr--`
Added: - Numeric notation: `755`, `644`, etc.
Added:
Added: ### Changing Permissions and Ownership
Added:
Added: - Modify file permissions: `chmod 755 filename`
Added: - Change file ownership: `chown user:group filename`
Added: - Recursive permission changes: `chmod -R 755 directory/`
Added:
Added: ## Mounting and Unmounting Filesystems
Added:
Added: Linux allows mounting external filesystems, such as USB drives and network shares, into the directory structure.
Added:
Added: ### Mounting a Filesystem
Added:
Added: To manually mount a filesystem:
Added:
Added: ```bash
Added: mount /dev/sdb1 /mnt/usb
Added: ```
Added:
Added: This mounts the device `/dev/sdb1` to the `/mnt/usb` directory.
Added:
Added: ### Unmounting a Filesystem
Added:
Added: To unmount a mounted device:
Added:
Added: ```bash
Added: umount /mnt/usb
Added: ```
Added:
Added: ## The `/proc` and `/sys` Virtual Filesystems
Added:
Added: Linux uses special virtual filesystems for real-time system monitoring:
Added:
Added: - **`/proc`**: Contains information about running processes, system uptime, and memory usage.
Added: - **`/sys`**: Provides a view into kernel parameters and hardware configurations.
Added:
Added: ### Checking System Information
Added:
Added: - View CPU information: `cat /proc/cpuinfo`
Added: - Check memory usage: `cat /proc/meminfo`
Added: - List kernel parameters: `ls /sys/kernel`
Added:
Added: ## Conclusion
Added:
Added: The Linux filesystem is a structured, highly efficient way to manage data. Understanding its hierarchy, supported filesystems, permissions, and mounting options is crucial for system administration.
Added:
Added: By mastering the Linux filesystem, users can optimize system performance, enhance security, and efficiently manage data storage in any environment.
Added:
Added: Some basic linux file management commands are present at **[Linux file management commands](https://devopsmedium.com/blog/linux-cheat-sheet#file-management)**, covering how to create, modify, and manage files and directories effectively.
Added:
Added: You can also check out **[Linux file permission commands](https://devopsmedium.com/blog/linux-cheat-sheet#file-permission-commands)** to gain a deeper understanding of managing user access rights in Linux.