Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Jul 2009 11:09:44 -0800
From:      Mel Flynn <mel.flynn+fbsd.questions@mailing.thruhere.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: limit to number of files seen by ls?
Message-ID:  <200907261109.44586.mel.flynn%2Bfbsd.questions@mailing.thruhere.net>
In-Reply-To: <8A69BBD9-5F3C-44B8-96C0-586C1B5A386F@identry.com>
References:  <20090725222918.AC51DB7E0@kev.msw.wpafb.af.mil> <200907260045.12045.mel.flynn%2Bfbsd.questions@mailing.thruhere.net> <8A69BBD9-5F3C-44B8-96C0-586C1B5A386F@identry.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sunday 26 July 2009 10:24:31 John Almberg wrote:
> On Jul 26, 2009, at 4:45 AM, Mel Flynn wrote:
> > On Saturday 25 July 2009 23:34:50 Matthew Seaman wrote:
> >> It's fairly rare to run into this as a practical
> >> limitation during most day to day use, and there are various
> >> tricks like
> >> using xargs(1) to extend the usable range.  Even so, for really big
> >> applications that need to process long lists of data, you'ld have
> >> to code
> >> the whole thing to input the list via a file or pipe.
> >
> > ls itself is not glob(3) aware, but there are programs that are,
> > like scp. So
> > the fastest solution in those cases is to single quote the argument
> > and let
> > the program expand the glob. for loops are also a common work around:
> > ls */* == for f in */*; do ls $f; done
> >
> > Point of it all being, that the cause of the OP's observed behavior
> > is only
> > indirectly related to the directory size. He will have the same
> > problem if he
> > divides the 4000 files over 4 directories and calls ls */*
>
> H'mmm... I haven't come back on this question, because I want my next
> question to be an intelligent one, but I'm having a hard time
> understanding what is going on. I'm reading up on this, and as soon
> as I know enough to either understand the issue, or ask an
> intelligent question, I will do so...

When a program is executed with arguments, there is a system imposed limit on 
the size of this argument list. On FreeBSD this limit can be seen with sysctl 
kern.argmax, which is the length in bytes.
When you do "ls *", what really happens is that the shell expands the asterisk 
to all entries in the current directory, except entries starting with a dot 
("hidden" files and directories). As a result, ls is really called as:
ls file1 file2 .... fileN

If the string length of file1 to fileN is bigger then kern.argmax, then you 
will get argument list too long error.
-- 
Mel



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907261109.44586.mel.flynn%2Bfbsd.questions>