Archive

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:

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

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

Categories: bash, coding