Essential Bash scripts for learning Linux fundamentals, system administration, and cybersecurity basics.
This repository contains 10 essential Bash scripts that cover fundamental to intermediate concepts used in:
- System Administration: Automating repetitive tasks
- Cybersecurity: Reconnaissance, log analysis, automation
- DevOps: Scripting for deployments and monitoring
All scripts are based on knowledge from Securiters Academy, a cybersecurity training program, and adapted for practical learning.
These scripts are educational materials derived from:
- Securiters Academy - Cybersecurity course (Marta Barrio)
- Personal practice and improvements
- Real-world use cases in penetration testing and system administration
bash-scripts-learning/
├── README.md
├── LICENSE
├── .gitignore
│
├── 01-basics/
│ ├── arguments.sh # Handle command-line arguments
│ ├── helloWorld.sh # Variable and printing the variable data
│ ├── requestData.sh # Identify the entered number if it is one
│ └── variables.sh # Work with varibales, arrays, arithmetic
│
├── 02-conditionals/
│ ├── file_checker.sh # Validate files and permissions
│ └── menu.sh # Interactive menus with case
│
├── 03-loops/
│ ├── for_directory.sh # Analyze directories with for loops
│ └── while_counter.sh # Counters and file reading with while
│
├── 04-functions/
│ ├── functions_lib.sh # Reusable function library
│ └── use_library.sh # Import and use functions (source)
│
├── 05-text-processing/
│ ├── search_text.sh # Search text with grep
│ └── parse_data.sh # Extract data with cut/awk
│
└── 06-automation/
└── nmap_wrapper.sh # Automate network scanning (pentesting)
| Script | Real-World Use | Key Takeaway |
|---|---|---|
| arguments.sh | Accept user input in scripts | Essential for automation - every script needs input validation |
| variables.sh | Store and manipulate data | Foundation of all scripting - understand data types |
| file_checker.sh | Validate files before processing | Critical for security - always validate before acting |
| menu.sh | Create user-friendly tools | Professional scripts need interfaces |
| for_directory.sh | Process multiple files | Common in log analysis and backups |
| while_counter.sh | Read files line by line | Essential for log parsing and data processing |
| functions_lib.sh | Write reusable code | DRY principle - don't repeat yourself |
| use_library.sh | Organize large projects | Real projects have multiple files |
| search_text.sh | Find information in logs | Daily task in security and sysadmin |
| parse_data.sh | Extract specific data | Critical for report generation |
| nmap_wrapper.sh | Automate security tools | Real pentesting workflow automation |
Reconnaissance Phase:
# You'll automate tasks like:
# - Scanning multiple targets
# - Parsing nmap results
# - Extracting open ports
# - Generating reportsLog Analysis:
# Real scenarios:
# - Searching for failed login attempts
# - Extracting IP addresses from logs
# - Counting attack patterns
# - Generating alertsPost-Exploitation:
# Automate information gathering:
# - List running processes
# - Extract user accounts
# - Check network connections
# - Collect system informationDaily Tasks:
# Automate repetitive work:
# - Backup scripts
# - User management
# - Disk space monitoring
# - Service health checksWhat it teaches: How to make scripts accept input.
Real-world example:
# Instead of hardcoding values:
target="192.168.1.1"
# You can do:
./scan.sh 192.168.1.1Key concept: $1, $2, $@, $# - These are how scripts become flexible.
What it teaches: How to store and manipulate data.
Real-world example:
# Store scan results
results=$(nmap -p 80,443 target.com)
# Count findings
vulnerabilities=$((critical + high))Key concept: Variables are the memory of your scripts.
What it teaches: How to validate before acting.
Real-world example:
# Before processing a file:
if [ ! -f "report.txt" ]; then
echo "Error: Report not found"
exit 1
fiKey concept: Always validate input - prevents crashes and security issues.
What it teaches: How to create user-friendly tools.
Real-world example:
# Professional pentesting scripts have menus:
1) Quick scan
2) Full scan
3) Vulnerability assessment
4) Generate reportKey concept: Good scripts are easy to use - menus make tools professional.
What it teaches: How to process multiple items.
Real-world example:
# Scan multiple targets from a list:
for target in $(cat targets.txt); do
nmap -sV $target >> results.txt
doneKey concept: Automation means doing the same task for many items.
What it teaches: How to read files line by line.
Real-world example:
# Parse log file:
while read line; do
if [[ $line == *"FAILED"* ]]; then
echo $line >> failed_logins.txt
fi
done < /var/log/auth.logKey concept: Most data processing involves reading files line by line.
What it teaches: How to organize code professionally.
Real-world example:
# Instead of repeating code:
# Script 1: validates IP
# Script 2: validates IP (same code)
# Script 3: validates IP (same code)
# Use a library:
source lib/validation.sh
validate_ip $targetKey concept: Professional projects use libraries - write once, use everywhere.
What it teaches: How to find information in files.
Real-world example:
# Find all error messages:
grep "ERROR" /var/log/syslog
# Find failed SSH attempts:
grep "Failed password" /var/log/auth.logKey concept: grep is the most-used command in security analysis.
What it teaches: How to extract specific fields.
Real-world example:
# Extract usernames from /etc/passwd:
cut -d: -f1 /etc/passwd
# Extract IP addresses from logs:
awk '{print $1}' access.log | sort -uKey concept: cut and awk turn messy data into useful information.
What it teaches: How to automate security tools.
Real-world example:
# Instead of typing commands manually:
sudo nmap -sS -p 1-65535 192.168.1.1
sudo nmap -A 192.168.1.1
sudo nmap -sn 192.168.1.0/24
# Use a menu script that does it for youKey concept: Professionals automate repetitive tasks - scripts save time.
- Bash 4.0+ (check:
bash --version) - Linux/Unix system (Ubuntu, Kali, Debian, Arch, etc.)
- Basic tools (usually pre-installed):
grep,awk,cut,sed
- Optional (for
nmap_wrapper.sh):nmap- Install withsudo apt install nmap
# Solution: Make it executable
chmod u+x script.sh# Solution: Use ./ to run from current directory
./script.sh# Solution: Run with bash explicitly
bash script.shAfter learning each script, try these challenges:
- Modify
arguments.shto accept a-hhelp flag - Extend
file_checker.shto check file size - Create a new menu option in
menu.sh - Write a function that checks if a port is open
- Automate a log analysis task
- Securiters Academy - Cybersecurity courses
- OverTheWire Bandit - Practice Bash
- Bash Guide - Complete reference
- ShellCheck - Validate your scripts
- ExplainShell - Understand commands
- OWASP Top 10 - Web security
- GTFOBins - Unix binaries exploitation
- HackTricks - Pentesting techniques
Important: These scripts are for educational purposes only.
-
✅ Use on systems you own or have permission to test
-
✅ Practice in virtual machines (VirtualBox, VMware)
-
✅ Use for learning and skill development
-
❌ Do NOT use on systems without authorization
-
❌ Do NOT use for illegal activities
-
❌ Do NOT use to harm or disrupt systems
Unauthorized access to computer systems is illegal and may result in criminal prosecution.
- Securiters Academy - Foundation and methodology
- Marta Barrio - Instructor and course creator
- Open Source Community - Tools and resources