Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!emory!mephisto!mcnc!rti!dg-rtp!hunt From: hunt@dg-rtp.dg.com (Greg Hunt) Newsgroups: comp.unix.shell Subject: Re: How to do mv *.xyz *.abc in shell script?? Message-ID: <1990Sep7.181513.20568@dg-rtp.dg.com> Date: 7 Sep 90 18:15:13 GMT References: <5569@minyos.xx.rmit.oz> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hunt@dg-rtp.dg.com Organization: Data General Corp., Research Triangle Park, NC Lines: 49 In article <5569@minyos.xx.rmit.oz>, rcoahk@chudich.co.rmit.oz (Alvaro Hui Kau) writes: > Hi all experts out here! > > Sorry for the stupid query, but I just don't know how to do > it. Once in a while I want to change the names of a bunch of > files from *.xyz to *.abc for example. I know there is a better > way to do this than doing it one by one but I just can't > find any way to do it. I know it can be done using shell script > but I don't know (yet) how to write them. > > So, Is there anyone out there can help me on this problem? > > Thanks in advance. > There are no stupid questions. Just ones you don't know the answers to yet. This is how I change the names of files like you need to in the Bourne shell: for tmp in $* ; do mv $tmp `basename $tmp .xyz`.abc done The basename program returns just the file name portion of a pathname, and optionally removes a suffix. Since there is no pathname portion if you're in the directory the files exist in, all that this example does is to remove the suffix. Then it puts on the new suffix, and the files get renamed the way you want. Put the above lines into a file named whatever you want with an editor. Exit the editor. Then type 'chmod 755 your_script_name'. This changes the file permissions to user{read,write,execute}, group{read,execute}, other{read,execute}. The "execute" permission is the key to being able to run shell scripts. To use the script, type: your_script_name *.xyz As you learn more about scripts, you can make it more general by allowing you to specify the old and new suffixes as arguments to the script as well (hint - look at the shift shell command and specify the old and new suffixes as the first two arguments). Enjoy! -- Greg Hunt Internet: hunt@dg-rtp.dg.com DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt Data General Corporation Research Triangle Park, NC These opinions are mine, not DG's.