Fundamentals 17 min read

Master Linux Filesystem Hierarchy: Essential Directories and Commands Explained

This guide explains the Linux Filesystem Hierarchy Standard (FHS), detailing the purpose and typical contents of each top‑level directory, the difference between absolute and relative paths, and essential shell commands for navigating and managing directories.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Filesystem Hierarchy: Essential Directories and Commands Explained

Overview of the Linux Filesystem Hierarchy Standard (FHS)

Linux and UNIX use a single root / as the starting point of a tree‑like file system. To avoid the chaotic naming schemes of early UNIX implementations, the File System Standard (FSSTND) was introduced in 1994 and later evolved into the File System Hierarchy Standard (FHS), which most Linux distributions now follow.

FHS defines two layers of rules: the first layer specifies what type of data belongs in top‑level directories such as /etc, /bin, and /sbin; the second layer refines the contents of /usr and /var sub‑directories.

Key Directories Defined by FHS

/home

Default location for user home directories.

/boot

Contains static files required for booting the system, such as the Linux kernel ( vmlinuz) and, when using grub2, the /boot/grub2 directory.

Never delete /boot ; doing so can render the system unbootable.

/dev

Holds device nodes representing physical and virtual devices. Important examples include /dev/hda, /dev/hdb, /dev/tty0, /dev/tty1, /dev/sda, and /dev/lp0.

/etc

Stores system‑wide configuration files (e.g., /etc/passwd, /etc/fstab, /etc/modprobe.d). Binary executables belong in /bin or /sbin, not in /etc. Sub‑directories like /etc/x11 and /etc/opt hold X Window and third‑party configuration respectively.

/lib

Contains shared libraries needed by binaries in /bin and /sbin.

/media

Mount points for removable media such as USB drives, CDs, and DVDs.

/mnt

Temporary mount point for manually mounting additional devices.

/opt

Provides a location for optional application software packages. Each package typically creates its own sub‑directory (e.g., /opt/sample/bin for binaries).

/proc

A virtual filesystem exposing kernel and process information in memory. Notable files include /proc/cpuinfo, /proc/dma, /proc/interrupts, and /proc/net.

/sbin

Executable utilities used by the root user for system administration and recovery (e.g., arp, halt, init, ifconfig, shutdown).

/tmp

Stores temporary files that are cleared on reboot.

/sys

Another virtual filesystem that mirrors hardware and kernel state, similar to /proc.

/usr

Holds the majority of user‑land software. Contrary to a common misconception, usr stands for “Unix System Resources.” Important sub‑directories include: /usr/bin – user commands (mirrored by /bin on recent systems) /usr/lib – libraries (linked from /lib) /usr/local – locally compiled software /usr/sbin – system administration binaries (linked from /sbin) /usr/share – architecture‑independent data (man pages, docs, locale files) /usr/include – C/C++ header files /usr/src – source code, typically kernel sources under

/usr/src/linux

/run

Modern FHS places runtime information (previously under /var/run) here.

/var

Variable data that grows during system operation, such as caches ( /var/cache), logs ( /var/log), crash dumps ( /var/crash), and temporary files ( /var/tmp).

/srv

Data for specific services (e.g., web or FTP servers).

CentOS 7 reorganizes many directories by symlinking the traditional locations to their counterparts under /usr (e.g., /bin → /usr/bin, /sbin → /usr/sbin, /lib → /usr/lib).

Absolute vs. Relative Paths

Absolute paths start at the root ( /) and uniquely identify a file, while relative paths are interpreted from the current working directory (e.g., ../var/log). Special entries . and .. represent the current and parent directories respectively.

For long paths, relative notation can be more convenient, but absolute paths are safer for scripts because they remain valid regardless of the current directory.

Essential Directory‑Related Commands

cd

Changes the current working directory. Four common forms:

cd /path        # change to specified directory
cd ./           # stay in current directory
cd ..           # move to parent directory
cd ~            # go to the user's home directory

pwd

Prints the absolute path of the current working directory. It can also display the path of a specified directory.

mkdir

Creates a new directory. Useful options: -m – set permissions explicitly -p – create parent directories as needed (recursive)

Example to create a protected directory:

mkdir -m 711 test2

rmdir

Removes an empty directory. Use rmdir -p for recursive removal of empty parent directories. To delete non‑empty directories, use rm -r.

mv

Renames or moves files and directories.

PATH Environment Variable

When a command like ls is executed, the shell searches each directory listed in the PATH variable for an executable named ls. This explains why many commands are available from any location.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

FHSDirectories
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.