Home » Questions » Computers [ Ask a new question ]

Rename files and extensions in one command in Mac OS X

Rename files and extensions in one command in Mac OS X

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

Asked by: Guest | Views: 308
Total answers/comments: 2
Guest [Entry]

"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."
Guest [Entry]

"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."