euglug.org

[Eug-lug] size of files from a shell script, portably

작성자

카테고리:



Jacob MeuserThu Dec 9 14:21:01 PST 2004

On Thu, Dec 09, 2004 at 09:29:23AM -0800, Bob Miller wrote:
> Jacob Meuser wrote:
> 
> > well, I didn't know about wc -c, thanks.  however, the output,
> > at least on my system, is not easily parsable, as it is oddly
> > aligned, with varying amounts of space.
> 
> If you use "wc -c < file" instead of "wc -c file" then wc
> doesn't print the file name.

ah, nice.  I was worried about the leading spaces as well, but printf
seems to take care of that:

$ tb=0; for i in *; do b=`wc -c < $i`; b=`printf "%d" $b`; \
tb=`expr $tb + $b`; done; echo $tb

-- 
<jakemsr at jakemsr.com>