rostamia@umbc3.UMBC.EDU (Rouben Rostamian) (10/27/89)
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}' (which I alias to something.) I run ULTRIX. The command "ls -s" in ULTRIX lists the files in the current directory, gives the size of each file in kilobytes, and also gives the total kilobytes for the files in that directory. 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. Am I missing something obvious? -- Rouben Rostamian Phone: 301 455-2458 Department of Mathematics e-mail: University of Maryland Baltimore County rostamian@umbc.bitnet Baltimore, MD 21228 rostamian@umbc3.umbc.edu
fischer@iesd.auc.dk (Lars P. Fischer) (10/27/89)
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)
madd@world.std.com (jim frost) (10/27/89)
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}' [...] |Am I missing something obvious? Yes. You could just do "wc -c foo* | tail -1". If you don't do the tail it will display the size of each followed by a summary line; with it you get just the summary line or -- if there's only one file -- just the size. jim frost software tool & die "The World" Public Access Unix for the '90s madd@std.com +1 617-739-WRLD 24hrs {3,12,24}00bps
brian@cvl.umd.edu (Brian Miller) (10/28/89)
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}'
Assuming everything equal (what am I saying...this is Unix), this
might work (at least it does for me)...
cat foo* | wc -c
Any typos are the responsibility of my cat.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Has anyone seen my old friend brain?
University of Merryland, Center for Automation Research
-A nice place to live, but I wouldn't want to work there.
envbvs@epb2.lbl.gov (Brian V. Smith) (10/28/89)
In article <1989Oct27.130914.12943@world.std.com>, madd@world.std.com (jim frost) writes: < 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}' < [...] < |Am I missing something obvious? < < Yes. You could just do "wc -c foo* | tail -1". If you don't do the < tail it will display the size of each followed by a summary line; with < it you get just the summary line or -- if there's only one file -- < just the size. Try that on some LARGE files and you will quickly (slowly) see that "wc" is much slower than the "ls." _____________________________________ Brian V. Smith (bvsmith@lbl.gov) Lawrence Berkeley Laboratory I don't speak for LBL, these non-opinions are all mine.