Pipes and man Pages
Level 1 · Typing commands
How to read the built-in help for any command with man. How the | sign joins small commands into one line that does a bigger job.
Course contentsLesson 2 of 10
Level 1 · Typing commands
Level 2 · Files, users and permissions
Level 3 · Software and services
Level 4 · Timed jobs and the firewall
After this lesson you can
- Open and leave a man page
- Join two commands with a pipe
- Build a short chain to answer a question
10 mincovers 2 glossary entries
Worth reading first: Terminal and Shell Basics
How to find help and join commands
Every Linux command comes with a help page, called a man page. Type man and the command's name, such as man ls. The page says what the command does, how to type it and what each option means. Press the space bar to go down a page and q to leave. The help is on the machine, so it works with no internet.
A man page has the same parts every time. The name and one line on what it does. The synopsis, which shows how to type it. The description. Then a list of options. Square brackets in the synopsis mark parts you may leave out.
Linux commands are small on purpose. Each one does one job. ls lists files. sort puts lines in order. grep keeps only the lines that hold a word. wc counts lines. On their own they are plain. Joined together they do a lot.
The pipe is how you join them. It is the | sign, typed between two commands. It takes everything the first one prints and hands it to the second one, instead of to the screen. You can chain as many as you like, each one feeding the next.
So ls | wc -l lists the files and counts the lines, which tells you how many files there are. A pipe works like a kitchen line. One cook chops, the next fries, and the last one plates. No single cook does the whole dish.
Many commands can also read a file instead of a pipe. grep error app.log reads the file directly. Either way works, and you will see both in guides.
A common mistake is to search the web before reading the man page. A web answer may be for a different version, or for macOS, where some options differ. The man page on the machine always matches the command you are about to run.
$ printf "pear\napple\nfig\n" | sort
apple
fig
pearWorked example
Lucy counts the errors in a log
Lucy's app wrote a log of 50,000 lines overnight. She wants to know how many lines say error.
She types grep error app.log | wc -l. grep keeps the 212 lines that hold the word, and wc counts them. It takes under a second.
The words for this lesson2
Check yourself
What does the | sign do between two commands?
Finished this lesson?
Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.