brew install rename
to install
rename "s/SEARCH/REPLACE/g" *
This will replace the string SEARCH
with REPLACE
in every file (that is, *
). The /g
means global, so if you had a SEARCH_SEARCH.jpg
, it would be renamed REPLACE_REPLACE.jpg
. If you didn't have /g
, it would have only done substitution once, and thus now named REPLACE_SEARCH.jpg
. If you want case-insensitive, add /i
(that would be, /gi
or /ig
at the end).
Uses Perl REGEX for i.e. ^
target beginning $
target end
Delete a string
rename 's/myString//' *
Add a Prefix
rename 's/^/MyPrefix_/' *
document.pdf
renamed to MyPrefix_document.pdf
rename -n -N 0001 's/.*/$N.jpg/' *.jpg
sequentially rename a series of images (e.g. if there is an image sequence with some numbers missing in the sequence and you would like to rename everything sequentially).
rename 's/^CD RIP //' *
CD RIP 01 Song.mp3
to 01 Song.mp3
Notice the extra space in '^CD RIP '
, without the space all files would have a space as the first character of the file. Also note, this will work without the ^
character, but would match CD RIP
in any part of the filename. The ^
guarantees it only removes the characters if they are the beginning of the file.
use -n