10 Bash Scripts Every Dev Should Have in Their Toolbox

Leader 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!

0 votes
0 votes
0 votes

More Posts

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelskiverified - Mar 19

Everyone says DeepSeek is cheaper, but I got tired of guessing the exact math. So I built a calculat

abarth23 - Apr 27

AI Agents Don't Have Identities. That's Everyone's Problem.

Tom Smithverified - Mar 13

Why Email-Only Contact Forms Are Failing in 2026 (And What Developers Should Do Instead)

JayCode - Mar 2

Top 10 Features Every CRM System Should Have

Muzzamil Abbas - May 28, 2024
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!