0

I was trying to change a bunch of files extensions from yml to yaml, and I've found a very good answer here in Stackoverflow. Based on that answer which was:

for file in *.yml
do
  mv "$file" "${file%.yml}.yaml"
done

I've turned it into a command to make my life easier, which I've tried to share there as a comment, but since it required me 50 points to add a comment, I couldn't, then I decided to create this question as a kind of post. How can we convert that answer into a command:

Create the file chgext to add the script

vi chgext

Copy and paste the script below into the chgext file
#!/bin/bash

for file in *.$1
do
  mv "$file" "${file%.$1}.$2"
done

Save and exit pressing: esc + : + x + enter

Make chgext executable

chmod +x chgext

Move it to /usr/local/bin so it can be called from any directory as any other linux command

sudo mv chgext /usr/local/bin

Now you are ready to go, call chgext passing old_extension and new_extension as params, like this from the directory where your files are

chgext yml yaml

The original answer is here

  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], and read [ask]. Also please read [how to write the "perfect" question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/), especially its [checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Then please [edit] your question to improve it, like changing your title from being very generic to something that is a short description of your actual problem. – Some programmer dude Jul 14 '23 at 10:24

0 Answers0