linux管道工具集中一個相當有用的小tool,從名字中即可看出,主要是從來處理標準輸入中的arguments,可以對一批arguments進行重組,提示,位置替換等功能。(爲何要重組:和shell命令一次最多能處理多少argument有關,替換可以使命令更加靈活)
標準用法:
xargs [options] [command ]
適用場景 :配合ls、find等使用
Options
Option | Description |
-n# | Execute command once for every # argument. For example, -n2 bundles arguments into groups of two or less and executes command on each argument bundle. |
-l# | Execute command once for every # lines of input. For example, -l1 creates a bundle of arguments for every one line of input and executes command on each argument bundle. |
-i | Normally xargs places input arguments at the end of command . Used with the -i option, xargs will replace all instances of {} with input arguments. You need to put them in single brackets or use a backslash (/) before each bracket to keep the shell from interpreting the special characters. |
-t | Echo each command before executing. Nice for debugging |
-p | Prompts the user before executing each command . Useful for debugging. |
Examples
ls | xargs -i{} mv {} {}.old