Skip to content
ohsudo, Home

Module 2: Text and logs

Connect commands: pipes and redirects

Each command does one small job. The real power comes from connecting them: the output of one becomes the input of the next, or goes into a file.

● Runs 100% in your browser. Nothing here can harm a real system.

Step 1 of 6

The pipe

| sends the output of the command on its left to the command on its right.

Your task

Send logs/app.log from cat into grep, and keep the ERROR lines.

guest@ohsudo: ~ — Ubuntu 24.04

Starting the terminal…

What you'll practice

  1. The pipe. | sends the output of the command on its left to the command on its right.
  2. Count with a pipe. wc -l counts lines. Any command that prints lines can feed it.
  3. Save to a file. > writes the output to a file instead of the screen. If the file exists, it's overwritten without asking.
  4. Add to a file. >> adds to the end of a file, and keeps what's there.
  5. Hide the errors. Programs print errors on a separate stream, number 2, which > doesn't catch by itself. 2>/dev/null throws those errors away, which is handy when searching places you can't read.
  6. See it and save it. tee does both: it writes to a file, and passes the text on to the screen. With sudo tee you can also write to a file only root can change, which sudo echo … > can't do.

See also