Argument list too long


因为zmap的扫描一次只能针对单一端口(虽可以指定多个IP),所以只能自己写循环,不过这样产生的扫描结果文件就多了,导致最后在处理结果的时候报错,报错信息如下:

/bin/ls: Argument list too long
/bin/cat: Argument list too long
/bin/rm: Argument list too long
# 对应的命令为:
$ ls *.csv
$ cat *.csv
$ rm *.csv
搜索关键字:
http://search.aol.com/aol/search?q=%2Fbin%2Fls%3A+Argument+list+too+long
总结:

This limits is a safety for both binary programs and your Kernel. You’ll see on this page more information about it, and how it’s used and computed.There is no such limit on pipe size.

出现该错误的原因在于内核的安全机制(参数大小限制),但是对于管道而言就没有该限制,所以可以使用find+xargs替代直接的ls/cat/rm *.txt操作(在处理大量文件的情况下)。
参考链接:
,

《 “Argument list too long” 》 有 2 条评论

  1. The “Argument List Too Long” Error in Linux Commands
    https://www.baeldung.com/linux/argument-list-too-long-error
    `
    1. Overview

    In this tutorial, we’ll look at the “argument list too long” problem, often encountered while working with a large number of files. First, we’ll discuss what’s causing it. Then, we’ll discuss a few solutions that will help us to solve this issue.

    2. What Causes the Error

    Let’s consider a case where we have a large number of files residing within a directory:

    While performing filename expansion, Bash expands the asterisk (*) with every matching file. In effect, this produces a very long list of command-line arguments that Bash isn’t able to handle.
    When the number of files to be expanded as arguments is larger than the arguments buffer space, Bash fails to handle it. Note that this buffer is shared with the environment space info, so the real available space is smaller than this buffer size.

    $ getconf ARG_MAX

    $ xargs –show-limits

    3. Overcoming the Limitation

    Let’s dive into various approaches we can utilize to solve this problem. What all the proposed solutions have in common is they avoid parameter expansion.

    3.1. Using the find Command

    We can iterate on the list of files using the find command and then use either the exec option or the xargs command:

    3.2. Using the for Loop Approach

    Another interesting approach is to iterate on the files using the for loop:

    3.3. Manual Split

    We can split the files into smaller bunches and execute the commands (such as rm, cp, mv, wc, ls) repeatedly with a different set of strings as arguments each time:

    3.4. When We Just Need to Remove the Content of a Directory

    Consider a case where we are trying to get rid of all files in a directory and it fails:

    4. Conclusion

    In this tutorial, we looked at multiple techniques to address the “argument list too long” issue.
    First, we discussed what’s causing this error. Then, we learned various solutions that can be utilized to solve the problem both in general and in particular cases.
    `

  2. Argument list too long for ls
    https://unix.stackexchange.com/questions/38955/argument-list-too-long-for-ls
    `
    Your error message argument list too long comes from the * of ls *.txt.
    This limit is a safety for both binary programs and your Kernel. See ARG_MAX, maximum length of arguments for a new process for more information about it, and how it’s used and computed.
    There is no such limit on pipe size. So you can simply issue this command:

    find -type f -name ‘*.txt’ | wc -l

    NB: On modern Linux, weird characters in filenames (like newlines) will be escaped with tools like ls or find, but still displayed from *. If you are on an old Unix, you’ll need this command

    find -type f -name ‘*.txt’ -exec echo \; | wc -l
    `

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注