Understanding the UNIX command xargs

前端 未结 5 851
[愿得一人]
[愿得一人] 2021-01-31 16:37

I\'m pretty much confused on this. Need some clarifications.

Example 1 :

pgrep string | xargs ps

Example 2 :

5条回答
  •  臣服心动
    2021-01-31 17:00

    $ echo 'line1
    > line2
    > line3
    > ...
    > lineN ' | xargs cmd1 -a -b
    

    will result in:

    $ cmd1 -a -b line1 line2 line3 ... lineN
    

    xargs will break cmd1 ... into several executions of cmd1 if the line count gets too large.

    xargs may be used for many other tasks related to passing stdin lines as positional arguments. Take a look at the capital -P option in xargs(1) for running several instances of a command in parallel.

提交回复
热议问题