Premium
BASH Snippets.

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

BASH

Parse Command-Line Arguments with `getopts`

Discover how to effectively parse command-line arguments using Bash's built-in `getopts` for creating flexible and user-friendly shell scripts with options.

View Snippet →
BASH

Check Website Availability and HTTP Status

Monitor your web services by checking website availability and HTTP status codes using a simple Bash script with `curl` to ensure uptime and health.

View Snippet →
BASH

Find and Replace Text Recursively in Files

Perform a powerful recursive find and replace operation across multiple files in a directory using Bash with `find` and `sed` for quick code refactoring.

View Snippet →
BASH

Create Timestamped Backups of Files and Directories

Learn to create reliable timestamped backups of your important files and directories using Bash with `tar` and `gzip` for easy recovery.

View Snippet →
BASH

Automate Git Clone and Node.js Dependency Installation

Streamline web project setup. This bash script automates cloning a Git repository and installing Node.js dependencies with npm or yarn, simplifying initial project setup for developers.

View Snippet →
BASH

Generate Random Alphanumeric String for Passwords or Keys

Create secure, random alphanumeric strings with a specified length using '/dev/urandom' and 'tr'. Ideal for temporary passwords, API keys, or unique identifiers in scripts.

View Snippet →
BASH

Monitor and Restart a Systemd Service

Ensure critical web services remain active. This bash script checks if a specified systemd service is running and restarts it if it's found to be inactive or in a failed state.

View Snippet →
BASH

Basic Log File Archiving

Perform simple rotation for application log files. This script archives old log files by compressing and renaming them with a timestamp, then truncates the original log file for fresh logging.

View Snippet →
BASH

Find and Delete Old Files in a Directory

Reclaim valuable disk space by automatically locating and removing files older than a specified number of days in a target directory. Useful for cleaning up temporary files or old backups.

View Snippet →
BASH

Robust Bash Script Error Handling and Cleanup

Enhance Bash script reliability using 'set -e' for immediate exits on error and 'trap' for guaranteed resource cleanup, critical for stable deployment or build processes.

View Snippet →
BASH

Parsing Command-Line Arguments with Getopts

Learn to parse command-line options and arguments efficiently in Bash scripts using 'getopts', enabling flexible configuration for your automated tasks.

View Snippet →
BASH

Robust File Download with Curl and Retries

Master downloading files in Bash using 'curl', featuring progress, error handling, retries, and timeouts for resilient asset fetching in web development workflows.

View Snippet →