cock and balls command lines
January 24 2004 10:40 PM

a manager i used to work for often referred to overly concise shell/perl scripts as "cock and balls scripts". well i recently had the chance to pull together a unix command line that would have impressed him.

it all started with a few dozen TIFF files with no extension. writing a command line to fix this was not hard:

find . -exec bash -c "mv {} {}.tif" \;

a couple hours later, while in the root of my home directory, i decide to rapidly scroll up to find a long command line i had used and didn't feel like retyping (i think it was an ssh tunnel thing) - well, i scrolled a bit too far and hit enter. i landed on the above command line. now all my files in my home directory had the .tiff extension.

on a mac this is particularly bad. there is a Library directory where preferences and mail and other nice to have safe things are kept. well, mine was now called Library.tiff. all of the sudden my dock wouldn't show up, mail.app went into conniptions, and other weird things.

back to the command line. to get everything back to normal i came up with this doozy:

find . -name "*.tif" -exec bash -c "mv {} \`echo {} | sed s/.tif//\`" \;

from now on i'll try to use the -ok option in place of -exec.

Comments (0), Add Comment