Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list number of files in mulitple directories

Status
Not open for further replies.

mmcds

MIS
Jul 5, 2007
28
US
I have /home/test directory. Off that directory I have about 20 subdirectories. I want to be able to list the total number of files in each of those directories. For example directory1 has 100 files, directory2 has 20 files, directory3 has 55 files, etc. Is there a command to do this?
 
find /pathname -type f | wc -l

or more explicitly:

find /home/test -type d | while read DIRNAME
do
echo "${DIRNAME} \c"
find ${DIRNAME} -type f | wc -l
done
 
Hi

An alternative could be :
Code:
find /home/test -mindepth 2 -type f -printf '%P\n' | cut -d/ -f1 | uniq -c
Tested with GNU [tt]find[/tt], [tt]cut[/tt] and [tt]uniq[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top