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

  • 相关阅读:
    poj 3278 catch that cow
    POJ 1028 Web Navigation
    poj 2643 election
    hdu 1908 double queues
    hdu_2669 Romantic(扩展欧几里得)
    0/1背包 dp学习~6
    校验码
    最长上升子序列(LIS经典变型) dp学习~5
    LCS最长公共子序列~dp学习~4
    最长上升子序列(LIS) dp学习~3
  • 原文地址:https://www.cnblogs.com/chendeming/p/9394188.html
Copyright © 2011-2022 走看看