#!/bin/bash
# ordnergewicht.sh is a wrapper for "ls"
# (c) 2006, 2008 by Lukas Gantert, GPL
# 20090610 added: number of symlinks
# Synopsis: ordnergewicht [ Pfad | File ]
# Bugs: - Verzeichnis- und Datei-Namen, die auf ":" enden,
# werden ignoriert, ...
[ $# = 0 ] && echo "$(basename $0): Pfad oder Datei angeben!" && exit
tmpfile=/tmp/ordnergewicht$$
ls -lRAsp -- "$1" | grep -Ev -- '^$|\:$' > $tmpfile
awk < $tmpfile '
{ sum1 += $1 }
{ sum2 += $6 }
END { printf "%14g block(s)\n%14g byte(s)\n", sum1, sum2 }
'
n_dirs=$(grep -c -- '\/$' $tmpfile)
n_slinks=$(grep -c -- '->' $tmpfile)
n_files=$(($(grep -Evc -- '^total |\/$' $tmpfile) - $n_dirs - $n_slinks -1 ))
printf "%14g directorie(s)\n%14g file(s)\n%14g symlink(s)\n" \
"$n_dirs" "$n_files" "$n_slinks"
rm $tmpfile