Disk System
Disk & System — Quick Reference
Section titled “Disk & System — Quick Reference”df — Disk Space by Filesystem
Section titled “df — Disk Space by Filesystem”df -h # human-readable sizes (GB, MB)df -h / # space on root partition onlydf -hT # include filesystem typedf -i # inode usage instead of spacedu — Directory / File Size
Section titled “du — Directory / File Size”du -sh * # size of each item in current dirdu -sh /var/log # size of a specific directorydu -h --max-depth=1 /var # one level deepdu -sh * | sort -rh # sort by size, largest firstdu -ah . | sort -rh | head -20 # top 20 largest files/dirsls — List Files
Section titled “ls — List Files”ls # basic listingls -l # long format (permissions, size, date)ls -lh # human-readable sizesls -la # include hidden filesls -lt # sort by modification timels -lS # sort by file sizels -R # recursivels -d */ # directories onlychmod — File Permissions
Section titled “chmod — File Permissions”chmod 644 file.txt # rw-r--r--chmod 755 script.sh # rwxr-xr-x (executable)chmod 600 secret.key # rw------- (private)chmod +x script.sh # add execute for allchmod -x script.sh # remove executechmod -R 755 ./dir # recursivePermission Octal Reference:
| Octal | Binary | Meaning |
|---|---|---|
7 | 111 | read + write + execute |
6 | 110 | read + write |
5 | 101 | read + execute |
4 | 100 | read only |
0 | 000 | no permissions |
Order: [owner][group][others] — e.g. 755 = owner full, group+others read+execute.
chown — Change Ownership
Section titled “chown — Change Ownership”chown user file.txt # change ownerchown user:group file.txt # change owner and groupchown -R user:group ./dir # recursivechown :group file.txt # change group only (same as chgrp)ln — Create Links
Section titled “ln — Create Links”# Symbolic link (like a shortcut)ln -s /path/to/target linkname
# Hard link (same inode, survives target deletion)ln /path/to/file hardlink
# Update existing symlinkln -sf /new/target linknameenv / export — Environment Variables
Section titled “env / export — Environment Variables”env # list all environment variablesecho $PATH # print a specific variableexport MY_VAR=value # set for current shell + child processesunset MY_VAR # remove variable
# Set for a single command onlyMY_VAR=value ./script.sh
# Add to PATHexport PATH="$PATH:/new/dir"which / whereis — Locate Binaries
Section titled “which / whereis — Locate Binaries”which python3 # full path of binary in PATHwhich -a python3 # all matches in PATHwhereis python3 # binary + man page + source locationstype ls # whether it's a builtin, alias, or binarymount / umount — Filesystems
Section titled “mount / umount — Filesystems”mount # list all mounted filesystemsmount /dev/sdb1 /mnt/disk # mount a devicemount -t ext4 /dev/sdb1 /mnt # specify filesystem typeumount /mnt/disk # unmountdf -h # verify after mountingfree — Memory Usage
Section titled “free — Memory Usage”free -h # human-readable RAM + swap usagefree -s 2 # refresh every 2 secondsuname — System Info
Section titled “uname — System Info”uname -a # all system infouname -r # kernel versionuname -m # architecture (x86_64, arm64, etc.)uptime — System Load
Section titled “uptime — System Load”uptime # uptime + load averages (1m, 5m, 15m)Load average > number of CPU cores = system under pressure.
iostat — Disk I/O Stats
Section titled “iostat — Disk I/O Stats”iostat # CPU + disk I/O statsiostat -x 2 # extended stats, refresh every 2siostat -h # human-readabledu -sh * | sort -rh | head -10is the fastest way to find what’s eating disk space.chmod 600for private keys — SSH will refuse to use keys that are too permissive.- Always use
-hwithdfanddu— raw bytes are unreadable at a glance. ln -ssymlinks are relative by default — use absolute paths to avoid broken links when moving things around.