What is a pipe and give an example?

A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the output of the preceding command to be passed as input to the following command. Example : ls -l | prThe output for a command ls is the standard input of pr. When a sequence of commands are combined using pipe, then it is called pipeline.

Showing Answers 1 - 11 of 11 Answers

Brennan Hildebrand

  • May 24th, 2005
 

More generally, a pipe is a method of Inter-Process Communication (IPC). Pipes do not necessarily require command-line specification but can also be opened programatically. The standard "|" pipe is actually a redirection of one programs (left) standard output to anothers (right) standard input. Programatically these redirections are not limited to stdout and stdin but can also include stderr and any other file descriptor the programmer creates.

  Was this answer useful?  Yes

Ramakrishna Choudarapu

  • Nov 4th, 2005
 

A much better example is:

who|wc -l

This redirects the outut of the "who" command to the wc -l and thus displays number of users that currently logged on...

  Was this answer useful?  Yes

pipe is used to redirect output of one command as input of another command.eg $ls|wc -l will mean that output of ls command will serve as input for wc command. As a result we'll get total number of files in current disrectory.

  Was this answer useful?  Yes

Vishal Maheshwari

  • Jul 27th, 2006
 

The shell enables the (standard) output of one command to be conected as (standard) input to another.Operator used - | (pipe).

Eg.     $ who | wc -l

Here, the output of who has been passed directly to the input of wc, and who is said to be piped to wc.

No intermediate files are created when they are used.

  Was this answer useful?  Yes

wow_suraj

  • May 7th, 2008
 

Pipe '|' is used to combine two or more commands to be executed at the sameinstance.

Pipe redirects output of the first command (before '|') as input to the second command (after '|') and gives the output as the execution of last command of pipe should have.

Ex. $> who | sort -r

The first command 'who', will list all the persons logged in and this list will be redirected to the second command as input and the second command will sort the list in reverse order and will be displayed on standard output terminal.

  Was this answer useful?  Yes

The Unix commands alone are powerful, but when two or more commands get combine together, we can accomplish complex task with ease.
In unix we can combine the two or more commands together to perform multiple action simulatenously with the help of Pipe and filter.
Piping is the way to combine two or more commands.

|(symbol) is use as PIPE in unix to combine commands.

The pipe function is lot like the > standard output used to redirect the first command output to the second command which should be right side of PIPE.
So, pipe is used to pass the output of one command to another command, not a file.

Example:
$ cat sat1.txt

this will display the contents of file sat1.txt.

$cat sat1.txt | WC

This will display the number no characters present in the file(sat1.txt)
3 4 21
this won't display the contents of file as file contents commands redirected to WC which count character and display the output.

We can combine many commands with pipes on a single command line . The below is an example where the commnd WC counts the caharacter from the existing files and then mail to the satyamkr@Rediffmail.com

$ cat sat.txt | wc | mail -s "The count" satyamkr@rediffmail.com

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions