Link to home
Start Free TrialLog in
Avatar of damohickey
damohickey

asked on

How to find number of files in a directory tree

What is the easiest way to find the number of files in a directory tree with the answer showing the number of files in each sub directory?

Note the change to this question.

Cheers,

Damo
Avatar of yuzh
yuzh

If you want to find the number of regular file in a dir, type in:

   cd mydir
   find . -type f -print | wc -l

   will give the number of regular files in that dir.

   or use:


   find /full-path-to-mydir -type f -print | wc -l

If you want to find the number of files of all tree,
  ls -R |wc -l
Avatar of damohickey

ASKER

Here is the answer:

find <root of directory tree> -type d > <in_file>
cat <in_file> | while read FILE
do
echo "$FILE `ls $FILE | wc -l`" >> <out_file>
done


Cheers,

Damo
Here is the answer:

find <root of directory tree> -type d > <in_file>
cat <in_file> | while read FILE
do
echo "$FILE `ls $FILE | wc -l`" >> <out_file>
done


Cheers,

Damo
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- PAQ & refund points

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial