How to change extension of multiple files at once on Linux

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.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *