How to change extension of multiple files at once on Linux

Last updated on June 22, 2020 by Dan Nanni

Question: On my Linux computer, I have many picture files whose extension I want to change from *.JPEG to *.jpg. In general, how can I change the extension of multiple files at once?

Most Linux distros come with a command line utility called rename pre-installed, which, as the name implies, can rename multiple files at once. This tool is actually a Perl script, and takes as an argument a regular-expression based renaming rule, which changes all file names that are matched with the rule. The usage of rename is as follows.

rename [-vnf] <regular_expression> <files>

With -n option, rename will show what files would be renamed, without actually changing file names. This option is useful when you want to test a renaming rule beforehand.

To change the extension of all files from .JPEG to .jpg:

$ rename 's/.JPEG$/.jpg/' *

To convert all uppercase letters including extensions to lowercase counterparts:

$ rename 'y/A-Z/a-z/' *

To strip the extension of all files matching "*.bak":

$ rename 's/.bak$//' *

Check the other tutorial for more use cases of rename command.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean