Home > Perl, Unix > How big is you MP3 collection all over your hard drives ?

How big is you MP3 collection all over your hard drives ?

December 17th, 2008 Leave a comment Go to comments

You want to know the total size of all your .mp3 files ? (or any kind of file, juste change the locate argument)

Try :

locate .mp3 | perl -e 'while(<STDIN>) { chop ; $tsize += -s $_; } print $tsize/1048576 . "Mo\n"'

or

locate .mp3 | perl -e 'foreach (<>) { chop and $_["+"]+=-s$_ } print $_["+"]/1048576 . "Mo\n"'

or if you didn’t have perl (sorry for you ;))

locate .mp3 | awk '{print "\"" $0 "\""}' | xargs ls -l | awk 'BEGIN{s=0}{s+=($5/1024/1024)}END{print s "Mo"}'
Categories: Perl, Unix Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.