Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Renaming multiple files (changing extension)

Suppose I have a bunch of files with the extension .x and I want to change them so that they have the extension .y. I know $ mv *.x *.y wouldn't work because I havn't expressed each file to change their respective extensions (that and the command expects *.y to be a directory).

What command should I issue?

share|improve this question
add comment

marked as duplicate by jasonwryan, Michael Mrozek Sep 26 '11 at 2:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 1 down vote accepted

You can use rename to rename files based on a pattern, and one of the examples from the man page is changing the extension of a group of files. It takes the source pattern, modified pattern, and the files to operate on, so in your case:

$ rename .x .y *.x

It changes the first occurrence of .x to .y, so if you happen to have .x anywhere other than the end of the filename it's going to change that first

share|improve this answer
    
I get this: $ rename .x .y *.x Transliteration pattern not terminated at (eval 1) line 2. However 's/.x/.y/' as a pattern seems to work. –  oadams Sep 26 '11 at 1:55
    
You have to take into account the difference between Red Hat rename and Debian rename. And then there are Unices that have neither. –  Ignacio Vazquez-Abrams Sep 26 '11 at 2:32
    
That's annoyingly distro-specific... –  Michael Mrozek Sep 26 '11 at 2:34
add comment

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