Premium
BASH Snippets.

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

BASH

Extract Data from JSON Files using jq

A bash script demonstrating how to parse and extract specific data from JSON files or API responses using the powerful `jq` command-line JSON processor.

View Snippet →
BASH

Delete Old Files and Directories by Age

Automatically clean up stale log files, temporary build artifacts, or cached data by deleting files and empty directories older than a specified number of days to free up space.

View Snippet →
BASH

Monitor and Restart a Background Process

Ensure critical background services (like Node.js apps or queue workers) stay running by checking their status and automatically restarting them if they're down.

View Snippet →
BASH

Automate Frontend Build and Sync

Streamline your web development workflow by automating the 'npm install' and 'npm run build' steps for frontend projects, then synchronizing the build output to a target directory.

View Snippet →
BASH

Recursive Text Find and Replace

Efficiently update text strings across multiple files and directories in your project. Ideal for refactoring variable names, updating URLs, or changing configuration values recursively.

View Snippet →
BASH

Load Environment Variables from .env Files

Discover how to securely load environment-specific variables from .env files into your bash scripts, preventing sensitive data from hardcoding.

View Snippet →
BASH

Automate Git Clone and Initial Setup

Streamline your development workflow by automating the cloning of a Git repository and performing initial setup tasks like dependency installation.

View Snippet →
BASH

Check for Required Commands and Install If Missing

Ensure your bash scripts have all necessary tools by checking for required commands and guiding users to install missing packages.

View Snippet →
BASH

Parse and Query JSON Data with jq

Efficiently parse, filter, and transform JSON data from API responses or files directly within your bash scripts using the powerful jq tool.

View Snippet →
BASH

Monitor Disk Space Usage and Alert

Monitor server disk space, identifying partitions nearing capacity and sending an alert if usage exceeds a predefined threshold, crucial for web server health.

View Snippet →
BASH

Graceful Reload of Web Server (Nginx/Apache)

Gracefully reload Nginx or Apache configuration without dropping active connections, essential for applying changes to web servers in production environments.

View Snippet →
BASH

Daily Web Server Log Archiving

Automate daily archiving and compression of web server access and error logs, reducing disk space usage and organizing logs for easier historical analysis.

View Snippet →