Linux Rename Multiple Files Extension With Examples

We can use mv command to change the file name. We can use it to change the file extension too. But, it works with a single file only and it doesn’t take wild characters.

We can create a shell script to change the extension of multiple files at once.

Linux Shell Script to Change Extension of Multiple Files

Let’s look at the script code where we will use the mv command in a for loop to change the extension of all the files in the current directory.

Usage: multimove.sh doc txt (to change all .doc to .txt)

Testing the Rename Shell Script

Below is the sample output from the above program execution.

Linux rename multiple files extension

Script Assumptions and Limitations

  1. The files have only one period (.)
  2. It loops through all files in the current directory only. However, you can extend it to look for files in the child directories also.
  3. Whitespaces in the file name can cause a problem with the script. It has worked on my system with filenames having spaces but I can’t guarantee that it will work for you too.

Further Readings: Linux mv command

By admin

Leave a Reply