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.dbor/var/lib/plocate/) updated via the background utilityupdatedb(configured in/etc/updatedb.conf).Command identification tools serve distinct functions:
whichlocates executables in$PATH,whereisfinds binaries, man pages, and source files, andtype(a Bash builtin) determines whether a command is a shell builtin, alias, function, keyword, or external executable.
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:
findperforms deep, real-time filesystem traversal;locateperforms fast indexed lookups against precompiled databases generated byupdatedb;whichsearches the user's$PATH;whereisfinds binaries, manual pages, and source trees; andtypeidentifies 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
| Directory | Classification | FHS 3.0 Standard Description & Requirements |
|---|---|---|
/ | Unshareable / Static | Root directory. The top of the unified directory tree; must contain all files essential to boot, repair, and restore the system. |
/bin | Shareable / Static | Essential user command binaries required for single-user mode and system recovery (often a symlink to /usr/bin in modern distros). |
/sbin | Shareable / Static | Essential system administration binaries required for boot and recovery (e.g., fsck, init, fdisk; often a symlink to /usr/sbin). |
/boot | Unshareable / Static | Static files of the bootloader (GRUB config), Linux kernel images (vmlinuz), and initial RAM disk images (initramfs). |
/dev | Unshareable / Static | Device nodes representing physical and virtual hardware components, dynamically populated by udevd. |
/etc | Unshareable / Static | Host-specific system-wide configuration files. FHS strictly mandates that /etc must contain NO executable binaries. |
/home | Shareable / Variable | User home directories containing personal user data, profiles, and configurations. |
/lib, /lib64 | Shareable / Static | Essential shared libraries required by binaries in /bin and /sbin, and loadable kernel modules (/lib/modules/). |
/media | Unshareable / Variable | Mount points for removable media (e.g., /media/cdrom, /media/usb). |
/mnt | Unshareable / Variable | Temporarily mounted filesystems used by administrators for manual repair or maintenance. |
/opt | Shareable / Static | Add-on application software packages. Reserved for self-contained, third-party software (e.g., /opt/google/chrome, /opt/gitlab). |
/proc | Unshareable / Variable | Virtual pseudo-filesystem providing an interface to kernel data structures and process metrics. |
/root | Unshareable / Variable | Home directory for the root superuser account (separated from /home to ensure availability if /home fails to mount). |
/run | Unshareable / Variable | Runtime variable data since last system boot (e.g., daemon PID files, UNIX domain sockets); mounted as tmpfs. |
/srv | Shareable / Variable | Site-specific data served by this system (e.g., web server data /srv/www, FTP data /srv/ftp). |
/sys | Unshareable / Variable | Virtual pseudo-filesystem exposing the kernel device driver model and hardware subsystem parameters (sysfs). |
/tmp | Unshareable / Variable | Temporary files; may be cleared automatically on reboot or by automated cleanup utilities. |
/usr | Shareable / Static | Secondary user hierarchy. Contains the bulk of read-only user utilities and applications. |
/var | Unshareable / Variable | Variable 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/binand/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,cronjobs in/var/spool/cron)./var/cache: Application cache data (e.g.,aptpackage cache,dnfmetadata)./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 Flag | Syntax & Format | Technical 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 [f|d|l|b|c|s|p] | Filters by file type: f (regular file), d (directory), l (symlink), b (block device), c (character device), s (socket), p (named pipe). |
-size [+/-]\<N>[c|k|M|G] | -size +100M | Matches files larger than (+), smaller than (-), or exactly equal to size. Units: c (bytes), k (KiB), M (MiB), G (GiB). |
-mtime [+/-]<N> | -mtime -7 | Matches files modified within the last <N> 24-hour periods (-N), more than <N> days ago (+N), or exactly <N> days ago. |
-atime / -ctime | -atime +30 | Matches based on last access time (atime) or inode status change time (ctime). |
-user <user> | -user alice | Matches files owned by the specified username or UID. |
-group <group> | -group developers | Matches files owned by the specified group name or GID. |
-perm [mode] | -perm -4000 | Matches permissions: exact mode (755), all bits set (-mode), or any bit set (/mode). |
-maxdepth <N> | -maxdepth 2 | Restricts directory traversal depth to at most <N> levels below starting path. |
-empty | -empty | Matches 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
| Flag | Long Option | Detailed Operational Description |
|---|---|---|
-i | --ignore-case | Ignores case distinctions in pattern matching. |
-b | --basename | Matches pattern against the filename (basename) only, ignoring leading path directories. |
-c | --count | Suppresses path output and prints only the total number of matching files found. |
-r | --regexp | Interprets the search pattern as a regular expression. |
-e | --existing | Prints 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):
| Flag | Functional Target |
|---|---|
-b | Search only for binary executables. |
-m | Search only for manual pages (man). |
-s | Search 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 —
whichvs.typeon Shell Builtins: Runningwhich cdorwhich killoften produces misleading results or errors becausecdis 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 thetypecommand.
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?
/opt
/usr/bin
/srv
/etc
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?
find /tmp -type f -name "*.tmp" -exec rm -f {} +
find /tmp -type f -name "*.tmp" -exec rm -f {} \;
find /tmp -type f -name "*.tmp" | rm -f
find /tmp -type f -name "*.tmp" -execall rm -f
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?
which echo
type -a echo
whereis -e echo
locate -b echo
Sections you finish are checked off in the contents.
You've completed this section
Continue exploring other exams