Fundamentals 32 min read

Unlock Linux Filesystem Secrets: Directory Structure, FHS, and File Types Explained

This comprehensive guide explains the Linux filesystem hierarchy, the purpose of the Filesystem Hierarchy Standard, the roles of top‑level directories such as /, /usr and /var, the differences between absolute and relative paths, common file types, extensions, and how to interpret file attributes using standard commands.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Unlock Linux Filesystem Secrets: Directory Structure, FHS, and File Types Explained

Overview

Understanding the Linux filesystem layout is essential for anyone learning or administering a Linux system. The filesystem is organized as a tree rooted at /, and the Filesystem Hierarchy Standard (FHS) defines the intended purpose of each top‑level directory.

Filesystem Hierarchy Standard (FHS)

The FHS was created by a community of Linux enthusiasts to provide a consistent layout so that users and developers can predict where software and configuration files reside. It classifies directories by two dimensions: whether they are shareable (can be exported via network mounts) or unshareable , and whether they are static (rarely change) or variable (change frequently).

Four Types of Directories

Shareable & Static : e.g., /usr – software that can be shared across machines.

Unshareable & Static : e.g., /etc – configuration files specific to the host.

Shareable & Variable : e.g., /var/mail – user mailboxes.

Unshareable & Variable : e.g., /var/run – runtime data such as PID files.

Top‑Level Directories

Root Directory ( / )

The root is the entry point of the filesystem and contains files needed for booting and system recovery. FHS recommends keeping the root partition as small as possible and not placing large software packages there.

Key sub‑directories under /: /bin: Essential binaries usable in single‑user mode. /boot: Kernel images and bootloader configuration. /dev: Device nodes representing hardware. /etc: System-wide configuration files (readable by all, writable only by root). /home: Home directories for regular users. /lib: Shared libraries required by binaries in /bin and /sbin. /media: Mount points for removable media. /mnt: Temporary mount points for additional filesystems. /opt: Third‑party optional software. /root: Home directory of the root user. /sbin: System binaries used for administration. /srv: Data for services such as web or FTP. /tmp: Temporary files; cleared on reboot.

/usr Directory

/usr

stands for "Unix Software Resource" and holds shareable, static data. It is analogous to Windows' C:\Windows and C:\Program Files. Important sub‑directories include: /usr/bin: Most user commands. /usr/include: Header files for C/C++ development. /usr/lib: Libraries for applications; architecture‑specific sub‑directory /usr/lib64 may exist. /usr/local: Locally compiled software, mirroring the bin, etc, include, lib layout. /usr/sbin: Non‑essential system daemons. /usr/share: Architecture‑independent read‑only data (man pages, docs, locale files). /usr/src: Source code, often used for kernel sources.

/var Directory

/var

stores variable data that grows during system operation. Typical sub‑directories: /var/cache: Application cache files. /var/lib: Persistent state information (e.g., /var/lib/mysql for MySQL databases). /var/lock: Lock files to prevent concurrent access. /var/log: System and application log files. /var/mail or /var/spool/mail: User mailboxes. /var/run: Runtime data such as PID files. /var/spool: Queued data for services (mail, print, cron).

Path Types

Linux distinguishes between absolute paths (starting with /, e.g., /home/user/.bashrc) and relative paths (relative to the current working directory, e.g., ../var/log). The special entries . (current directory) and .. (parent directory) are used to construct relative paths.

Example

cd /var/spool/mail      # absolute path
cd ../cron             # relative path from /var/spool/mail

This demonstrates moving between sibling directories without returning to the root.

File Types and Extensions

Linux classifies files into several types, each identified by the first character of the permission string shown by ls -l: -: Regular file (text, binary, data). d: Directory. c: Character device (e.g., /dev/tty). b: Block device (e.g., /dev/sda1). s: Socket (used for inter‑process communication, often under /var/run). l: Symbolic link (shortcut). p: FIFO/pipe (first‑in‑first‑out).

File extensions such as .sh, .tar.gz, .html are conventions only; execution permission ( x) determines whether a file can be run.

Sample ls Output

[root@localhost ~]# ls -al /dev/tty
crw-rw-rw- 1 root tty 5, 0 Nov 15 11:11 /dev/tty

[root@localhost ~]# ls -la /dev/sda1
brw-r----- 1 root disk 8, 1 Jul 11 12:34 /dev/sda1

The leading c indicates a character device, while b indicates a block device.

File Attributes

Using ls -lih displays detailed attributes:

Inode number – unique identifier for the file within the filesystem.

Permission string – type and access rights (e.g., -rw-r--r--).

Link count – number of hard links.

Owner and group.

File size.

Timestamp – last access or modification.

File name.

Example:

2095112 -rw-r--r-- 1 root root 296K Nov 03 06:03 log2012.log

Here 2095112 is the inode, the file is a regular readable file owned by root, and its size is 296 KB.

Inode Concept

An inode stores metadata about a file (size, owner, permissions, timestamps, block locations). The filesystem uses the inode to locate the actual data blocks quickly. Think of the inode as the index of a book and the data blocks as the pages.

Visual Overview

Linux directory tree diagram
Linux directory tree diagram
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.

LinuxDirectory Structurecommand-lineFHSFile Types
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.