ITeye博客

xargs

elihe2011 · 2013-07-08 15:51 · Linux命令 · 操作系统 · Markdown

xargs:产生某个命令行参数,xargs可以读入stdin的数据,并且以空格或换行符做分割,将stdin分割成arguments

xargs [-0pen] command
-0: stdin含特殊字符(`,\,空格等),可将这些字符还原成普通字符,让其失去特殊意义
-p: prompt,没执行一个argument,都询问
-e: EOF(end of file),后面接一个字符,当xargs分析道这个字符串时,停止继续工作
-n: 后接次数,每次command执行时,要使用几个参数

eg:
cut -d":" -f1 /etc/passwd | head -n 3 | xargs -p finger

cut -d":" -f1 /etc/passwd | xargs -p -e"lp" finger

ls 不支持管道流:
find /sbin -perm +7000 | ls -l   # 得到当前目录下文件列表
find /sbin -perm +7000 | xargs ls -l   # 正确

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。