Free tutorial · 30 lessons

Bash Tutorial

Learn Bash and the Linux command line step by step: navigating and managing files, pipes, grep, sed, awk, find, variables, quoting, conditionals, loops, functions, arrays, script options, strict mode and trap, permissions, processes, environment variables and scheduling. Every example is a real script with the output it printed.

Start learning →

Bash Basics

  1. Bash Introduction — What Bash is, where you'll use it, and how the examples in this tutorial work.
  2. Bash Get Started — Open a terminal, check your Bash version, and write and run your first script with a shebang line.
  3. Bash Commands and Getting Help — How commands, options and arguments work, and how to find help with --help, man and type.
  4. Bash Navigating the File System — Move around with pwd, cd and ls, and understand absolute and relative paths.
  5. Bash Files and Directories — Create, copy, move, rename and delete files and directories safely.
  6. Bash Viewing Files — Read files with cat, head, tail and less, and count lines, words and bytes with wc.
  7. Bash History & Versions — Where the Unix shell came from, how Bash became the default shell of Linux, every major Bash release on one timeline, the Shellshock vulnerability, and which version you're likely to meet today.

Pipes and Text Processing

  1. Bash Redirection and Pipes — Send output to files, read input from files, separate errors, and chain commands with pipes.
  2. Bash grep: Search Text — Find lines matching text or regular expressions with grep, recursively, with context and counts.
  3. Bash sed: Edit Text Streams — Substitute, delete and print lines with sed, and edit files in place safely.
  4. Bash awk: Process Columns — Split lines into fields, filter rows and compute totals with awk.
  5. Bash sort, uniq, cut and tr — Sort lines, remove duplicates, extract columns and translate characters.
  6. Bash find and xargs — Find files by name, type, size and age, and run commands on them safely with -exec and xargs.

Bash Scripting

  1. Bash Variables and Quoting — Assign and use variables, understand single versus double quotes, and capture command output.
  2. Bash Parameter Expansion — Defaults, string length, substrings and search-and-replace inside variables, without extra commands.
  3. Bash Arithmetic — Integer maths with $(( )), counters, and floating-point calculations with bc or awk.
  4. Bash Conditionals: if, [[ ]] and case — Make decisions with if, test strings, numbers and files with [[ ]], and match patterns with case.
  5. Bash Loops — Repeat work with for, while and until loops, read files line by line, and use break and continue.
  6. Bash Functions — Define functions, pass arguments, return values with output and exit codes, and keep variables local.
  7. Bash Arrays and Associative Arrays — Store lists in indexed arrays and key-value pairs in associative arrays.
  8. Bash Script Arguments and Options — Read positional arguments, validate them, and parse options with getopts.
  9. Bash Error Handling: set -euo pipefail and trap — Make scripts stop on errors, catch failures in pipelines, and clean up with trap.
  10. Bash Here Documents and printf — Write multi-line text with here-documents and format output reliably with printf.

Linux System Skills

  1. Bash File Permissions — Read and change file permissions with ls -l, chmod and umask, and understand owners and groups.
  2. Bash Processes and Jobs — List processes, run commands in the background, wait for them, and stop them with signals.
  3. Bash Environment Variables and PATH — Use environment variables, export them to child processes, configure PATH, and set up your shell profile.
  4. Bash Archives, Compression and Checksums — Create and extract tar.gz archives, compress files, and verify downloads with checksums.
  5. Bash Scheduling with cron and systemd Timers — Run scripts on a schedule with cron and systemd timers, and write scripts that behave well when scheduled.

Writing Good Scripts

  1. Bash Script Style and ShellCheck — Write maintainable scripts: a standard template, naming, quoting, and linting with ShellCheck.
  2. Bash Next Steps — Where to go after this tutorial: deeper Linux skills, automation, and related tutorials and courses.

Was this page helpful?