Possible Duplicate:
Renaming multiple files (changing extension)

Suppose that in my current/working directory I have five files:


Is there any way that I can rename all files in the current/working directory with the extension .xvg and give them the new extension .txt (leaving the .eps files alone)? Can this be done with rename, mv, or mmv perhaps? I am using Ubuntu Linux. Thanks!


For your particular question this command will work. Verify that you are happy with the proposed renaming, then drop the -n to have the operation proceed.

rename -n 's/\.xvg$/.txt/' *.xvg

This basically means for all files with the .xvg extension in the current directory find the files that end ($) with .xvg and change that part of the name to .txt.

More detail and an example below.

Yes, the rename command will do this for you. A short example where I rename all of my files with the .html extension to .html_bak, ignoring other files in the directory.

I would strongly recommend using the -n command line option first (explained below) to see what changes would happen before executing the actual command.

What I start out with:

$ ls
a.html  a.txt  b.html  htmlfile

the -n means do a "trial run" .. just show what would change, don't change anything!

$ rename -n 's/\.html$/.html_bak/' *
a.html renamed as a.html_bak
b.html renamed as b.html_bak

Still have the original files.

$ ls
a.html  a.txt  b.html  htmlfile

Now for real:

$ rename  's/\.html$/.html_bak/' *

Files have been renamed.

$ ls
a.html_bak  a.txt  b.html_bak  htmlfile

In the above examples I use * to specify the files to be considered for the rename operation. I could have restricted this to .html files only with *.html.

For more information consult the rename man page

| improve this answer | |

This can be done like this:

rename 's/xvg$/txt/' *.xvg

The glob pattern ensures that only *.xvg files are affected.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.