home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!howland.reston.ans.net!bogus.sura.net!darwin.sura.net!Sirius.dfn.de!news.DKRZ-Hamburg.DE!regen.DKRZ-Hamburg.DE!m212022
- From: m212022@regen.DKRZ-Hamburg.DE (Wolfgang Welke)
- Subject: Re: How to total file sizes for selected files?
- Message-ID: <1992Dec30.184600.720@news.DKRZ-Hamburg.DE>
- Sender: news@news.DKRZ-Hamburg.DE
- Organization: Deutsches Klimarechenzentrum GmbH, Hamburg
- References: <103335@netnews.upenn.edu> <1992Dec29.144421.23845@news.eng.convex.com> <1992Dec30.083126.26511@ptsfa.PacBell.COM>
- Date: Wed, 30 Dec 92 18:46:00 GMT
- Lines: 43
-
- In article <1992Dec30.083126.26511@ptsfa.PacBell.COM> dmturne@PacBell.COM (Dave Turner) writes:
- >From the keyboard of gasser@eniac.seas.upenn.edu (Nathan Gasser):
- >:I'm wondering how to print the total size for only selected files.
- >:For example, "du" gives the total space occupied by all files in
- >:this directory. I want only those files, say, that end in .zip.
- >:
- >:% du
- >:. 2883
- >:
- >:% du -s *.zip
- >:123 file1.zip
- >:188 arc2.zip
- >:13 game.zip
- >:
- >:See, what I want is for the above example to print the total
- >:space for the .zip files, ie. 324.
- >
- >Assuming find -ls output resembling this:
- >
- >(inum block mode links user group bytes mtime name)
- > 38976 544 -rw-rw-r-- 1 tchrist swtools 531409 Dec 15 1989 ./etc/hosts
- >
- >You might try wc:
- >
- > wc -c *.zip | sed -n '$p'
- >--
- >Dave Turner (510) 823-2001 {att,bellcore,sun,ames,decwrl}!pacbell!dmturne
-
- There are reasons not to use 'wc':
- Files are read by wc, whereas du uses directory information.
- On systems with some data migration facility it's even worse,
- because wc causes files to be reloaded from the backup system
- (i.e. tapes).
- If du wants to summarize directories, why not give it one?
-
- mkdir temporary
- ln *.zip temporary
- du temporary
- rm temporary/*
- du temporary
-
- The second du gives the size of the directory without files
- (usually one, if there are not too many *.zip files)
-