Premium
BASH Snippets.

Curated list of production-ready BASH scripts and coding solutions.

BASH

Parse Command-Line Arguments with Getopts for Flexible Bash Scripts

Learn to parse short command-line options and their arguments in Bash using `getopts`, enabling more powerful and user-friendly script interactions for developers.

View Snippet →
BASH

Graceful Service Restart with PID File and Health Check

Implement a robust Bash script to gracefully stop, start, and restart a service using a PID file, including a basic HTTP health check for reliability in deployments.

View Snippet →
BASH

Efficiently Find Large Files in a Directory and Subdirectories

Locate and list the largest files within a specified directory, including subdirectories, sorted by size, useful for disk space management and web asset optimization.

View Snippet →
BASH

Load Environment Variables from .env File

A Bash script to source and export variables from a .env file, making environment-specific configurations accessible in your shell or for specific commands.

View Snippet →
BASH

Check Website Uptime and HTTP Status

A robust Bash script to perform a health check on a given URL, reporting its HTTP status code and response time, essential for monitoring web services.

View Snippet →
BASH

Batch Rename Files with a Specific Pattern

Automate the renaming of multiple files in a directory using Bash. This script allows you to add prefixes, suffixes, or replace substrings in filenames.

View Snippet →
BASH

Extract Unique IPs and Request Counts from Access Logs

Analyze web server access logs using Bash to identify unique visitor IP addresses, count their requests, and gain insights into traffic patterns and potential security issues.

View Snippet →
BASH

Manage a Local Node.js Development Server

A Bash script to easily start and stop a Node.js development server (e.g., Express, React app) using its process ID, streamlining local development workflows.

View Snippet →
BASH

Automate Git Pull for Multiple Repositories

Streamline your development workflow by automating 'git pull' across all your Git repositories within a specified directory to keep them up-to-date.

View Snippet →
BASH

Simple Website and Database Backup Script

Create a robust bash script for scheduled backups of your website files and MySQL or PostgreSQL databases, ensuring data safety and quick recovery.

View Snippet →
BASH

Parse and Extract Data from JSON API Responses with curl and jq

Leverage `curl` to fetch JSON data from a web API and use `jq` to efficiently parse and extract specific fields for command-line scripting and automation.

View Snippet →
BASH

Monitor Disk Space and Send Email Alerts

Implement a critical server monitoring script that checks disk space usage and dispatches email alerts to administrators when thresholds are surpassed.

View Snippet →