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

  • 相关阅读:
    【python cookbook】找出序列中出现次数最多的元素
    2018/1/21 Netty通过解码处理器和编码处理器来发送接收POJO,Zookeeper深入学习
    读《风雨20年》小感
    两个知识点的回顾(const指针和动态链接库函数dlopen)
    小试牛刀
    chmod,chown和chgrp的区别
    node.js中使用node-schedule实现定时任务
    在 Node.js 上调用 WCF Web 服务
    nodejs发起HTTPS请求并获取数据
    openstack 之~云计算介绍
  • 原文地址:https://www.cnblogs.com/chendeming/p/9394188.html
Copyright © 2011-2022 走看看