27

Example: In a Terminal command

xdpyinfo | grep resolution
(that I have taken from an answer), does the
|
character mean that the
xdpyinfo
output shall be sent to the grep program input for printing a line containing the
resolution
string? Where should I seek for such an information to avoid filling this forum by too simple questions? Thanks.

1
  • 4
    I bet if you knew it was called a pipe ... ;)
    – Rinzwind
    Sep 23, 2013 at 12:53

4 Answers 4

35

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.

0
10

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:

1

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.

1

The character | is sometimes called a pipe and is used to connect the output from one command and feed it into the other.

So that xdpyinfo | grep resolution first runs the command xdpyinfo (a utility which displays information about X) without displaying any output. The output of this command is fed into grep (regular expression parser) to find any entries which contain resolution.

What you see is just the info you want and not the complete output of the xdpyinfo command.

Not the answer you're looking for? Browse other questions tagged .