[Novalug] Re: [Ma-linux] How to get the number of files in a given directory

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

  See http://www.oreilly.com/catalog/upt3

...jlg


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

Jay

> 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
> 4
> $ perl -le 'my @files=(glob("*")); print scalar @files'
> 1
>
> - Morty
>


_______________________________________________
Novalug mailing list
Novalug at calypso.tux.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://calypso.tux.org/pipermail/novalug/attachments/20080110/5c101d1c/attachment.html 


More information about the Novalug mailing list