The UNIX Filesystem Hierarchy Standard

December 30, 2019

Why did I write this?

To introduce readers to the UNIX Filesystem Hierarchy Standard.

If you’ve worked in a Unix environment, you’ve worked with directories such as: /etc, /tmp, /opt, /var, /usr, /dev, /bin, /sbin.

But have you ever wondered why these exist and what the differences between them are? Well, after a some years I finally researched and came across the UNIX Filesystem Hierarchy Standard.

Summary of the Filesystem Hierarchy Standard Specification

I’ve abridged the contents of the spec, and would encourage anyone to read the original for a more in-depth look

The root file system

  • /bin: Essential user command binaries (for use by all users)
  • /dev: Device files
  • /opt: Add-on application software packages
  • /etc: Host-specific system configuration
  • /root: Home directory for the root user (optional)
  • /home: User home directories (optional)
  • /sbin: System binaries
  • /tmp: Temporary files
  • /srv: Data for services provided by this system
  • /lib: Essential shared libraries and kernel modules
  • /media: Mount point for removable media
  • /mnt: Mount point for a temporarily mounted filesystem

The /usr hierarchy

/usr is the second major section of the filesystem. /usr is shareable, read-only data. That means that /usr should be shareable between various FHS-compliant hosts and must not be written to. Any information that is host-specific or varies with time is stored elsewhere.

  • /usr/bin: Most user commands
  • /usr/include: Directory for standard include files.
  • /usr/lib: Libraries for programming and packages
  • /usr/libexec: Binaries run by other programs (optional)
  • /usr/local: Local hierarchy

    • /usr/local/share : Local architecture-independent hierarchy
    • /usr/sbin : Non-essential standard system binaries
    • /usr/share : Architecture-independent data

The /var hierarchy

/var contains variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files.

/var is specified here in order to make it possible to mount /usr read-only. Everything that once went into /usr that is written to during system operation (as opposed to installation and software maintenance) must be in /var.

If /var cannot be made a separate partition, it is often preferable to move /var out of the root partition and into the /usr partition. (This is sometimes done to reduce the size of the root partition or when space runs low in the root partition.) However, /var must not be linked to /usr because this makes separation of /usr and /var more difficult and is likely to create a naming conflict. Instead, link /var to /usr/var.

Patrick El-Hage

I'm Patrick El-Hage and I live and work in San Francisco. I'm also on Twitter.