How to change all file extensions in a folder

To make sure that you do not destroy your real files make a copy to temporary folder.

# mkdir /tmp
# cd tmp

Now, I’m in the folder /tmp. Currently, this is a empty working directory. We  make 500 new files in the extension .dot as the following:

# for x in {1..500};

do

touch “file$x.dot”;

done

And 200 new files as Gif images

# for x in {1..200};

do

touch “testimage$x.gif”;

done

Now, how can I rename all files .dot to .bak in the folder /tmp? The following command can solve this problem.

# for x in *.dot;

do

mv “$x” “${x%.dot}.bak”;

done

Other example :

# for x in *.mov;

do

mv “$x” “${x%.mov}.flv”;

done

Leave a Comment

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

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top