Listing number of files

T. 'Nifty New Hat' Mitchell mitch48 at sbcglobal.net
Fri Jun 18 02:31:18 UTC 2004


On Wed, Jun 09, 2004 at 06:59:53PM +0100, Dylan Parry wrote:
> To: "For users of Fedora Core releases" <fedora-list at redhat.com>
> Date: Wed, 09 Jun 2004 18:59:53 +0100
> From: "Dylan Parry" <me at dylanparry.com>
> Subject: Re: Listing number of files
> Reply-To: For users of Fedora Core releases <fedora-list at redhat.com>
> 
> On Wed, 9 Jun 2004 13:52:08 -0400, Matt Brodeur  
> <mbrodeur+rhlp at NextTime.com> wrote:
> 
> >>...for example, I could find out exactly how many OGG files I have in  
> >>total :)
> >
> >   Something like:
> >$ find . -type f -iname \*.ogg  | wc -l
> 
> Thanks, this does the job nicely. Jeremiah: your solution, although giving  
> me a figure, seems to me a little out so I'm not exactly sure what else it  
> is counting... :)

It is counting dirs and other stuff including, informational
lines like "total xxx" and blank lines for formatting.  Dirs 
get counted twice.

 $ ll -R lib |wc -l
     53
 $ find lib -type f | wc -l
     32

Since ll is a default alias (ll='ls -l --color=tty') specific to bash
and these flavors of linux it is not good fuel for examples without a comment
that it is an alias.  i.e. man ll finds nothing of value.

Inspect the output and see what is cooking.  Recursive ls listings
are good stuff, just not exactly what is needed here.

 $ ll -R lib | less

It might be valuable to notice files that are not .ogg too.
Compare the results of this pair.

 $ find . -type f -iname \*.ogg  | wc -l
 $ find . -type f                | wc -l

Friends of regular expressions will wonder about the dot
and will be happy to see the  -iregex flag.

  $  mkdir gark
  $ touch gark/gllogg
  $ find . -type f -iname \*ogg  | wc -l
   49
  $ find . -type f -iname \*.ogg  | wc -l
   48

System admins will find that find is a fine friend.


-- 
	T o m  M i t c h e l l 
	/dev/null the ultimate in secure storage.





More information about the fedora-list mailing list