Xref: utzoo comp.unix.ultrix:2041 comp.unix.questions:17227 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!ginosko!cs.utexas.edu!uunet!mcsun!sunic!dkuug!iesd!iesd!fischer From: fischer@iesd.auc.dk (Lars P. Fischer) Newsgroups: comp.unix.ultrix,comp.unix.questions Subject: Re: Can ls show total Kbytes of "foo*"? Message-ID: Date: 27 Oct 89 04:58:54 GMT References: <2453@umbc3.UMBC.EDU> Sender: news@iesd.auc.dk (UseNet News) Organization: Mathematics and Computer Science, University of Aalborg Lines: 33 In-reply-to: rostamia@umbc3.UMBC.EDU's message of 26 Oct 89 22:26:06 GMT In article <2453@umbc3.UMBC.EDU> rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes: >I wonder if there is an obvious way to compute the total size of all >"foo*" files in a directory. The only way I know how is the ridiculously >complicated construction: > >ls -1s foo* | awk 'BEGIN{size=0} {size += $1} END{print "total: " size}' You don't need the BEGIN part, e.g. ls -1s foo* | awk '{s += $1} END{print "total: " s}' would do the job. What's so ridiculous about that? Instead of making 'ls' support some silly feature, you use general unix tools. As you say, you can easily create a script/alias. If you need the feature often, you could also create a "total" script, taking the col. to sum as an argument, eg. ls -s foo* | total -1 would do the job (compare with "ls foo* | wc -l"). Creating "total" using awk would be very simple. >It stands to reason to expect that the command "ls -s foo*" would provide >the corresponding information for all files "foo*" in the directory. >Alas, it does not work that way; although the size of each "foo*" >is displayed, the total kilobytes for the "foo*" files is not. Yeah, one could imagine the BSD guys making 'ls' do all kind of things, but that's not the way to go. Making 'ls' display a total was a mistake in the first place. You're on a unix system. Use it. -- Lars Fischer, fischer@iesd.auc.dk | Seek error on /dev/brain (core dumped). CS Dept., Univ. of Aalborg, DENMARK. | -- (null)