find total files

hi,

how to find total files in a directory?
 thanx
bsherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
What are total files?
0
graham_kCommented:
ls the directory, piping it into a file. Then use word count to count the lines. unfortunately, I am stuck at a windows machine, so will have to guess. The method is correct, even if the details are wrong :-)

ls | num_files
wc - l num_files
rm num_files
0
tfewsterCommented:
ls -l |wc -l will give you the number of entries in directory (files + subdirectories) + 1 (for the "total blocks" line)

ls -l | grep "^-" |wc -l will give you the number of ordinary files in a directory

find . -type f -print |wc -l will give you total ordinary files in the directory & subdirectories
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

graham_kCommented:
hey, tfewster that answer looks supiciously like my comment - I want a share of those 9 points !
0
graham_kCommented:
only joking, of course :-)
0
tfewsterCommented:
graham_k - you admitted to using windows, so you forfeit all rights to points in the Unix areas!

BTW, I think you meant "ls > num_files", (redirect rather than pipe) ; However, I'm not going to argue over points; Get bsher to reject my answer & accept your comment as answer, assuming s/he has an acceptable answer to the original Q.
0
graham_kCommented:
"No way" on the reject your answer option.

I'm glad that you noticed the smiley & didn't take me seriously. Your crack about using windows forfeiting all rights to points in the Unix area cracked me up! That should be enshrined in the rules somewhere.

Happy experting,

Graham
0
ahoffmannCommented:
> ls -l
DID NOT give all files and dirs
so the suggestion based on this are all wrong
I wait 'til ozo's question is answered by bsher ;-)
0
tfewsterCommented:
Point taken ahoffman - Even if bsher's Q IS as easy as it first appears I should have said ls -la
0
ahoffmannCommented:
. and even ls -la|wc may not be wrong
0
bsherAuthor Commented:
i got alot of messages in my forums , so i would like to calculate the exact total messages in each forum
0
ozoCommented:
What files are the messages in?
Are there more than one directories for each forum?
Are there more than one forums for each directory?
Are there more than one messages per file?
In what format are the messages stored in the files?
0
bsherAuthor Commented:
is in .txt format. And there are 10 forums out there, forum1 - forum10..

i just want to figure out how many *.txt in the 10 forums, and total files in each individual forum.
0
ozoCommented:
ls -1 forum*/*.txt | wc -l
sh -c 'for f in forum*;  do echo -n $f ;  ls -1 $f | wc -l ; done'
0
ahoffmannCommented:
just in case of someone created crazy filenames, I suggest:
  ls -q
or
  ls -b
instead of ls -1
0
ozoCommented:
or maybe even
  ls -q --
which could help in case of crazy *.txt names, but in case of crazy forum* names, it may not be enough...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.