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)?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityWith Homebrew, a package manager for OS X:
brew install rename
Then you can run the same rename
commands as in Linux.
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.
*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.
Jun 15, 2010 at 18:58
*
instead of .*
to get all. *?
seems to work like non-greedy .*?
. 2) for me, ^
and $
for start and end of string seemed to cause it to match nothing
Jul 21, 2014 at 14:51
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
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
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
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.
This shouldn't be difficult but apparently it is. Example, I want to rename all file's extension from aiff to aifc.
find . -iname "*.aiff" -exec bash -c 'mv "$0" "${0%\.aiff}.aifc"' {} \;
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.
the equivalent command in renamer (cross-platform) is
$ renamer --regex --find 'old_pattern' --replace 'new_pattern' *glob
If you like Sublime Text's multiselect you could use it with qmv:
qmv --editor="/usr/bin/s3 -w" files
I just went ahead and found my favorite I've seen referred to as perl-rename giving the rename
command where help looks like this:
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
That's how I know I got the one I like.
For Mac, even in Homebrew they have others where I just vaguely remember having trouble. So it's not the rename
package, and it's not the nongnu renameutils
package either.
Got it from here and just did the install like they mention: https://github.com/subogero/rename
rename
on Mac OS X: macosxhints.com/article.php?story=20050630022203488