Premium
BASH Snippets.

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

BASH

Find and Delete Old Files by Age and Extension

Recursively locate and remove files older than a specified number of days, filtered by file extension, to help manage disk space on web servers.

View Snippet →
BASH

Synchronize Local Files to Remote Server with rsync

Efficiently deploy and synchronize local website files to a remote server using rsync, transferring only changed files and excluding specific patterns for faster updates.

View Snippet →
BASH

Basic Web Service Health Check with cURL

Perform a simple health check on a web service endpoint using cURL, verifying its HTTP status code and response time, useful for monitoring.

View Snippet →
BASH

Automate Git Repository Backup

Create a timestamped, compressed backup of a local Git repository, ideal for safeguarding project history or migrating repositories.

View Snippet →
BASH

Monitor and Auto-Restart Systemd Service

A robust bash script to check the status of a systemd service (e.g., Nginx, Apache) and automatically restart it if it's inactive or failed, ensuring service uptime.

View Snippet →
BASH

Robust Command Line Argument Parsing

Master parsing command-line options and arguments in bash scripts using `getopts` for creating flexible and user-friendly utilities with short flags.

View Snippet →
BASH

Automate Static Website Deployment via SCP

Streamline static website deployment to a remote server using a simple bash script that utilizes SCP for efficient and secure file transfer.

View Snippet →
BASH

Basic Log File Rotation and Archiving

Implement a straightforward bash script to rotate and archive application log files, preventing excessive disk usage and maintaining a clean server environment.

View Snippet →
BASH

Processing JSON Data in Bash with JQ

Master parsing and manipulating JSON data in Bash scripts using the powerful `jq` command-line JSON processor, essential for API interactions and data extraction.

View Snippet →
BASH

File Integrity Check with MD5/SHA256

Ensure file integrity in Bash scripts using MD5 or SHA256 checksums to verify downloads or detect unauthorized modifications, crucial for secure deployments.

View Snippet →
BASH

Loading Environment Variables from a .env File

Securely manage configuration in Bash scripts by loading environment variables from a `.env` file, preventing hardcoding sensitive data and improving portability.

View Snippet →
BASH

Robust File Download with Progress and Retries

Implement robust file downloads in Bash scripts using `curl` with progress indicators, timeout handling, and automatic retries for reliable fetching of external resources.

View Snippet →