Premium
BASH Snippets.

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

BASH

Batch Rename Files by Pattern

Learn how to batch rename multiple files in a directory using a specified pattern or string replacement with a simple Bash script.

View Snippet →
BASH

Find and Replace Text Across Multiple Files

Efficiently find and replace specific text strings within multiple files in a directory or project using a combination of `find` and `sed`.

View Snippet →
BASH

Check and Install Missing CLI Tools

Create a robust Bash script to check for the presence of command-line tools and conditionally install them if they are not found, enhancing environment setup.

View Snippet →
BASH

Robust Script Cleanup with Trap

Ensure proper cleanup of temporary files or resources by using the `trap` command in Bash to execute specific actions on script exit, error, or interruption.

View Snippet →
BASH

HTTP Requests and JSON Parsing

Learn how to make basic HTTP GET requests using `curl` and parse the JSON response effectively with `jq` in your Bash scripts for API interactions.

View Snippet →
BASH

Automating File and Directory Backups

Create a simple Bash script to automate daily backups of specified files or directories, compressing them and adding a timestamp for easy recovery.

View Snippet →
BASH

Monitoring and Restarting a Process Automatically

Implement a Bash script to continuously monitor a specific process (e.g., a web server or background worker) and automatically restart it if it's found to be down.

View Snippet →
BASH

Parsing Script Arguments with Getopts

Learn how to parse command-line options and arguments in Bash scripts using `getopts`, enabling flexible and user-friendly script execution with various parameters.

View Snippet →
BASH

Automating Remote File Deployment with SCP

Deploy files and directories to a remote web server securely using `scp` within a Bash script, streamlining your deployment workflow for web applications.

View Snippet →
BASH

Implementing Basic Log File Rotation

Manage growing log files by implementing a simple Bash script for rotation, compression, and deletion of old logs, preventing disk space exhaustion on servers.

View Snippet →
BASH

Securely Deploy Static Website via Rsync with Configuration

Automate the deployment of a static website to a remote server using rsync, including secure SSH key authentication and configurable paths for web developers.

View Snippet →
BASH

Check and Wait for a TCP Port to Become Available

Create a robust Bash script to repeatedly check if a specific TCP port on a host is open, useful for ensuring service dependencies are ready in CI/CD pipelines.

View Snippet →