Premium
BASH Snippets.

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

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 →
BASH

Git: Create and Push New Feature Branch from Development

A Bash script to automate the common Git workflow of creating a new feature branch from the 'development' branch, switching to it, and pushing it to the remote repository.

View Snippet →
BASH

Clear Common Web Project Cache Directories

A Bash script to quickly clear common cache and temporary directories for various web development projects (e.g., Laravel, Node.js builds) to resolve stale data issues.

View Snippet →
BASH

Check Website Uptime and Send Alert

A Bash script to continuously monitor a website's availability, checking its HTTP status code, and sending an email alert if it's detected as down.

View Snippet →
BASH

Automated MySQL/PostgreSQL Database Backup

A robust Bash script to automate daily backups of a MySQL or PostgreSQL database, compress the dumps, and manage retention of old backups.

View Snippet →
BASH

Deploy Static Website Files with rsync

A simple Bash script to efficiently deploy local static website files to a remote server using rsync, ensuring only changed files are transferred.

View Snippet →
BASH

Automate Git Pull and Service Restart

A simple bash script to automate pulling the latest code from a Git repository and restarting a web service, ideal for basic deployment workflows.

View Snippet →
BASH

Read and Process File Line by Line

A bash script to efficiently read and process text files line by line, useful for parsing logs, configuration files, or lists of data for web development tasks.

View Snippet →