Operating System - HP-UX
1833322 Members
2932 Online
110051 Solutions
New Discussion

Re: Find No. of files in a filesystem

 
david_252
Frequent Advisor

Find No. of files in a filesystem

Hi:

How do i find the no. of files in a filesystem?

Thanks
David.
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Find No. of files in a filesystem

Hi David:

How about:

# cd
# find . -type f -print|wc -l

Regards!

...JRF...
Sridhar Bhaskarla
Honored Contributor

Re: Find No. of files in a filesystem

Hi David,

You can use df -i and take a note of used i-nodes.

df -i /file_system |grep used i-nodes

Hardway is

find /file_system |wc -l

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
S.K. Chan
Honored Contributor

Re: Find No. of files in a filesystem

or ..

# ls -lR|grep \^-|wc -l
Govind
Frequent Advisor

Re: Find No. of files in a filesystem

Try "df -g" that gives the entire info about the filesystem you want and it gets this from the statvfs. It is much faster than anyother commands. As a Inode is allocated to each File the "total number allocated free inodes" lets you know how many files are there in the file system.
Goodluck
Govind
Dont try to fix something till it Aint Broke...Honesty is not always the best policy.....
Jose Mosquera
Honored Contributor

Re: Find No. of files in a filesystem

Hi,

#cd /
#find . -xdev -type f|wc -l

the -xdev keeps the search within the wanted FS and avoid scan in any other possible mounted FS inside of .

If you need include directories as file counter, pls omit "-type f" option.

Rgds
Patrick Wallek
Honored Contributor

Re: Find No. of files in a filesystem

It seems to me that all the solutions so far have holes in them. JRF's will not take into account whether or not a file system has filesystem mounted below it. To solve that problem you could use:

# find /filesystem -type f -xdev | wc -l

The solutions using 'df' will tell you the number of inodes used, but you have to remember that a directory, which is really a different type of file, also uses an inode. So if you just want 'files' then the df output will be misleading.

Take the following example on one of my machines.

# find / -type f -print | wc -l
91269
This found ALL files on the system, including those in /var, /usr, /tmp, etc.

Now this:

# find / -type f -xdev -print | wc -l
740
Found just files in /, and not any of the mounted filesystems.

# df -i
...excerpt....
2436 used inodes

That number is pretty close to the number of files and directories in /.

# find / -xdev | wc -l
2475

So, I think your best bet, be it a bit slow maybe, is

# find /filesystem_name -xdev -print | wc -l

Giri Sekar.
Trusted Contributor

Re: Find No. of files in a filesystem

Hi:

You can also do df -t and look at used inodes.

Thanks

Giri Sekar.
"USL" Unix as Second Language
James R. Ferguson
Acclaimed Contributor

Re: Find No. of files in a filesystem

HI (again) David:

Jose and Patrick are correct. One should add '-xdef' to the find criteria to avoid crossing mountpoints.

Regards!

...JRF...