What does the '|' (vertical bar) character mean in a Terminal command? [duplicate]

The vertical bar | is commonly referred to as a "pipe". It is used to pipe one command into another. That is, it directs the output from the first command into the input for the second command. So your explanation is quite accurate.


It is called a pipe (or a pipeline) and it means that the output of the command in front of it are made as input to the command behind it.

Example:

dmesg | tail
bash --version | tac

You are welcomed to try the command without the pipe.

And yes you are correct: in this case the command xdpyinfo shows information and it is parsed to grep. grep filters the results and only shows lines that have resolution in them.

More information on pipe:

  • https://stackoverflow.com/questions/1072125/how-does-piping-work-in-linux
  • http://www.linfo.org/pipes.html
  • http://linuxtutorial.info/modules.php?name=MContent&pageid=21
  • https://workaround.org/linuxtip/pipes
  • http://en.wikipedia.org/wiki/Pipeline_%28Unix%29

Your interpretation is correct. The | character pipes the output of the first command into the input stream of the second. The two commands are actually running in parallel, as two concurrent processes. It is an illustration of the 'paradigm of pipes and filters' (building complex functions by pipelining simple ones), which is a hallmark of Unix.

For more information on this, I would suggest you follow through some tutorial on bash or shell scripting. There are plenty of those the web. I bet you will be surprised by the elegance and power of Unix/GNU shells.