Questions
- How can I combine existing commands to do new things?
Objectives
- Redirect a command’s output to a file.
- Construct command pipelines with two or more stages.
- Explain what usually happens if a program or pipeline isn’t given any input to process.
- Explain the advantage of linking commands with pipes and filters.
Key points
wc
counts lines, words, and characters in its inputs.cat
displays the contents of its inputs.sort
sorts its inputs.head
displays the first 10 lines of its input.tail
displays the last 10 lines of its input.command > [file]
redirects a command’s output to a file (overwriting any existing content).command >> [file]
appends a command’s output to a file.[first] | [second]
is a pipeline: the output of the first command is used as the input to the second.- The best way to use the shell is to use pipes to combine simple single-purpose programs (filters).