Solved

How to find number of files in a directory tree

Posted on 2002-05-22
6
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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 21

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

688 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