Premium
BASH Snippets.

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

BASH

Identifying and Terminating Processes Using a Specific Port

Quickly resolve 'address already in use' errors by finding which process occupies a given TCP port and how to gracefully or forcefully terminate it using `lsof` and `kill`.

View Snippet →
BASH

Batch Renaming Files with Prefixes or Suffixes

Efficiently rename multiple files in a directory by adding custom prefixes or suffixes, useful for organizing assets, images, or managing build outputs.

View Snippet →
BASH

Automating Static Site Deployment to AWS S3

Deploy your static web projects to Amazon S3 buckets efficiently using the AWS CLI within a bash script, including synchronization, cache control, and public-read access.

View Snippet →
BASH

Automating Log Rotation and Compression

A bash script to automate log file rotation, compression, and cleanup of old archives, essential for maintaining server disk space and managing historical data.

View Snippet →
BASH

Checking Website and API Health Status

A bash script to monitor the HTTP status of multiple web services or API endpoints, providing quick feedback on their availability and response codes.

View Snippet →
BASH

Finding and Deleting Old Files by Age

A simple yet powerful bash script to locate and safely remove files or directories older than a specified duration, ideal for cleaning up temporary files or old caches.

View Snippet →
BASH

Timestamped Directory Backup with Rsync

A robust bash script for creating efficient, timestamped backups of important directories using rsync, ensuring data integrity and versioning.

View Snippet →
BASH

Extracting and Exporting Environment Variables from .env

A bash script to parse a .env file, ignoring comments and empty lines, and export key-value pairs as environment variables for use in shell sessions or scripts.

View Snippet →
BASH

Configure Essential Security Headers in Nginx

Enhance web application security by configuring critical HTTP security headers like X-Content-Type-Options and Referrer-Policy directly within your Nginx server block.

View Snippet →
BASH

Automate Git Pull & Status for Multiple Repos

Streamline your workflow by automating `git pull` and checking the status across multiple Git repositories in different directories with a single Bash script.

View Snippet →
BASH

Sync Files for Deployment with `rsync`

Efficiently synchronize local development files to a remote server for deployment or backup, excluding sensitive files, using `rsync` in a Bash script.

View Snippet →
BASH

Extract Log Data with `grep` and `awk`

Efficiently filter and extract specific data from large log files (e.g., web server access logs) using a combination of `grep` for pattern matching and `awk` for column-based extraction.

View Snippet →