Linux.com

CLI Magic: For geek cred, try these one-liners

Posted by: Anonymous [ip: 216.241.105.6] on July 23, 2008 03:52 PM
Recently, I had to convert a bunch of files image files (137,000 total) from JPG to GIF and reduce colors to 8.

This is what I came up with:
for file in $(ls *.jpg) ; do convert -verbose -colors 8 ${file} ${file%.jpg}.gif ; done

8 hours later, it was done.

Next I had to convert a bunch of WAV files to MP3s and set the bit rate to 32. (all in multiple directories).

for DIR in $(ls -1) ; do for FILE in $(ls -1 ${DIR}/*.wav); do lame -b 32 "${FILE}" "${FILE%.wav}.mp3" ; done ; done

Remember loops for anything you have to do more than once.

#

Return to CLI Magic: For geek cred, try these one-liners