zoukankan      html  css  js  c++  java
  • xargs命令

    一、官方解读

     The xargs utility(功效,此处翻译为执行程序) reads space, tab, newline and end-of-file delimited strings from the standard input and executes utility with the strings as arguments. 
    Any arguments specified on the command line are given to utility upon each invocation, followed by some number of the arguments read from the standard input of xargs.
    The utility is repeatedly executed until standard input is exhausted(完结).

    总结来说:

    (1)xargs从stdio读取以空格、tab、换行、文件开头、文件终结的字符串组

      换言之,xargs会使用类似于java中的String.split方法截断空格、tab、换行、文件开头、文件终结把返回内容变成String[],然后来个for循环将String[]的内容作为参数用于执行后面的命令

      例如:

        find . -name "*.xml" | xargs grep project

        ps:

          find . -name "*.xml"会按行返回当前目录下所有xml文件

          Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。

        

        那么用此命令的执行类似于这个情况

        String filePaths = find . -name "*.xml";

        String[] arrFilePath = filePaths.split(" ");

        for(String filePath:arrFilePath){

          filePath grep project;//在文件filePath中查找包含project关键字的内容

        }

            

    常用的xargs命令

    #以arg.txt文件内容作为脚本参数执行传入
    cat arg.txt | xargs -I {} ./sk.sh -p {} -l
    
    ./sk.sh -p aaa -l
    ./sk.sh -p bbb -l
    ./sk.sh -p ccc -l
    #将所有某类型文件拷贝至某文件夹下
    ls *.jpg | xargs -n1 -I cp {} /data/images
    #统计系统内php文件数量
    find . -type f -name "*.php" -print0 | xargs -0 wc -l

    参见网站: 

      http://man.linuxde.net/xargs

  • 相关阅读:
    angular 1.26 版本 window.history.back() 自动去顶部
    CK editor 制作 ”小“plugin
    CSS 3 过渡效果之jquery 的fadeIn ,fadeOut
    了解 : angular controller link nginit 顺序
    规范 : jobbox 中英文
    了解 : angular translate 和 google translate 和 微软 translate
    业务逻辑 : 未完 : easybook.com
    List和ArrayList的区别
    Select什么时候会产生重作日志
    几点对专用服务器与共享服务器差异的理解
  • 原文地址:https://www.cnblogs.com/chendeming/p/9394188.html
Copyright © 2011-2022 走看看