Solved

How to find number of files in a directory tree

Posted on 2002-05-22
6
227 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:damohickey
6 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 7026401
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

0
 
LVL 6

Expert Comment

by:bira
ID: 7027310
If you want to find the number of files of all tree,
  ls -R |wc -l
0
 

Author Comment

by:damohickey
ID: 7028977
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:damohickey
ID: 7031037
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
0
 
LVL 20

Expert Comment

by:tfewster
ID: 7921216
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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7967090
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now