[ale] Stupid Shell Trick
jeff_hubbs at mcgraw-hill.com
jeff_hubbs at mcgraw-hill.com
Thu Feb 11 14:56:27 EST 1999
Oh, I've been absolutely giddy! After four years of NT experience, it
really fascinates me that I was able to pull off (with considerable
assistance from you guys - especially Mic, whose response wound up being
what I actually used) this arcane little renaming stunt in ONE LINE!!! I
am grateful for your constant-memory suggestion as well - I'm gonna file
your message!
Before I asked for help, I did do a man bash but with no prior bash or UNIX
script experience at all I was quickly snowed under. However, what I saw
in the man gave me the feeling that what I wanted to do was within the
grasp of shell scripting, though I have to say I didn't expect to be able
to do it in one line. This is the sort of thing that makes me feel like
Linux is so incredibly powerful.
BTW, what this is all about is that ever since 1992, I've been carrying
around a 10-1/2" tape from my VAX /VMS days at Robins AFB - through SIX
household moves. I haven't taken particularly good care of the tape,
either. Until my current job I haven't had access to a VMS machine with a
9-track tape drive, so last week I fired up the tape and everything was
still on there - no errors! What I wanted to do was get these files into
my main PC at home so I could write them onto a CD.
The MicroVAX that the tape drive was hooked to could not FTP to anything
else but another VMS machine and vice versa for unknown reasons, so I put
the files back into a single save set file (a little like VMS' version of
tar) and FTPed it to an Alpha. From there, I used WS_FTP on Win95 to get
them into my laptop (it was the only FTP client I had that would recurse).
I had two problems: the text files (including source code) got screwed up
after having FTPed everything as binary, and in Win95 I was left with the
VMS-style semicolon and version number on the end of every filename.
I went through by hand and re-FTPed the text files in ASCII mode, but I
found the semicolon and version number impossible to deal with, so I copied
the whole tree to my Linux server via SMB and did the "stupid shell trick"
over there and pulled all the renamed files back to my laptop where I
zipped them into one file. NOW I get to try to get this 6.5MB file over to
the machine that's got the CD burner!!!
- Jeff
Todd Graham Lewis <tlewis at mindspring.net> on 02/11/99 10:30:35 AM
To: Wandered Inn <esoteric at denali.atlnet.com>
cc: Jeff Hubbs/Tower, Michelangelo Grigni <mic at mathcs.emory.edu>,
ale at ale.org
Subject: Re: [ale] Stupid Shell Trick
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