How to add .xml extension to all files in a folder in Unix/Linux How to add .xml extension to all files in a folder in Unix/Linux unix unix

How to add .xml extension to all files in a folder in Unix/Linux


On the shell, you can do this:

for file in *; do    if [ -f ${file} ]; then        mv ${file} ${file}.xml    fidone

Edit

To do this recursively on all subdirectories, you should use find:

for file in $(find -type f); do    mv ${file} ${file}.xmldone

On the other hand, if you're going to do anything more complex than this, you probably shouldn't use shell scripts.

Better still

Use the comment provided by Jonathan Leffler below:

find . -type f -exec mv {} {}.xml ';'


Don't know if this is standard, but my Perl package (Debian/Ubuntu) includes a /usr/bin/prename (and a symlink just rename) which has no other purpose:

rename 's/$/.xml/' *


find . -type f \! -name '*.xml' -print0 | xargs -0 rename 's/$/.xml/'