Understanding the Linux Filesystem Hierarchy Standard (FHS)

Understanding the Linux Filesystem Hierarchy Standard (FHS)


The Filesystem Hierarchy Standard (FHS) provides a standardized directory structure for Linux systems, promoting consistency across distributions. While not mandatory, most Linux distributions adhere to it.


The Directory Tree

Think of the filesystem as a tree, with the root directory (/) as its trunk. From this trunk, various branches (/bin, /boot, etc.) hold specific types of files. Here's a breakdown of the key directories:

  • /: The root directory, containing all other directories.
  • /bin: Essential command binaries accessible to all users (e.g., ls, cat, cp).
  • /boot: Files required for the boot process, including the kernel and initrd.
  • /dev: Device files, representing both physical and virtual devices.
  • /etc: Host-specific system-wide configuration files.(e.g. nginx configuration files are in /etc/nginx )
  • /home: Home directories for users, storing personal files and settings. Typically, /home/username (e.g., /home/john).
  • /lib: Shared libraries essential for the system and programs in /bin and /sbin.
  • /media: Mount point for removable media (e.g., USB drives, CDs).
  • /mnt: Temporary mount point for filesystems mostly network attached storage (NAS)
  • /opt: Optional application software packages.
  • /root: Home directory for the root user.
  • /run: Runtime variable data, including process IDs.
  • /sbin: System binaries, often used for system administration (root-only commands).
  • /srv: Data served by the system (e.g., web server content).
  • /tmp: Temporary files, often cleared on boot.
  • /usr: Read-only user data.
  • /proc: Virtual filesystem with information about running processes.
  • /var: Variable data written during system operation (e.g., logs, caches, printing spools).

Important Note: Some directories, like /etc, /usr, and /var, have their own complex sub-directory hierarchies.

Temporary Files: Where Do They Go?

Temporary files are used briefly by programs and can include data like:

  • Running process data
  • Crash logs
  • Autosave files
  • Cache files

The FHS defines specific locations for temporary files:

  • /tmp: For temporary files that can be deleted on boot.
  • /var/tmp: For temporary files preserved between reboots.
  • /run: For runtime variable data, cleared on boot.

While programs can technically create temporary files anywhere, following the FHS guidelines ensures consistency and predictable behavior.


Resources:

https://learning.lpi.org/en/learning-materials/101-500/104/104.7/104.7_01/

https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html

要查看或添加评论,请登录

Andrew Anter的更多文章

  • Django + HTMX

    Django + HTMX

    What is htmx? htmx is a JavaScript library that allows you to access AJAX, CSS Transitions, WebSockets, and Server Sent…

  • Django Inclusion Tags: Power and Flexibility for Your Templates

    Django Inclusion Tags: Power and Flexibility for Your Templates

    Django's template system is renowned for its flexibility and ease of use. One of its hidden gems is the inclusion tag…

社区洞察

其他会员也浏览了