Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 03-20-2007, 04:15 AM   #1
LQ Newbie
Registered: Mar 2007
Posts: 5

Rep: Reputation: 0
Count the number of files in a directory and sub-directories within that directory

Hi all,
i want to count the number of files in a particular directory(including the files in the ub-directory also).

i have tried with
ls -1lR | wc -l

it showing 1088

but when i give just
ls -l

it showing 9833.

Actually, there is sub-directoris which also have files. Please tell me how do i get the exact count.
Old 03-20-2007, 04:21 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
I think that I would use:
find <directory> -type f | wc -l

This will include files in subdirectories but exclude the directories themselves.
Old 03-20-2007, 04:53 AM   #3
LQ Newbie
Registered: Mar 2007
Location: India
Distribution: Redhat, Fedora
Posts: 4

Rep: Reputation: 0
Yes, its working, but also showing the hidden files in dir/subdir,
can we exclude the hidden files?

Old 03-20-2007, 06:47 AM   #4
Registered: May 2005
Location: Sydney, Australia
Distribution: Ubuntu 5.04, Debian 3.1
Posts: 74

Rep: Reputation: 15

Try this

# find <directory> -type f ! -path './.*' -print

I think this should exclude all the hidden files.
Old 03-20-2007, 07:22 AM   #5
LQ Newbie
Registered: Mar 2007
Posts: 5

Original Poster
Rep: Reputation: 0
yes, it is working properly......

thnx a lot..........


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of files in directory bullium Linux - General 13 08-31-2011 09:50 AM
Maximum number of files in a directory neranjana General 14 05-13-2010 02:33 PM
how to get count of files in a directory? hongxing Linux - Software 2 11-10-2005 10:06 PM
finding number of files in a directory pantera Programming 2 08-20-2004 11:17 AM
finding the number of files in each directory ridertech Programming 1 06-02-2004 11:26 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:45 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration