Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-25
6
Medium Priority
?
1,803 Views
Last Modified: 2013-12-06
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.
0
Comment
Question by:sharscho
  • 3
  • 2
6 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16534553
Hi sharscho,

  ls | wc -l

Good Luck!
Kent
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 16534560
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
 

Author Comment

by:sharscho
ID: 16534588
Ok Kent, I did not know it was so easy. It worked. I will have to remember this.
Thanks alot.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:ravenpl
ID: 16534898
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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16535081
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
 

Author Comment

by:sharscho
ID: 16536577
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

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question