Skip to content
Advertisement

Pipes in Bash: One at a Time (Line by Line) or All at Once

JavaScript

First, I create 5 files

JavaScript

In the following example, xargs seems to get all the results from find via the pipe all at once:

JavaScript

In the following example, xargs seems to get all the results from find via the pipe one at a time (line by line):

JavaScript

In the following example, xargs seems to get all the results from ‘find’ via the pipe one at a time (line by line); and wc seems to get all the results from xargs via the pipe all at once.

Otherwise, if wc got the results line by line, you would see 1 appear 5 times instead of a 5 at the end.

JavaScript

So do pipes get results from previous command One at a Time (Line by Line) or All at Once?

Advertisement

Answer

The behavior you are observing comes from the xargs options you are using. The -i option specifically instructs xargs to create one new process for each input token, and replace the {} placeholder with that token.

Pipes by themselves do not stipulate any specific behavior; many kernels will pass one full I/O buffer at a time (hence the many questions about I/O buffering with pipes, along the lines of “this command doesn’t seem to do anything in a pipe” when the actual symptom is just that the output buffer isn’t full yet).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement