xargs process input from command via pipe

process input from command, for the use in anther command as parameters.
will work as echo if no extra instructions is included.

<command> | xargs -n1
will divided the input to one parameter per handling. similarly if we use:
<command> | xargs -n2
every two parameters will used per command handling.

<command1> | xargs <command2>
will concatenated the standard output of command1 to  command2, and then will run the result concatenated command.
For example if we want to tar all visible file (file that don’t have . prefix) in the current directory (we assume no directory in the current directory):
ls | xargs tar cvzf helloworld.tgz
This will tar and gzip all the fill and directory in the current directory into helloworld.tgz

 

Advertisements

One thought on “xargs process input from command via pipe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s