Bash Tutorial¶
A comprehensive guide to bash shell usage, from fundamentals to advanced scripting and modern tooling.
What You'll Learn¶
This tutorial covers everything from basic command-line navigation to writing production-ready scripts:
- Fundamentals - Shell basics, file operations, permissions, and I/O redirection
- Configuration - Dotfiles, environment variables, aliases, and prompt customization
- Scripting - Variables, conditionals, loops, arrays, and error handling
- Tools - Text processing, file finding, modern replacements, and JSON handling
- Advanced - Job control, subshells, signals, and performance optimization
- Reference - Quick reference cards and cheat sheets
Learning Path¶
Beginner¶
If you're new to the command line, start here:
- Shell Basics - Understanding shells and terminals
- Navigation - Moving around the filesystem
- Files & Directories - Basic file operations
- Viewing Files - Reading file contents
- Permissions - Understanding Unix permissions
- Redirection & Pipes - Connecting commands
Intermediate¶
Once comfortable with basics:
- Dotfiles - Configuring your shell
- Environment Variables - PATH and exports
- Aliases - Creating shortcuts
- Shell Functions - Reusable commands
- Scripting Basics - Writing your first scripts
- Conditionals - Decision making
- Loops - Iteration patterns
Advanced¶
For deeper understanding:
- Arrays - Working with collections
- Error Handling - Robust scripts
- Job Control - Background processes
- Signals - Process communication
- Performance - Optimization techniques
Prerequisites¶
- A terminal emulator (Terminal.app on macOS, or any Linux terminal)
- Bash 3.2+ (macOS default) or 5.0+ (Linux/Homebrew)
- Basic computer literacy
Check your bash version:
macOS Note¶
macOS ships with Bash 3.2 due to licensing (GPLv2 vs GPLv3). For modern features like associative arrays and mapfile, install Bash 5.x via Homebrew:
This tutorial notes when features require Bash 4.0+.
Modern Tools¶
Throughout this tutorial, we highlight modern replacements for classic Unix tools:
| Classic | Modern | Benefits |
|---|---|---|
ls | eza | Colors, git integration, tree view |
cat | bat | Syntax highlighting, line numbers |
grep | ripgrep | Faster, respects .gitignore |
find | fd | Simpler syntax, faster |
top | btop | Better visualization |
See Modern Replacements for installation and usage.
Conventions Used¶
Code Blocks¶
Commands to type:
Expected output:
Prompts¶
The $ symbol represents your shell prompt - don't type it:
Placeholders¶
Angle brackets indicate values you should replace:
Notes and Warnings¶
Pro Tip
Helpful suggestions for better workflows.
Caution
Important warnings about potential issues.
Note
Additional context or explanations.
Quick Start¶
If you're impatient, here's the minimum to get productive:
# Navigate
cd ~/projects # Change directory
pwd # Print working directory
ls -la # List files with details
# Files
cat file.txt # View file
cp src dest # Copy
mv old new # Move/rename
rm file # Remove (careful!)
# Search
grep "pattern" file # Find in file
find . -name "*.md" # Find files
# Help
man command # Manual page
command --help # Quick help
Now dive into Shell Basics for the full journey.