Skip to content

Terminal window
df -h # human-readable sizes (GB, MB)
df -h / # space on root partition only
df -hT # include filesystem type
df -i # inode usage instead of space

Terminal window
du -sh * # size of each item in current dir
du -sh /var/log # size of a specific directory
du -h --max-depth=1 /var # one level deep
du -sh * | sort -rh # sort by size, largest first
du -ah . | sort -rh | head -20 # top 20 largest files/dirs

Terminal window
ls # basic listing
ls -l # long format (permissions, size, date)
ls -lh # human-readable sizes
ls -la # include hidden files
ls -lt # sort by modification time
ls -lS # sort by file size
ls -R # recursive
ls -d */ # directories only

Terminal window
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 all
chmod -x script.sh # remove execute
chmod -R 755 ./dir # recursive

Permission Octal Reference:

OctalBinaryMeaning
7111read + write + execute
6110read + write
5101read + execute
4100read only
0000no permissions

Order: [owner][group][others] — e.g. 755 = owner full, group+others read+execute.


Terminal window
chown user file.txt # change owner
chown user:group file.txt # change owner and group
chown -R user:group ./dir # recursive
chown :group file.txt # change group only (same as chgrp)

Terminal window
# 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 symlink
ln -sf /new/target linkname

Terminal window
env # list all environment variables
echo $PATH # print a specific variable
export MY_VAR=value # set for current shell + child processes
unset MY_VAR # remove variable
# Set for a single command only
MY_VAR=value ./script.sh
# Add to PATH
export PATH="$PATH:/new/dir"

Terminal window
which python3 # full path of binary in PATH
which -a python3 # all matches in PATH
whereis python3 # binary + man page + source locations
type ls # whether it's a builtin, alias, or binary

Terminal window
mount # list all mounted filesystems
mount /dev/sdb1 /mnt/disk # mount a device
mount -t ext4 /dev/sdb1 /mnt # specify filesystem type
umount /mnt/disk # unmount
df -h # verify after mounting

Terminal window
free -h # human-readable RAM + swap usage
free -s 2 # refresh every 2 seconds

Terminal window
uname -a # all system info
uname -r # kernel version
uname -m # architecture (x86_64, arm64, etc.)

Terminal window
uptime # uptime + load averages (1m, 5m, 15m)

Load average > number of CPU cores = system under pressure.


Terminal window
iostat # CPU + disk I/O stats
iostat -x 2 # extended stats, refresh every 2s
iostat -h # human-readable

  • du -sh * | sort -rh | head -10 is the fastest way to find what’s eating disk space.
  • chmod 600 for private keys — SSH will refuse to use keys that are too permissive.
  • Always use -h with df and du — raw bytes are unreadable at a glance.
  • ln -s symlinks are relative by default — use absolute paths to avoid broken links when moving things around.

← Linux