I have a directory full of files ending with .xxx. (Apple.xxx
, Orange.xxx
, Bannana.xxx
)
I want to change their extensions to .yyy. (Apple.yyy
, Orange.yyy
, Bannana.yyy
)
What's the quickest way to accomplish this using basic shell commands?
Take a look at the rename command:
rename .xxx .yyy *.xxx
The percent sign in "${i%.*}" means use the glob pattern that is after the percent sign, apply it to the value of the variable i, and remove the shortest possible match from the tail end of that value. This called Parameter / Variable expansion, and has many uses. You can also make it so the glob is longest possible match or make the glob match from the start as well. This Linux Journal article is all about parameter expansion.
It is put in double quotes so that if there are spaces in the filename and the IFS variable is set to include spaces (the norm), the filename will still be passed to mv as one argument.
Install mmv and then do this:
Already a bunch of answers, but I'll add my own.