zsh-workers
 help / color / mirror / code / Atom feed
* Length of argument list
@ 2015-06-10 18:48 Manfred Lotz
  2015-06-10 20:09 ` Mikael Magnusson
  2015-06-10 21:46 ` Clint Hepner
  0 siblings, 2 replies; 6+ messages in thread
From: Manfred Lotz @ 2015-06-10 18:48 UTC (permalink / raw)
  To: zsh-workers

Hi all,
I created 1 million files in a directory callend manyfiles/.

Now 
ls manyfiles/* |wc -l

gives 
zsh: argument list too long: ls


Question: Is there a way to change the maximum size of the argument
list?



-- 
Manfred


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Length of argument list
  2015-06-10 18:48 Length of argument list Manfred Lotz
@ 2015-06-10 20:09 ` Mikael Magnusson
  2015-06-11  9:23   ` Manfred Lotz
  2015-06-10 21:46 ` Clint Hepner
  1 sibling, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2015-06-10 20:09 UTC (permalink / raw)
  To: Manfred Lotz; +Cc: zsh-workers

On Wed, Jun 10, 2015 at 8:48 PM, Manfred Lotz <manfred.lotz@arcor.de> wrote:
> Hi all,
> I created 1 million files in a directory callend manyfiles/.
>
> Now
> ls manyfiles/* |wc -l
>
> gives
> zsh: argument list too long: ls
>
>
> Question: Is there a way to change the maximum size of the argument
> list?

That depends on your operating system, on linux it is guided by ulimit
-s (in particular, the argument list is a quarter of the stack size).
On other operating systems, the limit is traditionally quite small.
I'm assuming the above is just an example, but that particular thing
would be better handled by () { echo $# } manyfiles/*, or some
xargs/zargs contraption if you want to be more general.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Length of argument list
  2015-06-10 18:48 Length of argument list Manfred Lotz
  2015-06-10 20:09 ` Mikael Magnusson
@ 2015-06-10 21:46 ` Clint Hepner
  2015-06-11  9:27   ` Manfred Lotz
  1 sibling, 1 reply; 6+ messages in thread
From: Clint Hepner @ 2015-06-10 21:46 UTC (permalink / raw)
  To: Manfred Lotz; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 640 bytes --]

This is the wrong way to count files in the first place; any matching file
names containing newlines (yes, they're legal) would give the wrong count.

One alternative is

    a=( manyfiles/* )
    echo ${#a}

to create an array containing all the file names, then check the number of
elements in the array.

On Wed, Jun 10, 2015 at 2:48 PM, Manfred Lotz <manfred.lotz@arcor.de> wrote:

> Hi all,
> I created 1 million files in a directory callend manyfiles/.
>
> Now
> ls manyfiles/* |wc -l
>
> gives
> zsh: argument list too long: ls
>
>
> Question: Is there a way to change the maximum size of the argument
> list?
>
>
>
> --
> Manfred
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Length of argument list
  2015-06-10 20:09 ` Mikael Magnusson
@ 2015-06-11  9:23   ` Manfred Lotz
  0 siblings, 0 replies; 6+ messages in thread
From: Manfred Lotz @ 2015-06-11  9:23 UTC (permalink / raw)
  Cc: zsh-workers

On Wed, 10 Jun 2015 22:09:06 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:

> On Wed, Jun 10, 2015 at 8:48 PM, Manfred Lotz <manfred.lotz@arcor.de>
> wrote:
> > Hi all,
> > I created 1 million files in a directory callend manyfiles/.
> >
> > Now
> > ls manyfiles/* |wc -l
> >
> > gives
> > zsh: argument list too long: ls
> >
> >
> > Question: Is there a way to change the maximum size of the argument
> > list?
> 
> That depends on your operating system, on linux it is guided by ulimit
> -s (in particular, the argument list is a quarter of the stack size).

Interesting. Didn't know. This works indeed.

Do you know how it is in FreeBSD, for instance?

> On other operating systems, the limit is traditionally quite small.
> I'm assuming the above is just an example, but that particular thing

Yes, just an example. I want to see if it possible to use simple
command when dealing with directories containing many files.


> would be better handled by () { echo $# } manyfiles/*, or some
> xargs/zargs contraption if you want to be more general.
> 

..and for f in *... and things like this.


In the end it means if a directory contains a large number of files
then the usual commands rm, cp, mv etc cannot be used easily without
additional support (find,xargs, for loops etc).

-- 
Manfred






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Length of argument list
  2015-06-10 21:46 ` Clint Hepner
@ 2015-06-11  9:27   ` Manfred Lotz
  2015-06-11 13:20     ` Stephane Chazelas
  0 siblings, 1 reply; 6+ messages in thread
From: Manfred Lotz @ 2015-06-11  9:27 UTC (permalink / raw)
  To: zsh-workers

On Wed, 10 Jun 2015 17:46:24 -0400
Clint Hepner <clint.hepner@gmail.com> wrote:

> This is the wrong way to count files in the first place; any matching

As said already this was an example.


> file names containing newlines (yes, they're legal) would give the
> wrong count.
> 

I know but when dealing with files I never take into account
that file names contain newlines. IMHO, only crazy people create file
names which contain newlines.


-- 
Manfred


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Length of argument list
  2015-06-11  9:27   ` Manfred Lotz
@ 2015-06-11 13:20     ` Stephane Chazelas
  0 siblings, 0 replies; 6+ messages in thread
From: Stephane Chazelas @ 2015-06-11 13:20 UTC (permalink / raw)
  To: zsh-workers

2015-06-11 11:27:16 +0200, Manfred Lotz:
[...]
> I know but when dealing with files I never take into account
> that file names contain newlines. IMHO, only crazy people create file
> names which contain newlines.
[...]

Crazy, careless (copy-paste in a terminal) or malicious.

There are lots of security vulnerabilties around that are caused
by code that assumes file names cannot contain newline
characters.

-- 
Stephane


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-11 13:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-10 18:48 Length of argument list Manfred Lotz
2015-06-10 20:09 ` Mikael Magnusson
2015-06-11  9:23   ` Manfred Lotz
2015-06-10 21:46 ` Clint Hepner
2015-06-11  9:27   ` Manfred Lotz
2015-06-11 13:20     ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).