Read more

Linux: rename or change extension of multiple files

Arne Hartherz
February 16, 2011Software engineer at makandra GmbH

When you need to bulk rename files you can not call "mv *.foo *.bar" to change the extension of all .foo files to bar (because bash resolves wildcards and replaces them with the list of matched files).

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

This works on linuxes who use the Perl version of the rename command (like Ubuntu):

rename 's/\.foo$/\.bar/' *

You can also use this to rename other parts of the file, e.g. from flag_en.png, flag_de.png etc. to just en.png or de.png:

rename 's/^flag_//' *

Note that we used $ and ^ to explicitly look at the end and start of the filenames.

Posted by Arne Hartherz to makandra dev (2011-02-16 15:31)