cat temp.txt
welcome
to
groad
cat temp.txt |xargs
welcome to groad
# cat temp.txt
1 2 3 4 5 6 7 8 9 10 11 12 13
# cat temp.txt |xargs -n 3
1 2 3
4 5 6
7 8 9
10 11 12
13
# cat temp.txt
welcome~to~www~groad~net
# cat temp.txt |xargs -d '~'
welcome to www groad net
# cat temp.txt |xargs -d '~' -n 2
welcome to
www groad
net
./mysc.sh -s yourarg -p
$ cat myarg.txt | xargs -I {} ./mysc.sh -s {} -p
$ find . -name "core" -print | xargs echo "" >/tmp/core.log
$ find /apps/audit -perm -7 -print | xargs chmod o-w
在下面的例子中,我们用 grep 命令在所有的普通文件中搜索 device 这个词:
[quote]$ find / -type f -print | xargs grep "device"
$ find . -name \* -type f -print | xargs grep "DBO"
# ls -l
total 0
-rw-r--r-- 1 root root 0 2012-03-23 13:59 groad.txt
-rw-r--r-- 1 root root 0 2012-03-23 13:59 hello groad.txt
# find . -type f -name "*.txt" -print | xargs rm -f
# ls -l
total 0
-rw-r--r-- 1 root root 0 2012-03-23 13:59 hello groad.txt
# find . -name "*.txt" -print0 |xargs -0 rm -f
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |