I didn't want to download everything again, so I decided to simply rename all *.php to *.html, and fix the links inside so they were pointing to renamed files. It proved to be not an easy task for a novice Linux user such as myself :)
The following command recursively replaces the extension ".php" to ".html", starting from the current directory:
find . -name *.php -type f -print0 | xargs -0 -I '{}' rename 's/\.php/\.html/' '{}'
Now fixing hyperlinks inside the web pages:
find . -name *.html -exec sed -i 's/\.php/\.html/' '{}' \;
That's it :)
find plus xargs plus sed is certainly one way to do it, but it's certainly not the easiest way. A guy who calls himself seth has written an excellent Perl script that makes even the most complex file and directory renaming operations very easy for anybody who's familiar with regular expressions, Perl or otherwise. The script is named ren_ext.pl and can be found here:
ReplyDeletehttp://www.wg-karlsruhe.de/seth/tools.php
This would change all file extensions from php to html recursively:
ren_ext.pl -r '\.php$' '.html'
Quite a bit shorter, isn't it?