← Back

Automate Tasks Using Bash Scripts

·2 min read·Learn Termux

Learn how to automate tasks in Termux using simple Bash scripts for backups, commands, and daily workflows.

Automate Tasks Using Bash Scripts

What Is a Bash Script?

A Bash script is a file that contains Linux commands that run automatically.

Instead of typing the same commands repeatedly, you can save them inside a script and execute everything with one command.

Bash scripts are useful for:

- Automating tasks - Running backups - Cleaning files - Starting tools - Saving time

---

Create Your First Script

Create a new file:

bash
nano hello.sh

Add this:

bash
#!/bin/bash

echo "Hello from Termux"

Save the file.

---

Make the Script Executable

Run:

bash
chmod +x hello.sh

This gives execution permission.

---

Run the Script

Execute the script:

bash
./hello.sh

Output:

text
Hello from Termux

---

Example: Update Termux Automatically

Create a script:

bash
nano update.sh

Add:

bash
#!/bin/bash

pkg update -y && pkg upgrade -y echo "System Updated"

Save and make it executable:

bash
chmod +x update.sh

Run it:

bash
./update.sh

---

Example: Backup a Folder

Create a backup script:

bash
nano backup.sh

Add:

bash
#!/bin/bash

cp -r /storage/emulated/0/Documents /storage/emulated/0/Backup echo "Backup Completed"

Run:

bash
chmod +x backup.sh
./backup.sh

---

Useful Bash Commands

Print text:

bash
echo "Hello"

Pause script:

bash
sleep 5

Create folder:

bash
mkdir test

Delete file:

bash
rm file.txt

---

Run Scripts From Anywhere

Move scripts to:

bash
~/bin

Example:

bash
mkdir -p ~/bin
mv hello.sh ~/bin

Now you can run:

bash
hello.sh

from anywhere.

---

Common Error

Permission Denied

Fix it with:

bash
chmod +x script.sh

---

Final Thoughts

Bash scripting is one of the best ways to automate tasks in Termux.

Start with small scripts, then slowly build more advanced automation workflows as you learn Linux commands.

Dexter

Dexter

Sharing practical Termux guides, Linux tips, and Android hacking tutorials for beginners and advanced users.

Newsletter

Stay in the loop

Get new posts delivered straight to your inbox. No spam, unsubscribe anytime.