Posted on 08/15/2014 4:37:21 AM PDT by ShadowAce
Here's a fun trick for linuxers....
#!/usr/bin/bash if [ "$1" == "" -o "$2" == "" ] then echo "Syntax:" echo "$0 extension path" exit fi ls -lR $2 | grep \\.$1 | awk '{ total += $5 } END { print total }'
What does it do? It accepts one arguments. The first argument is a file extension. The second is a directory name. If you want it to start from the directory you are in, use ".".
This script will start in the directory specified and will find all files with that extension, add up all the file sizes, then print a total for that file type.
$ columnsum mp3 /home/av/music/bluegrass/ 1500935414 $ columnsum mp3 . 488423164
Yeah, it's been a while since I've been to that site, but I recall it having some really cool one liners.
I actually used that very simple script to teach some of the basics of life in the shell to a nephew. It was originally exactly 1 line that was hardcoded to look for and total up mp3 files. We first made it look for any type of file extension, which is actually trickier than you'd think because you have to escape the "." or you'll get false positives. Then we made it take a path for input. Lastly, put some checking to make sure you had two arguments. Was kinda cool. Very simple, but he was easily able to understand it. The idea I was trying to show was how to take something that did one thing and make it more general.
Disclaimer: Opinions posted on Free Republic are those of the individual posters and do not necessarily represent the opinion of Free Republic or its management. All materials posted herein are protected by copyright law and the exemption for fair use of copyrighted works.