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.

© December 2004 (various authors)

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  https://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

Inexpensive and informative Apple related e-books:

Photos for Mac: A Take Control Crash Course

Take Control of High Sierra

Take Control of Parallels Desktop 12

Digital Sharing Crash Course

Take Control of Upgrading to El Capitan

Printer Friendly Version

Have you tried Searching this site?

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

Printer Friendly Version

I wanted to learn how to swim, so Google showed me how to turn on the water at the sink and let me splash it around a bit. They then dragged me into a helicopter, flew way out into the ocean and dumped me out. (Tony Lawrence)

Linux posts

Troubleshooting posts

This post tagged:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode

SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)