zoukankan      html  css  js  c++  java
  • [已解决]Argument list too long如何处理?

    Argument list too long 本质是需要处理的长度超过系统的长度,因此无法执行相关命令。
    经过搜索发现了两种方法,思想都是将参数切分成小的段落进行执行。
    法一:通过xargs传递参数 (数据量大了还是不太奏效)

    find . -name "*.log" | xargs -0 rm
    
    ls | xargs -t -I {} mv {} ../matchres/ 可以把当前目录下的所有文件移到 "../matchres"下
    
    ls | head -n 50 |xargs -t -I {} mv {} ../ 可以把当前目录中的前50个移动到上级目录
    
    
    合并201301目录文件到 hbtmp/bill201301.txt
    cd 201301/
    ls | xargs -t -I {} cat {} >> ../hbtmp/bill201301.txt
    

    xargs使用的命令一次会被调用2000〜4000次左右,因此,如果列出的日志有一万笔的话,可能就会被分成3到5次左右来执行,因而避开了。

    find -maxdepth 1 -type f ( -exec grep -q '^- ' {} ; -o -print )
    
    • maxdepth 深度
    • type 文件类型

    法二:shell脚本循环执行rm命令

    #!/bin/bash
    # 设定需要删除的文件夹
    RM_DIR='/var/spool/clientmqueue'
    cd $RM_DIR
    for I in `ls`
    do
      rm -f $I
    done
    

    一行表达式:

    for f in *.pdf; do rm "$f"; done
    

    法三:将文件群手动划分为比较小的组合

    mv [a-l]* ../foo2
    mv [m-z]* ../foo2
    
  • 相关阅读:
    建表关系
    设计模式-策略模式
    设计模式-适配器模式
    在线操作word和在线预览查找的资料记录
    Elasticsearch 使用-安装
    12-factors
    Kafka 使用-安装
    Apache Zookeeper 使用-安装
    Java 使用-安装
    设计模式-模板方法模式
  • 原文地址:https://www.cnblogs.com/everfight/p/shell_error.html
Copyright © 2011-2022 走看看