Premium
BASH Snippets.

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

BASH

Archive and Clean Old Log Files

Maintain server health and free up disk space by automatically archiving and removing old log files, ensuring efficient log management.

View Snippet →
BASH

Find and Replace Text in Multiple Files

Perform quick and powerful text replacements across numerous files in your project using a single Bash command, ideal for refactoring or bulk updates.

View Snippet →
BASH

Configure Essential Security HTTP Headers in Nginx

Enhance your web application's security by configuring critical HTTP headers like HSTS, X-Frame-Options, X-Content-Type-Options, and CSP directly in your Nginx server block.

View Snippet →
BASH

Automating Git Pull and Build on a Server

A bash script to automate pulling the latest code from a Git repository, installing dependencies, and building a web project on a remote server for deployments.

View Snippet →
BASH

Archive and Rotate Web Server Log Files

A bash script to archive web server log files with a timestamp, compress them, and optionally remove old archives to manage disk space on the server.

View Snippet →
BASH

Parse JSON Output with JQ

A bash script demonstrating how to parse and extract specific values from a JSON string or file using the powerful command-line JSON processor, 'jq'.

View Snippet →
BASH

Simple Timestamped File and Directory Backup

A bash script to create timestamped backups of individual files or entire directories, compressing them into `.tar.gz` archives for safe storage.

View Snippet →
BASH

Find and Kill Process by Port

Quickly identify and terminate any process listening on a specific TCP port using `lsof` and `kill`, resolving common port conflicts during development.

View Snippet →
BASH

Generate Basic Project Structure

Automate the creation of a common web project directory structure with subdirectories for `src`, `public`, `assets`, `dist`, and configuration files.

View Snippet →
BASH

Automate Git Commit and Push

Simplify common Git workflows by automatically adding all changes, committing with a predefined message or a provided one, and pushing to the current branch.

View Snippet →
BASH

Start Local Web Server & Open Browser

Launch a basic HTTP server using Python's `http.server` or PHP's built-in server on a specified port, then automatically open the default web browser to that address.

View Snippet →
BASH

Monitor and Auto-Restart a System Service

Ensure your critical web services stay online with this bash script that periodically checks a service's status and automatically restarts it if it's found to be inactive.

View Snippet →