Premium
BASH Snippets.

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

BASH

Automating Nginx/Apache Configuration Reload

Learn to automate web server configuration reloads with a bash script. This snippet safely tests Nginx or Apache configs and reloads services, ideal for deployments.

View Snippet →
BASH

Deploy Static Files with Rsync over SSH

Automate static website deployments with this bash script using `rsync` over SSH. It efficiently transfers and synchronizes files to a remote server.

View Snippet →
BASH

Automate Directory Backup with Timestamp

Learn to create a robust Bash script for automating directory backups, appending a timestamp to each archive for easy versioning and recovery.

View Snippet →
BASH

Check and Restart System Service with Bash

Implement a Bash script to monitor a critical system service like Nginx or MySQL, automatically restarting it if it's not running to maintain uptime.

View Snippet →
BASH

Automate Deletion of Old Files

Learn to write a Bash script that efficiently finds and deletes files older than a specified number of days, perfect for log rotation or temporary file cleanup.

View Snippet →
BASH

Automate File Backup with Timestamp and Compression

Create a robust Bash script to automatically backup specified files or directories, adding a timestamp to the archive name and compressing it using `tar` and `gzip` for storage.

View Snippet →
BASH

Check if Command Exists and Install if Missing

Write a Bash script to verify the presence of a required command (e.g., `jq`, `curl`) and provide instructions or attempt installation using common package managers like `apt`, `yum`, or `brew`.

View Snippet →
BASH

Fetch and Parse JSON from an API with curl and jq

Learn to make HTTP GET requests to a REST API using `curl`, and efficiently parse the resulting JSON data on the command line using the powerful `jq` tool for data extraction.

View Snippet →
BASH

Implement Robust Error Handling with trap and Logging

Learn to make your Bash scripts more resilient by using `trap` to catch errors and signals, implementing a custom error handler, and logging script execution to a file for better debugging.

View Snippet →
BASH

Filter Web Server Access Logs by IP or Status Code

A Bash script to efficiently filter large web server access logs by specific IP addresses or HTTP status codes, useful for debugging and analysis.

View Snippet →
BASH

Load .env File into Current Shell Environment

A simple Bash snippet to parse and load key-value pairs from a .env file into the current shell's environment variables, essential for local development.

View Snippet →
BASH

Start a Simple Local HTTP Server and Open in Browser

A Bash script to quickly start a local HTTP server using Python's http.server and automatically open the served directory in your default web browser.

View Snippet →