Premium
BASH Snippets.

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

BASH

Gracefully Restart a Web Service and Check Status

A robust bash script to gracefully restart common web services (e.g., Nginx, Apache, PHP-FPM) and verify their running status, minimizing downtime during deployments or configuration changes.

View Snippet →
BASH

Automate Git Pull and Web Project Update

A bash script to automate pulling latest Git changes, installing Node.js dependencies, and building a web project for efficient updates and deployments.

View Snippet →
BASH

Backup a Directory with Timestamp and Cleanup Old Backups

Create timestamped tar.gz backups of a directory and automatically delete backups older than a configurable number of days, saving disk space.

View Snippet →
BASH

Managing Temporary Files and Directories

Securely create and manage temporary files or directories in Bash scripts, ensuring proper cleanup on exit for clean and robust automation.

View Snippet →
BASH

Robust File Existence and Permission Checks

Implement robust file existence and permission checks in Bash scripts using conditional expressions to ensure script reliability and prevent errors.

View Snippet →
BASH

Processing Text Data with awk for Columnar Output

Process and reformat text or log files column-wise using 'awk' in Bash, extracting specific fields and manipulating data efficiently for reports or parsing.

View Snippet →
BASH

Downloading Files Conditionally with curl (If-Modified-Since)

Download files from a URL in Bash using 'curl', conditionally updating only if the remote file is newer, optimizing bandwidth and speeding up deployments.

View Snippet →
BASH

Automated Directory Backup with Timestamp and Compression

Learn to create a robust bash script for automated directory backups, compressing them into a timestamped tarball for easy recovery and versioning on web servers.

View Snippet →
BASH

Efficient Static Site Deployment with rsync

Master efficient website deployments using rsync for static sites or build artifacts. This bash script ensures only changed files are transferred, saving bandwidth and time.

View Snippet →
BASH

Search and Replace Text Recursively Across Files

Perform powerful global search and replace operations in your codebase using a bash script. Recursively update text patterns across multiple files with sed, ideal for refactoring.

View Snippet →
BASH

Simple Log File Monitor for Keywords with Notification

Set up a bash script to continuously monitor log files for critical keywords like 'error' or 'failed'. Get instant console notifications when a match is found, improving debugging workflows.

View Snippet →
BASH

Manage Multiple Git Repositories (Pull All)

Keep all your local Git repositories up-to-date with a single bash command. This script recursively finds and pulls changes from all repos within a directory, streamlining development workflows.

View Snippet →