Premium
BASH Snippets.

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

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

Automate Git Pull, Dependency Install, and Service Restart for Web Deployments

A Bash script to automate web application deployments. It pulls the latest code, installs dependencies, and restarts your service efficiently.

View Snippet →
BASH

Parse and Query JSON Data from the Command Line with jq

Master 'jq' for command-line JSON processing. Extract values, filter arrays, and format API responses or config files directly in your terminal.

View Snippet →
BASH

Securely Execute Commands on Remote Servers via SSH

Learn to securely run commands on remote servers using SSH. Execute single commands, multi-line scripts, and pass arguments for server management.

View Snippet →
BASH

Implement a Basic Web Service Health Check Script

Create a simple Bash script to check the availability and HTTP status code of a web service or API endpoint using `curl`, crucial for monitoring.

View Snippet →
BASH

Run Bash Commands in the Background Reliably with nohup

Use `nohup` and `&` to run long-running commands or services in the background, ensuring they continue even after logging out.

View Snippet →
BASH

Find and Replace String in Multiple Files

Safely find and replace a specific string across multiple files within a directory, with an optional backup, using `find` and `sed` commands for web project refactoring.

View Snippet →
BASH

Graceful Web Service Restart with Config Check

Safely restart or reload common web services like Nginx, Apache, or PHP-FPM after configuration changes, including a syntax check before reloading to prevent downtime.

View Snippet →