Yash Verma / Cloud runbook

Linux commands

26 commands from the cloud runbook. Fill in a placeholder once and every command uses it.

Largest items in the current directory

Lists the 10 largest files and directories here (dotfiles excluded).

du -hs * | sort -rh | head -10

disk, storage, du

Find files over 100 MB

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

disk, files, find

Tail systemd service logs

Follows journalctl logs for a service in real-time.

journalctl -u <service-name> -f

logs, systemd

Stop the process listening on a port

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)

process, port, kill

Find the processes using the most CPU

Lists the top 10 processes consuming the most CPU.

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -11

cpu, performance, ps

Search string recursively

Searches for a string inside all files in a directory.

grep -rnw '/path/to/somewhere/' -e 'pattern'

search, grep, files

Set permissions on directories only

Recursively changes permissions of directories only (leaving files untouched).

find . -type d -exec chmod 755 {} \;

permissions, chmod, directories

Print specific columns with awk

Prints only the 3rd and 5th columns of a space-separated file.

awk '{print $3, $5}' data.txt

awk, text, processing

Find and replace in a file with sed

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.

sed, replace, text

Delete log files older than 30 days

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

find, cleanup, logs

Sync directories securely

Uses rsync to synchronize two directories over SSH, showing progress.

rsync -avz --progress /local/dir/ user@remote:/remote/dir/

rsync, sync, ssh

Check free memory

Shows total, used and available memory in human-readable units.

free -h

memory, ram

Check disk space

Shows filesystem disk space usage and types.

df -Th

disk, storage

Find and change owner

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 {} +

chown, permissions

Create tar.gz archive

Compresses a directory into a tarball.

tar -czvf archive.tar.gz /path/to/dir

tar, compress

Watch a command output

Runs a command repeatedly every 2 seconds, refreshing output.

watch -n 2 'kubectl get pods'

watch, monitoring, repeat

List listening ports and their processes

Shows TCP and UDP sockets in the LISTEN state with the owning process. The modern replacement for netstat -tulnp.

sudo ss -tulpn

ss, ports, netstat

List block devices

Shows all block devices (disks, partitions) in a tree view.

lsblk -f

disk, partitions, lsblk

Enable service on boot

Enables a systemd service to start automatically on boot.

sudo systemctl enable <service-name>

systemd, boot, service

Search command history

Searches your bash history for a specific command.

history | grep <keyword>

history, search, bash

Edit cron jobs

Opens the crontab editor to schedule recurring tasks.

crontab -e

cron, schedule, automation

Create a new user

Creates a new system user with a home directory.

sudo useradd -m -s /bin/bash <username>

user, admin, account

Check system uptime and load

Shows how long the system has been running plus load averages.

uptime

uptime, load, health

View kernel messages

Shows kernel ring buffer messages, useful for hardware/driver debugging.

sudo dmesg --level=err,warn -T | tail -30

kernel, dmesg, hardware

Extract tar.gz archive

Extracts a compressed tarball archive to the current directory.

tar -xzvf archive.tar.gz

tar, unzip, archive