Archive for March, 2017

Summing up numeric values using bash

March 22, 2017 Leave a comment

For example to add up the disk usage at several disjoint locations:

me@box$ numfmt --to=iec $[$(du -s /home/*/docs | cut -f 1 | paste -sd+)]

The $[..] is for arithmetic evaluation in bash.
Alternatively pipe to the bc command.

Categories: bash, coding