spreading work across all cores
credit where credit is due: I adapted this from:
https://bbs.archlinux.org/viewtopic.php?id=92290
I've made the framework generic, so all you need to do is replace the "work" portion to do whatever particular work on a file.
#!/bin/bash -f
# the number of cores you have on your system
cores=`grep -c ^processor /proc/cpuinfo`
process() {
for file; do
# begin replace ----------------------------
#whatever you want done on all files. example:
fileout=$(echo "$file" | sed s'/.wav//')
lame -V 2 "$file" "$fileout".mp3;
# end replace ----------------------------
done
}
export -f process
# by default works on all files in or under the current directory which match the provided argument
find . -name $* -print0 | xargs -0 -n 1 -P $cores bash -c 'process "$@"' --
Put the above in a file, say, "forall". Then run:
chmod 755 forall
Then you can run:
forall *.wav
...and forall will run lame on all the *.wav files under the current directory.