Rename and Copy Multiple Files at Once in Zsh

Here’s a tip to rename multiple files after copying at once in zsh.

As a general security practice, it is advised not to git track your secrets of your Rails application like application.yml or secrets.yml.

But you have to somehow share the default minimal contents required for the app to your teammates either by tossing around in your IM or via email.

Nowadays, it is a common practice to have sample yml files in your project for other team mates to copy. The copied file is git ignored allowing devs to experiment freely on their local machine while production or staging servers have different secret values.

But there’s that hassle of copying and renaming all those YAML files one by one. If you’re using zsh then zmv comes in handy allowing you to copy all those files while renaming in a single command.

$ zmv -C config/*.example.yml config/*.yml

You can read more on zmv via info --index-search=zmv zsh or searching zmv in man zshcontrib.

Feel free to experiment with various aliases and other use cases of zmv.

Saroj Maharjan (zoras)

Web Developer, Speaker, Mentor, Freelancer, Meetup Organizer, Promoter, Available for Ruby and Rails Consulting

Kathmandu, Nepal