1

Hi basically I wanted to know what multiple pipe symbols mean in UNIX, I understood what was happening with 2 pipe symbols but the 3rd one threw me off.

Here is the code

raptor$ grep and *.txt | head -n 10 | tail -n 5

could someone let me know what this is doing?

user5647516
  • 1,083
  • 1
  • 9
  • 19
  • Possible duplicate of [What is a simple explanation for how pipes work in BASH?](http://stackoverflow.com/questions/9834086/what-is-a-simple-explanation-for-how-pipes-work-in-bash) – Nuetrino Dec 15 '15 at 19:05

1 Answers1

4

The pipe symbol | always means "use the output of the previous command as the input for the following command". When multiple pipes are strung along in sequence, the piping occurs from left to right (A | B | C means: take the output of A, and put it into B. Then, take the output of B, and put it into C). It may help to visualize parentheses around usages of pipes, starting from the left ((A | B) | C has a clearer order of operations).

In your specific case, the command says

  1. Tell me what files have the word "and" in them in the current directory.
  2. Only show me the first 10 matches you find.
  3. Only show me the last 5 of the first 10 matches.

In other words, it's asking to see the fifth through tenth files it finds that have the word "and" in the current directory.

mwobee
  • 524
  • 2
  • 7