#sysadmin Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Bash Find Largest Files and Directories
Quick "where did all my disk go?" answer. du sorts by size, ncdu (interactive) is better for exploration.
Bash Memory / CPU / Load Quick Check
One-liners for the three most-requested system metrics. Use in monitoring scripts or as ad-hoc sanity checks.
Bash Generate a Random Password
Three approaches: pwgen (purpose-built), openssl (universally available), /dev/urandom + tr (zero deps). Pick by what's installed.
Bash Check Systemd Service Is Running
`systemctl is-active` is the right tool — exit code 0 if running, non-zero otherwise. Combine with restart-on-fail for poor-man's supervision.
Bash Tar Archive with Timestamp
Pack up a directory with a date-stamped filename for easy backups. -z for gzip, -j for bzip2, -J for xz (smallest, slowest).
Bash Disk Space Alert
Cron-friendly script that checks disk usage on each filesystem and emails (or webhooks) if any partition exceeds a threshold.
Bash Cron Entry From Script
Append a cron job idempotently — grep first to avoid duplicates on re-run. Doesn't require editing files manually.
Bash OS / Distro Detection
Read /etc/os-release for distro info — it's the standard on every modern Linux. Branch deploy scripts on distro to pick apt vs. dnf vs. apk.
Bash Detect Whether Running as Root
Several scripts must run as root (or refuse to). EUID is more reliable than `whoami == root` because sudo without -E may change one but not the other.
Bash Rotate Logs Manually
If a service doesn't hook into logrotate, you can still rotate a log file yourself in one safe pattern: rename current → .1, truncate the original, signal the process to re-open if needed.
Bash Create User With Sensible Defaults
Provision a new user account with a home directory, default shell, and sudo membership. Idempotent — re-running on an existing user is a no-op.