[ale] Stupid Shell Trick

Todd Graham Lewis tlewis at mindspring.net
Thu Feb 11 10:30:35 EST 1999


On Wed, 10 Feb 1999, Wandered Inn wrote:

> for f in $(find . -name '*\;*' -print); do mv -i "$f" "${f%;*}"; done

This consumes an amount of memory proportional to the size of the
directory tree.  To do it in constant space, do the following:

# find . -name '*\;*' -print | while read f
while> do 
while> mv -i "$f" "${f%;*}"
while> done

When you start dealing with really big directory trees, you start thinking
about stuff like this.

Incidentally, I am not sure which shells support the ${foo%bar} and
${foo#bar} syntax, but I know that zsh does.  Ah, ok, bash does too.
I still remember when Drew Hobson showed me that trick and how amazed
I was that the shell could do substitution like that.

--
Todd Graham Lewis            32°49'N,83°36'W          (800) 719-4664, x2804
******Linux******         MindSpring Enterprises      tlewis at mindspring.net

"A pint of sweat will save a gallon of blood."          -- George S. Patton






More information about the Ale mailing list