Operating System - HP-UX
1829012 Members
2288 Online
109986 Solutions
New Discussion

Counting number of files into a directory

 
Miguel Cuesta
Advisor

Counting number of files into a directory

Hi!

I do not remember the way to count the number of files and subfolders stored into the same directory.

Could anybody help me?
8 REPLIES 8
Andreas Voss
Honored Contributor

Re: Counting number of files into a directory

Hi,

you can use this:

find | wc -l

or for files only:

find -type f |wc -l

or for subdirs only:

find -type d |wc -l

Regards
Mike_21
Frequent Advisor

Re: Counting number of files into a directory

I would try ls|wc...........
harry d brown jr
Honored Contributor

Re: Counting number of files into a directory


go to the directory and use this for counting regular files:

find . -type f | wc -l

and this for counting directories:

find . -type d | wc -l
Live Free or Die
James R. Ferguson
Acclaimed Contributor

Re: Counting number of files into a directory

Hi:

One way is this:

For files:

# ls -lR mydir|grep ^-|wc -l

For directories:

# ls -lR /tmp|grep ^d|wc -l

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Counting number of files into a directory

Hi (again):

Sorry, the uniform example I meant used "mydir" in both cases!

One way is this:

For files:

# ls -lR mydir|grep ^-|wc -l

For directories:

# ls -lR mydir|grep ^d|wc -l

...JRF...
Ravi_8
Honored Contributor

Re: Counting number of files into a directory

Hi,
#find . -type f |wc -l

gives you the no. of files existing in the present directory.
never give up
Edgar Matzinger
Advisor

Re: Counting number of files into a directory

Hi Miguel,

how about "cd ; find . -print | wc -l"? You have to substract one for the current directory. This counts all the entries in the entire directory-tree. If you only want a single level (no recursion), do "cd ; ls -A | wc -l".

HTH, Edgar.
MANOJ SRIVASTAVA
Honored Contributor

Re: Counting number of files into a directory

Hi Miguel Cuesta

Try this

find . -depth -print | wc -l


Manoj Srivastava