Note that in -v var=value, awk will expand ANSI C sequences as \n, \r... While shells do export PWD, so you can use ENVIRON["PWD"] in awk which doesn't have that kind of problem for directories having backslashes in their name.
–
Stéphane ChazelasFeb 2 '13 at 17:58

If you just need the average size in bytes, you can use find . -type f -exec stat -f%z {} +|awk '{s+=$0}END{print s/NR}'.
–
ؘؘؘؘApr 29 '14 at 8:55

nice. Just add -k to du invocation to have the result in 1024bytes (kb) instead of 512bytes (default size of a file chunk).
–
Olivier DulacFeb 1 '13 at 16:30

2

du -s will add up the disk usage (not size) of all the files and directories and other non-regular files, excluding extra hard links to the same file, while find will count all the regular files. Also, filenames with newline characters will be counted several times. du -S is GNU specific. du -s will report sectors or kilobytes depending on the OS.
–
Stéphane ChazelasFeb 1 '13 at 17:20

As usual @StephaneChazelas your knowledge of linux/unix astounds me and shows me how dirty my quick and dirty solutions are. How long have you been using linux/unix?
–
Drake ClarrisFeb 1 '13 at 18:14

Answer is horribly wrong and should be deleted. Explained by Stephane.
–
A-B-BMay 16 '14 at 20:57