Loading Depth Study
Preparing your workspace
Shell pipes and redirection allow the output of one command to become input to another command or be written to a file.
Command-line tools become much more powerful when combined. A pipe sends one command's output into another command. Redirection can write output to a file or read input from one. Commands such as grep, sort, wc, head, and tail can then process text efficiently. These concepts are the foundation of shell automation and scripting.
A developer can search a large log file for errors and then count how many matching lines exist.
cat app.log | grep ERROR cat app.log | grep ERROR | wc -l printf "one\ntwo\n" > output.txt cat output.txt
The commands filter log entries, count matching lines, write text to a file, and read it back.