#bash 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 Multipart File Upload via cURL
Upload one or more files using -F. Optional extra form fields go through the same flag — quote carefully to preserve spaces.
Bash Count Occurrences of a Pattern
Several ways to count matches: lines containing X, total matches across a file, matches grouped by capture, etc.
Bash Format Date Like a Pro
`date` accepts a format string + optional override of the date being formatted. The +%FT%TZ form gives you ISO-8601 / RFC-3339 in one call.
Bash Filter Lines by Regex
grep -E (extended regex) is the right tool 95% of the time. Combine -i (case-insensitive), -v (invert), -n (line numbers), -B/-A (context lines).
Bash Check If Port Is Open
Several ways to probe a remote port: nc (most portable), bash's /dev/tcp pseudo-device (zero deps), or curl. Pick by what's available.
Bash Wait For Docker Container to Be Healthy
docker-compose entrypoints often need to wait for a sibling service (DB, cache) to be healthy before starting work. Poll the health-check status until healthy or timeout.
Bash Kill Process by Port
When a port is "already in use" — find the offending process and (carefully) kill it. `lsof` is the gold standard; `ss` is the lighter modern alternative.
Bash Wait For Service With Timeout
Block until a TCP port accepts connections, with a deadline. Used everywhere in docker-compose entrypoints — wait for the DB to be ready before running the app.
Bash Print Environment Variables Matching Pattern
Quick audit of env vars by prefix — useful when debugging containerized apps that read from `STRIPE_*`, `DB_*`, etc.
Bash SSH to Multiple Hosts in Parallel
Run the same command on a fleet of hosts. Three patterns: serial loop (simplest), GNU parallel (fastest), pssh (purpose-built).
Bash Background Jobs + wait
Run several commands in parallel with `&`, then wait for all of them with `wait`. Collect exit codes via $! and check after wait returns.
Bash Prune Dangling Docker Images
Reclaim disk space from Docker. `prune` operates on stopped containers, dangling images, build cache, and unused networks. Run periodically on CI runners.
Bash Trap Signals for Cleanup
Use `trap` to delete temp files / kill background workers when the script exits — even on Ctrl-C or an unhandled error. Single most-undervalued bash feature.
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 Epoch ↔ Human Date Conversion
`date +%s` gives now-as-epoch; `date -d @N` converts an epoch number back to a human date. Often what API responses expect / return.
Bash Deduplicate Array (preserve order)
Bash's associative arrays let you dedupe in a single pass while keeping the original order — `sort -u` would shuffle.
Bash Associative Array (hash map)
Bash 4+ supports key-value associative arrays. Must `declare -A` first — Bash won't infer it. Iterate keys with !arr[@].
Bash Tail Logs from Multiple Containers
`docker compose logs -f` already does this — but the one-liner with --tail and filters is the more useful day-to-day workflow when you only care about recent activity from a subset of services.