xfs
[Top] [All Lists]

Re: Max file number in single directory

To: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Subject: Re: Max file number in single directory
From: "Stephen C. Tweedie" <sct@xxxxxxxxxx>
Date: Mon, 2 Sep 2002 09:34:54 +0100
Cc: root@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, linux-xfs@xxxxxxxxxxx
In-reply-to: <20020901235658.A13582@infradead.org>; from hch@infradead.org on Sun, Sep 01, 2002 at 11:56:58PM +0100
References: <20020901223911.13399.qmail@larry.minfin.government.bg> <20020901235658.A13582@infradead.org>
Sender: linux-xfs-bounce@xxxxxxxxxxx
User-agent: Mutt/1.2.5.1i
Hi,

On Sun, Sep 01, 2002 at 11:56:58PM +0100, Christoph Hellwig wrote:
 
> > root@larry:~/phones/new_scripts# ls CHEPELARE/*.htm
> > bash: /bin/ls: Argument list too long

> > root@larry:~/phones/new_scripts# ls CHEPELARE/ |wc -l
> >   30303

> It's a general Linux limitation - but nothing related to the number of files
> in a directory.  By doing a ls CHEPELARE/*.htm you let the shell glob the
> filenames and pass all matching ones to /bin/ls.  With 30303 html files in
> directory these are quite a lot and the resulting array overflows the 
> hardcoded
> change for the argument size in the kernel binary loader.

... so you need to chop the argument list up into smaller chunks.  You
can do that easily with "find" and "xargs".  Find will list the given
files, including doing "*" filename glob matching, and xargs will take
a stream of arguments on its standard input and pass them, one chunk
at a time, to some command as arguments:

        find CHEPELARE -name "*.htm" | xargs ls

or, if there are oddly-named files in the tree which might otherwise
confuse xargs (eg. files with spaces in their names), you can use the
more-reliable null-terminated form to pass the find output to xargs:


        find CHEPELARE -name "*.htm" -print0 | xargs -0 ls

That's not _quite_ the same as your original ls, because the find will
recurse many directories deep --- use the "-maxdepth" argument to find
to prevent that --- and because ls's field formatting may get reset
each time xargs starts it up again.  But it's the most reliable way of
running some command over an arbitrarily long list of files.

Cheers,
 Stephen


<Prev in Thread] Current Thread [Next in Thread>