# Shell Scripting Basics: Automating Daily Tasks in Linux

One of the most powerful features of Linux is its ability to **automate repetitive tasks** using shell scripts. As a cloud engineer, DevOps professional, or system administrator, shell scripting is a must-have skill.

In this article, we’ll explore what shell scripting is, why it’s important, and how you can start writing simple scripts to automate your daily Linux tasks.

---

## 🐚 What is Shell Scripting?

The **shell** is the command-line interface that allows you to interact with the Linux operating system. Popular shells include **Bash (Bourne Again Shell)**, Zsh, and Fish.

A **shell script** is simply a text file containing a series of commands that you would normally type manually in the terminal. By running the script, Linux executes all the commands automatically.

---

## ⚡ Why Learn Shell Scripting?

Here’s why shell scripting is valuable:

* **Automation** → Save time by automating tasks like backups, updates, or file management.
    
* **Consistency** → Perform tasks the same way every time without manual errors.
    
* **Productivity** → Run multiple commands with just one script.
    
* **Integration** → Works seamlessly with cron jobs, cloud automation, and DevOps pipelines.
    

---

## 📝 Writing Your First Shell Script

Let’s start with a simple script.

1. Open a text editor and create a file:
    

```bash
nano hello.sh
```

2. Add the following code:
    

```bash
#!/bin/bash
# This is a simple shell script

echo "Hello, Linux World!"
```

3. Save the file and make it executable:
    

```bash
chmod +x hello.sh
```

4. Run your script:
    

```bash
./hello.sh
```

Output:

```plaintext
Hello, Linux World!
```

Congratulations 🎉 You just wrote your first shell script!

---

## 🔄 Examples of Automating Daily Tasks

Here are some practical shell script examples:

### 1\. **System Update Script**

```bash
#!/bin/bash
# Update and upgrade system packages

sudo apt update && sudo apt upgrade -y
echo "System updated successfully!"
```

---

### 2\. **Backup Script**

```bash
#!/bin/bash
# Backup home directory to /backup folder

tar -czf /backup/home_backup_$(date +%F).tar.gz /home/yourusername
echo "Backup completed on $(date)"
```

---

### 3\. **Disk Usage Alert Script**

```bash
#!/bin/bash
# Check if disk usage is above 80%

USAGE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//')

if [ $USAGE -gt 80 ]; then
  echo "Warning: Disk usage is above 80%! Current usage: $USAGE%"
fi
```

---

## ⏰ Automating with Cron Jobs

To run your scripts automatically at specific times, you can use **cron jobs**.

Example: Run a backup script every day at midnight.

```bash
crontab -e
```

Add this line:

```plaintext
0 0 * * * /home/yourusername/backup.sh
```

---

## Final Thoughts

Shell scripting is the **foundation of automation in Linux**. By learning it, you’ll save time, reduce errors, and boost your productivity.

👉 Start with simple scripts, practice regularly, and soon you’ll be automating complex workflows in servers and cloud environments.

---
