Premium
BASH Snippets.

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

BASH

Efficiently Deploy Web Project Files with Rsync

Learn to use rsync in a bash script for efficient, incremental file synchronization and deployment of web project files to a remote server over SSH, saving time and bandwidth.

View Snippet →
BASH

Monitor and Auto-Restart a Critical Web Service

Implement a bash script to periodically check if a critical web service (e.g., a Node.js app, Gunicorn) is running and automatically restart it if it's found to be down.

View Snippet →
BASH

Extract Specific Configuration Values from Files

A bash script to parse and extract specific key-value pairs from configuration files like .env or INI files, useful for scripting deployment or environment setup.

View Snippet →
BASH

Batch Git Pull Across Multiple Local Repositories

A convenient bash script to automate `git pull` across several local Git repositories, simplifying updates for multi-project development environments or local server setups.

View Snippet →
BASH

Automate Git Pull Across Multiple Repositories

Learn how to write a bash script to iterate through a directory of Git repositories and perform a 'git pull' on each, keeping all local branches up-to-date efficiently.

View Snippet →
BASH

Implement Robust Error Handling and Logging in Bash

Create more reliable bash scripts by incorporating comprehensive error handling with `set -e`, `trap`, and functions for structured logging to stdout and a log file.

View Snippet →
BASH

Find and Delete Old Files Recursively

Learn to use the `find` command with various options to locate and safely remove files older than a specified number of days from a directory and its subdirectories.

View Snippet →
BASH

Monitor Disk Usage and Send Email Alerts

Set up a bash script to monitor disk space on critical partitions, sending an email alert when usage exceeds a defined threshold, ensuring proactive system maintenance.

View Snippet →
BASH

Configure Essential HTTP Security Headers

Enhance web application security by configuring critical HTTP headers like Content-Security-Policy (CSP), HSTS, and X-Frame-Options to mitigate common attacks.

View Snippet →
BASH

Automating Timestamped Directory Backups

Learn how to create an automated bash script to back up a specified directory with a unique timestamp, ideal for web project deployments or configuration management.

View Snippet →
BASH

Checking if a Network Port is Open and Listening

Discover a concise bash snippet to verify if a specific TCP port is active and listening on your server, useful for debugging network services or pre-deployment checks.

View Snippet →
BASH

Recursively Find and Replace Text in Files

Implement a powerful bash command to recursively search and replace text strings across multiple files within a directory, perfect for batch code updates or configuration changes.

View Snippet →