O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Playing with xargs

We use pipes to redirect stdout (standard output) of a command to stdin (standard input) of another command. For example:

cat foo.txt | grep "test"

But, some of the commands accept data as command-line arguments rather than a data stream through stdin (standard input). In that case, we cannot use pipes to supply data through command-line arguments.

We should go for alternate methods. xargs is a command that is very helpful in handling standard input data to the command-line argument conversions. xargs can manipulate stdin and convert to command-line arguments for the specified command. Also xargs can convert any one line or multiple line text input into other formats, such as multiple lines (specified number of columns) or a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required