Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4030018
  • 博文数量: 251
  • 博客积分: 11197
  • 博客等级: 上将
  • 技术积分: 6862
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-05 14:41
个人简介

@HUST张友东 work@taobao zyd_com@126.com

文章分类

全部博文(251)

文章存档

2014年(10)

2013年(20)

2012年(22)

2011年(74)

2010年(98)

2009年(27)

分类: LINUX

2010-12-02 09:06:32

Man page of xargs

xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command  (default is /bin/echo) one or more times with any initial-arguments followed by items read from standard input.  Blank lines on the standard input are ignored.

 

我的理解:xargs从标准输入读取由空格或者换行符分隔的条目,并将其作为xargs后面所跟命令参数的一部分(默认使用/bin/echo,所接的命令可以带参数),然后执行命令。

 

常用参数:

-f file 从文件中读取条目而不是从标准输入;

-0 读取的条目以null作为结束,而不是以空格或换行符进行分隔;

-d delim 指定分隔符;

--verbose 执行命令前显示所执行的命令;

-n max-args 指定参数个数

 

1xargs  –verbose       #从标准输入读,使用-f可从文件读参数

输入:hello world (Ctrl + D)

输出:/bin/echo hello world   #--verbose显示的执行命令

hello world

 

2ls /home/ydzhang/xargs | xargs rm –rf  #从管道读

输入:/home/ydzhang/xargs目录下的条目

输出:rm –rf a b c a,b,c/home/ydzhang/xargs下的文件)

 

3find /home/ydzhang | xargs grep “hello” #从管道读

输入:/home/ydzhang下的所有文件名

输出:/home/ydzhang目录下所有包含hello的文件对应的行

 

4find /home/ydzhang –print0 | xargs -0 grep “hello” #从管道读

输入:以null作为字符串结束符的文件名序列(-print0),将这些参数传给xargs时,如果使用默认参数,xargs将不能正确解析,必须告诉xargs这个信息,即使用-0参数。

输出:/home/ydzhang目录下所有包含hello的文件对应的行

 

阅读(2839) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~