Batch Rename “.css” to “.scss” in a Snap!

Ever been in that situation where you wanted to switch things up and turn all your “.css” files into “.scss“?

I got a brand new project which is based on an HTML template. The problem is the template uses plain CSS, but I want to use SCSS so I can take advantage of many functions that it includes. But renaming about 50 files manually will take too much time. Well, guess what? I’ve got a slick bash command to make that transformation quick and easy.

Just open up your trusty terminal and paste in this line:

find . -type f -name '*.css' -exec bash -c 'mv "$0" "${0%.css}.scss"' {} \;

Execute it and everything should be done in a second. It takes care of all subdirectories as well.

If you want to learn how it’s done, let’s decode the wizardry:

  1. find .: Starts the quest in your current directory. It’s like sending out a search party.
  2. -type f: Zeroes in on regular files. We don’t want to mess with anything else.
  3. -name '*.css': Targets only those files with the “.css” ending. Bullseye!
  4. -exec bash -c 'mv "$0" "${0%.css}.scss"' {} \;: The grand finale! This line does the renaming dance – swapping “.css” for “.scss” like a style guru.

Just be sure you’re in the right directory before hitting enter. We wouldn’t want to unintentionally restyle files in the wrong place!

That’s it! 💅🔄

Member since January 2, 2019

As a seasoned WordPress developer with expertise in various tech stacks and languages, I bring years of experience to every project I handle. My passion for coding and dedication to delivering exceptional work ensures that each project I take on is of the highest quality. I specialize in creating custom themes, developing plugins, and building full-scale web systems. By staying up-to-date with the latest industry trends and best practices, I incorporate cutting-edge solutions into my work.

Comments

    Your email address will not be published. Required fields are marked *