Bash Tutorial

Learn Bash from your first command to production scripts: the filesystem, quoting, pipes, grep/sed/awk, scripting, processes, cron, and real deployment tooling.

Bash is the shell you meet on almost every Linux server, in Docker containers, in CI pipelines and in the macOS and WSL terminals. Knowing it well is the difference between copying commands you half understand and automating your work with confidence.

This path starts at the very beginning — what a shell is and how a command is put together — and builds up through files and permissions, variables and quoting, redirection and pipes, and the text tools (grep, sed, awk) that make the command line so effective. From there you write real scripts with proper error handling, manage processes and scheduled jobs, and finish by building production-quality backup, reporting and deployment tools. Every example was run on Bash 5.2, and every article ends with exercises and worked solutions.

What You'll Learn

  • Getting Started
  • Files and the Filesystem
  • Shell Fundamentals
  • Text Processing
  • Scripting
  • System Administration
  • Real-World Projects

22 tutorials · Beginner to advanced · Exercises with solutions in every article · Free, no sign-up

Start here

Introduction to Bash

What a shell actually is, why Bash still runs servers, containers and CI pipelines, how a command line is put together, and how to get help without leaving the terminal.

Section 1. Getting Started

Start here to learn the Bash basics.

  • —Introduction to Bash – What a shell actually is, why Bash still runs servers, containers and CI pipelines, how a command line is put together, and how to get help without leaving the terminal.
  • —Setting Up Bash and Your Terminal – Get a current Bash on Linux, macOS or Windows, learn which startup file runs when, and set up your prompt, history, completion, shortcuts and aliases properly.

Section 2. Files and the Filesystem

  • —Navigating the Filesystem – Find your way around a Linux filesystem: what lives in each top-level directory, absolute and relative paths, cd shortcuts, symlinks and pwd -P, ls options, and pushd/popd.
  • —Working with Files and Directories – Create, copy, move, delete and inspect files safely in Bash: mkdir -p, cp -a, mv, rm with guards, tail -F, file and stat, hard and symbolic links, and du.
  • —Wildcards, Globbing, and Brace Expansion – How Bash turns *, ?, [...], ** and extglob patterns into file names, how brace expansion differs, what happens when nothing matches, and how to view it all with tree.
  • —File Permissions and Ownership – How Linux file permissions work: reading ls -l, rwx on files versus directories, chmod in symbolic and octal form, umask, owners and groups, special bits, and sudo.
  • —Finding Files with find, locate, and xargs – A practical guide to find (names, types, sizes, times, permissions, -prune, -exec and -delete), xargs for batch and parallel work, locate, and command lookup with type.

Section 3. Shell Fundamentals

  • —Variables, Quoting, and the Environment – How Bash variables really work: assignment rules, quoting and word splitting, parameter expansion, exporting to child processes, PATH lookup, and loading .env files.
  • —Redirection and Pipes – How Bash wires stdin, stdout and stderr: send output to files, merge or discard errors, feed input with here-documents, and build pipelines that fail loudly.
  • —Command Substitution, Chaining, and Exit Codes – How Bash commands report success and failure, how to chain them safely with &&, || and grouping, and how to capture their output with $( ) and xargs.

Section 4. Text Processing

  • —Searching and Filtering Text: grep, cut, sort, uniq – Answer real questions from logs and CSV files with grep, cut, sort, uniq, wc, tr, head, tail, paste and column, building up to a complete access-log report.
  • —sed: Editing Text Streams – How sed processes text line by line, and how to use substitution, addresses, ranges and safe in-place editing to change config files and logs from scripts.
  • —awk: Processing Columns and Records – Use awk to filter, sum, count and reformat columns in logs, CSV files and command output, from one-line field extraction to complete single-pass reports.

Section 5. Scripting

  • —Your First Scripts: Arguments, Exit Codes, and Conditionals – Write Bash scripts that take arguments, validate their input, return meaningful exit codes, and branch with test, [[ ]], if and case, built around a real log-archiving tool.
  • —Loops, Functions, and Reading Input – Repeat work with for, while and until, read files and CSVs line by line without losing data, prompt users safely, and organise scripts into functions with local variables and main().
  • —Arrays, Associative Arrays, and Arithmetic – Store lists and key-value maps safely in Bash arrays, build command lines without quoting bugs, count things with associative arrays, and do integer and decimal math correctly.
  • —Error Handling, Traps, and Debugging – Make Bash scripts fail safely with set -euo pipefail and its real caveats, clean up with traps, handle Ctrl-C and SIGTERM, and find bugs with bash -x, PS4 and shellcheck.

Section 6. System Administration

Section 7. Real-World Projects