How to rename multiple files at one go?

Hi,

I have hundreds of files with XXX in their file name and I want to rename all of them with YYY in place of XXX .

for ex:

$ ls -1
123XXX789
345XXX678

Output

$ ls -1
123YYY789
345YYY678

I know we can loop in each file and sed to replace and rename each file but ren *XXX* *YYY* worked in windows but mv *XXX* *YYY* did not in UNIX

Pls advise, TIA

Dont know about windows, but in UNIX world mv *XXX* *YYY* meaning move all files with XXX inside their file to anything with YYY in their filename... how is the OS going to choose to what?
You have no other coice than using a loop...

Hello reddyr,

Following may help in same.

for file in *XXX* 
do new_name=`echo $file | awk '{gsub("XXX","YYY",$0);print $0}'`
mv $file $new_name
done

Thanks,
R. Singh

for file in *XXX*
  do mv $file ${file/XXX/YYY}
  done

This will replace the first occurrence of XXX only using parameter expansion of recent shells.

Hi.

See also post # 4 in thread Rename more than 1 file and the warning in post # 8 in thread [SOLVED] Copy+Rename multiple files at once

Best wishes ... cheers, drl