...making Linux just a little more fun!

2-Cent Tips

2 cent tip: Guide to Ubuntu on the Intel Apple iMac

Peter Knaggs [peter.knaggs at gmail.com]

Thu, 12 Jul 2007 21:41:01 -0700

I've been gathering together all the hardware setup info needed to get Ubuntu working (surprisingly well) with the Intel Apple iMac


There's not much original work on that page, but at least having all the hardware setup info one place is handy, so I thought I'd post it as a 2 cent tip.

2-cent tip: Summing up file sizes

Ben Okopnik [ben at linuxgazette.net]

Thu, 12 Jul 2007 16:32:00 -0400

I just got an iPod Shuffle, and am about to load it up with my favorite tunes; however, I didn't want to dink around with multiple reloads of the song list if it was too big. Since flash devices only have so many write cycles before they start losing their little brains, minimizing writes is a Good Thing. So, I needed to figure out the total size of the files in my M3U playlist - and given the kind of questions that often come up in my shell scripting classes and on LG's Answer Gang lists, I thought that our readers would find some of these techniques (as well as the script itself) useful. Herewith, the "m3u_size" script. Enjoy!

# Created by Ben Okopnik on Thu Jul 12 15:27:45 EDT 2007
# Exit with usage message unless specified file exists and is readable
[ -r "$1" ] || { printf "Usage: ${0##*/} <file.m3u>\n"; exit; }
# For the purposes of the loop, ignore spaces in filenames
# Get the file size and sum it up
for n in `cat "$1"`; do s=`ls -l "$n" | cut -d ' ' -f 5`; ((total+=$s)); done
# Restore the IFS
# Define G, M, and k
Gb=$((1024**3)); Mb=$((1024**2)); kb=1024
# Calculate the number of G+M+k+bytes in file list
echo "Total: $total (${G}G ${M}M ${k}k ${b}b)"
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

[ Thread continues here (13 messages/20.54kB) ]

Talkback: Discuss this article with The Answer Gang

Copyright © 2007, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 141 of Linux Gazette, August 2007