Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing all file's extensions in a folder using CLI in Linux

Tags:

linux

shell

How to change all file's extensions in a folder using one command on CLI in Linux?

like image 916
Jeegar Patel Avatar asked Mar 05 '14 09:03

Jeegar Patel


People also ask

How do I change the extension of multiple files in Linux?

The most common way to change file extensions recursively in a directory is to use a bash for loop. We can prompt the user to enter the target directory, old extension, and the new extension to rename using a bash script.


2 Answers

You could use a for-loop on the command line:

for foo in *.old; do mv $foo `basename $foo .old`.new; done

this will take all files with extension .old and rename them to .new

like image 165
MichielB Avatar answered Oct 25 '22 17:10

MichielB


Use rename:

rename 's/.old$/.new/' *.old

like image 26
DBedrenko Avatar answered Oct 25 '22 16:10

DBedrenko