1

I need to rename *-dev.example.com.cfg to *-prod.example.com.cfg

For example, if the filename is db-dev.example.com.cfg I need to rename it db-prod.example.com.cfg

There are like a 200+ files, is there a way to do it via command line ?

4
  • 1
    Is there anything you have done to try to solve this problem? We will be more willing to answer your question if you tell us what you have tried so far. (Helpful links for asking better questions: How to Ask, help center) Commented Jul 9, 2013 at 18:15
  • Do you have rename installed? Commented Jul 9, 2013 at 18:16
  • Seems that you aren't inclined to put in any effort. A simple search would have fetched you multiple solutions. Commented Jul 9, 2013 at 18:19
  • @ExplosionPills rename did the trick thanks. Commented Jul 9, 2013 at 18:21

3 Answers 3

1

You can do this in pure bash with parameter substitution.

for file in *-dev.example.com.cfg; do
  mv "$file" "${file/%-dev.example.com.cfg/-prod.example.com.cfg}"
done
Sign up to request clarification or add additional context in comments.

Comments

0

Regex are not required for this, so since you're on Linux, you can use rename from util-linux. On Debian and derivatives like Ubuntu, the command is called rename.ul.

rename dev.example.com.cfg prod.example.com.cfg *.cfg

Comments

0

zsh has zmv, that might be handy if doing such things regularly http://zshwiki.org/home/builtin/functions/zmv

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.