Command-line and systems tools with Rust
You write and ship fast, single-binary tools that work with files, processes and the network using clap, serde and the standard library.
Level 301 · 17 lessons · 15 practice labs
Lessons
A command-line tool
- Arguments and subcommands with clap
- Reading files, BufReader and error context
- JSON and TOML with serde
- Walking a directory tree
- Exit codes, stdin and stdout
- Short task: a simple search tool with coloured output
Processes and the network
- Running commands with std::process
- TCP client and server with std::net
- An HTTP client with reqwest
- Timeouts and retries
- Short task: a tool that probes the lab services
Quality and shipping
- Integration tests and test data
- Benchmarking with criterion
- Static and cross compilation
- Dependency checks with cargo audit and cargo deny
- Short task: version and package your tool
Capstone
- Capstone: a file integrity monitoring tool
Practice labs
- A line service that shuts down gracefully on a signal: Add graceful shutdown to a line-based service: on a termination signal refuse new connections, finish open requests and exit when the deadline passes.
- Validating options with clap: Add --days and --target options to a backup tool with clap derive and give a clear error for an invalid number.
- A tag tool with subcommands: Define add, list and remove subcommands with clap and verify each one's exit code with tests.
- A filter tool that reads from a pipe: Complete a filter that reads from a file or stdin, writes errors to stderr and returns the right exit code.
- Reading a JSON inventory with serde: Read a server inventory JSON file into structs with serde and use default values for missing fields.
- Merging TOML settings with environment variables: Write code that overrides TOML settings with environment variables and proves the precedence order with tests.
- Finding large files in a directory tree: Write code that walks a directory tree listing files above a size limit, warning on unreadable directories without stopping.
- Capturing a command's output: Run df with std::process::Command, parse the usage percentages and return an error when the command fails.
- A TCP connection check with a timeout: Write a checker that connects to permitted ports on the lab targets with connect_timeout and tells open, closed and timed-out apart.
- An HTTP client with retries: Add up to three retries with exponential backoff to a client calling the lab API, without retrying 4xx responses.
- A line-based echo server: Write a std::net server that sends each line back in upper case and test it with two clients at once.
- An integration test for a CLI tool: Add an integration test in tests/ that really runs the tool and checks its output and exit code.
- Measuring a parser with criterion: Write a criterion benchmark for a line parser, remove needless String allocations and show the speed-up.
- Updating a vulnerable dependency: Update the vulnerable version cargo audit reports, fix the cargo deny licence rule and prove the build still works.
- Building a static binary: Build the tool statically for the musl target, confirm with ldd that nothing is linked dynamically and embed the version.
About this course
You write and ship fast, single-binary tools that work with files, processes and the network using clap, serde and the standard library.
What you will learn
- A command-line tool
- Processes and the network
- Quality and shipping
- Capstone
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.