Re: (General Question) how to count how many files in a directory tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It would appear that on May 16, Rod Haper did say:

> If you want to count only files in the current directory and all 
> subdirectories, try this:
> 
> find . -type f -print | wc -l
> 
> Btw, the method you used in your email above skips dot (.*) files and 
> includes directories, links, fifos, etc.  If you don't care about that, 
> just add the -R or --recursive switch to your ls command.

Just a couple quick points, "ls -1R" seams to add a line with ".:" at
the beginning and a blank line between each directory listing, that
would have to be filtered out. 

A quick empirical test of your find command includes  any extra "HARD"
links to the same file.  (don't know about "fifo's etc")

Another alternative that does include directories, (.*) files, and "SOFT"
links but skips additional "HARD" links is based on the disk usage
command:

du -a | wc -l

It also adds a single total line, but that predictable quantity can be
easily compensated for:

expr `du -a | wc -l` - 1

(Note for those with tired eyes: those are back quotes NOT single quotes)

Or if you didn't want the directories:

expr `du -a | wc -l` - `du |wc -l`

(the two total lines cancel each others line count out...)

There seams to be more than one way to do most things in *nix
environments.  Often with similar but not quite the same results.
Which one you use would depend on what parts of the result you care
about. ;) 

-- 
|   ---   ___
|   <0>   <->	   Joe (theWordy) Philbrook
|	^		J(tWdy)P
|    ~\___/~	     <<jtwdyp@xxxxxxxx>>

But if I actually knew everything, then I'd know I was an idiot...



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux