Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of using named pipes in Linux shell (Bash)

Can someone post a simple example of using named pipes in Bash on Linux?

like image 620
Drew LeSueur Avatar asked Nov 06 '10 16:11

Drew LeSueur


People also ask

How use named pipe Linux?

A FIFO, also known as a named pipe, is a special file similar to a pipe but with a name on the filesystem. Multiple processes can access this special file for reading and writing like any ordinary file. Thus, the name works only as a reference point for processes that need to use a name in the filesystem.

What is pipes in Linux with example?

A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing.

What is a named pipe bash?

What is a named pipe? On Unix-based operating system like Linux, a named pipe, or FIFO (first-in, first-out), is a “special” kind of file used to establish a connection between processes. Unlike a “standard” pipe, a named pipe is accessed as part of the filesystem, just like any other type of file.


1 Answers

One of the best examples of a practical use of a named pipe...

From http://en.wikipedia.org/wiki/Netcat:

Another useful behavior is using netcat as a proxy. Both ports and hosts can be redirected. Look at this example:

nc -l 12345 | nc www.google.com 80 

Port 12345 represents the request.

This starts a nc server on port 12345 and all the connections get redirected to google.com:80. If a web browser makes a request to nc, the request will be sent to google but the response will not be sent to the web browser. That is because pipes are unidirectional. This can be worked around with a named pipe to redirect the input and output.

mkfifo backpipe nc -l 12345  0<backpipe | nc www.google.com 80 1>backpipe 
like image 172
Brian Clements Avatar answered Sep 17 '22 17:09

Brian Clements