设为首页 收藏本站
查看: 346|回复: 0

[经验分享] xargs命令使用手册翻译总结

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2015-12-18 08:35:20 | 显示全部楼层 |阅读模式
一、xargs基础属性
      [iyunv@localhost~]# type xargs           # 外置命令
        xargs is/usr/bin/xargs
      [iyunv@localhost~]# whereis xargs    #二进制文件、源、使用手册位置
       xargs:/usr/bin/xargs/usr/share/man/man1/xargs.1.gz/usr/share/man/man1p/xargs.1p.gz
      [iyunv@localhost~]# whatis xargs     #所在使用手册的章节位置
       xargs      (1) - build and execute command lines from standard input
       xargs     (1p) - construct argument lists and invoke utility
     [iyunv@localhost ~]# manxargs



二、xargs官方DESCRIPTION
xargs - build and execute command lines fromstandard input从标准输入建立和执行命令行
     1.xargs从标准输入读取,由空格或者换行界定;
        从紧随其后的标准输入执行一次或者多次初始参数  
     2.xargs从标准输入读入时空白行将被忽略
     3.Unix默认文件名可以包含空格和换行机制会导致xargs命令错误处理
         (1)此时使用-0选项,但需要确保项目产生输入xargs还可以使用空白标记符作为分隔符
         (2)如果是GNU项目可以使用 -print0 选项
      4.如果任何调用命令的退出状态是255,xargs将立即停止读入任何数据,同时发出一个错误消息

NAME
       xargs -build and execute command lines from standard input


DESCRIPTION
       Thismanual page documents the GNU version of xargs. xargs reads items from the
       standardinput, delimited by blanks (which can be protected with double or  sin-
       gle  quotes or  a  backslash) or newlines, and executes thecommand (default is
      /bin/echo) one or more times with any initial-arguments followed by  items read
       fromstandard input.  Blank lines on thestandard input are ignored.

      Because  Unix  filenames can contain blanks and newlines,this default behaviour
       is oftenproblematic; filenames containing blanks and/or newlines are incorrect-
       ly  processed by xargs.  In these situations itis better to use the -0 option,
       whichprevents such problems.   When using thisoption you will need  to  ensure
       that  the program which produces the input for xargs also uses a null character
       as aseparator.  If that program is GNU findfor  example,  the -print0  option
       does thisfor you.

       If anyinvocation of the command exits with a status of 255, xargs will stop im-
       mediatelywithout reading any further input. An  error  message is  issued  on
       stderrwhen this happens.



三、使用格式
SYNOPSIS
      xargs   [-0prtx]  [-E eof-str]  [-e[eof-str]]  [--eof[=eof-str]]  [--null] [-d
      delimiter]   [--delimiter   delimiter]  [-I   replace-str]    [-i[replace-str]]
      [--replace[=replace-str]]  [-l[max-lines]]  [-L  max-lines] [--max-lines[=max-
       lines]][-n max-args]  [--max-args=max-args]  [-s max-chars]  [--max-chars=max-
      chars]   [-P   max-procs] [--max-procs=max-procs]  [--interactive]  [--verbose]
      [--exit]  [--no-run-if-empty]  [--arg-file=file]   [--show-limits]   [--version]
       [--help][command [initial-arguments]]
     [OPTION]
  -0, --null:处理文件名中包含的空格和换行,GUN--->-print0
-a file, --arg-file=file: 从指定文件读取数据作为标准输入
--delimiter=delim, -d delim:分隔符,默认的xargs分隔符是回车,argument的分隔符是空格
-e [eof-str], --eof[=eof-str],-E eof-str:匹配到给定字符串结束
-n max-args,--max-args=max-args:在执行的时候一次用的argument的个数,默认所有
-p,--interactive:当每次执行一个argument的时候询问一次用户
-r, --no-run-if-empty  :当xargs的输入为空的时候则停止xargs,不用再去执行了



四、EXAMPLES
       1.find /tmp -name core -type f -print | xargs  /bin/rm -f
       2.find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
       3. find /tmp -depth-name core -type f -delete
       4.cut -d: -f1 < /etc/passwd | sort | xargs echo
       5.xargs sh -c 'emacs "$@" < /dev/tty' emacs



五、总结
   1.说明:
         (1)xargs适用于将上一个命令的输出结果当成标准输入,传递给其后不支持接收管道传递数据的命令
   例如   find  |  xargs  COMMAND
      (2)xargs是给命令传递参数的一个过滤器,也是组合多个命令的一个工具。
      (3)它把一个数据流分割为一些足够小的块,以方便过滤器和命令进行处理。
      (4)读取数据方式:管道、stdin标准输入、从文件的输出中读取数据
      (5)xargs的默认执行命令:echo
      (6)管道传递给xargs的输入将会包含换行和空白,xargs会将换行和空白将用空格取代。
      (7)一般配合 find(1), locate(1),  locatedb(5),updatedb(1), fork(2), execvp(3), kill(1), signal(7)使用



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-152691-1-1.html 上篇帖子: Ubuntu网页无法播放视频 下篇帖子: find命令详解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表