xargs is probably one of the most useful CLI tools in Unix/Linux.
Many people just forget that xargs can fork processes, to multithread an otherwise slow operation.
If you have a directory full of WAV files you want to encode and a quad core, fork that.
ls *.wav|xargs -n1 -P4 -i lame -h {} {}.mp3
rename ‘s/\.wav//g’ *.mp3
The -P option is for the maximum number of processes. The -n option is to limit to 1 argument per xargs call. The -i option gives us the {} substitution. Xargs will substitute the filename for {}. This means we get an output file called blah.wav.mp3, so I added the Perl utils rename step.
xargs has many uses with forking, and you could probably even use a VAAPI-enabled mencoder to transcode a whole directory of files this way.
Just don’t fork yourself or you’ll go blind.
Until next time!
-LightningCrash
Tags: fork, multithreaded, xargs