Search code examples
linuxunixfile-rename

How to rename multiple files from one extension to another in Linux / Unix?


I have a number of files that end in a '.1', for example:

example.file.ex1.1
example.file.ex2.1
example.file.ex3.1

Is there a way that I can quickly rename them all without the '.1' at the end (e.g. example.file.ex1, example.file.ex2, etc.)?

Thanks!


Solution

  • Pure bash solution:

    for curFile in example.file.*.1; do
        mv -- "$curFile" "${curFile:0:-2}"
    done