Operating System - HP-UX
1834628 Members
3198 Online
110069 Solutions
New Discussion

Count number of files command

 
SOLVED
Go to solution
someone_4
Honored Contributor

Count number of files command

I have a dir /var/sendmail
this is where all the sendmail user files are stored. I is there a count command that I can run that tells me how many files i have in that dir ?
10 REPLIES 10
Pedro Sousa
Honored Contributor

Re: Count number of files command

Hi!
Try:
ll /var/sendmail|wc -l
A. Clay Stephenson
Acclaimed Contributor

Re: Count number of files command

This should be close
cd /var/sendmail
find . -type f | wc -l
If it ain't broke, I can fix that.
Volker Borowski
Honored Contributor

Re: Count number of files command

Hi,

find . | nl | tail -n 1 | awk '{ print $1 }'

should do it. I do not know if there is an upper limit for the "nl" program. This might be the only problem.

Volker
Victor BERRIDGE
Honored Contributor

Re: Count number of files command

Hi,
Try ll?wc -l
But if you think you have so many , you will not be able to count them like that (exeeds ....) you will have to use xargs also

Good luck

Victor
Pedro Sousa
Honored Contributor

Re: Count number of files command

Maybe ls /var/sendmail |wc -l is better because it wont count the "Total" line.
someone_4
Honored Contributor

Re: Count number of files command

#ll /var/mail |wc -l
sits there
# find . -type f | wc -l
Gives me 989
# find . | nl | tail -n 1 | awk '{ print $1 }'
Gives me 996
# wc -l
sits there
# ls /var/mail |wc -l
Gives me 967
-------------
Why am I getting a differnt count every time? maybe one is counting a sub dir and the files in the sub dir?
A. Clay Stephenson
Acclaimed Contributor

Re: Count number of files command

the find -type f command just lists regular files; not directories, pipes, etc.
If it ain't broke, I can fix that.
Joseph C. Denman
Honored Contributor

Re: Count number of files command

I feel sure the find command is giving you the desired result. ...only the files...

...jcd...
If I had only read the instructions first??
someone_4
Honored Contributor

Re: Count number of files command

What if I only want a count of the files not owned by root ?
Jim Moffitt_1
Valued Contributor
Solution

Re: Count number of files command

cd /var/sendmail
find . -type f ! -user root| wc -l

This should work.