Archive for April, 2009

h1

Rename files the easy way in OS X

29 April 2009

Can’t find that unix rename command to change filename in batches? Here’s a way to do what you need without rename in the terminal.

Step 1: try out the command first without hurting any files!

ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2'

This will just print out a list of changes that could be made. foo*.jpg is the search for files to change. foo is the text to search for and bar is what to replace it with.

Step 2: Ready to make some changes? the same command as before with a little extra will change all those filenames with no need to open automator.

ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh