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 filesImportant 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,
/binand/sbinare usually symbolic links to/usr/binand/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 generatorCommon Device Files
| Device | Description |
|---|---|
/dev/null | Discards all written data |
/dev/zero | Provides infinite null bytes |
/dev/random | Generates random data |
/dev/sda | First SATA/SCSI hard disk |
/dev/nvme0n1 | First NVMe hard disk |
/dev/tty | Current terminal |
/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 configurationImportant Configuration Files
| File | Description |
|---|---|
/etc/passwd | User account information |
/etc/shadow | Encrypted passwords |
/etc/group | User group information |
/etc/fstab | Disk mount configuration |
/etc/hosts | Local DNS resolution |
/etc/hostname | Hostname |
/etc/resolv.conf | DNS server configuration |
/etc/crontab | System scheduled tasks |
/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/media and /mnt
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 versionCommon 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 codeSubdirectory Description
| Directory | Description |
|---|---|
/usr/bin | User commands |
/usr/sbin | System administration commands |
/usr/lib | Library files |
/usr/local | Locally installed software |
/usr/share | Shared data (docs, icons, etc.) |
/usr/include | C/C++ header files |
/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 filesImportant 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 packagesFile Types
In Linux, everything is a file. File types include:
| Symbol | Type | Description |
|---|---|---|
- | Regular file | Text, binary, images, etc. |
d | Directory | Container for other files |
l | Symbolic link | Points to another file |
b | Block device | Hard drive, USB, etc. |
c | Character device | Terminal, keyboard, etc. |
s | Socket | Inter-process communication |
p | Pipe | FIFO, inter-process communication |
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 specialMounting 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 2Manual 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/usbCommon Filesystem Types
| Type | Description |
|---|---|
| ext4 | Default Linux filesystem, stable and reliable |
| xfs | High performance, suitable for large files |
| btrfs | Supports advanced features like snapshots, compression |
| ntfs | Windows filesystem |
| fat32/vfat | Good compatibility, common for USB drives |
| exfat | Large file support, cross-platform |
| nfs | Network filesystem |
| tmpfs | Memory-based filesystem |
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 dataFinding File Locations
which - Find Command Location
$ which ls
/usr/bin/ls
$ which python
/usr/bin/pythonwhereis - Find Command, Source, and Manual
$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gztype - 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/lsSummary
Understanding Linux filesystem structure is the foundation of using Linux:
- Root directory
/is the starting point of the entire filesystem /homestores user personal files/etcstores system configuration/varstores variable data (logs, etc.)/usrstores user programs/tmpstores temporary files/dev、/proc、/sysare 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