巴什的参数数目!= NUM​​最大CP参数? [英] Maximum number of Bash arguments != max num cp arguments?

查看:230
本文介绍了巴什的参数数目!= NUM​​最大CP参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在复制和移动大量文件(〜40万)。我知道,有对可以bash命令行上进行扩展参数的数量限制,所以我一直用xargs的限制所产生的数字。

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 command line, so I have been using xargs to limit the numbers produced.

出于好奇,我想知道的,我可以用参数的最大数量是,我发现的这个帖子称这是系统相关的,而且我可以运行此命令来找出:

Out of curiosity, I wondered what the maximum number of arguments that I could use was, and I found this post saying that it was system-dependant, and that I could run this command to find out:

$ getconf ARG_MAX

要我惊讶的是,我回来了anwser是:

To my surprise, the anwser I got back was:

2621440

就在 260万。正如我所说的,我正在处理文件的数量比这少得多 - 400K左右。我一定要使用移动和复制这些文件中的的xargs 方法,因为我试图用一个正常的 MV * ... CP * ... ,并得到了参数列表太长的错误。

Just over 2.6 million. As I said, the number of files that I am manipulating is much less than this -- around 400k. I definitely need to use the xargs method of moving and copying these files, because I tried using a normal mv * ... or cp * ... and got a 'Argument list too long' error.

所以,做好 MV CP 命令对参数的数量自己固定的限制,我可以使用(我找不到他们的手册页的任何东西),还是我失去了一些东西?

So, do the mv and cp commands have their own fixed limit on the number of arguments that I can use (I couldn't find anything in their man pages), or am I missing something?

推荐答案

作为伊格纳西奥说, ARG_MAX 缓存的最大长度传递给参数的exec(),而不是文件的最大数量(的此页面有一个非常深入的解释)。具体来说,它列出了 FS / exec.c 作为检查下列条件:

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:

在32位Linux上,这就是 ARGMAX / 4-1(32767)。这成为相关的,如果参数的平均长度小于4。
  由于Linux 2.6.23,在如果数量超过此功能检查 MAX_ARG_STRINGS < Linux的/ binfmts.h> ( 2 ^ 32-1 = 4294967296-1)。
  而作为额外的限制,一个参数必须不大于 MAX_ARG_STRLEN (131072)。

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).

这篇关于巴什的参数数目!= NUM​​最大CP参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆