how to rename multiple files with a single command

Hi

I have following list of files at a path:

01.AR.asset
01.AR.index
01.AR.asset.vf
01.AR.asset.xv

I want to rename all these files as follows:

73.AR.asset.Z
73.AR.index.Z
73.AR.asset.vf.Z
73.AR.asset.xv.Z

Can any body give me a single command to acheive the above results.

Thnx & Regards,
Tayyab

Yeah...but it is a rather complex command and requires a powerful shell (I'm using ksh). We need a pattern that will match those 4 files and only those 4 files. I will assume that 01.AR.* will do that.

$ ls *AR*
01.AR.asset     01.AR.asset.vf  01.AR.asset.xv  01.AR.index
$ for i in 01.AR.* ; do mv $i 73${i#01}.Z ; done
$ ls *AR*
73.AR.asset.Z           73.AR.asset.xv.Z
73.AR.asset.vf.Z        73.AR.index.Z
$
1 Like

Thanks Perderabo for your reply. It worked perfectly. Can you pls explain me the 73${i#01} part of this command. It'll be a great favor. Thnx & Rgrds, Tayyab

${i} is the value of the variable i
${i#01} is the value of the variable i with any leading "01" removed

That leading 73 is just like the trailing .Z which you didn't ask about. We are just tacking some constant text on to both ends of the value of the variable.

I got it, Thanks for your explanation. This command will save a lot of my time.

Regards,
Tayyab

Hi tyub,

This is Antony. Do you remember me.? you want to use this in Kerridge AR module.

its like this

for i in *
do
mv $i $i.Z
done

Hopefully this helps you..

Regards,
Antony