LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-20-2007, 03:15 AM   #1
soumyajit.haldar
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, 03:21 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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, 03:53 AM   #3
sanjaykatiyar1
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?

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

Rep: Reputation: 15
Hi,

Try this

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

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

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

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


Reply


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 08:50 AM
Maximum number of files in a directory neranjana General 14 05-13-2010 01:33 PM
how to get count of files in a directory? hongxing Linux - Software 2 11-10-2005 09:06 PM
finding number of files in a directory pantera Programming 2 08-20-2004 10:17 AM
finding the number of files in each directory ridertech Programming 1 06-02-2004 10:26 PM


All times are GMT -5. The time now is 08:27 PM.

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