Skip to content

EnekoDev/learning-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🐚 Shell Scripting Exercises (Beginner → Advanced)

A progressive set of exercises to help you master shell scripting step by step.


🟢 Beginner Level (Basics)

Focus: commands, variables, simple scripts

1. Hello Script

  • Write a script that prints:

    • “Hello, World!”
    • Your username
    • Current date

2. Variables Practice

  • Ask the user for their name and age
  • Print: “You will be X years old in 5 years”

3. File Check

  • Ask for a filename

  • Check:

    • If it exists
    • If it’s readable
    • If it’s writable

4. Simple Calculator

  • Take two numbers as arguments

  • Output:

    • Sum
    • Difference
    • Product

5. Loop Practice

  • Print numbers from 1 to 20
  • Then print only even numbers

🟡 Intermediate Level (Logic & Automation)

Focus: conditionals, loops, functions

6. Backup Script

  • Copy all .txt files from one folder to another
  • Add a timestamp to the backup folder name

7. Log Analyzer

  • Given a log file:

    • Count number of lines
    • Count occurrences of the word “ERROR”

8. User Menu Script

Create a menu:

1. Show current directory
2. List files
3. Show disk usage
4. Exit
  • Keep looping until user exits

9. Function Practice

  • Write functions:

    • is_even
    • factorial
  • Call them from the script

10. File Organizer

  • Move files into folders based on extension:

    • .jpg → images/
    • .txt → text/
    • .sh → scripts/

🔵 Upper-Intermediate (Real-world Tasks)

Focus: pipes, awk/sed, process handling

11. Process Monitor

  • Show top 5 processes by CPU usage
  • Refresh every 5 seconds

12. Disk Usage Reporter

  • Show directories larger than a given size
  • Sort them by size

13. Bulk Rename Tool

  • Rename files:

    • Replace spaces with underscores
    • Add prefix or suffix

14. CSV Parser

  • Given a CSV file:

    • Print a specific column
    • Filter rows based on a condition

15. Simple Deployment Script

  • Pull latest code from a Git repo
  • Restart a service
  • Log the deployment

🔴 Advanced Level (Scripting Mastery)

Focus: robustness, system tools, automation

16. Argument Parser

  • Support flags like:

    • -f <file>
    • -v (verbose)
  • Use getopts

17. Parallel Execution Script

  • Run multiple commands in parallel
  • Wait for all to finish
  • Collect exit statuses

18. System Health Check Tool

  • Report:

    • CPU usage
    • Memory usage
    • Disk usage
  • Output a nicely formatted report

19. Cron Job Manager

  • Script to:

    • Add cron jobs
    • List cron jobs
    • Remove cron jobs

20. Interactive CLI Tool

  • Build a full CLI utility with:

    • Help menu (--help)
    • Subcommands
    • Error handling

⚫ Expert Challenges (Optional but Powerful)

21. Build Your Own grep

  • Search for a pattern in a file

  • Support flags like:

    • Case insensitive
    • Line numbers

22. Mini Shell

  • Implement a basic shell:

    • Read command input
    • Execute commands
    • Handle cd, exit

23. Log Rotation System

  • Archive logs when they exceed a size
  • Compress old logs
  • Keep only the last N logs

24. API Data Fetcher

  • Use curl to fetch data from an API
  • Parse JSON (using jq)
  • Display formatted output

25. Automated Backup System

  • Incremental backups
  • Compression
  • Remote sync (e.g., rsync)

💡 Tips

  • Try solving exercises without looking up solutions first

  • Practice using:

    • grep, awk, sed
    • cron, systemctl, ps
  • Add error handling:

    • set -e
    • trap

Happy scripting! 🚀

About

Exercises generated by chatgpt to work some shell scripting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors