Operating System - HP-UX
1820271 Members
3553 Online
109622 Solutions
New Discussion юеВ

Re: How to Calculate number of files under filesystem

 
ramkumar
Valued Contributor

How to Calculate number of files under filesystem

Hi all
can anybody tell how to calculate the total number of files under a filesystem .
20 REPLIES 20
Sudeesh
Respected Contributor

Re: How to Calculate number of files under filesystem

du -x /usr | wc -l

will give you total numeber of files on device /usr.


Sudeesh
The most predictable thing in life is its unpredictability
ramkumar
Valued Contributor

Re: How to Calculate number of files under filesystem

hi Sudeesh
this will not do . du -x will give you the size not the number of files . please go through man page of du .


ram
Rajeev  Shukla
Honored Contributor

Re: How to Calculate number of files under filesystem

To find the number of files in a directory, cd to that directory and do
ll |wc -l

the number of files is one less than the returned value

cheers
Rajeev
Sudeesh
Respected Contributor

Re: How to Calculate number of files under filesystem

pls see the wc -l at the end sfter pipe


Sudeesh
The most predictable thing in life is its unpredictability
Sudeesh
Respected Contributor

Re: How to Calculate number of files under filesystem

small spelling mistake in previous post change it to 'after' pls.....

[rx260-11]/ >du -x /usr | wc -l
1388
[rx260-11]/ >


Sudeesh

The most predictable thing in life is its unpredictability
Alex Lavrov.
Honored Contributor

Re: How to Calculate number of files under filesystem

Simpliest way to do this:


find . | wc -l


Just lists all the files under all directories and then counts the output.


Regards.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
renarios
Trusted Contributor

Re: How to Calculate number of files under filesystem

A find . would also count all directories. I would try:
find . -xdev -type f | wc -l
This will give a count off all files on the local filesystem.

Cheerio,

Renarios
Nothing is more successfull as failure
Muthukumar_5
Honored Contributor

Re: How to Calculate number of files under filesystem

You can get files count under specific file system with -xdev option on find command.

find -xdev -type f | wc -l

Get the file system patch with bdf command.

HTH.
Easy to suggest when don't know about the problem!
Steve Post
Trusted Contributor

Re: How to Calculate number of files under filesystem

find . -print | wc -l

Directories are files too. That is unless you don't feel like counting them. Otherwise this would work.

Let's break it down.
find . <--means find everything in this directory and below. So you would want to be at the top of the filesystem.

"-print" outputs what the find command finds.

wc -l <--this counts the lines from what goes into it. The find command spits out one file per line. So by counting the lines, you are counting the files.

"-xdev" ? I never heard of this. It's not in the man page for the find I have. But I'm using hpux11.0. Perhaps that's in BSD, Linux, AIX, or HPUX11i.

One last gocha....
You have two filesystems.

/disk1 and /disk1/a/b.
The filesystem mounted to /disk1/a/b is a filesystem of it's own. Should it be counted in the total of files for /disk1? No I don't think so. It is its own filesystem. So the total files on /disk1 are the total files found on /disk1 minus the total files found in /disk1/a/b. Do you have this case? Everybody has this case.

/opt is mounted to the / filesystem.
/var is too.
hey...just about everything is.
So how many files are in in root (/)?

Run bdf to see what filesystems are mounted to the system.


Alex Lavrov.
Honored Contributor

Re: How to Calculate number of files under filesystem

Well, I have both, 11.11 and 11.00 and there is "-xdev" on both of them.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Steve Post
Trusted Contributor

Re: How to Calculate number of files under filesystem

that's great.
what is it?
Steve Post
Trusted Contributor

Re: How to Calculate number of files under filesystem

AH! Nevermind.
I just had to run the man on a more recent hpux box.

It tells find to avoid crossing into filesystem mount points. That's what I was just talking about. So that means you CAN run "find / -xdev -print | wc -l" to get just the files under the ROOT filesystem.
NICE!
Alex Lavrov.
Honored Contributor

Re: How to Calculate number of files under filesystem

From man:

-xdev A position-independent term that causes find
to avoid crossing any file system mount
points that exist below starting points
enumerated in pathname_list. The mount point
itself is visited, but entries below the
mount point are not. Always true.

I don't give a damn for a man that can only spell a word one way. (M. Twain)
Steve Post
Trusted Contributor

Re: How to Calculate number of files under filesystem

Thank you Alex.
Sorry I was so short (in text).

Steve Post
Leif Halvarsson_2
Honored Contributor

Re: How to Calculate number of files under filesystem

Hi,
A "fast" method is du -i (see man pages for du). It actually reports number of used inodes.
john korterman
Honored Contributor

Re: How to Calculate number of files under filesystem

Hi,
you could just execute
# bdf -i
with or without a mount point as argument. The number of files under a filesystem should be equivalent to the number of i-nodes used (iused).

regards,
John K.
it would be nice if you always got a second chance
V. Nyga
Honored Contributor

Re: How to Calculate number of files under filesystem

@Steve:

from 'man find' (btw. from 11.0):

-xdev
A position-independent term that causes find
to avoid crossing any file system mount
points that exist below starting points
enumerated in pathname_list. The mount point
itself is visited, but entries below the
mount point are not. Always true.

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Alex Lavrov.
Honored Contributor

Re: How to Calculate number of files under filesystem

Btw, ramkumar, you got here almost every possible way to count files in the directory, so it will be very nice to assign points to the answers that helped you the most ;-)

Alex.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Leif Halvarsson_2
Honored Contributor

Re: How to Calculate number of files under filesystem

Hi,
Sorry, my previous reply was wrong. It should (of course) be "df -i" not "du -i".
Sandman!
Honored Contributor

Re: How to Calculate number of files under filesystem

simplest to do would be...

# find -type f | wc -l