From owner-freebsd-questions Fri Dec 11 11:43:53 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA17839 for freebsd-questions-outgoing; Fri, 11 Dec 1998 11:43:53 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from horton.iaces.com (horton.iaces.com [204.147.87.98]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA17831 for ; Fri, 11 Dec 1998 11:43:51 -0800 (PST) (envelope-from proot@horton.iaces.com) Received: (from proot@localhost) by horton.iaces.com (8.8.8/8.8.8) id NAA05604; Fri, 11 Dec 1998 13:43:42 -0600 (CST) (envelope-from proot) From: "Paul T. Root" Message-Id: <199812111943.NAA05604@horton.iaces.com> Subject: Re: Recursing directories? In-Reply-To: <36716768.BBCAEA1@lundahl.com> from "James A. Taylor" at "Dec 11, 98 11:41:44 am" To: jataylor@lundahl.com (James A. Taylor) Date: Fri, 11 Dec 1998 13:43:42 -0600 (CST) Cc: freebsd-questions@FreeBSD.ORG X-Organization: USWEST !nterprise Networking - ACES X-Phone: (612) 664-3385 X-Fax: (612) 664-4779 X-Page: (800) SKY-PAGE PIN: 537-7270 X-Address: 600 Stinson Blvd, Fl 1S X-Address: Minneapolis, MN 55413 X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In a previous message, James A. Taylor said: > First of all thanks to Paul for his help with the mv command. > > Is it possible to have a shell script recurse a directory tree? > Still the same situation as my last email I have a directory tree > with .shtml files. I want to recurse the directory tree renaming > each .shtml to a .html file. Paul sent me the following script that > allows me to mv all .shtml in a single directory: > > #!/bin/sh > for i in *.shtml > do > j=`basename $i .shtml` > mv $i $j.html > done > > This script works and changes all of the .shtml in the current > directory. Is their a way I can get the script to recurse my > directory tree? sure, name it nos (or some such). #!/bin/sh for i in * do if [ -d $i ];then cd $i nos cd .. else echo $i |grep ".shtml$" >/dev/null if [ $? -eq 0 ]; then j=`basename $i .shtml` mv $i $j.html fi fi done Ok, that's a little crude but it works. Be sure to have the script in your path and be executable. -- The only thing that makes life worth living is the willingness to risk everything. Unless you risk everything, you don't have a life. -- Roger Payne To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message