Premium
BASH Snippets.

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

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 →
BASH

Parse CSV File Line by Line

Process CSV data efficiently in bash. This script reads a CSV file line by line, splitting each record by a delimiter, and allows for custom processing of individual fields.

View Snippet →
BASH

Monitor and Restart a Linux Service

Keep your services running reliably. This bash script checks the status of a specified systemd service and restarts it if it's found to be inactive or failed, ensuring uptime and stability.

View Snippet →
BASH

Configure X-Content-Type-Options: nosniff Header to Prevent MIME-Sniffing Attacks

Enhance web security by configuring the `X-Content-Type-Options: nosniff` header in Nginx or Apache, preventing browsers from misinterpreting content types and mitigating XSS risks.

View Snippet →
BASH

Batch Find and Replace Text in Multiple Files

Learn how to efficiently find and replace specific text strings across multiple files within a directory using a simple Bash script, perfect for configuration updates or quick code refactoring.

View Snippet →
BASH

Verify and Install Essential Command-Line Tools

Automate the verification and installation of critical command-line tools required for your development environment, ensuring all dependencies are met for your projects and setups.

View Snippet →
BASH

Batch Git Pull Across Multiple Repositories

Streamline your workflow by automating the process of pulling the latest changes from multiple Git repositories within a specified root directory, ideal for monorepos or related projects.

View Snippet →
BASH

Make HTTP Requests with Error Handling using Curl

Learn to perform robust HTTP GET requests using `curl` in Bash, including checking HTTP status codes for success or failure and handling network issues, useful for API health checks and simple integrations.

View Snippet →
BASH

Automate System Package Updates

A robust Bash script to efficiently update and upgrade system packages on Debian/Ubuntu and RHEL/CentOS distributions, ensuring your servers are up-to-date and secure.

View Snippet →