Linux File System Explained: Directory Hierarchy and Structure
A comprehensive guide to the Linux filesystem hierarchy, directory structure, file types, mount points, and navigation commands.
Understanding the Linux Filesystem
The Linux filesystem is a hierarchical tree structure rooted at /. Unlike Windows which uses separate drive letters (C:, D:, E:), Linux treats every storage device, partition, and network share as a directory within a single unified tree. This design provides consistency across systems and simplifies path management.
The Filesystem Hierarchy Standard (FHS) defines the purpose and contents of directories in Linux systems. Most distributions follow the FHS, so the directory structure is similar across Ubuntu, Kali, Fedora, and others.
Prerequisites
Basic familiarity with the command line including ls,cd, and pwd commands. Understanding file paths (absolute vs relative) is helpful.
The Root Directory
Navigation across the filesystem tree utilizes directory shortcuts including parent directory navigation via cd .., home directory targeting with cd ~, previous working directory switching via cd -, and directory stack navigation with pushd, popd, and dirs.
The root directory / is the top of the filesystem tree. Every file and directory on the system branches from this single point. All paths that start with / are absolute paths because they begin at the root.
Essential Directories Explained
/bin — Essential User Binaries
/bin contains essential command binaries needed for system booting and repair. These commands are available even if other filesystems are not mounted. Common binaries include ls, cp, mv, rm, cat, echo, bash, and sh.
ls /bin | head -10
# Output: bash, cat, chmod, cp, date, echo, grep, kill, less, ln
On modern distributions, /bin is often a symbolic link to /usr/bin.
/boot — Boot Loader Files
/boot contains everything needed to boot Linux: the kernel (vmlinuz), initial RAM disk (initrd.img), boot loader configuration (GRUB), and System.map (kernel symbol table). This directory is often kept small and may be a separate partition.
ls /boot
# vmlinuz-6.1.0-kali9-amd64 initrd.img-6.1.0-kali9-amd64 grub/
/dev — Device Files
Linux treats hardware devices as files. /dev contains device nodes that represent hardware components like hard drives (/dev/sda), partitions (/dev/sda1), terminals (/dev/tty), sound cards (/dev/audio), and random number generators (/dev/urandom).
ls /dev | head -10
# sda, sda1, sda2, tty, null, zero, random, urandom, cdrom, usb
For enumerating attached hardware buses and peripheral controllers, see our guides on PCI hardware with lspci and USB devices with lsusb.
/etc — Configuration Files
/etc (et-cetera) contains system-wide configuration files. This is one of the most important directories for system administration. Examples include:
/etc/passwd — User account information/etc/shadow — Encrypted passwords/etc/ssh/sshd_config — SSH server configuration/etc/network/interfaces — Network configuration/etc/apt/sources.list — Package repository list/etc/hosts — Static hostname mapping/etc/fstab — Filesystem mount tablecat /etc/os-release
# PRETTY_NAME="Kali GNU/Linux Rolling"
# NAME="Kali GNU/Linux"
/home — User Home Directories
Each regular user gets a subdirectory under /home (except root, whose home is /root). User data, personal configurations (dotfiles), and user-installed programs reside here. The path /home/username is often accessible as ~ for the current user.
ls -la /home
# drwxr-xr-x user1 user1 /home/user1
# drwxr-xr-x user2 user2 /home/user2
/lib — System Libraries
/lib contains shared libraries needed by binaries in /bin and /sbin. These are the equivalent of DLLs on Windows. Library files typically have extensions like .so (shared object) or .a (archive). Kernel modules reside in /lib/modules.
/media and /mnt — Mount Points
/media is used for removable media (USB drives, CD-ROMs) that are automatically mounted. /mnt is a generic mount point for temporary manual mounts.
# Mount a USB drive
sudo mount /dev/sdb1 /mnt/usb
ls /mnt/usb
For mounting filesystems into the directory hierarchy and safely unmounting storage volumes, consult our references on mount and umount.
/opt — Optional Software
/opt is reserved for third-party software packages that are not part of the distribution's package manager. Software here is self-contained in its own subdirectory. Examples include Google Earth, Oracle Database, and some commercial tools.
/proc — Process Information
Kernel state and hardware interaction can be directly queried via lsmod to enumerate active kernel modules and modinfo to inspect module metadata and driver firmware parameters.
/proc is a virtual filesystem that provides runtime system information. It contains files for every running process (numbered directories), system information (/proc/cpuinfo, /proc/meminfo), and kernel parameters (/proc/sys). Files in /proc are dynamically generated and do not occupy disk space.
cat /proc/cpuinfo | head -5
cat /proc/meminfo | head -5
ls /proc | grep -E '^[0-9]+$' | head -10 # Process IDs
To inspect hardware diagnostic logs directly from the kernel ring buffer, explore our dmesg command reference, and for real-time virtual memory, paging, and CPU statistics, see vmstat. To rapidly find files across the indexed filesystem hierarchy without live disk traversal, consult our locate command guide. For high-performance archive compression and decompression, review our references for bzip2, bunzip2, xz, unxz, and multi-format archiving with 7z.
/root — Root Home Directory
The home directory for the root (administrator) user is /root, not /home/root. This separation ensures root can log in even if /home is unmounted during recovery.
/sbin — System Binaries
/sbin contains system administration binaries used for system maintenance. These commands typically require root privileges. Examples include partition table inspection and creation with fdisk and modern GPT partitioning with parted, block device UUID and attribute discovery with blkid, filesystem creation with mkfs, filesystem consistency checking with fsck, low-level block copying with dd, and interactive visual disk space analysis with ncdu.
/tmp — Temporary Files
/tmp is world-writable and stores temporary files. Files in /tmp are typically deleted on system boot. The sticky bit (t) on /tmp prevents users from deleting each other's files.
ls -la / | grep tmp
# drwxrwxrwt ... /tmp
/usr — User System Resources
/usr is the largest directory on a typical Linux system. It contains user utilities, applications, libraries, documentation, and source code.
/var — Variable Data
/var stores data that changes frequently during system operation: logs (/var/log), spools (/var/spool), temporary files preserved between reboots (/var/tmp), cache data (/var/cache), web server root (/var/www), and database state (/var/lib).
du -sh /var/log
ls /var/log/
File Types in Linux
Linux treats everything as a file. The first character of ls -l output indicates the file type:
| Character | File Type | Example |
|---|---|---|
- | Regular file | -rw-r--r-- |
d | Directory | drwxr-xr-x |
l | Symbolic link | lrwxrwxrwx |
c | Character device | crw-rw-rw- |
b | Block device | brw-rw---- |
Mount Points and Partitions
mount | head -10
Real-World Examples
Finding Large Log Files: du -sh /var/log/* | sort -rh | head -10
Checking Disk Usage by Directory: du -sh /* 2>/dev/null | sort -rh | head -10
Finding Configuration Files: find /etc -name "*.conf" -type f
Common Mistakes
Confusing /bin and /usr/bin — on modern systems they are often symlinked. Never delete files in /proc or /sys. Ignoring /etc when troubleshooting.
Best Practices
Use df -h to monitor disk space. Use du -sh for directory sizes. Keep /boot clean of old kernels. Understand symbolic links — they are pointers, not copies.
Related Tools
ncdu — Interactive disk usage analyzer. du — Estimate directory space. df — Filesystem disk space. lsblk — List block devices. find — Search for files. tree — Display directory structure.
Related Articles
Summary
The Linux filesystem follows the FHS with a single root directory /. Key directories include /bin (commands), /etc (configuration), /home (user data), /var (logs), /tmp (temporary files), and /usr (applications). Understanding this structure is fundamental to Linux administration and security.
Knowledge Check
Frequently Asked Questions
Continue Learning
Command Line Essentials: Mastering the Terminal for Security Work
Essential command line skills for cybersecurity professionals including navigation, text processing, scripting, and automation.
Linux · BeginnerLinux Package Management: APT, DPKG, and Beyond
Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.
Linux · BeginnerLinux Process Management: Monitoring and Controlling Processes
Learn to manage Linux processes effectively including monitoring tools, signals, priority control, background jobs, and automation with systemd.
Linux · BeginnerWhat is Linux? Understanding the Open Source Operating System
A beginner-friendly introduction to Linux covering its history, architecture, distributions, kernel, and why it is essential for cybersecurity professionals.
Related Security Tools
SMBClient
Learn how to use SMBClient on Kali Linux: install Samba's FTP-like SMB/CIFS client, list shares, connect as a guest or with credentials, browse folders, and upload or download files on Windows, Samba, or NAS devices. For authorized assessments, check ports 139/445 with Nmap before testing share permissions.
Information GatheringEnum4linux
Learn how to use Enum4linux to enumerate Windows and Samba systems over SMB: install it on Kali Linux, run your first scan, read the users, shares, groups and password policy it returns, and switch to enum4linux-ng for modern hosts that block null sessions.
Password AttacksHydra
Hydra is a parallelized login cracker that supports numerous protocols including FTP, HTTP, HTTPS, SMB, SSH, and many more. It performs rapid dictionary attacks against login pages and services to test password strength.
Post ExploitationEvil-WinRM
Learn how to use Evil-WinRM, a Ruby-based client for the Windows Remote Management (WinRM) protocol. This guide covers installation, your first connection, password, pass-the-hash and Kerberos authentication, file transfers and script execution, all for use in authorized lab environments.