Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question

marked as duplicate by Warren Hill, roadmr, Alaa Ali, guntbert, Braiam Sep 24 '13 at 1:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
I bet if you knew it was called a pipe ... ;) –  Rinzwind Sep 23 '13 at 12:53

4 Answers 4

up vote 4 down vote accepted

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.

share|improve this answer

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:

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.