Premium
BASH Snippets.

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

BASH

Run Multiple Dev Servers Concurrently

Discover a simple bash script to simultaneously start multiple web development servers (e.g., frontend, backend, mock API) in the background, streamlining your local development workflow.

View Snippet →
BASH

Check for Open Ports and Kill Processes

Learn how to use a bash script to check if a specific port is in use and, if desired, automatically identify and terminate the process occupying that port.

View Snippet →
BASH

Automate Git Branch Cleanup

Streamline your Git workflow with a bash script that automatically deletes merged local branches that are no longer needed, helping to keep your repository tidy.

View Snippet →
BASH

Dynamic API Endpoint Switching

Configure dynamic API endpoints for development, staging, or production environments using a simple bash script that exports environment variables.

View Snippet →
BASH

Automate Daily Backups with Timestamps

Learn to create a bash script for automating daily backups of a directory, incorporating timestamps for unique archives and using tar for compression.

View Snippet →
BASH

Monitor Directory for New Files and Process

Implement a bash script that continuously monitors a specified directory for new files, processes them, and moves them to an archived location.

View Snippet →
BASH

Robust Error Handling and Logging

Enhance your bash scripts with robust error handling and logging capabilities, ensuring critical failures are caught and reported clearly.

View Snippet →
BASH

Find and Delete Old Files for Cleanup

Automate disk space management by creating a bash script to efficiently find and safely delete files older than a specified number of days in a given directory.

View Snippet →
BASH

Enforce HTTPS with HSTS (HTTP Strict Transport Security) in Nginx

Configure Nginx to enforce HTTP Strict Transport Security (HSTS), forcing browsers to communicate with your website exclusively over secure HTTPS connections.

View Snippet →
BASH

Implement a Robust Content Security Policy (CSP) for XSS Defense

Configure a Content Security Policy (CSP) HTTP header to mitigate Cross-Site Scripting (XSS) attacks by controlling which resources your web page is allowed to load.

View Snippet →
BASH

Find and Delete Files Older Than N Days

Automate cleanup of old log files or temporary data. This bash script efficiently finds and removes files modified before a specified number of days, freeing up disk space.

View Snippet →
BASH

Batch Rename Files with a Prefix/Suffix

Easily rename multiple files in a directory by adding a common prefix or suffix. This bash snippet uses a loop and `mv` to apply a consistent naming convention across many files.

View Snippet →