APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

The script referenced is a Ksh script. Note that you MUST quote wild cards to avoid shell expansion.

It is a complex script. "ren -h | wc -l" generates 251 lines alone!

Be aware of ambiguous cases and collisions - the script tries to be intelligent about those things, but they are ultimately your responsibility.

I tested this on Mac OS X and only had to change the "#!/bin/ksh93" to "#!/bin/ksh".

Without this, the simple case is trivial from the command line:

for i in 01*; do j=`echo $i | sed 's/^01/02/'`; mv $i $j; done 

The more complex tasks are not that much harder, though I'd go to Perl for those.

renaming files ren

Subject: Re: renaming files
References: <3c00bafe.1518158@news.libero.it> 
From: spcecdt@deeptht.armory.com (John DuBois)
Date: 26 Nov 2001 07:37:15 GMT

In article <3c00bafe.1518158@news.libero.it>,
Duilio Foschi <dedalus@yifan.net> wrote:
>I want to rename all files starting with 01 into files starting with
>The command 
>ren 01*.* 02*.*
>works under Dos.
>I was expecting the command 
>mv 01* 02*
>to work under Unix, but it doesn't.

I would do:

ren '01*' '02*'

Or, if what I actually wanted was to increment the first two digits of every

ren '[0-9][0-9]*' '[0-9][0-9]*.tmp'
ren -m1:2=i+1 -z2 '[0-9][0-9]*.tmp' '[0-9][0-9]*'


John DuBois  spcecdt@armory.com.  KC6QKZ/AE  http://www.armory.com./~spcecdt/

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> renaming files ren ––>Re: renaming files with wildcards

Increase ad revenue 50-250% with Ezoic

Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Some people, when confronted with a problem, think "I know, I'll use sed." Now they have two problems. (Jamie Zawinski)

This post tagged: