Question: I have several files with
In an earlier post, you learned how to change a character from all the filenames in Linux. I used rename command in that tip.
To change the extensions of multiple files at once, we’ll use the same rename command here.
The scenario is really simple. You have files with names like my_file.xyz and you want to rename these files so that they become something like my_file.abc.
To do that, you can use rename command in the following manner:
rename 's/.xyz$/.abc/' *.xyz
Let me explain the above command to you.
‘s/.xyz$/.abc/’ : This is a regex expression that means replace the .xyz character at the end of the line with .abc.
*.xyz : It is searching for all the files that end with .xyz.
So the rename command looks for all the files ending with .xyz and then it replaces .xyz at the end of those filename with .abc.
It is important to note that the .xyz is at the end of the filename else you may accidently change the xyz from the middle of the filename if there are files myxyz.xyz.
I hope you liked this quick Linux tip on renaming file extensions. Stay tuned for more.