Premium
BASH Snippets.

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

BASH

Interactive Bash Menu for Common Developer Tasks

Enhance your development workflow with an interactive Bash menu script, allowing you to select and execute common project tasks like testing or building with ease.

View Snippet →
BASH

Automatically Clean Up Old Log and Temp Files

Learn to create a Bash script that automatically identifies and deletes old log files or temporary files from a specified directory, preventing disk space issues.

View Snippet →
BASH

Extract Unique IP Addresses from Web Server Access Logs

Create a Bash script to efficiently parse web server access logs (Apache/Nginx) and extract all unique IP addresses, useful for security analysis or traffic monitoring.

View Snippet →
BASH

Check if a Port is in Use or a Service is Running

Write a Bash script to verify if a specific TCP port is actively being used by a process or if a given service process is currently running on the system.

View Snippet →
BASH

Batch Rename Multiple Files with a Specific Pattern

Learn to use a Bash script to efficiently rename multiple files in a directory by applying a common prefix, suffix, or replacing parts of their names.

View Snippet →
BASH

Sync Local Directory to Remote Server with rsync

Automate efficient and incremental file synchronization from your local machine to a remote web server using rsync over SSH, perfect for deployments.

View Snippet →
BASH

Filter and Count HTTP Error Codes from Nginx Access Logs

Quickly analyze Nginx access logs to identify and count specific HTTP error codes (e.g., 4xx, 5xx) using `grep`, `awk`, and `sort` for web server monitoring.

View Snippet →
BASH

Automated MySQL Database Backup with Timestamp

Create a robust bash script to automate daily MySQL database backups, compressing them with a timestamp for easy recovery and storage management.

View Snippet →
BASH

Monitor and Restart a Systemd Service if Down

Create a bash script to periodically check the status of a critical systemd service (e.g., Nginx, PHP-FPM) and automatically restart it if it's found to be inactive.

View Snippet →
BASH

Parse Command Line Arguments with getopts for Script Customization

Learn to build robust bash scripts that accept and parse command-line arguments using `getopts`, enabling flexible execution with options and values.

View Snippet →
BASH

Extracting and Analyzing Web Server Logs

Learn to process web server access logs using `grep` and `awk` to extract common errors, unique IP addresses, and request statistics for debugging.

View Snippet →
BASH

Check and Restart a Linux Service by Name

Automate checking if a critical Linux service (e.g., Nginx, a Node.js process) is running and restart it if it's found to be inactive, ensuring application uptime.

View Snippet →