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