|$ curl https://forge-ai.dev/api/markdown?path=docs/linux/filesystem
$cat docs/linux-file-system.md
updated Recently·22 min read·published
Linux File System
Introduction
Everything in Linux is a file: documents, directories, devices, sockets, and pipes. Understanding how the file system is organized and how to inspect it is essential for debugging, deployment, and automation.
Filesystem Hierarchy Standard
| Path | Purpose |
|---|---|
| /bin | Essential command binaries for all users |
| /sbin | Essential system administration binaries |
| /etc | System-wide configuration files |
| /home | Personal directories for users |
| /root | Home directory for root user |
| /var | Variable data: logs, caches, spool |
| /tmp | Temporary files, often cleared on reboot |
| /usr | User utilities, libraries, documentation |
| /opt | Optional add-on software |
| /mnt | Temporary mount points |
| /media | Removable media mount points |
Absolute vs Relative Paths
paths.sh
Bash
| 1 | # Absolute path — starts from root |
| 2 | cd /home/alice/projects/webapp |
| 3 | |
| 4 | # Relative path — starts from current directory |
| 5 | cd src/components |
| 6 | cd ../assets |
| 7 | cd ./styles |
| 8 | |
| 9 | # Special directories |
| 10 | . # current directory |
| 11 | .. # parent directory |
| 12 | ~ # current user's home directory |
| 13 | ~bob # user bob's home directory |
Hard & Symbolic Links
links.sh
Bash
| 1 | # Hard link — points to the same inode |
| 2 | ln original.txt hardlink.txt |
| 3 | |
| 4 | # Symbolic (soft) link — points to a path |
| 5 | ln -s /opt/app/current app |
| 6 | ln -s ../config/.env .env |
| 7 | |
| 8 | # Inspect links |
| 9 | ls -li file.txt # inode number |
| 10 | readlink .env # target of symlink |
📝
note
A hard link cannot cross file systems and cannot link to directories. A symbolic link can point anywhere, but it breaks if the target is moved or deleted.
Disk Usage
disk.sh
Bash
| 1 | # Free disk space by filesystem |
| 2 | df -h |
| 3 | |
| 4 | # Directory sizes |
| 5 | du -sh /var/log |
| 6 | du -sh * | sort -h # sort directories by size |
| 7 | |
| 8 | # Find large files |
| 9 | find . -type f -size +100M |
| 10 | |
| 11 | # Disk usage tree view |
| 12 | ncdu /var/log |
Mounts
mounts.sh
Bash
| 1 | # List mounted filesystems |
| 2 | mount |
| 3 | findmnt |
| 4 | |
| 5 | # Mount a device |
| 6 | sudo mount /dev/sdb1 /mnt/backup |
| 7 | |
| 8 | # Unmount |
| 9 | sudo umount /mnt/backup |
| 10 | |
| 11 | # Persist mounts in /etc/fstab |
| 12 | # /dev/sdb1 /mnt/backup ext4 defaults,noatime 0 2 |