Thursday, September 6, 2007

Newsflash: find does printf

Maybe it's not news to you that find has a printf action, but I learned my Unix from a printed copy of an early version of AT&T's Programmers Workbench I bought at a flea market over <gulp> twenty years ago. "Bought for free" -- the seller didn't have a clue what it was and was happy to free up the four inches of shelf space. I read the commands for sections 1, 2, 3, and 8 practically from cover to cover. This came in very handy when I was transferring files between Suns and SCO boxes in the early 90s (way before SCO became vilified) using the venerable cpio command.

The hard copy was way better than reading man pages on 80x24 monochrome terminals. But the disadvantage of learning so much early on was that I rarely used man commands to look them up, and didn't discover new additions. So there was an email discussion going on at work on a build issue, and the sys admin mentioned a command along the lines of this:
find dir -name '*.foo' printf "mkdir -p ../../target/%h ; cp %p ../../other-dir/%h\n" | sh
Next time I'm about to write a command like
for i in `find` ; do
...
done
I'm going to try using the printf ... | sh combination instead. Not on OS X, you say? Pity.

No comments: