---
title: "Chapter 20: Building Command-Line Programs"
description: "The 7 lessons of chapter 20: Building Command-Line Programs, in teaching order."
url: "https://learnrust.net/chapter-20/"
last_updated: "2026-06-13"
---

# Chapter 20: Building Command-Line Programs

- [20.1 Command-line arguments](https://learnrust.net/chapter-20/command-line-arguments.md): Reading the arguments a user passes to your program with std::env::args, collecting them into a Vec, and the convention of argument zero.
- [20.2 Reading and writing files](https://learnrust.net/chapter-20/reading-and-writing-files.md): The one-line conveniences fs::read_to_string and fs::write for small files, and File with BufReader and BufWriter for big ones.
- [20.3 stdin, stdout, and stderr](https://learnrust.net/chapter-20/stdin-stdout-stderr.md): The three standard streams every program has, piping between programs, why errors belong on stderr, and exit codes.
- [20.4 Environment variables](https://learnrust.net/chapter-20/environment-variables.md): Reading configuration from the environment with env::var, the Result it returns, and when an env var beats a command-line flag.
- [20.5 Project: a text-search tool, part 1](https://learnrust.net/chapter-20/text-search-tool-part-1.md): Building a real grep-like tool: parsing arguments into a Config, reading the file, and splitting logic into lib.rs and a thin main with Result everywhere.
- [20.6 Project: a text-search tool, part 2](https://learnrust.net/chapter-20/text-search-tool-part-2.md): Finishing minigrep: a search function written test-first, a case-insensitive flag from an environment variable, errors to stderr, and an iterator refactor.
- [20.x Chapter 20 summary and quiz](https://learnrust.net/chapter-20/chapter-20-summary-and-quiz.md): Review of command-line arguments, files, the standard streams, environment variables, and the minigrep project, with an extension exercise.

## Sitemap

See the full [sitemap](https://learnrust.net/sitemap.md) for all pages.
