Overview
The Linux Command-Line By Example tutorial provides hands-on learning through practical, annotated code examples. This tutorial targets experienced developers who want to quickly understand command-line patterns and shell scripting techniques through direct code exploration.
Tutorial Approach
This tutorial follows the by-example methodology:
- Code-first learning - Examples presented with minimal prose
- Annotated commands - Inline comments explain syntax and behavior
- Progressive complexity - Examples build from basic to advanced patterns
- Real-world scenarios - Commands and scripts based on practical use cases
- Immediate applicability - Copy, modify, and use examples in actual work
What You'll Learn
By working through these examples, you'll understand:
- Shell Basics - Command syntax, options, arguments, and shell behavior
- File System Navigation - Moving through directories and locating files
- File Operations - Creating, copying, moving, deleting, and managing files
- Text Processing - Searching, filtering, transforming, and analyzing text
- Pipes and Redirection - Combining commands and controlling I/O streams
- Process Management - Monitoring, controlling, and scheduling processes
- Shell Scripting - Writing reusable automation scripts
- Environment Configuration - Customizing shell behavior and profiles
- Command Composition - Building complex workflows from simple commands
Prerequisites
This tutorial assumes:
- Linux access - WSL, virtual machine, or native Linux installation
- Terminal familiarity - Comfort opening and using a terminal emulator
- Programming experience - Understanding of variables, loops, and conditionals
- Text editor skills - Ability to create and edit text files
No prior shell scripting experience required - the examples teach through demonstration.
Coverage Overview
This tutorial provides 95% coverage of essential Linux shell skills through 80 annotated examples, organized into three levels:
Beginner Level (Examples 1-30, 0-40% Coverage)
- Basic Commands: echo, ls, cd, pwd, mkdir, rm, cp, mv, touch, cat
- File Viewing: less, head, tail, wc
- Text Search: grep, find
- Pipes & Redirection: |, >, >>, <, 2>&1, tee
- Variables: assignment, expansion, command substitution, environment
- Conditionals: if/else, test, [[]], case
- Loops: for, while, arrays
- Functions: definition, arguments, return values
Intermediate Level (Examples 31-55, 40-75% Coverage)
- Text Processing: sed, awk for log analysis and data transformation
- Scripting Patterns: argument parsing, error handling, exit codes
- Process Management: ps, kill, jobs, signals
- Permissions: chmod, chown, file security
- Archiving: tar, gzip, zip for backups
- Network: curl, wget, ssh, scp, rsync
- Scheduling: cron, at for automation
- Best Practices: production-ready script patterns
Advanced Level (Examples 56-80, 75-95% Coverage)
- Advanced Scripting: Complex automation, error handling patterns
- Signal Handling: Trap commands, process lifecycle management
- Performance: Optimization techniques, parallel processing
- Debugging: Advanced troubleshooting, script profiling
- System Administration: User management, service configuration
- Security: Secure scripting patterns, permission handling
- Production Patterns: Enterprise-grade scripts, monitoring integration
How to Use This Tutorial
- Read the code - Study each example to understand command structure
- Run the commands - Execute examples in your terminal to see results
- Modify and experiment - Change parameters to explore command behavior
- Apply to projects - Adapt examples to solve real problems in your work
- Reference later - Return to specific examples when facing similar tasks
Example Format
Examples follow a consistent annotation pattern:
# Descriptive comment explaining the command's purpose
command --option argument # Inline note about specific syntax
# Multi-line examples include step-by-step comments
variable="value" # Variable assignment
echo "$variable" # Variable expansion in double quotesWhat is "By Example"?
By-example tutorials are code-first learning materials designed for experienced developers switching to or deepening their Linux shell knowledge. Unlike narrative tutorials, by-example focuses on:
- Working, runnable code - Every example is copy-paste-executable
- Heavy annotations - Inline comments with
# =>notation show outputs and states - Self-contained examples - Each example includes all necessary context
- Production relevance - Real-world patterns used in actual work
- Progressive complexity - Examples build from basics to production patterns
Tutorial Structure
- Examples 1-30 (Beginner): Core commands, file operations, basic scripting (0-40% coverage)
- Examples 31-55 (Intermediate): Text processing, automation, production patterns (40-75% coverage)
- Examples 56-80 (Advanced): Performance, debugging, system administration, security patterns (75-95% coverage)
Next Steps
Start with Beginner examples for fundamentals, then progress to Intermediate for production patterns, and finally Advanced for expert-level techniques.
Examples by Level
Beginner (Examples 1–30)
- Example 1: Echo and Basic Output
- Example 2: Variables and Assignment
- Example 3: Command Structure and Options
- Example 4: Navigating Directories (pwd, cd, ls)
- Example 5: Creating and Removing Directories (mkdir, rmdir, rm)
- Example 6: File Viewing (cat, less, head, tail)
- Example 7: File Operations (cp, mv, rm)
- Example 8: File Permissions (ls -l, chmod)
- Example 9: Output Redirection (>, >>, <, 2>)
- Example 10: Pipes (|)
- Example 11: Searching Files (find)
- Example 12: Searching Text (grep)
- Example 13: Text Processing (cut, sort, uniq)
- Example 14: Command Substitution and Subshells
- Example 15: Environment Variables (export, env, PATH)
- Example 16: Conditional Execution (&&, ||, ;)
- [Example 17: Test Conditions ([[]], test, )
- Example 18: If Statements
- Example 19: For Loops
- Example 20: While and Until Loops
- Example 21: Case Statements
- Example 22: Functions
- Example 23: Command Line Arguments (
$1,$2,$#,$@) - Example 24: Exit Codes and
$? - Example 25: Quoting and Escaping
- Example 26: Here Documents and Here Strings
- Example 27: Brace Expansion
- Example 28: Globbing and Wildcards
- Example 29: Process Substitution
- Example 30: Job Control (bg, fg, jobs, &)
Intermediate (Examples 31–55)
- Example 31: Text Processing (sed)
- Example 32: Text Processing (awk)
- Example 33: Command Line Arguments and Parsing
- Example 34: Error Handling and Exit Codes
- Example 35: Process Management (ps, kill, jobs)
- Example 36: File Permissions and Ownership (chmod, chown)
- Example 37: Archiving and Compression (tar, gzip, zip)
- Example 38: Network Operations (curl, wget, ssh)
- Example 39: Scheduling Tasks (cron, at)
- Example 40: Script Best Practices
- Example 41: Find Command Mastery
- Example 42: Regular Expressions in Shell
- Example 43: Array Manipulation
- Example 44: Associative Arrays
- Example 45: String Manipulation
- Example 46: Arithmetic Operations
- Example 47: Date and Time Handling
- Example 48: Here Documents
- Example 49: Process Substitution
- Example 50: Subshells and Command Grouping
- Example 51: Temporary Files and Directories
- Example 52: Lock Files and Mutex Patterns
- Example 53: Signal Handling Deep Dive
- Example 54: Debugging Shell Scripts
- Example 55: Environment Variables
Advanced (Examples 56–80)
- Example 56: Process Management and Job Control
- Example 57: Signal Handling and Traps
- Example 58: Advanced Parameter Expansion
- Example 59: Process Substitution and Named Pipes
- Example 60: Advanced Looping and Iteration
- Example 61: Debugging and Error Handling
- Example 62: Performance Optimization and Benchmarking
- Example 63: Secure Scripting Practices
- Example 64: Advanced Text Processing (awk)
- Example 65: Production Deployment Script Pattern
- Example 66: Docker Integration
- Example 67: Kubernetes CLI Integration
- Example 68: AWS CLI Automation
- Example 69: Git Automation
- Example 70: Database Operations
- Example 71: Log Analysis and Monitoring
- Example 72: Performance Monitoring
- Example 73: API Integration Patterns
- Example 74: Security Automation
- Example 75: CI/CD Pipeline Scripts
- Example 76: Configuration Management
- Example 77: Parallel Processing
- Example 78: Data Transformation
- Example 79: Disaster Recovery Scripts
- Example 80: Production Deployment Patterns
Last updated December 30, 2025