Batch Rename ".css" to ".scss" in a Snap!
Tips & Tricks

Batch Rename ".css" to ".scss" in a Snap!

Andrei Surdu Andrei Surdu ยท

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! ๐Ÿ’…๐Ÿ”„

Tags:
#css #scss #terminal

Comments

Share your thoughts and join the conversation

Loading comments...

Leave a Comment

Your email will not be published

Comments are moderated and will appear after approval

0/2000