Largest items in the current directory
Lists the 10 largest files and directories here (dotfiles excluded).
du -hs * | sort -rh | head -10
26 commands from the cloud runbook. Fill in a placeholder once and every command uses it.
Lists the 10 largest files and directories here (dotfiles excluded).
du -hs * | sort -rh | head -10
Finds files over 100 MB on the root filesystem, largest first.
sudo find / -xdev -type f -size +100M -exec du -h {} + 2>/dev/null | sort -rh | head -20
Follows journalctl logs for a service in real-time.
journalctl -u <service-name> -f
Sends SIGTERM to the process listening on a TCP port.
Caution. Use kill -9 only if the process ignores SIGTERM: -9 skips its shutdown and cleanup.
kill $(lsof -t -i:<port> -sTCP:LISTEN)
Lists the top 10 processes consuming the most CPU.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -11
Searches for a string inside all files in a directory.
grep -rnw '/path/to/somewhere/' -e 'pattern'
Creates a symbolic link pointing to a target file or directory.
ln -s /path/to/target /path/to/link
Recursively changes permissions of directories only (leaving files untouched).
find . -type d -exec chmod 755 {} \;
Prints only the 3rd and 5th columns of a space-separated file.
awk '{print $3, $5}' data.txt
Replaces 'old-string' with 'new-string' inline in a file.
sed -i 's/old-string/new-string/g' config.yaml
GNU sed. On macOS, use sed -i '' instead of sed -i.
Finds .log files older than 30 days under /var/log and deletes them.
Caution. Deletes files permanently. Run it once without -delete to see the list first.
sudo find /var/log -type f -name "*.log" -mtime +30 -delete
Uses rsync to synchronize two directories over SSH, showing progress.
rsync -avz --progress /local/dir/ user@remote:/remote/dir/
Shows total, used and available memory in human-readable units.
free -h
Shows filesystem disk space usage and types.
df -Th
Finds files owned by root and changes them to another user.
Caution. Changes ownership of everything it matches. Check the path first; run against / it can break the system.
find /path -user root -exec chown user:group {} +
Compresses a directory into a tarball.
tar -czvf archive.tar.gz /path/to/dir
Runs a command repeatedly every 2 seconds, refreshing output.
watch -n 2 'kubectl get pods'
Shows TCP and UDP sockets in the LISTEN state with the owning process. The modern replacement for netstat -tulnp.
sudo ss -tulpn
Shows all block devices (disks, partitions) in a tree view.
lsblk -f
Enables a systemd service to start automatically on boot.
sudo systemctl enable <service-name>
Searches your bash history for a specific command.
history | grep <keyword>
Opens the crontab editor to schedule recurring tasks.
crontab -e
Creates a new system user with a home directory.
sudo useradd -m -s /bin/bash <username>
Shows how long the system has been running plus load averages.
uptime
Shows kernel ring buffer messages, useful for hardware/driver debugging.
sudo dmesg --level=err,warn -T | tail -30
Extracts a compressed tarball archive to the current directory.
tar -xzvf archive.tar.gz