Premium
BASH Snippets.

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

BASH

Load Environment Variables from .env File in Bash

Learn how to load environment variables from a .env file into your Bash script for dynamic configuration, commonly used in web development projects.

View Snippet →
BASH

Validate Presence of Essential CLI Tools in Bash

Ensure your Bash scripts have all necessary command-line tools installed (e.g., node, npm, git) before execution, providing robust error handling.

View Snippet →
BASH

Create Timestamped Directory Backup with Tar

Safely backup your web project directories by creating a timestamped gzipped tar archive, ensuring you have a restore point before major changes.

View Snippet →
BASH

Robust HTTP Server Health Check with Retries

Implement a Bash script to health-check a web server's HTTP status with retry attempts, crucial for deployment verification and CI/CD pipelines.

View Snippet →
BASH

Automate NVM Setup and Node Version Switching

Streamline your Node.js development workflow by automating NVM (Node Version Manager) initialization and switching between Node versions in Bash scripts.

View Snippet →
BASH

Automate Web Server Restart with Status Check

Learn to write a robust bash script for restarting Nginx or Apache, including pre-check for configuration syntax and post-check for service status.

View Snippet →
BASH

Deploy Project Files Incrementally with rsync

Efficiently deploy web project files to a remote server using rsync, ensuring only changed files are transferred and excluding sensitive directories.

View Snippet →
BASH

Automate Log File Archiving and Cleanup

Create a bash script to automatically archive and clean up old log files, helping manage disk space and keeping server logs organized.

View Snippet →
BASH

Backup a Directory to a Timestamped Tar Archive

Automate creating local, timestamped `.tar` archives of important directories. Essential for quick backups of web application files, configuration, or user uploads.

View Snippet →
BASH

Monitor Server Disk Usage and Alert

Keep an eye on your server's disk space. This Bash script checks partitions' usage and triggers an alert if any exceed a predefined threshold.

View Snippet →
BASH

Extract Specific Data from JSON Output with jq

Master `jq` to efficiently parse and extract specific data from JSON responses from APIs or command-line tools, making automation simpler.

View Snippet →
BASH

Managing Project-Specific Environment Variables

Load project-specific environment variables from a .env file into your Bash session or scripts, ensuring consistent configurations across different development environments.

View Snippet →