10 Bash Scripts Every Dev Should Have in Their Toolbox

Leader 42 124 284
calendar_todayschedule2 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.
```bash
!/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.
```bash
!/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.
```bash
!/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.
```bash
!/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.
```bash
!/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.
```bash
!/bin/bash
find . -type f %%MATH_BLOCK_0%% -delete
```

---

## 10. **URL Status Checker**
Check if a website or API is online.
```bash
!/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!

3 Comments

0 votes
0 votes
0 votes
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

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

Karol Modelskiverified - Mar 19

ERC20 Edge Cases Every Smart Contract Engineer Should Know

BinnaDev - Jun 24

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 Every Frontend Project Should Have Its Own UI Layer

aleklabs.dev - May 20
chevron_left
16.8k Points450 Badges
Rivers State, Nigeriagiftbalogun.name.ng
84Posts
365Comments
48Connections
I’m a backend-focused full stack developer with over 6 years of experience building scalable, secure... Show more

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!