>_linuxexercises
← All guides
LINUX FIELD NOTES

Combine commands with pipes and redirection

Use small commands together to filter, count and save useful information.

Connect output to input

A pipe connects one command’s standard output to the next command’s standard input. You can filter a log and count the matching lines without a temporary file.

grep ERROR app.log | wc -l

Sort before removing adjacent duplicates

uniq compares neighboring lines. Sort first if repeated values might be separated. The fixture contains repeated names in different positions.

sort names.txt | uniq

Save the result

A single > redirects standard output into a file and replaces any existing contents. Check the destination carefully on a real system.

grep ERROR app.log > errors.txt

Append instead of replacing

Two angle brackets append output. This makes it possible to add a note without discarding existing lines.

echo "Review complete" >> draft.txt

Make it stick.

Try the matching guided exercise in your browser. The first 10 exercises are free; later exercises require a plan.

Practice this skill →