10 Bash Scripts Every Dev Should Have in Their Toolbox

posted 2 min read

Whether you're managing servers, automating tasks, or just trying to save time, Bash scripts are powerful allies. Here are 10 essential Bash scripts that every developer should keep handy to boost productivity and simplify daily tasks.


1. Auto Backup Script

Automatically back up important directories or databases to a remote server or local storage.

!/bin/bash
tar -czf /backup/$(date +%F)-project.tar.gz /var/www/project

2. Server Health Check Script

Monitor CPU, memory, and disk usage and get notified if thresholds are exceeded.

!/bin/bash
TOP_CPU=$(top -bn1 | grep "Cpu" | awk '{print $2}')
FREE_MEM=$(free -m | awk '/Mem:/ { print $4 }')
df -h > /tmp/disk_usage.txt

3. Git Auto Commit and Push Script

Save and sync your work with one command.

!/bin/bash
git add .
git commit -m "$1"
git push origin main

4. MySQL Database Dump Script

Create a dump of your MySQL database for backups or migrations.

!/bin/bash
mysqldump -u root -pYourPassword database_name > backup.sql

5. Project Bootstrapper

Spin up a new project directory with folders and initial files.

!/bin/bash
mkdir $1 && cd $1
mkdir src tests docs
code .

6. Service Monitor Script

Check if a service like NGINX or MySQL is running and restart it if it's not.

!/bin/bash
SERVICE=$1
if ! pgrep -x "$SERVICE" > /dev/null
then
    systemctl restart $SERVICE
fi

7. SSH Key Setup Script

Quickly generate and copy SSH keys to a remote server.

!/bin/bash
ssh-keygen -t rsa -b 4096 -C "$1"
ssh-copy-id user@$2

8. Log Rotation Script

Archive and compress old logs to keep storage in check.

!/bin/bash
find /var/log -name "*.log" -mtime +7 -exec gzip {} \;

9. Code Cleaner Script

Remove unnecessary files like .DS_Store, Thumbs.db, or compiled Python files.

!/bin/bash
find . -type f \( -name '*.pyc' -o -name '*.DS_Store' -o -name 'Thumbs.db' \) -delete

10. URL Status Checker

Check if a website or API is online.

!/bin/bash
URL=$1
STATUS=$(curl -o /dev/null -s -w "%{http_code}\n" $URL)
echo "Status for $URL: $STATUS"

Final Thoughts

These Bash scripts are just the tip of the iceberg. They can save time, improve consistency, and automate tedious tasks. Save them, modify them to fit your workflow, and add them to your developer toolbox today!

If you read this far, tweet to the author to show them you care. Tweet a Thanks

Great list of Bash scripts! These will definitely make daily tasks more efficient. The Git Auto Commit and Push Script caught my eye – it’s such a time-saver. I’m curious, though, how do you manage handling sensitive data (like passwords) in these scripts, especially when automating backups or database dumps? Would love to hear any tips you have!

Thank you! We're glad you found the list helpful—especially the Git Auto Commit and Push Script! It really does save a ton of time during active development.

Great question about handling sensitive data! When automating tasks like backups or database dumps, here are a few best practices we recommend:

  1. Use .env Files: Store credentials in a separate .env file and source it in your script. This keeps your sensitive data out of the main script.
  2. Set Proper Permissions: Always set restrictive permissions (chmod 600) on scripts or config files that contain sensitive data.
  3. Use SSH Keys Instead of Passwords: When possible, authenticate with SSH keys for remote backups instead of plain-text passwords.
  4. Avoid Hardcoding: Never hardcode passwords or secrets directly into the script.
  5. Environment Variables: For scheduled cron jobs, use environment variables in the crontab or source a secure file with credentials before executing.

We'll consider doing a follow-up article diving deeper into this topic—thanks for the inspiration!

This is a solid and practical list—thanks for sharing!
Each script serves a real-world use case and can seriously boost productivity, especially for developers managing servers or automating repetitive tasks.

That said, I’d recommend a few quick enhancements for clarity and impact:

Use proper code formatting (#!/bin/bash with triple backticks) so readers can easily copy and run the scripts.

A bit more markdown structure (like headings for each script) would make it easier to skim.

Would love to see a short explanation above each script on why or when to use it—adds more context.

And a slightly more robust conclusion could help tie everything together.

Still, it’s a great starting toolkit for devs—simple, powerful, and super handy.

More Posts

Top 10 Features Every CRM System Should Have

Muzzamil Abbas - May 28, 2024

Tired of writing HTML for vanilla JavaScript projects? Meet DOMSculpt.

Temi_lolu - Mar 18

6 Amazing Websites For Developers That You Don’t Know Till Yet.

paruidev - Jan 26

Webpack vs. Vite: Should Developers Still Manually Set Up Webpack in 2025?

eze ernest - Feb 25

How Devs Can Build, Launch & Earn from Their Own Software Products

Ijeoma JahsWay - Apr 24
chevron_left