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

  • 相关阅读:
    【阿里云IoT+YF3300】6.物联网设备报警配置
    【阿里云IoT+YF3300】5. Alink物模型之服务下发
    【阿里云IoT+YF3300】4.Alink物模型之事件触发
    【阿里云IoT+YF3300】3. Alink物模型之属性上传和下发
    腾讯物联TencentOS tiny上云初探
    【阿里云IoT+YF3300】2.阿里云IoT云端通信Alink协议介绍
    【阿里云IoT+YF3300】1.时代大背景下的阿里云IoT物联网的现状和未来
    阿里云的物联网之路
    阿里云智能接入网关体验
    imx:MfgTool
  • 原文地址:https://www.cnblogs.com/chendeming/p/9394188.html
Copyright © 2011-2022 走看看