Number of files in a directory?

Conor P. Cahill cpcahil at virtech.uucp
Sun May 19 21:17:27 AEST 1991


mikeh at fsd.cpsc.ucalgary.ca (Michael Hoffos) writes:


>Dumb question time.  I have been using UNIX for many years, but I have
>never figured out how to do something: how can you get the number of
>files that are in a directory?  This would be really handy for figuring

The following will always work:

	for a single directory:		ls -a | wc -l
	for a directory hierarchy:	find [dirname] -print | wc -l

If on a v7 style filesystem you can get the size of the directory and
divide it by 16, but that only works on a single directory,  is non-portable
and definately doesn't work for BSD style file systems.

>out how efficient a backup was (you need the number of files backed-up in
>order to figure in the header info tar adds for each file).

A better way to do this is to run a tar -tv of the tape and use the
number of lines to figure the number of entries, use the size of 
each item to calculate the minimum amount of tape space that would
be required.  Then all you need is the size of the tar header and
the blocking factor (also provided by the tar  -tv) and you should be
able to determine the efficiency of the backup with respect to 
tape file size.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.questions mailing list