π Linux: File System Hierarchy β Understanding Linux Directory Structure
π§² Introduction β Why Learn the Linux File System Hierarchy?
The Linux file system is more than just foldersβit’s a well-organized, logical hierarchy designed for both simplicity and scalability. Understanding this structure is essential for system navigation, software installation, permission control, and troubleshooting. Unlike Windows, everything in Linux is a file, including hardware and processes.
π― In this guide, youβll learn:
- The purpose of each top-level directory in Linux
- How Linux treats files, directories, and devices
- Common paths used by users, admins, and developers
- Best practices for file storage and configuration
ποΈ Overview: Linux Directory Structure
The Linux file system is rooted at /
(root directory) and branches out like a tree. Below is a simplified overview:
/
βββ bin
βββ boot
βββ dev
βββ etc
βββ home
βββ lib
βββ media
βββ mnt
βββ opt
βββ proc
βββ root
βββ run
βββ sbin
βββ srv
βββ sys
βββ tmp
βββ usr
βββ var
Letβs explore each of these in detail.
π /
β Root Directory
- The top-most directory in Linux.
- All other directories stem from here.
- Equivalent to
C:\
in Windows.
π§ /bin
β Essential User Binaries
- Contains essential binary commands needed for system boot and repair.
- Common commands:
ls
,cp
,mv
,cat
,mkdir
π§ͺ Example:
/bin/ls
βοΈ /sbin
β System Binaries
- Contains system administration binaries.
- Commands typically used by
root
user:fsck
,reboot
,ifconfig
π¦ /lib
, /lib64
β Shared Libraries
- Essential libraries for binaries in
/bin
and/sbin
. - Think of them as Linuxβs DLLs (like in Windows).
π§© /etc
β Configuration Files
- System-wide configuration files live here.
- Examples:
/etc/passwd
,/etc/ssh/sshd_config
,/etc/fstab
π§ͺ View hostname config:
cat /etc/hostname
π /home
β User Home Directories
- Personal folders for users.
- Files, downloads, and settings are stored here (e.g.,
/home/john
).
π /root
β Root User’s Home
- Home directory for the root (superuser).
- Not to be confused with
/
.
π§ͺ Access only via:
sudo su
cd /root
πΎ /boot
β Boot Loader Files
- Contains files needed to boot the OS.
- Includes the Linux kernel (
vmlinuz
),initrd
, andgrub
.
β οΈ Caution: Modifying this folder can make the system unbootable.
π₯οΈ /dev
β Device Files
- Represents devices as files.
- Includes:
/dev/sda
(hard disk),/dev/null
,/dev/tty
π§ͺ Example:
ls /dev
π§ /proc
β Process & Kernel Information
- Virtual file system providing real-time system info.
- Files like
/proc/cpuinfo
,/proc/meminfo
, and/proc/uptime
π§ͺ View CPU Info:
cat /proc/cpuinfo
π€ /sys
β System and Hardware Info
- Similar to
/proc
, but for devices and drivers. - Used by the kernel and
udev
.
π /run
β Runtime Variable Data
- Stores temporary runtime data like PID files, sockets.
- Cleared at every reboot.
π /tmp
β Temporary Files
- Used by apps and users to store temporary files.
- Automatically cleared after reboot.
π¦ /opt
β Optional Software Packages
- Used for installing third-party software not from default repos.
- E.g.,
/opt/google/chrome
for Google Chrome.
π /srv
β Service Data
- Contains files related to system services like
ftp
,httpd
.
π /mnt
and /media
β Mount Points
Directory | Usage |
---|---|
/mnt | Temporary mount points (manually mounted devices) |
/media | Auto-mounted removable devices (USB, CD-ROM) |
π§ͺ Example:
mount /dev/sdb1 /mnt
π Summary β Recap & Next Steps
The Linux file system hierarchy is designed for modularity, security, and predictability. Mastering it helps you navigate, configure, and troubleshoot like a pro. Each directory has a dedicated role, which contributes to system stability and organization.
π Key Takeaways:
- Everything starts at
/
and branches downward. /etc
= config,/home
= users,/bin
= essential binaries,/boot
= boot files.- Device files (
/dev
), process info (/proc
), and temporary data (/tmp
) are managed by the kernel. - Understanding the file system helps in backups, scripting, permissions, and system recovery.
β FAQs
β What is the root directory in Linux?
β
The root directory /
is the base of the Linux file system. All other files and directories are placed under it.
β Whatβs the difference between /bin
and /sbin
?
β
/bin
contains essential user commands; /sbin
holds administrative/system commands for root users.
β Where are user files stored in Linux?
β
In the /home/username/
directory. Each user gets their own subfolder.
β What is /proc
used for?
β
/proc
is a virtual filesystem that displays system and process info directly from kernel memory.
β Can I delete files in /tmp
?
β
Yes, but it’s usually cleared automatically on reboot. Use with care during active sessions.
Share Now :