Exploring the Linux Filesystem Hierarchy
The Linux operating system, renowned for its stability, flexibility, and open-source nature, relies on a hierarchical filesystem structure that serves as the backbone for organizing and managing its myriad of files and directories. Understanding this filesystem hierarchy is fundamental for anyone working with Linux systems, whether you’re a system administrator, developer, or simply an enthusiast exploring the depths of this powerful operating system.
In this guide, we embark on a journey to explore the intricate web of directories that form the Linux filesystem hierarchy. From the root directory to specialized locations for system binaries, configuration files, user data, and more, each directory plays a vital role in orchestrating the symphony of processes and resources within a Linux system.
Join us as we unravel the mysteries of the Linux filesystem, shedding light on the purpose and function of each directory along the way. Whether you’re a newcomer seeking to understand the basics or a seasoned Linux veteran looking to deepen your knowledge, this exploration promises to illuminate the inner workings of one of the most revered operating systems in the world.
This standard defines the directory structure and organization of files in Linux distributions. Let’s delve into the main directories and their purposes, along with examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/
├── bin
├── boot
├── dev
├── etc
├── home
├── lib
├── lib64
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── srv
├── sys
├── tmp
├── usr
└── var
This tree structure represents the main directories in the Linux filesystem hierarchy, all stemming from the root (“/”) directory.
/ (Root Directory):
- The root directory is the top-level directory in the filesystem hierarchy.
- All other directories and files are subdirectories or files of the root directory.
- Example:
/bin
,/etc
,/home
,/usr
,/var
are all subdirectories of the root directory.
/bin (Binaries):
- Contains essential binaries (executable programs) required during booting and for repairing the system.
- Example:
/bin/ls
,/bin/cat
,/bin/mkdir
.
/sbin (System Binaries):
- Similar to
/bin
, but contains binaries used by the system administrator for system maintenance. - Example:
/sbin/ifconfig
,/sbin/reboot
,/sbin/fsck
.
/etc (Configuration Files):
- Contains system-wide configuration files for various programs and services.
- Example:
/etc/passwd
(user account information),/etc/apt/sources.list
(APT package manager sources).
/usr (User):
- Contains user-related programs, libraries, documentation, and other non-essential binaries.
- Split into
/usr/bin
,/usr/sbin
,/usr/lib
,/usr/include
, etc. - Example:
/usr/bin/gcc
(GNU Compiler Collection),/usr/share/doc
(documentation),/usr/local/bin
(user-installed binaries).
/var (Variable Data):
- Contains variable data files like logs, databases, mail, and temporary files.
- Example:
/var/log/syslog
(system log),/var/spool/mail
(user mailboxes).
/tmp (Temporary Files):
- Used for temporary storage of files by programs and users.
- Contents are typically deleted upon system reboot.
- Example:
/tmp/file.txt
,/tmp/sock
.
/home (User Home Directories):
- Contains user home directories.
- Each user has their own subdirectory within
/home
. - Example:
/home/user1
,/home/user2
.
/lib (Libraries):
- Contains shared libraries required by programs in
/bin
and/sbin
. - Example:
/lib/libc.so.6
(C library).
/dev (Device Files):
- Contains device files representing physical and virtual devices.
- Example:
/dev/sda
(first SATA hard drive),/dev/tty1
(first virtual console).
/mnt (Mount Point):
- Used as a temporary mount point for mounting external filesystems.
- Example:
/mnt/usb
(USB drive),/mnt/cdrom
(CD-ROM drive).
/boot (Boot Loader Files):
- Contains files needed for the boot process.
- Example:
/boot/vmlinuz
(Linux kernel),/boot/grub
(GRUB bootloader configuration).
/proc (Process Information):
- A virtual filesystem that provides information about running processes and system resources.
- Example:
/proc/cpuinfo
(CPU information),/proc/meminfo
(memory information),/proc/[pid]
(directory for each running process).
/sys (System Information):
- Another virtual filesystem that exposes information about kernel and hardware to user-space processes.
- Example:
/sys/class
(directory hierarchy for various device classes),/sys/devices
(directory hierarchy for all devices).
/opt (Optional Packages):
- Contains add-on or third-party software packages.
- Typically used for software not managed by the system’s package manager.
- Example:
/opt/google/chrome
(Google Chrome browser),/opt/java/jdk
(Java Development Kit).
/srv (Service Data):
- Contains data for services provided by the system.
- Often used by web servers to store data for web services.
- Example:
/srv/www
(web server files),/srv/ftp
(FTP server files).
/media (Removable Media):
- Mount point for removable media such as USB drives, CDs, DVDs.
- Automatically populated by the system when removable media are inserted.
- Example:
/media/usb
(USB drive),/media/cdrom
(CD-ROM).
/run (Runtime Data):
- Contains runtime data for running processes and system services.
- Often used for process IDs (PIDs) and sockets.
- Example:
/run/udev
(udev runtime directory),/run/systemd
(systemd runtime directory).