1. Introduction
The key to using this command is that many commands do not support | Pipelines to pass parameters, and in daily work there is a need for the Xargs command, for example:
Find /sbin-perm +ls -l This command is the wrong find /sbin-perm + Xargs ls -L--this is right.
Use the file name as a parameter to the touch command
Echo " 1.txt 2.txt " Xargs Touch
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
Output
-A file is read from files as Sdtin, (see example I)
-e flag, note that sometimes-e,flag must be a space-delimited flag that stops when Xargs analyzes the flag that contains flag. (Example II)
-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 means that the command is printed before execution. (Example V)
-I or-I, which depends on Linux support, will be the xargs of each name, usually a line assigned to {}, you can use {} instead. (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 at most max-lines nonblank input lines per command line.-s contains spaces.
-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 0 times 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