Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!samsung!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: Number of files in a directory? Message-ID: <1991May19.111727.18637@virtech.uucp> Date: 19 May 91 11:17:27 GMT References: <1991May19.034308.9149@cpsc.ucalgary.ca> Organization: Virtual Technologies Inc. Lines: 31 mikeh@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