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

Yes, try this with rename :

rename -n 's/\.1$//' *

remove the -n (dry-run mode switch) if your tests are valid.

warning There are other tools with the same name which may or may not be able to do this, so be careful.


If you run the following command (linux)

$ file $(readlink -f $(type -p rename))

and you have a result like

.../rename: Perl script, ASCII text executable

then this seems to be the right tool =)

If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :

$ sudo update-alternatives --set rename /path/to/rename

Last but not least, this tool was originally written by Larry Wall, the Perl's dad.


Pure bash solution:

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

Another bash solution using parameter expansion:

for curFile in example.file.*.1; do
    mv "$curFile" "${curFile%.1}"
done