Linux file structure


The Linux file system follows a hierarchical structure, often referred to as the Linux directory structure or Filesystem Hierarchy Standard (FHS). It organizes files and directories into a tree-like structure, starting from the root directory (/). Here's a breakdown of the typical Linux file structure with descriptions of common directories and options associated with them.

1. / (Root Directory)

  • Description: The root directory is the top-level directory in the file system. All other directories are subdirectories of this root directory.
  • Example:
    / ├── bin/ ├── home/ ├── etc/ ├── var/ ├── lib/ └── usr/

2. /bin

  • Description: Contains essential command binaries (executables) needed for the system to function in single-user mode. These are required for basic system functionality, such as ls, cp, cat, etc.
  • Example:
    /bin/ls /bin/cp /bin/bash

3. /boot

  • Description: Holds files required for booting the system, such as the Linux kernel and bootloader configuration files.
  • Example:
    /boot/vmlinuz /boot/grub/

4. /dev

  • Description: Contains device files that represent hardware devices (like hard drives, USB devices, and terminals). These files provide an interface for interacting with hardware.
  • Example:
    /dev/sda /dev/tty0 /dev/null

5. /etc

  • Description: Contains system configuration files and scripts used by various system programs. This is where the main configuration files for system services reside.
  • Example:
    /etc/passwd # User account information /etc/fstab # File system table /etc/hostname # Hostname

6. /home

  • Description: Contains the personal directories of all users on the system. For example, /home/john would be the home directory for the user john.
  • Example:
    /home/john/ /home/jane/

7. /lib

  • Description: Contains essential shared libraries required by system binaries in /bin and /sbin. These libraries are necessary for system programs to function.
  • Example:
    /lib/x86_64-linux-gnu/ /lib/libc.so.6

8. /media

  • Description: This directory is used to mount removable media like CDs, DVDs, and USB drives. It provides a location where removable media can be accessed.
  • Example:
    /media/usb/ /media/cdrom/

9. /mnt

  • Description: A temporary mount point for mounting filesystems, usually used for mounting storage devices during system maintenance or administration.
  • Example:
    /mnt/external_drive/

10. /opt

  • Description: Contains optional software packages that are not part of the default system installation. These are often third-party applications installed manually.
  • Example:
    /opt/google/ /opt/lampp/

11. /proc

  • Description: A virtual file system that provides information about system processes and kernel parameters. The files in this directory do not exist on disk but are created dynamically by the kernel.
  • Example:
    /proc/cpuinfo /proc/meminfo /proc/1/status

12. /root

  • Description: The home directory for the system's root user (superuser). This is different from /home, which contains regular users' home directories.
  • Example:
    /root/.bashrc

13. /run

  • Description: Contains runtime data for processes started since the last boot, including system information and PID files for services.
  • Example:
    /run/utmp # User login information /run/lock # Lock files for running processes

14. /sbin

  • Description: Contains system binaries (executables) used for system administration tasks, such as fsck, mount, and shutdown. These programs are typically for the root user.
  • Example:
    /sbin/mount /sbin/reboot

15. /srv

  • Description: Contains data for services provided by the system, such as web or FTP servers.
  • Example:
    /srv/http/ # Web server data /srv/ftp/ # FTP server data

16. /sys

  • Description: A virtual file system providing information about devices, kernel parameters, and more. It is used for kernel and device management.
  • Example:
    /sys/class/ /sys/block/ /sys/devices/

17. /tmp

  • Description: A directory for temporary files used by applications or the system. Files in /tmp are often cleared upon reboot or after a certain period.
  • Example:
    /tmp/tempfile.txt

18. /usr

  • Description: Contains system-wide read-only data and programs. It holds most user utilities and applications, as well as libraries and documentation.
    • /usr/bin/: Essential user command binaries
    • /usr/lib/: Shared libraries
    • /usr/share/: Architecture-independent data, such as documentation
  • Example:
    /usr/bin/ls /usr/lib/libc.so

19. /var

  • Description: Contains variable files, such as logs, caches, and databases. It is meant for files that are expected to grow or change during normal system operation.
    • /var/log/: Log files
    • /var/lib/: State information for applications
    • /var/spool/: Mail, print queues, etc.
  • Example:
    /var/log/syslog /var/spool/mail

Summary of Common Directories

DirectoryDescription
/Root directory, the base of the file system
/binEssential binaries for system operation
/bootBootloader and kernel files
/devDevice files
/etcSystem-wide configuration files
/homeUser home directories
/libEssential system libraries
/mediaMount points for removable media
/mntTemporary mount points
/optOptional software packages
/procVirtual file system for system processes
/rootRoot user's home directory
/runRuntime system information
/sbinSystem binaries for administration
/srvData for services
/sysKernel and device information
/tmpTemporary files
/usrUser programs and data
/varVariable data, such as logs and caches

This file structure ensures consistency and organization, allowing for easier system maintenance and management.