The Hierarchical Tree Structure in Linux File System - snir1551/DevOps-Linux GitHub Wiki

The Hierarchical Tree Structure in Linux File System

The Linux file system is organized as a single hierarchical tree, where:

  • The root of the tree is represented by /.
  • Every file, directory, device, and resource is located somewhere within this tree.
  • Each item in the system has a unique path starting from / that identifies its location.

This structure allows Linux to maintain a clear, organized, and scalable file system, where everything is part of a single, unified directory tree.


/
β”œβ”€β”€ bin/
β”œβ”€β”€ boot/
β”œβ”€β”€ dev/
β”œβ”€β”€ etc/
β”œβ”€β”€ home/
β”‚   β”œβ”€β”€ user1/
β”‚   β”œβ”€β”€ user2/
β”‚   └── ...
β”œβ”€β”€ lib/
β”œβ”€β”€ media/
β”œβ”€β”€ mnt/
β”œβ”€β”€ opt/
β”œβ”€β”€ proc/
β”œβ”€β”€ root/
β”œβ”€β”€ sbin/
β”œβ”€β”€ tmp/
β”œβ”€β”€ usr/
└── var/

  • Absolute Path:

    • Always starts from /
    • Describes the complete location of a file or directory in the system.
    • Examples:
      • /etc/passwd
      • /home/user1/documents/resume.pdf
  • Relative Path:

    • Starts from the current working directory.
    • For example, if you are in /home/user1 and want to access documents/resume.pdf, you can reference it as:
      • documents/resume.pdf

The file system resembles an inverted tree:

  • The root (/) is the top of the tree.
  • Directories branch out from the root (branches), and files are like leaves.

Key Directories in the Linux File System

The Linux file system is organized in a standardized way. Each major directory has a specific purpose. Here’s an overview of the most important directories:

  • / – Root Directory

    • The starting point of the file system hierarchy. Everything in the system is organized under this directory.
  • /bin – Essential User Binaries

  • Contains essential command-line binaries (programs) that are required for basic system functionality. Examples: ls, cp, mv, bash, cat.

  • /sbin – System Binaries

    • Contains system administration binaries that are typically used by the system or by the root user. Examples: fsck, reboot, ifconfig.
  • /etc – Configuration Files

    • Contains system-wide configuration files and scripts. Examples:
      • /etc/passwd – User account information.
      • /etc/fstab – Filesystem mount points.
  • /home – User Home Directories

    • Contains personal directories for each user. For example: /home/user1/ , /home/user2/
    • Each user’s files, configurations, and data are stored here.
  • /root – Root User Home Directory

    • The home directory for the root user (system administrator).
    • Equivalent to /home/root for the superuser.
  • /var – Variable Files

    • Contains files that are expected to grow, such as:
      • Logs (/var/log).
      • Spools (/var/spool).
      • Temporary mail files, caches, etc.
  • /usr – User Programs and Data

    • Contains user-installed programs and their data. Subdirectories include:
      • /usr/bin – Non-essential user binaries.
      • /usr/lib – Libraries.
      • /usr/share – Shared data like documentation, icons, and locale files.
      • /usr/include – Header files for development (e.g., C libraries).
  • /lib – Essential Shared Libraries

    • Contains shared libraries needed for programs in /bin and /sbin to run.
      • For example: libc.so.6.
  • /dev – Device Files

    • Contains files that represent devices on the system (everything is a file in Linux). Examples:
      • /dev/sda – Hard disk.
      • /dev/tty – Terminals.
      • /dev/null – Discard output.
  • /proc – Virtual Filesystem for Process and Kernel Information

    • A pseudo-filesystem that provides dynamic information about running processes and the kernel. Examples:
      • /proc/cpuinfo
      • /proc/meminfo
      • /proc/1234/ (information about process with PID 1234).
  • /tmp – Temporary Files

    • Used for storing temporary files created by users or applications. Files here are usually deleted upon system reboot.
  • /media and /mnt – Mount Points

    • /media – Mount points for removable devices (e.g., USB drives, CD-ROMs).
    • /mnt – A general mount point for mounting temporary filesystems.
  • /opt – Optional Software

    • Used for installing add-on application software packages.
Directory Purpose
/ Root directory – top of the file system hierarchy.
/bin Essential binaries for all users.
/sbin System binaries for administrative tasks.
/etc Configuration files.
/home User home directories.
/root Root user's home directory.
/var Variable data: logs, spools.
/usr User programs and libraries.
/lib Essential shared libraries.
/dev Device files.
/proc Process and kernel information.
/tmp Temporary files.
/media Mount points for removable media.
/mnt Temporary mount point.
/opt Optional software packages.