From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24896 invoked from network); 18 Apr 1998 18:27:24 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 18 Apr 1998 18:27:24 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id OAA16142; Sat, 18 Apr 1998 14:08:46 -0400 (EDT) Resent-Date: Sat, 18 Apr 1998 14:08:18 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980418110803.ZM4082@candle.brasslantern.com> Date: Sat, 18 Apr 1998 11:08:03 -0700 In-Reply-To: <199804180936.JAA08808@dal-tsa19-60.cyberramp.net> Comments: In reply to TGAPE! "Re: backing up with zsh" (Apr 18, 9:36am) References: <199804180936.JAA08808@dal-tsa19-60.cyberramp.net> X-Mailer: Z-Mail (4.0b.820 20aug96) To: TGAPE! , zsh-users@math.gatech.edu Subject: Re: backing up with zsh MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"hEQLg.0.gx3.HmEEr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1473 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Apr 18, 9:36am, TGAPE! wrote: } Subject: Re: backing up with zsh } } ~/.P;for x in **/*(D) } do } if [ $x != ${x#pics} && $(file $x | grep -c picture) -gt 0 ]; then } n=pics/${x##*/} } ln $x $n } for y in **/*(D.) } do } sed "s@$x@$n@g" $y > /tmp/nopics.$$ } mv /tmp/nopics.$$ $y } done } rm $x } fi } done } } should go a long way to moving all your pictures and fixing your links. Various remarks: Using ~/.P; like that only works if autocd is set. What's the reason for including directories in the glob for the outer loop? It's probably a -lot- faster to run "file" on multiple filenames, rather than on every name individually. Most implementations of /etc/magic (the "file" database) use "image" rather than "picture" for GIF, JPEG, etc. files. ${x:t} is equivalent to ${x##*/}. The second parameter to "ln" can be the name of a directory, so it can be run once on all the picture files. The inner loop runs sed on both the html files and the picture files, which is probably going to corrupt the pictures. You're running sed and then mv once per picture file per every other file. Once per html document should be enough. /tmp is probably in another filesystem, which means the mv is no better than a cp. Why put the temp file there? So that leaves us with: function shufflepics() { setopt localoptions extendedglob local pics docs sedit cd ~/.P file **/*~pics/*(D.) | while read name type do name=${name%:*} case ${(L)type} in (*image*|*picture*) sedit=($sedit -e "s@${name}@pics/${name:t}@g") pics=($pics $name);; (*html*) docs=($docs $name);; esac done ln $pics pics for f in $docs do sed $sedit $f > $$-${f:t} && mv $$-${f:t} $f done rm -f $pics $$-* } How's that? -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com