Show sum of file sizes in directory listing

There's already a UNIX command for this: du

Just do:

du -ach 

As per convention you can add one or more file or directory paths at the end of the command. -h is an extension to convert the size into a human-friendly format, -a gives you the "apparent" size (file size instead of disk usage), and -c gives a total at the end.


The following function does most of what you're asking for:

dir () { ls -FaGl "${@}" | awk '{ total += $4; print }; END { print total }'; }

... but it won't give you what you're asking for from dir -R *.jpg *.tif, because that's not how ls -R works. You might want to play around with the find utility for that.


You can use du -h -c directory|tail -1

This will generate a single line with memory usage.