Batch / bulk rename file extensions in macOS Terminal

A copy & paste macOS terminal command that simply does what the title says: rename the extensions of multiple files in multiple directories (recursively).

Code first, talk later #

Don’t need the explanation? Then simply copy & paste this code:

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"' {} \;
→ Call to action ←

Sounds interesting?

Then let's make the virtual gap between us a little bit shorter!