command | xargs -I {} test.sh -p {} #编写一个脚本test.sh,-p是脚本的一个选项,command命令生成的输出传递给xargs,然后通过xargs将其转变成test.sh脚本的参数.
find -. -type f -name "*.txt" -print0 | xargs -0 rm -f
#这条命令中print后面有个数字0,xargs后面也有个-0,为什么呢?因为如果文件名中含有空格的话,xargs就会将这个文件认为是两个文件(例如文件名是hello
world.txt,那么xargs就会对hello和world.txt这两个文件进行后续处理,假设存在这两个文件),为了解决这个办法,print0的含义就是将定界符空格,改成null(\0),而后面的-0也同样是这个意思[cactier@localhost ~]$ find -name "*.sh" -print0 ./prostatus.sh./name.sh./test.sh[cactier@localhost ~]$ find -name "*.sh" -print ./prostatus.sh ./name.sh ./test.sh
xargs通常用于将文件名列表作为命令行参数传递给其他命令,故当文件名作为命令行参数的时候,建议用null作为文件名终结符号,而不是用空格
原文:http://www.cnblogs.com/aaa103439/p/3512833.html