Skip to content

Latest commit

 

History

History
263 lines (196 loc) · 7.62 KB

File metadata and controls

263 lines (196 loc) · 7.62 KB
██████╗  █████╗ ███████╗██╗  ██╗    ███████╗ ██████╗██████╗ ██╗██████╗ ████████╗██╗███╗   ██╗ ██████╗
██╔══██╗██╔══██╗██╔════╝██║  ██║    ██╔════╝██╔════╝██╔══██╗██║██╔══██╗╚══██╔══╝██║████╗  ██║██╔════╝
██████╔╝███████║███████╗███████║    ███████╗██║     ██████╔╝██║██████╔╝   ██║   ██║██╔██╗ ██║██║  ███╗
██╔══██╗██╔══██║╚════██║██╔══██║    ╚════██║██║     ██╔══██╗██║██╔═══╝    ██║   ██║██║╚██╗██║██║   ██║
██████╔╝██║  ██║███████║██║  ██║    ███████║╚██████╗██║  ██║██║██║        ██║   ██║██║ ╚████║╚██████╔╝
╚═════╝ ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚══════╝ ╚═════╝╚═╝  ╚═╝╚═╝╚═╝        ╚═╝   ╚═╝╚═╝  ╚═══╝ ╚═════╝

automate everything. break nothing.


Shell Linux License PRs Welcome Maintained


🐚 A curated collection of Linux Bash scripts — from beginner fundamentals to real-world automation tools. Built for learners, sysadmins, and developers who love the terminal.


📖 Table of Contents


✨ About

This repository is a hands-on learning ground for Linux Bash Scripting.

Whether you're just starting out with shell scripts or looking to sharpen your automation game, you'll find practical, well-commented scripts covering a wide range of topics — from basic syntax and control flow to file manipulation, process management, and beyond.

$ echo "Why learn Bash?"
> Because the terminal is where the real power lives.

🗂️ Repository Structure

Linux-Bash-Scripting/
│
├── 📁 basics/               # Variables, input/output, comments
├── 📁 control-flow/         # if/else, loops, case statements
├── 📁 functions/            # Reusable functions and libraries
├── 📁 file-operations/      # Read, write, parse, manipulate files
├── 📁 system-admin/         # Disk, memory, process monitoring
├── 📁 networking/           # Ping checks, port scanners, curl scripts
├── 📁 automation/           # Cron jobs, backups, schedulers
├── 📁 text-processing/      # awk, sed, grep, cut, sort
└── 📁 projects/             # End-to-end real-world mini-projects

🚀 Getting Started

Prerequisites

Make sure you have the following:

  • A Linux / macOS system (or WSL on Windows)
  • bash version 4.0+
bash --version

Clone the Repository

git clone https://github.com/Kishan-Miskin/Linux-Bash-Scripting.git
cd Linux-Bash-Scripting

Run Your First Script

chmod +x basics/hello_world.sh
./basics/hello_world.sh

📜 Script Categories

Category Description Difficulty
🟢 Basics Variables, data types, user input, echo/printf Beginner
🟢 Control Flow if/elif/else, for, while, until, case Beginner
🟡 Functions Declaring, calling, scoping, return values Intermediate
🟡 File Operations Reading files, writing logs, parsing CSVs Intermediate
🟡 Text Processing awk, sed, grep, tr, cut, sort, uniq Intermediate
🔴 System Admin CPU/RAM monitoring, disk usage, process management Advanced
🔴 Networking Ping sweeps, port scanning, curl API calls Advanced
🔴 Automation Backup scripts, cron jobs, scheduled tasks Advanced

🛠️ Usage

Making a Script Executable

chmod +x script_name.sh
./script_name.sh

Running with Bash Directly

bash script_name.sh

Passing Arguments

./script.sh arg1 arg2
# Inside script: $1 = arg1, $2 = arg2

Debugging a Script

bash -x script.sh       # Trace execution
bash -n script.sh       # Syntax check only

💡 Tips & Best Practices

# ✅ Always start with a shebang
#!/bin/bash

# ✅ Use quotes around variables
echo "$variable"        # Prevents word splitting

# ✅ Check command success
if ! mkdir /tmp/mydir; then
  echo "Failed to create directory"
fi

# ✅ Use meaningful variable names
user_home="$HOME"

# ✅ Trap errors for cleanup
trap 'echo "Error on line $LINENO"' ERR
✅ Do This ❌ Avoid This
Quote your variables "$var" Unquoted variables $var
Use [[ for conditionals Use [ without escaping
Add set -e for strict mode Silent failure on errors
Comment your logic Writing cryptic one-liners
Use local for function vars Global vars everywhere

🤝 Contributing

Contributions are warmly welcome! 🎉

# 1. Fork the repository
# 2. Create your feature branch
git checkout -b feature/my-awesome-script

# 3. Commit your changes
git commit -m "Add: system health check script"

# 4. Push to your branch
git push origin feature/my-awesome-script

# 5. Open a Pull Request

Guidelines

  • 📝 Add comments to explain what your script does
  • 🧪 Test your script before submitting
  • 📁 Place scripts in the correct category folder
  • 🔤 Use snake_case for file names (e.g., disk_usage.sh)

📄 License

This project is licensed under the MIT License — feel free to use, share, and modify.


Made with 🖤 and a lot of $ _

GitHub

If this repo helped you, drop a ⭐ — it means the world!