Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursively list a file count

Status
Not open for further replies.

stevenriz

IS-IT--Management
May 21, 2001
1,069
Hi all, I would like to list the number of files in a subdirectory and have built a couple of commands, can any of you show me what if anything I am doing wrong?

I initially ran this command....

ls -R . | wc -l #which seemed to count semi accurately

So I built a test of a directory with 10 subdirectories, no files. ls -R . | wc -l resulted in a count of 34. with 10 subdirectories I manually counted 23 after running ls -R

When running ls -Ra. | wc -l I got a result of 70 and again when running it manually I counted 48... I don't understand...

I am looking for an accurate file count here... Thanks!!!
 
I think you are misusing the "-a" parameter.

Remember that folder entries "." and ".." are considered folders/directories and are listed by 'ls' by default.

I think you want to refine your work using "A" instead of "a" as part of the command chain.

Try that and see if it meets your needs.

D.E.R. Management - IT Project Management Consulting
 
Personally I'd use find instead, e.g.

[tt]find . -type f | wc -l[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top