Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: lssum - summing up sizes of files



On Jun 13,  6:10pm, Sven Guckes wrote:
} Subject: lssum - summing up sizes of files
}
} Does anyone have a nice and small function to sum up the sizes of files?
} I just hope this isn't a standard example in the zsh manuals - yet.
} but I think it should be.  ;-)

The manual is woefully short of examples; it's almost exclusively limited
to descriptive text.

In any case, in 3.1.4 with the "stat" module loaded, you can do it with

    sumsizes() {
        local sum sizes i
	stat -A sizes +size $*
	sum=0; for i in $sizes; ((sum += i))
	print sum
    }

E.g.
	sumsizes **/*.o

Replace +size with +block if you want the actual disk block usage.

In 3.0, there's no direct way to read the size of the file into the shell.
You'd have to run "ls" and parse the output, or something.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author