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
- The pipe.
|sends the output of the command on its left to the command on its right. - Count with a pipe.
wc -lcounts lines. Any command that prints lines can feed it. - Save to a file.
>writes the output to a file instead of the screen. If the file exists, it's overwritten without asking. - Add to a file.
>>adds to the end of a file, and keeps what's there. - Hide the errors. Programs print errors on a separate stream, number 2, which
>doesn't catch by itself.2>/dev/nullthrows those errors away, which is handy when searching places you can't read. - See it and save it.
teedoes both: it writes to a file, and passes the text on to the screen. Withsudo teeyou can also write to a file only root can change, whichsudo echo … >can't do.