Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to rename multiple files in one command. In Windows, I am aware of the command

ren *.* *.jpg

Is there a similar command in Mac OS X that i could run, instead of hitting enter on each and every individual file and doing the renaming.

share|improve this question

migrated from Jan 26 '12 at 12:24

This question came from our site for system and network administrators.

up vote 1 down vote accepted

With unix-like systems, it's easier to use find

find ./  

(try this first to make sure that your list of files looks like what you were expecting

find ./ -exec mv ${} ${}.jpg \; 

This will append .jpg to the end of every file found. The regex for changing the final extension, rather than just appending, is left as an exercise for the reader.

share|improve this answer
thank you. that helped. – Rajeshwaran S P Dec 28 '09 at 21:54

While using find and for loops are efficient, Perl usually comes with /usr/bin/rename (in Linux at least) but I'm not sure you have it on MacOSX (at least not in my old 10.3).

If you don't have it, you can get this script from the CPAN. And this is how to use it:

$ ls
   tata.jpg  titi.jpg  toto.jpg  truc  tutu
$ rename -v 's/\.jpg$/.JPG/' *.jpg
   tata.jpg renamed as tata.JPG
   titi.jpg renamed as titi.JPG
   toto.jpg renamed as toto.JPG
$ ls
   tata.JPG  titi.JPG  toto.JPG  truc  tutu
share|improve this answer
rename is not installed on MacOS X 10.6.2 by default, either. It is a script I copied from the original Camel book - it was dropped (for lack of space) in later editions. I still use it for exactly such purposes. The only oddball thing to worry about it is the Mac's case-insensitive file system. – Jonathan Leffler Dec 29 '09 at 1:48
For lack of space? /usr/bin/prename is hardly 3KB... – ℝaphink Dec 29 '09 at 6:58

This will work (and leads to much more flexibility):

shopt -s extglob
for file in *.*; do mv ${file} ${file/%.*([^.])/.jpg}; done

There are also non-standard Unix command-line tools that can do the job more succinctly.

share|improve this answer
Isn't .* greedy? Without trying it, I'd guess it would move files.2009.12.28.pic to files.jpg, which could be very much the wrong goal – Matt Simmons Dec 28 '09 at 21:41
D'Oh! you're right. I'll fix. – freiheit Dec 28 '09 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .