Joining Tools: The Pipe, grep, and Saving the Answer
Until now every command you ran printed its answer to the screen and stopped. Today that changes. You can take what one command produced and hand it straight to another one, and this is the single idea that makes the terminal more than a slow file manager.
First, a tool worth having
grep looks inside files and shows you only the lines that contain the text you asked for. Think of it as Ctrl+F that works on any number of files at once, and can hand its findings to something else.
grep error log.txtThat is already the difference between a file with three thousand lines being useless and being answerable. But it gets much better when you stop treating it as the end of the sentence.
The pipe: one character, whole new job
The vertical bar takes whatever the command on its left printed and feeds it into the command on its right, instead of to your screen. Nothing is saved, nothing is changed — the text just flows sideways.
grep error log.txt | wc -lThis is why the command line survived every app built to replace it. Nobody had to build a tool that searches and counts. Somebody built a tool that searches, somebody else built a tool that counts, and the pipe made them into one thing.
Searching more than one file
grep -r error .The output changes shape slightly: each line now starts with the filename it came from, then a colon, then the line. That is deliberate — you asked about many files, so it tells you which one each answer belongs to.
And when you want the files themselves rather than what is inside them, that is a different tool:
find . -name "*.txt"Keeping the answer
A pipe sends output to another command. An arrow sends it to a file instead.
grep error log.txt > errors.txtgrep warning log.txt >> errors.txtYou can now ask real questions of your machine. Which means you are ready for the thing that stops most people permanently: the moment a command answers back in red text instead of doing what you wanted.