rename multiple files

I need to rename files from
oct01
oct02
oct03
...
oct31

to
nov01
nov02
nov03
...
nov31

how do I do this?
longneckgoosieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brettmjohnsonCommented:
#!/bin/bash
# This Bash shell script emulates the linux 'rename (1)' command
# The "usage" man page help  was shamelessly stolen from Linux.
# 04 Aug 2004  Brett Johnson  

# Must have at least three args: fromtext, totext, file...
if [ $# -lt 3 ] ; then
  cat <<END
NAME
        rename - bulk rename files

SYNOPSIS
        rename fromtext totext files...

DESCRIPTION
        rename will rename the specified files by replacing the
        first occurrence of fromtext in their name with totext.

        For example, given the files foo1, ..., foo9, foo10, ..., foo278,
        the commands

          rename foo foo0 foo?
          rename foo foo0 foo??

        will turn them into foo001, ..., foo009, foo010, ..., foo278.

        And

          rename .htm .html *.htm

        will fix the extension of your html files.

END

else
  fromtext=$1
  totext=$2
  shift 2

  for f in "$@" ; do mv $f ${f/$fromtext/$totext} ; done
fi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
avizitCommented:
#!/bin/bash
for fil in `ls oct[0-9]*`
do
  echo $fil
  new=`echo $fil | sed  -e 's/oct/nov/g'`
  mv $fil $new
done


The above will do the same thing , but the downside being that it will also rename files  like oct32, oct44 ,,,,oct 999
so ifyou can gurantee that such files do not exist than this will work for you :)
0
brettmjohnsonCommented:
The script I provided was generic.  Use it as follows to solve your problem:

/path/to/rename oct nov oct[0-3][0-9]


0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

avizitCommented:
I think oct[0-3][0-9]   will also match oct39  if ever there is such a file
0
brettmjohnsonCommented:
> I think oct[0-3][0-9]   will also match oct39  if ever there is such a file

That is much less likely a problem than renaming oct31 to nov31  ;)

0
avizitCommented:
heh yeah.. I was thinking bout Feb .. dint strike me that the same problem can occur in almost every consecutive month save jul-aug
0
ahoffmannCommented:
either use mmv
  mmv 'oct*' 'nov#1'
or perl
  ls oct*|perl -ne 'm/(oct(.*))/;rename$1,"nov$2"'
0
byttaCommented:
#! /bin/bash
# just the days in your month...
for i in $( cal | tail +3);
do
[ i -lt 10 ] && i=0$i;# zero padding
mv oct$i nov$i;
done
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.