Premium
BASH Snippets.

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

BASH

Batch Rename Files with a Pattern

Efficiently rename multiple files based on a pattern using a Bash script, useful for organizing assets or cleaning up project directories in web development workflows.

View Snippet →
BASH

Gracefully Restart a Web Service

Implement a Bash script to gracefully restart a web service (e.g., Nginx, Apache, or a Node.js process) using systemd, ensuring minimal downtime and proper resource management during deployments.

View Snippet →
BASH

Automate PostgreSQL Database Backups with Retention

Learn to automate PostgreSQL database backups using bash, incorporating timestamps for versioning and implementing a retention policy to manage old backups efficiently.

View Snippet →
BASH

Securely Deploy Website Files with Rsync and SSH

Master using rsync over SSH for efficient and secure deployment of website files, including excluding specific directories and verbose output for debugging.

View Snippet →
BASH

Monitor Server Disk Space and Send Email Alerts

Implement a bash script to monitor server disk space usage, automatically sending an email alert when a predefined threshold is exceeded, preventing potential outages.

View Snippet →
BASH

Parse Command Line Arguments in Bash with getopts

Discover how to robustly parse command-line options and arguments in bash scripts using `getopts`, supporting both short and long options for flexible script execution.

View Snippet →
BASH

Interact with REST APIs using cURL and Parse JSON with jq

Learn to make authenticated GET and POST requests to REST APIs using `curl` and effectively parse the JSON responses with `jq` in your bash scripts for automation.

View Snippet →
BASH

Automate Daily Log Archiving and Cleanup

A Bash script to automatically compress and archive old application logs, then delete files older than a specified duration to manage disk space efficiently.

View Snippet →
BASH

Analyze Nginx Access Logs for Top IP Addresses

A Bash script to parse Nginx or Apache access logs, extract the source IP addresses, and list the top N most frequent IPs.

View Snippet →
BASH

Find and Stop a Process by Port Number

A simple Bash script to identify and terminate any process currently listening on a specified TCP port, resolving port conflicts efficiently.

View Snippet →
BASH

Initial Project Setup with Git Clone and Directory Structure

Quickly set up a new web development project by cloning a Git repository and creating standard subdirectories for assets, config, or logs.

View Snippet →
BASH

Download and Extract a Remote gzipped Tar Archive

Use Bash to download a gzipped tar archive from a given URL and extract its contents into a specified local target directory.

View Snippet →