Solved

How to find number of files in a directory tree

Posted on 2002-05-22
6
232 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

726 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