Rename many files in a directory

Hi,

I have around 100 xml file in a directory. I need to rename the files from .xml to .xml1. So i tried using the following command:

mv *.xml *.xml1

but i am getting the following error
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.

suggest me some solutions.

Thanks,
Ananthi.U

Hi.

Try:

ls *.xml | xargs -I{} mv {} {}1

Hi,

ls *.xml | xargs -i{} mv {} {}1

This command worked out... Thank u..

can u plz explain how it works??

Not really understand why use three {}s

ls *.xml |xargs -i mv {} {}1 

or if you want rename xml files in different sub-directory.

find . -type f -name "*.xml" -exec mv {} {}1 \;

The ReplaceString is not optional with -I (capital I).

---------- Post updated at 12:52 PM ---------- Previous update was at 12:32 PM ----------

That certainly doesn't work.

$ ls
file_1.xml  file_3.xml  file_5.xml  file_7.xml  file_9.xml
file_2.xml  file_4.xml  file_6.xml  file_8.xml

$ find . -type f -name "*.xml" -exec mv {} {}1 \;
$ ls
{}1

Interesting, it works in my computer.

Hmm, OK :slight_smile:

Just tested. It works in Linux, but not in UNIX (AIX, Solaris 8 or 10) find.

I would probably use xargs with that anyway, instead of exec.

From the POSIX man page for find:

From the man page of GNU find:

Judging from this, GNU find is the only one where your command would work as you intended.

With zsh:

zmv '*.xml' '${f}l'

Example:

zsh-4.3.10[t]% touch {1..5}.xml            
zsh-4.3.10[t]% print -l *
1.xml
2.xml
3.xml
4.xml
5.xml
zsh-4.3.10[t]% autoload -U zmv             
zsh-4.3.10[t]% zmv '*.xml' '${f}l'
zsh-4.3.10[t]% print -l *
1.xmll
2.xmll
3.xmll
4.xmll
5.xmll