Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used to rename file in Linux via a rename command:

rename 's/old_pattern/new_pattern/g' *glob

Is there something similar in Mac OS X (Snow Leopard)?

share|improve this question
The backticks are not showing up in your comment - you should probably add this as an answer or edit your question to include your solution. – Paul R Jun 15 '10 at 12:05

10 Answers

up vote 13 down vote accepted

Clumsy me:

for i in *.yourfiles; do mv "$i" "`echo $i | sed 's/old/new/g'`"; done 

And if you want to use it like I do often this way:

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

I recommend to use this litte script in ~/bin/rename:

#!/usr/bin/env zsh
SUBSEXPR=$1
shift
for i in $@; do mv $i `echo "$i" | sed $SUBSEXPR`; done
share|improve this answer
your script doesn't work for me "rename ACDC AC-DC ACDC*" result-> "ssed: can't read ACDC: No such file or directory" , I installed rename util from linux and now it works anwyay – holms Jan 30 '11 at 16:59

with brew

brew install rename 

:)

share|improve this answer
1  
thanks jp, this was super easy – yitwail Jan 10 '12 at 20:45
This is everything I ever wanted. Thank you! – trisweb Nov 16 '12 at 23:32

Use the power of ZSH wisely (type zsh in the terminal if you are one of those poor souls who don't use it by default):

autoload zmv
zmv '(*).htm' '$1.html'

ZMV follows MMV syntax.

share|improve this answer
but does that also allow regex replacement? This seems to be just some kind of enhanced shell globbing. – math Jun 15 '10 at 15:37
3  
@brubelsabs: Yes, zmv can do regexp replacement. For files that match *user*.html, change the extension to .html and change all occurrences of rc to final: zmv '(*user*).htm' '${1//rc/final}.html' @ghoppe: I think the zmv example in your answer needs -w or parentheses around its wildcard. – Chris Johnsen Jun 15 '10 at 18:58
I don't get it. I do zmv '*.png' '$1left.png' and it complains that 10.png and 1.png both map to left.png... I tried # instead of dollar, too. – Yar Sep 22 '11 at 1:38
note for mac: '*.htm' should be '(*).htm' – vincicat Sep 21 '12 at 9:14
Thanks @ChrisJohnsen and vincicat. I missed the parentheses the first time. It's never to late to get it right! :) – ghoppe Sep 21 '12 at 15:59

There are various version of rename. It looks like you are looking for the Perl-based one.

One version of this utility comes with the File::Rename Perl module. You can install it with something like sudo cpan -i File::Rename.

Or, you could go with the rename from Debian's perl package. It is just a single file to download. Put it where ever you like and chmod it so that it is executable.


An alternative is the zmv tool that comes with zsh. It does not have the same syntax, but it does come with your OS and it can easily take care of many of the common cases.

share|improve this answer
the perl rename is what this question shows as an example. – quack quixote Jun 15 '10 at 12:49

You can try to install MacPorts and install the renameutils package:

renameutils @0.10.0 (sysutils)

renameutils is a set of programs designed to make renaming files faster and less cumbersome

share|improve this answer
this package don't have the "rename" command. – juanpablo Jun 20 '10 at 21:38
1  
i didn't say that it does. qmv looks like it does the job. – lajuette Jun 21 '10 at 5:43
qmv is a great tool, while a bit too much work for simple regex renames, it's fantastic for intelligently naming and moving big numbers of arbitrary files – sapht Sep 21 '12 at 16:06

The best quick solution I've ever found has been using the built-in Automator. Check out this article for easy step by step help: http://www.tuaw.com/2008/11/11/mac-automation-rename-multiple-files-efficiently/

share|improve this answer

On Macs I use Aristotle Pagaltzis's freely available rename, which like Debian's is Perl-based. You can get it here. Or visit here to read it first - always a good idea.

You need to place that somewhere in your $PATH and make it executable (chmod +x rename) and then you're good to go.

share|improve this answer

The following article explains how to install rename on Mac OS X: http://www.macosxhints.com/article.php?story=20050630022203488

share|improve this answer
Thanks anyway :) – math Jun 15 '10 at 11:22
when I try this tutorial have problem in the make step, say "no support x86-64" – juanpablo Jun 20 '10 at 21:00

If you are looking for a GUI, try Name Mangler. It has a "preview" feature that shows what will happen if you follow through with the renaming.

share|improve this answer

The rename command is available from Homebrew for Mac OS X.

Install brew (if now already installed) by running:

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

Then, to install rename, just run

brew install rename

PS: Thanks 'juanpablo' above for the answer I needed. I couldn't give his answer a vote-up since I'm quite new here. All credits to him.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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