File System Structure
Overview
Linux adopts a hierarchical tree-like file system structure where all files and directories start from the root directory (/). Unlike Windows which uses multiple drive letters (C:, D:), Linux mounts all storage devices to this single directory tree.
Filesystem Hierarchy Standard (FHS)
Linux follows the Filesystem Hierarchy Standard (FHS), which defines specifications for directory structure and content.
Directory Tree Overview
/
├── bin → Basic command binary files
├── boot → Boot loader files
├── dev → Device files
├── etc → System configuration files
├── home → User home directories
├── lib → Shared library files
├── media → Removable media mount points
├── mnt → Temporary mount points
├── opt → Third-party applications
├── proc → Process and kernel information (virtual)
├── root → Root user's home directory
├── run → Runtime data
├── sbin → System administration commands
├── srv → Service data
├── sys → Kernel and device information (virtual)
├── tmp → Temporary files
├── usr → User programs and data
└── var → Variable data files
Important Directories Explained
/ (Root Directory)
The root directory is the starting point of the file system; all directories and files are its descendants.
$ ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
/bin and /sbin
Store binary files for basic commands.
# /bin - Basic commands available to all users
$ ls /bin
bash cat cp ls mkdir mv rm ...
# /sbin - System administration commands (usually require root permissions)
$ ls /sbin
fdisk fsck ifconfig init ip reboot shutdown ...
Note: In modern Linux distributions, /bin and /sbin are usually symbolic links to /usr/bin and /usr/sbin.
/boot
Contains files needed to boot Linux.
$ ls /boot
config-5.15.0-generic # Kernel configuration
initrd.img-5.15.0-generic # Initial ramdisk
vmlinuz-5.15.0-generic # Compressed Linux kernel
grub/ # GRUB boot loader
/dev
Device file directory. Linux represents hardware devices as files.
$ ls /dev
sda # First hard disk
sda1 # First partition of first hard disk
sdb # Second hard disk
nvme0n1 # NVMe SSD
tty # Terminal device
null # Null device (discards all input)
zero # Zero device (generates null bytes)
random # Random number generator
Common Device Files
/etc
System configuration files directory (Editable Text Configuration).
$ ls /etc
apt/ # APT package manager configuration
bash.bashrc # System-level Bash configuration
crontab # Scheduled tasks
fstab # Filesystem mount table
group # Group information
hostname # Hostname
hosts # Hostname resolution
network/ # Network configuration
passwd # User account information
shadow # Encrypted user passwords
ssh/ # SSH configuration
sudoers # sudo configuration
Important Configuration Files
/home
Home directory for regular users.
/home
├── maxwell/
│ ├── Desktop/
│ ├── Documents/
│ ├── Downloads/
│ ├── .bashrc # User Bash configuration
│ ├── .profile # Login configuration
│ └── .ssh/ # SSH keys
├── alice/
└── bob/
Each user has their own directory under /home for storing personal files and configuration.
# Home directory can be represented by ~
$ cd ~
$ cd ~/Documents
/lib and /lib64
Shared library files (similar to Windows DLL).
$ ls /lib
modules/ # Kernel modules
x86_64-linux-gnu/ # 64-bit library files
Mount point directories.
/media: Automatically mounted removable devices (USB, CD)
/mnt: Temporary manual mount points
# View mounted devices
$ ls /media/$USER/
USB_DRIVE/ CD_ROM/
# Manual mount
$ sudo mount /dev/sdb1 /mnt
/opt
Third-party application installation directory.
/opt
├── google/
│ └── chrome/
├── visual-studio-code/
└── lampp/
/proc
Virtual filesystem providing process and kernel information.
$ ls /proc
1/ # Process info with PID 1
self/ # Current process
cpuinfo # CPU information
meminfo # Memory information
version # Kernel version
Common Files
# View CPU information
$ cat /proc/cpuinfo
# View memory information
$ cat /proc/meminfo
# View kernel version
$ cat /proc/version
# View system uptime
$ cat /proc/uptime
# View specific process information
$ ls /proc/1234/
cmdline cwd environ exe fd maps status ...
/root
Home directory for root user (superuser).
# Note: Not /home/root
$ sudo ls /root
/run
Runtime data directory, storing temporary data since system boot.
$ ls /run
lock/ # Lock files
user/ # User runtime data
systemd/ # systemd data
/srv
Service data directory, storing data provided by system services.
/srv
├── ftp/ # FTP service data
├── http/ # Web service data
└── git/ # Git repositories
/sys
Virtual filesystem providing kernel, device, and driver information.
$ ls /sys
block/ # Block devices
bus/ # Bus
class/ # Device classes
devices/ # Devices
power/ # Power management
/tmp
Temporary files directory. Contents may be cleared after system reboot.
$ ls /tmp
systemd-private-xxx/
- All users can write to it
- Usually configured for periodic cleanup
- Suitable for storing temporary data
/usr
User programs and data (Unix System Resources).
/usr
├── bin/ # User commands
├── include/ # C header files
├── lib/ # Library files
├── local/ # Locally installed software
│ ├── bin/
│ ├── lib/
│ └── share/
├── sbin/ # System administration commands
├── share/ # Architecture-independent data
│ ├── doc/ # Documentation
│ ├── man/ # Manual pages
│ └── icons/ # Icons
└── src/ # Source code
Subdirectory Description
/var
Variable data files (Variable).
/var
├── cache/ # Application cache
├── lib/ # Program state data
├── log/ # Log files
├── mail/ # Mail
├── run/ # Runtime data (link to /run)
├── spool/ # Queue data
└── tmp/ # Persistent temporary files
Important Subdirectories
# Log files
$ ls /var/log/
syslog # System log
auth.log # Authentication log
kern.log # Kernel log
apt/ # APT log
nginx/ # Nginx log
# Package manager cache
$ ls /var/cache/apt/
archives/ # Downloaded deb packages
File Types
In Linux, everything is a file. File types include:
Viewing File Types
# Using ls -l, look at first character
$ ls -l
drwxr-xr-x 2 user user 4096 Jan 1 10:00 Documents # Directory
-rw-r--r-- 1 user user 123 Jan 1 10:00 file.txt # Regular file
lrwxrwxrwx 1 user user 7 Jan 1 10:00 link -> file # Symbolic link
# Using file command
$ file /bin/ls
/bin/ls: ELF 64-bit LSB pie executable...
$ file /etc/passwd
/etc/passwd: ASCII text
$ file /dev/sda
/dev/sda: block special
Mounting Filesystems
Understanding Mounting
Linux mounts different storage devices to specific locations in the directory tree.
# View mounted filesystems
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 15G 32G 32% /
/dev/sda2 200G 80G 110G 43% /home
/dev/sdb1 500G 100G 400G 20% /data
# Detailed mount information
$ mount
/dev/sda1 on / type ext4 (rw,relatime)
/dev/sda2 on /home type ext4 (rw,relatime)
/etc/fstab
Defines filesystems that are automatically mounted at system startup.
$ cat /etc/fstab
# <device> <mount point> <type> <options> <dump> <pass>
/dev/sda1 / ext4 defaults 0 1
/dev/sda2 /home ext4 defaults 0 2
/dev/sdb1 /data ext4 defaults 0 2
UUID=xxx /boot ext4 defaults 0 2
Manual Mounting
# Mount USB drive
$ sudo mount /dev/sdb1 /mnt/usb
# Mount ISO file
$ sudo mount -o loop ubuntu.iso /mnt/iso
# Mount network share
$ sudo mount -t nfs server:/share /mnt/nfs
# Unmount
$ sudo umount /mnt/usb
Common Filesystem Types
Hidden Files
Files or directories starting with a dot (.) are hidden.
# View hidden files
$ ls -a
. .. .bashrc .profile .config Documents
# Common hidden files
~/.bashrc # Bash configuration
~/.profile # Login configuration
~/.bash_history # Command history
~/.ssh/ # SSH configuration and keys
~/.config/ # Application configuration
~/.local/ # User local data
Finding File Locations
which - Find Command Location
$ which ls
/usr/bin/ls
$ which python
/usr/bin/python
whereis - Find Command, Source, and Manual
$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
type - Command Type
$ type ls
ls is aliased to `ls --color=auto'
$ type cd
cd is a shell builtin
$ type /usr/bin/ls
/usr/bin/ls is /usr/bin/ls
Summary
Understanding Linux filesystem structure is the foundation of using Linux:
- Root directory
/ is the starting point of the entire filesystem
/home stores user personal files
/etc stores system configuration
/var stores variable data (logs, etc.)
/usr stores user programs
/tmp stores temporary files
/dev、/proc、/sys are special virtual filesystems
Being familiar with the purpose of these directories will help you better manage and maintain your Linux system.
Previous chapter: Terminal Basics
Next chapter: File Operations