Disk Space Warning Script
Copy a disk space warning bash script using df, thresholds, cron, and email alerts. Monitor Linux servers and prevent full drives.
monitor · cron-ready · df
Full guide →
$bashsnippets.xyz
I got tired of re-searching the same bash one-liners every time I sat down at a terminal. So I started collecting them. This is that collection — real scripts, explained like a human wrote them, with the edge cases documented so you don't hit the same problems I did.
62 Working Scripts
100% Tested on Linux
0 Logins Required
Free Always
BashSnippets is a free bash script library for Linux developers, sysadmins, and DevOps engineers. Every script solves a specific operational problem — disk space monitoring, automated backups, service watchdogs, log cleanup — and comes with a plain-English explanation of what each line does and why.
Bash runs on every Linux server without installing anything. That means these scripts work on Ubuntu, Debian, Fedora, CentOS, and macOS without a dependency manager, a runtime, or a package.json. Copy the script, set a threshold or path, make it executable, and you're done. The 13 browser tools — cron builder, chmod calculator, exit code lookup — work the same way: open in a browser, get the answer, no account required.
Every snippet is ShellCheck-clean and explains the failure cases, not just the happy path.
Copy a disk space warning bash script using df, thresholds, cron, and email alerts. Monitor Linux servers and prevent full drives.
monitor · cron-ready · df
Full guide →A deleted file on Linux has no undo. This bash backup script timestamps every cp -r run with a date string, so no backup ever overwrites the one before it.
backup · cron-ready · rsync
Full guide →Unmanaged logs fill /var/log until writes fail and services crash. find -mtime deletes .log files older than N days; preview with -print before deleting.
cleanup · find · cron-ready
Full guide →Guessing server state mid-outage costs time. One bash script reports hostname, uptime, CPU load, RAM, disk usage and IP address in a single run, no packages.
monitor · reporting · system
Full guide →Opening files one by one to find a string wastes time. grep -rn searches every file under a directory and prints each match with its filename and line number.
grep · search · text
Full guide →Learning a site is down from a user complaint means the outage already cost you. A bash curl check that alerts on any non-200 status, ready for a 5-minute cron.
monitor · curl · uptime
Full guide →Bash keeps going after a failed command, so a broken cd followed by rm -rf hits the wrong directory. set -euo pipefail stops the script at the first failure.
error-handling · best-practices · set
Full guide →The wrong comparison operator makes a bash if statement fail silently on unexpected input. if/else, elif, integer and string tests, file checks, and quoting.
conditionals · basics · if
Full guide →Backup folders without dates overwrite old runs and sort unpredictably. date +%Y-%m-%d names each folder so ls sorts them chronologically, no packages needed.
files · date · mkdir
Full guide →The latest additions and the pages readers use most.
No install required. Open in your browser, get the answer.
The cron builder generates expressions visually and shows the human-readable schedule. The chmod calculator outputs octal, symbolic, and the exact chmod command. The exit code lookup explains what any exit code 0–255 means and which command typically produces it. All 13 tools run entirely in your browser — no server round-trips, no data collected.
$PATH Debugger
Paste your $PATH to surface duplicate entries, dead directories, and ordering problems that cause command-not-found errors.
Exit Code Lookup
Look up any exit code 0–255 and get a plain-English explanation.
Cron Builder
Build cron expressions visually with human-readable output.
Cron Wrapper Generator
Wrap a cron command with flock, timeout, and exponential-backoff retry so overlapping runs and hung jobs stop silently breaking your cron slot.
Boilerplate Generator
Generate a production-ready script header with set -euo pipefail, cleanup traps, and argument parsing before writing a single line of logic.
Chmod Builder
Permission matrix that outputs octal, symbolic, and chmod commands.
grep Builder
Build the exact grep command you need — recursive, case-insensitive, with context lines — and get a plain-English explanation for every flag.
ShellCheck Decoder
Enter any SC code to get the rule name, why it causes production failures, and a before/after fix example.
ShellCheck deep dives: SC2086 · SC2046 · SC2063 · SC2115 · SC2154 · SC2034 · SC2016
When a copy-paste script isn't enough — deep dives into the failure modes behind cron jobs, CI/CD pipelines, text processing, and server maintenance.
25 Bash Scripts Every Linux Sysadmin Needs
Disk-full outages, silent SSL expiry, dead services, permission holes — the scripts that prevent each failure, organized by failure mode.
guideBash Scripts That Survive Cron: Locking, Timeouts, and Retries
Overlapping runs, hung jobs, and silent 2am failures — the flock, timeout, and retry patterns that stop them.
guideBash Text Processing: find, grep, sed, and awk
The four commands that answer "what broke and where" — patterns for logs and config files you can paste into a shell.
guideBash Scripting for CI/CD Pipelines
GitHub Actions steps, deploy scripts, and Docker entrypoints that fail loudly in CI instead of silently in production.
guideThe Safe Bash Script Template: What set -euo pipefail Actually Changes
Strict mode is three flags, not one incantation — where errexit is silently switched off, why the ERR trap needs set -E, and the assembled template.
guideDiagnosing a Hung Process: The Commands to Run Before You Kill It
S answers signals, D cannot be killed at all — read wchan and the syscall without root, check the socket queues, and capture the evidence before kill -9 destroys it.
guideList Open Ports on Linux
What is listening, who owns it, and is it reachable — ss filters, the -e trick that names the owner without root, /proc/net/tcp by hand, docker-proxy, and a CSV audit that alerts on new listeners.
guideAuto-Restart a Stopped Service on Linux
Crashed, stopped on purpose, or running but not answering — three kinds of "down", and the systemd Restart=, reset-failed, and probe-based watchdog that handles each without a restart loop.
guideBash Error Messages, Decoded
Nine errors, each reproduced: what the shell was doing, the one check that names the cause, and the fix. command not found to Connection refused.
guidesystemd Timers vs Cron
The run cron skipped because the laptop was off, the tick a slow job queues instead of overlapping, and the OnFailure= alert — measured side by side on one machine.
guideShell Scripts That Talk to APIs
curl that fails when the API fails, jq instead of regex, and a Slack alert when it breaks — the pattern for calling HTTP from bash without silent poison downstream.
What is a bash script?
A text file of terminal commands that runs automatically in sequence. Saved with a .sh extension, starting with #!/bin/bash.
How do I run a bash script?
Make it executable: chmod +x script.sh — then run: ./script.sh. Or skip chmod and type: bash script.sh
How do I schedule a bash script?
Use cron. Run crontab -e and add a line like: 0 2 * * * /path/to/script.sh to run daily at 2am.
How do I stop my script on errors?
Add set -euo pipefail near the top. This exits on error, catches undefined variables, and handles pipe failures.
An operational script system + a 30-function shared library + a 52-page field guide. The production layer the free snippets don't cover.
Get the Toolkit →