Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!sdd.hp.com!news.cs.indiana.edu!ux1.cso.uiuc.edu!phil From: phil@ux1.cso.uiuc.edu (Phil Howard KA9WGN) Newsgroups: comp.unix.questions Subject: Re: Number of files in a directory? Message-ID: <1991May19.060736.26323@ux1.cso.uiuc.edu> Date: 19 May 91 06:07:36 GMT References: <1991May19.034308.9149@cpsc.ucalgary.ca> Organization: University of Illinois at Urbana Lines: 30 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 >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). Since you mention tar, I figure you also want to include all the files in all the subdirectories, the subdirectories themselves, and symlinks. find . -print | wc -l However, this might still be misleading in the case of making an estimate for tar when you have hard links. The tar program detects the hard link and writes out which file it is linked to, not the whole file. I am not sure how much space that will take. Of course the ULTIMATE estimate is: tar (appropriate options) | wc -c but that gets to be time consuming and wasteful. In cases where I really needed this I found it faster to write the file to disk instead (if there is space) and check the length of the file. It seems "wc" is slow. -- /***************************************************************************\ / Phil Howard -- KA9WGN -- phil@ux1.cso.uiuc.edu | Guns don't aim guns at \ \ Lietuva laisva -- Brivu Latviju -- Eesti vabaks | people; CRIMINALS do!! / \***************************************************************************/