1. Introduction
The key to using this command is that many commands do not support | Pipeline to pass parameters, and it is necessary in daily work, so there is the xargs command, for example:
Find/sbin-perm +700 |ls-l This command is wrong.
find /sbin -perm +700 |xargs ls -l
Xargs can read into the stdin data, and with blank characters or word-breaking characters as a resolution, the stdin data is separated into arguments . Because it is separated by a blank character, so, if there are some file names or other meanings of nouns containing empty white space, xargs may be misjudged ~ His usage is actually also full of simple! Just take a look at it first!
2. option Explanation
-0 when sdtin contains special characters, think of it as a general character, like /' spaces, etc.
For example:[email Protected]:~/test#echo "//" |xargs Echo
[Email Protected]:~/test#echo "//" |xargs-0 Echo
/
- A file is read from files as sdtin, (see example i)
-e flag-e,flag must be a space-delimited flag when xargsflag This sign is stopped. (example two)
-P asks the user once every time a argument is executed. (example III)
-N num followed by the number of times, indicating the number of times the command was executed at the time of execution, argument by default. (example IV)
-t
-i -i linux supported, will xargs {}{} Replace. (example VI)
- R no-run-if-empty stop Xargs when the input of Xargs is empty , no more execution. (example VII)
The best number of characters for the-S Num command line, which refers to the maximum number of command-line characters for the command after Xargs. (example VIII)
-L num use on most max-lines nonblank input lines per command Line.-s is a space.
-L and- l
The-D Delim delimiter, the default xargs delimiter is carriage return, the delimiter for argument is a space, and here the Xargs delimiter is modified (example nine)
-X exit means mainly with- s used.
-P Modify the maximum number of processes, the default is 1, for the 0 time as many as it can , this example I did not think, should normally not be used.
3. Application Examples
Example one:
[Email protected]:~/test#cat Test #!/bin/shecho"Hello world/n [email protected]:~/test#xargsecho#!/bin/sh echo Hello world/n[email protected]:~/test#
Example two:
[Email protected]:~/test#cat txt/bin Tao Shou Kun[email protected]:~/test#cat txt | Xargs ' Shou ' Echo/bin Tao[email protected]:~/test#
Example three:
[Email protected]:~/test#Cat txt| Xargs Echo echo /bin tao Shou kun ff? ... y/bin tao Shou kun ff
Example four:
[Email protected]:~/test#Cat txt| Xargs echo/Bintaoshoukun[email protected]:~/test3#cat txt| Xargs echo/bin tao Shou kun
Example five:
[Email protected]:~/test#Cat txt| Xargs Echo echo //bin Tao Shou kun
Example VI:
ls Xargs mv {} {}.bak
Example VII:
[Email protected]:~/test#echo]| Xargs MV MV MV file Operandtry ' mv --help' for more information. [email protected]:~/test#echo""| xargs -t-r mv[email protected]:~/test# (direct exit)
Example VIII:
[Email protected]:~/test#Cat Test | xargs -i-x echo"{}"exp1exp5file Xargs Long Linux-2[email protected]:~/test#
Example nine:
[Email protected]:~/test#CatTXT |Xargs-i-pEcho {}Echo/bin Tao Shou Kun?... y[email protected]:~/test#CatTXT |Xargs-i-p-D" " Echo {}Echo/bin?... yEchoTao?.../BinyEchoShou?... tao again: [email protected]:~/test#CatTest |Xargs-i-p-D" " Echo {}EchoEXP1EXP5fileLinux-2Ngis_posttaotesttxtxen-3?... y[email protected]:~/test#CatTest |Xargs-i-pEcho {}EchoExp1?... yEchoExp5?. .. exp1yEcho file?. .. exp5y
Xargs usage Explanation