limit to number of files seen by ls?

John Almberg jalmberg at
Mon Jul 27 13:03:46 UTC 2009

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


What I get is this:

 > sysctl kern.argmax
kern.argmax: 262144

Which is why I'm starting to think that (a) my problem is different  
or (b) I'm so clueless that there isn't any problem at all, and I'm  
just not understanding something (most likely scenario!)

I'm going to write a little script that generates a bunch of files to  
test my hypothesis that once I get more than n files in a directory,  
some things stop working correctly, like ls and ftp directory  
listings, and to discover the value of n. That will give me some hard  
data to work with.

This problem has been nagging at me for a while, so it's time I nail  
it down once and for all...

I'll be back...

-- John

More information about the freebsd-questions mailing list