Reputation: 15
I have a large number of files that are named in the format: ABC_XYZ_123.jpg.
I want to rename them in bulk so that I can get the format: 123.jpg.
How can I do this on a Mac?
Thanks!
Upvotes: 1
Views: 926
Reputation: 47169
Using find
in terminal:
find . -type f -name "*_*_*.jpg" -execdir bash -c 'mv "$0" "${0##*_}"' {} \;
Would result in:
ABC_XYZ_123.jpg -> 123.jpg
Upvotes: 1
Reputation: 9224
Because I can never remember the command lines of the stools that specialize on this kind of stuff (like rename
) I create a bash
script that does the task:
$ ls > x.sh
$ vi x. sh
Within VI
:
:%s/^[a-z_]*\(.*\)$/mv \0 \1/`
and then:
$ source x.sh
rename
can do the likes, but, as I said, I've never bothered to learn it.
$ brew install rename
Upvotes: 0