[Novalug] Re: [Ma-linux] How to get the number of files in a given directory
goldsmithj at yahoo.com
Thu Jan 10 16:33:40 EST 2008
Hmmm... this book you can: "Unix Power Tools" by Powers, Peek, O'Reilly and Loukides (yes, the O'Reilly is Tim O'Reilly, founder of O'Reilly Books). This is the definitive book on how to do "Unixy" things in a recipe format. I've worn out my first edition and still thumb through my new edition. Highly recommended.
Jay Hart <jhart at kevla.org> wrote: Wow, a very simple question got me some really great knowledge back.
Can't anyways get that from a book...
> On Thu, Jan 10, 2008 at 02:13:26AM -0500, Joseph S D Yao wrote:
>> On Wed, Jan 09, 2008 at 08:13:43PM -0500, Jay Hart wrote:
>> > Answered my own question, I wonder why I didn't see this first:
>> > ls | wc -l
> If you're just looking for an approximate count in a directory without
> pathological cases, ls | wc -l is probably good enough.
> If you need something really robust, remember that filenames can
> contain embedded newlines. I.e.:
> $ mkdir test
> $ cd test
> $ perl -e 'open A, ">crazy\nfile\nwith\nnewlines"'
> $ ls | wc -l
> $ perl -le 'my @files=(glob("*")); print scalar @files'
> - Morty
Novalug mailing list
Novalug at calypso.tux.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Novalug