I need a command to count the files in a directory on HP-UX

Hello expert, I have a directory on HP-UX where I have several files and I want to know for example how many file with the extension TAR exist in the directory. I read that the tree command does that in unix and linux but I don't have that tree command on HP-UX and neither on Solaris. can you tell me how I can issue a command to count the files with certain name in a directory on HP-UX? Thanks in advance.
sharschoAsked:
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.

Kent OlsenData Warehouse Architect / DBACommented:
Hi sharscho,

  ls | wc -l

Good Luck!
Kent
0
Kent OlsenData Warehouse Architect / DBACommented:
Hi sharscho,

  Of course, you can filter the file names in the ls statement:

  ls *.c | wc -l
  ls *.log | wc -l
  ls BR* | wc -l

etc....

Kent
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
sharschoAuthor Commented:
Ok Kent, I did not know it was so easy. It worked. I will have to remember this.
Thanks alot.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ravenplCommented:
But the answer is wrong!
It also counts matched directories! Consider You have subdirectory named 'subdir.TAR'

ls -1 *.TAR *.tar | while read line; do test -f "$line" && echo $line; done | wc -l
0
Kent OlsenData Warehouse Architect / DBACommented:
Hi sharscho,

ravenpl is right in that subdirectories and the implied directories "." and ".." can affect this.  If that becomes an issue, it's probably better to use find(1) than ls.

find "starting path" -maxdepth 0 -type f -name "*.log" | wc -l


Kent
0
sharschoAuthor Commented:
OK guys, thanks. The first one worked for me because I was looking for the amount of TAR files in a directory. and the TAR extension was in capital letters for all the files. I wanted to the amount of the files in order to be sure if my monthly extract procedure was finished for all the sites involved and it is about 70 sites so counting is not secure. I used wc -l but it was counting the lines within each file and I did not remember that I could combine iwc -l with another command like ls. But I will add your suggestions to my notes for the future. Thanks again!
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.