On Mon, Mar 04, 2013 at 12:54:49PM +0100, Paul de Weerd wrote:

> On Mon, Mar 04, 2013 at 12:32:32PM +0100, Paolo Aglialoro wrote:
> | Great one!
> | How to put that nice expression into an alias without console complaining
> | when executed?
> | 
> | 
> | # ls -l | awk '{ SUM += $5 } END { print SUM }'
> | 569047
> | 
> | # alias tot="ls -l | awk '{ SUM += $5 } END { print SUM }'"
> | # tot
> | awk: syntax error at source line 1
> |  context is
> |         { SUM +=  >>>  } <<<
> | awk: illegal statement at source line 1
> 
> Escape the "$" in the awk expression:
> 
> [weerd@despair] $ alias tot="ls -l | awk '{SUM+=\$5} END {print SUM}'"
> [weerd@despair] $ tot
> 207777
> 
> I still wonder why people want to know this (seemingly useless) value.
> What does it even mean ?
> 
> [weerd@despair] $ mkdir /tmp/test
> [weerd@despair] $ cd /tmp/test
> [weerd@despair] $ dd if=/dev/zero of=a bs=1024 seek=2048 count=1
> 1+0 records in
> 1+0 records out
> 1024 bytes transferred in 0.000 secs (34133333 bytes/sec)
> [weerd@despair] $ ln a b
> [weerd@despair] $ ls -l
> total 128
> -rw-r--r--  2 weerd  wheel  2098176 Mar  4 12:49 a
> -rw-r--r--  2 weerd  wheel  2098176 Mar  4 12:49 b
> [weerd@despair] $ tot
> 4196352
> [weerd@despair] $ du -csh a b
> 32.0K   a
> 32.0K   total
> 
> 
> (note the lie ls(1) spreads here)
> 
> | Btw, for higher readability, it would also be great to put periods in the
> | resulting output like: 1.264.691
> 
> Well, that should be easy enough to add yourself :)  Left as an
> exercise to the reader...
> 
> Cheers,
> 
> Paul 'WEiRD' de Weerd

But remember, file size and disk usage are two different things,

        -Otto

Reply via email to