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

aWebDeveloper :

I want to rename all files in a folder and add a .xml extension. I am using Unix. How can I do that?

Roshan Mathews :

On the shell, you can do this:

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

Edit

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

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

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 ';'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

Add file extension to all files in a folder in R

How to remove all files with specific extension in folder?

How to copy all files in a folder to another folder and change the extension?

Php: append extension to all files with no extension in a folder

How can I delete all files with a particular extension in a particular folder?

How to add parent folder name to all the files in a sub folder in Python

How to add a launcher that opens all files with a specific extension in XFce?

Find all files that are NOT of a specific type/extension in folder?

Move all Files of same extension to a Folder

Copying all the files of one extension into a folder

How to add file extension to the files which do not have an extension in a specific folder using Windows command prompt?

How to load all the Xml files from a folder to an XmlDocument

How to add a new line to the EOF in batch or ps for all files in a folder?

How to add an InputBox to search for words within all files in a designated folder

How to add a prefix to all files and folders in a folder? (windows)

How do I change extensions of all files in a folder to one common extension when all the files have different extensions?

How can I find all specified files in a folder with extension .thrift in shell recursively?

How can I find all files in a folder with a certain text string and an extension?

how to rename all files under folder with specific extension name ( recursive approach )

C# - How do I check if all files in folder have certain extension

How can find all files of the same extension within multiple subdirectories and move them to a seperate folder using python?

Windows CMD - How to append .txt to the names of all no-extension files in a folder and its nested subfolders?

add .sh extension to all bash files

Add suffix to all files in the directory with an extension

How to get all files in that folder

How to keep Folder/Files of extension in the uninstall process

How to add a folder with .desktop files?

Add all files under a folder to a CMake glob?