Maximum number of Bash arguments != max num cp arguments?

后端 未结 2 494
梦如初夏
梦如初夏 2020-12-08 19:23

I have recently been copying and moving a large number of files (~400,000). I know that there are limitations on the number of arguments that can be expanded on the Bash com

相关标签:
2条回答
  • 2020-12-08 20:07

    ARG_MAX is the maximum length of the arguments to the exec(3) functions. A shell is not required to support passing this length of arguments from its command line.

    0 讨论(0)
  • 2020-12-08 20:21

    As Ignacio said, ARG_MAX is the maximum length of the buffer of arguments passed to exec(), not the maximum number of files (this page has a very in-depth explanation). Specifically, it lists fs/exec.c as checking the following condition:

    PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *) / sizeof(void *)
    

    And, it seems, you have some additional limitations:

    On a 32-bit Linux, this is ARGMAX/4-1 (32767). This becomes relevant if the average length of arguments is smaller than 4. Since Linux 2.6.23, this function tests if the number exceeds MAX_ARG_STRINGS in <linux/binfmts.h> (2^32-1 = 4294967296-1). And as additional limit, one argument must not be longer than MAX_ARG_STRLEN (131072).

    0 讨论(0)
提交回复
热议问题