Bulk Rename File Extensions Recursively
- November 23rd, 2010
- Posted in Linux . NCLUG . Open Source / FOSS . Useful Software
- Write comment
Much of the information on the Web that I found related to bulk renaming files did not work recursively for me; most of it seemed to only rename files within the current working directory. As I am in the process of redesigning a rather large website and will be implementing the new site in PHP, I wanted to quickly be able to rename all of the .html files so that they would have .php file extensions. Some files are as much as five levels deep so it is important to me to be able to recursively rename all of the .html file extensions. I’ve put together a simple script that will perform this task. You’ll want to save the script to the directory from where you wish to start renaming files, and make sure that it’s executable. In the script, I have specified that any .html files will be renamed with a .php file extension. You’ll want to edit the code to suit your own needs. Here’s the meat of it:
find . -name "*.html" | while read i;
do
mv "$i" "${i%.html}.php";
done
Although it took me a little while to figure out, this little script saved me a huge amount of time. Hopefully this might make life easier for someone else too!
Or you could just use xargs as follows
$ find . -name ‘*.html’ | xargs -I {} mv {} {}.html
Hope this helps.
Cool script! Love the simplicity of it.
Thank you!
not sure about the find and mv combo above. on my version of linux the {} after the -i threw and error. Just the braces after the mv command were necessary to get the job done.
Thx for both tips.
Thanks for the tip man…I had a situation identical to yours, and this worked like a charm!
Man y thanks to you for that nice little script. What a life-saver – wild cherry even!