8.6 Filesystem Hierarchy Standard (FHS) & File Location (104.7)

Key Takeaways

  • The Filesystem Hierarchy Standard (FHS 3.0) specifies the standard directory structure and file locations across all Unix-like and Linux operating systems to ensure software portability and administration consistency.
  • Key FHS root directories include `/etc` (host-specific static configuration files; contains NO binaries), `/boot` (static bootloader files and kernels), `/opt` (third-party add-on software packages), `/srv` (site-specific service data), and `/var` (variable files such as logs, spool, and cache).
  • Real-time recursive filesystem searching is conducted using `find`, which searches live storage using extensive filter predicates (`-name`, `-type`, `-size`, `-mtime`, `-perm`, `-user`) and actions (`-exec`, `-delete`, `-print0`).
  • Fast indexed pattern searching is provided by `locate`, which queries a precompiled database (`/var/lib/mlocate/mlocate.db` or `/var/lib/plocate/`) updated via the background utility `updatedb` (configured in `/etc/updatedb.conf`).
  • Command identification tools serve distinct functions: `which` locates executables in `$PATH`, `whereis` finds binaries, man pages, and source files, and `type` (a Bash builtin) determines whether a command is a shell builtin, alias, function, keyword, or external executable.
Last updated: August 2026

8.6 Filesystem Hierarchy Standard (FHS) & File Location

Quick Summary: The Filesystem Hierarchy Standard (FHS) defines the standard directory structure and content requirements for Linux systems, ensuring interoperability between distributions and third-party software. Locating files, binaries, libraries, documentation, and configuration settings within this hierarchy requires a dedicated command toolkit: find performs deep, real-time filesystem traversal; locate performs fast indexed lookups against precompiled databases generated by updatedb; which searches the user's $PATH; whereis finds binaries, manual pages, and source trees; and type identifies shell builtins, aliases, and functions. Both FHS directory definitions and file search utilities are central to LPIC-1 Topic 104.7.


1. Filesystem Hierarchy Standard (FHS 3.0) Overview

The FHS categorizes directories along two primary axes:

  • Shareable vs. Unshareable: Shareable files can be stored on one central host and accessed over the network by multiple clients (e.g., /usr, /opt, /srv); unshareable files contain host-specific data (e.g., /etc, /boot, /var/log).
  • Static vs. Variable: Static files remain unchanged without administrator intervention (e.g., /bin, /lib, /usr/bin); variable files are continuously modified by running daemons and users (e.g., /var/log, /var/spool, /tmp, /run).

Comprehensive FHS Directory Reference Table

DirectoryClassificationFHS 3.0 Standard Description & Requirements
/Unshareable / StaticRoot directory. The top of the unified directory tree; must contain all files essential to boot, repair, and restore the system.
/binShareable / StaticEssential user command binaries required for single-user mode and system recovery (often a symlink to /usr/bin in modern distros).
/sbinShareable / StaticEssential system administration binaries required for boot and recovery (e.g., fsck, init, fdisk; often a symlink to /usr/sbin).
/bootUnshareable / StaticStatic files of the bootloader (GRUB config), Linux kernel images (vmlinuz), and initial RAM disk images (initramfs).
/devUnshareable / StaticDevice nodes representing physical and virtual hardware components, dynamically populated by udevd.
/etcUnshareable / StaticHost-specific system-wide configuration files. FHS strictly mandates that /etc must contain NO executable binaries.
/homeShareable / VariableUser home directories containing personal user data, profiles, and configurations.
/lib, /lib64Shareable / StaticEssential shared libraries required by binaries in /bin and /sbin, and loadable kernel modules (/lib/modules/).
/mediaUnshareable / VariableMount points for removable media (e.g., /media/cdrom, /media/usb).
/mntUnshareable / VariableTemporarily mounted filesystems used by administrators for manual repair or maintenance.
/optShareable / StaticAdd-on application software packages. Reserved for self-contained, third-party software (e.g., /opt/google/chrome, /opt/gitlab).
/procUnshareable / VariableVirtual pseudo-filesystem providing an interface to kernel data structures and process metrics.
/rootUnshareable / VariableHome directory for the root superuser account (separated from /home to ensure availability if /home fails to mount).
/runUnshareable / VariableRuntime variable data since last system boot (e.g., daemon PID files, UNIX domain sockets); mounted as tmpfs.
/srvShareable / VariableSite-specific data served by this system (e.g., web server data /srv/www, FTP data /srv/ftp).
/sysUnshareable / VariableVirtual pseudo-filesystem exposing the kernel device driver model and hardware subsystem parameters (sysfs).
/tmpUnshareable / VariableTemporary files; may be cleared automatically on reboot or by automated cleanup utilities.
/usrShareable / StaticSecondary user hierarchy. Contains the bulk of read-only user utilities and applications.
/varUnshareable / VariableVariable data files. Data that changes dynamically during normal operations (logs, mail spools, caches).

2. Key FHS Subdirectories & Exam Hotspots

1. The /usr Subhierarchy

  • /usr/bin: Primary directory for non-essential executable commands.
  • /usr/sbin: Non-essential system administration binaries.
  • /usr/lib, /usr/lib64: Shared libraries for binaries in /usr/bin and /usr/sbin.
  • /usr/local: Tertiary hierarchy used by system administrators for locally compiled software installed without package managers (e.g., /usr/local/bin, /usr/local/etc).
  • /usr/share: Architecture-independent shared data (icons, fonts, timezone data).
  • /usr/share/man: Standard location for system manual pages (man).
  • /usr/share/doc: Application documentation and release notes.
  • /usr/src: Kernel and application source code.

2. The /var Subhierarchy

  • /var/log: System and daemon log files (e.g., /var/log/messages, /var/log/syslog, /var/log/journal).
  • /var/spool: Queued application data waiting for processing (print queues, mail spools, cron jobs in /var/spool/cron).
  • /var/cache: Application cache data (e.g., apt package cache, dnf metadata).
  • /var/lib: Dynamic state information maintained by applications (e.g., package manager databases, database storage).
  • /var/tmp: Temporary files that must be preserved across system reboots (unlike /tmp, which may be cleared on boot).

3. Real-Time Searching with find

The find utility traverses the filesystem hierarchy in real time, evaluating files against user-defined predicates and executing specified actions.

find [starting-path] [search-criteria] [actions]

Essential find Search Criteria Reference

Criteria FlagSyntax & FormatTechnical Description & Examples
-name <pattern>find /etc -name "*.conf"Matches file names case-sensitively using shell globbing (*, ?, []).
-iname <pattern>find ~ -iname "report.pdf"Matches file names case-insensitively.
-type <t>`-type [fd
**`-size [+/-]<N>[ckM
-mtime [+/-]<N>-mtime -7Matches files modified within the last <N> 24-hour periods (-N), more than <N> days ago (+N), or exactly <N> days ago.
-atime / -ctime-atime +30Matches based on last access time (atime) or inode status change time (ctime).
-user <user>-user aliceMatches files owned by the specified username or UID.
-group <group>-group developersMatches files owned by the specified group name or GID.
-perm [mode]-perm -4000Matches permissions: exact mode (755), all bits set (-mode), or any bit set (/mode).
-maxdepth <N>-maxdepth 2Restricts directory traversal depth to at most <N> levels below starting path.
-empty-emptyMatches empty regular files (0 bytes) or empty directories.

find Actions: -exec, -delete, and -print0

# 1. Execute command once per file found (-exec ... {} \;):
$ find /var/log -name "*.old" -exec rm -f {} \;

# 2. Execute command with batched arguments (-exec ... {} +):
# Much faster because it launches fewer child processes:
$ find /tmp -type f -name "*.tmp" -exec rm -f {} +

# 3. Direct deletion action (-delete):
$ find /var/tmp -type f -atime +30 -delete

# 4. Safe null-terminated output for xargs:
$ find /srv/data -type f -print0 | xargs -0 chmod 644

4. Fast Indexed Searching: locate & updatedb

Unlike find, which scans physical storage disks in real time, locate queries a prebuilt, indexed database of the filesystem (typically stored at /var/lib/mlocate/mlocate.db or /var/lib/plocate/plocate.db). This makes locate virtually instantaneous.

The updatedb Indexer

The database is updated automatically via a daily cron or systemd.timer job running the updatedb command. Administrators can manually refresh the index immediately:

# Manually rebuild the locate database as root:
$ sudo updatedb

Configuration via /etc/updatedb.conf

The /etc/updatedb.conf file controls updatedb behavior:

  • PRUNEFS: Filesystem types to exclude from indexing (e.g., nfs, proc, sysfs, tmpfs, iso9660).
  • PRUNEPATHS: Directory paths to exclude from indexing (e.g., /tmp, /var/tmp, /media).
  • PRUNENAMES: Directory names to skip (e.g., .git, .svn).

Key locate Command Options

FlagLong OptionDetailed Operational Description
-i--ignore-caseIgnores case distinctions in pattern matching.
-b--basenameMatches pattern against the filename (basename) only, ignoring leading path directories.
-c--countSuppresses path output and prints only the total number of matching files found.
-r--regexpInterprets the search pattern as a regular expression.
-e--existingPrints only entries that currently exist on physical disk at query time (filters out deleted files).
# Find all files matching nginx.conf case-insensitively:
$ locate -i nginx.conf

# Count how many python script files are indexed:
$ locate -c "*.py"

5. Command Resolution Utilities: which, whereis & type

Linux provides three specialized tools for determining how command names are resolved.

1. The which Utility

The which utility takes a command name and searches the directories listed in the current user's $PATH environment variable, returning the absolute path of the first matching executable file:

$ which ls
/usr/bin/ls
$ which python3
/usr/bin/python3

2. The whereis Utility

The whereis utility searches standard system binary, manual page, and source code directories (independent of $PATH):

FlagFunctional Target
-bSearch only for binary executables.
-mSearch only for manual pages (man).
-sSearch only for source code trees.
$ whereis tar
tar: /usr/bin/tar /usr/include/tar.h /usr/share/man/man1/tar.1.gz

$ whereis -b tar
tar: /usr/bin/tar

$ whereis -m tar
tar: /usr/share/man/man1/tar.1.gz

3. The type Shell Builtin (Exam Favorite)

The type command is a Bash built-in utility that describes how a given command name will be interpreted if typed into the shell: whether it is a shell builtin, an alias, a shell function, a keyword, or an external executable on disk.

# Inspecting builtins, keywords, and aliases:
$ type cd
cd is a shell builtin

$ type for
for is a shell keyword

$ type ll
ll is aliased to `ls -l --color=auto`

# Finding all matching instances in search order (-a):
$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo

# Returning only the concise type identifier (-t):
$ type -t cd
builtin
$ type -t ls
alias
$ type -t grep
file

⚠️ LPIC-1 Trap — which vs. type on Shell Builtins: Running which cd or which kill often produces misleading results or errors because cd is a shell builtin that does not exist as an independent binary in $PATH. To accurately determine whether a command is a shell builtin or alias, always use the type command.

Loading diagram...
Linux File Location & Search Utility Architecture
Test Your Knowledge

According to the Filesystem Hierarchy Standard (FHS 3.0), which directory is specifically designated for host-specific system configuration files and must NOT contain any executable binaries?

A
B
C
D
Test Your Knowledge

A system administrator needs to delete all files ending with .tmp in /tmp using the find utility. Which command executes the deletion by batching filenames together to minimize spawned processes?

A
B
C
D
Test Your Knowledge

An administrator wants to verify if echo is a built-in shell command or an external binary stored on disk, including all locations in the search order. Which command provides this information?

A
B
C
D
Congratulations!

You've completed this section

Continue exploring other exams