Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.questions Subject: Re: What's wrong with this Bourne shell script? Message-ID: <9116@jpl-devvax.JPL.NASA.GOV> Date: 11 Aug 90 18:55:52 GMT References: <1990Aug3.193231.3166@silma.com> <1990Aug6.172225.20319@iwarp.intel.com> <850@jonlab.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 31 In article <850@jonlab.UUCP> jon@jonlab.UUCP (Jon H. LaBadie) writes: : In article <1990Aug6.172225.20319@iwarp.intel.com>, merlyn@iwarp.intel.com (Randal Schwartz) writes: : > In article <1990Aug3.193231.3166@silma.com>, aab@silma (Andy Burgess) writes: : > | While you're at it, is there a better way to get the total bytes : > | of the files in a directory? : > : > PERL SCRIPT DELETED : : A script of mine called "addcol" was printed in UNIX World's monthly : column Wizard's Grabbag and would do the same thing without perl; : : ls -ld | addcol -4 : : However, have we forgotten our roots? I'm surprised in this thread : that no one has mentioned: : : TOTAL=`cat * | wc -c` Let us be explicit about the advantages and disadvantages of these approaches. Any naive approach using ls is gonna screw up in /dev, and probably does the opposite of what you want on symbolic links. The cat approach has to read all the bytes (try it on a swapfile), but probably does what you want on symbolic links. It may or may not do what you want on files with holes in them. It doesn't do what you want with the last access times. It CERTAINLY doesn't do what you want in /dev, or in a directory containing a FIFO or a Unix domain socket. The stat structure in C is quite straightforward by comparison. Pity there's such a big ecological niche between shell and C... Larry