Code first, talk later #
Don’t need the explanation? Then simply copy & paste this code:
Warning!
Make 100% sure that you’re entering this command in the RIGHT folder on your system.
Or else risk renameing all extensions of all files on your ENTIRE system.
find . -iname "*.liquid" -exec bash -c 'mv "$0" "${0%\.liquid}.php"' {} \;
Explanation #
I downloaded a webshop HTML-template collection I liked, but it was customized for a system I don't use. Result: many files in various folders that had some kind of functionality in it, had an extension of .liquid
, and which I thus needed to rename to .php
.
But here is the problem: there were many files with that extension, and they were situated in multiple folders. It would be too much work to manually rename them all, and I also wasn't prepared to buy a piece of software because I knew the terminal should be able to help me.
(About) the code #
I tried several snippets (like mv *.liquid *.php
), but they didn't work. It also wasn't recursive, so I would still have to manually visit every folder and repeat the command.
Then I found this, and it worked like a charm. It finds all .liquid
files and renames (mv
) them to {filename}.php
:
find . -iname "*.liquid" -exec bash -c 'mv "$0" "${0%\.liquid}.php"' {} \;