[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Stupid Shell Trick
- Subject: [ale] Stupid Shell Trick
- From: tlewis at mindspring.net (Todd Graham Lewis)
- Date: Thu, 11 Feb 1999 10:30:35 -0500 (EST)
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