I have files named in the style 02.04.11 DJ Kilbot.mp3 (for several dates) and I want to reformat the name in this manner: DJ Kilbot 2011-02-04.mp3. In other words, the current format is MM.DD.YY DJ-NAME.mp3 and I want to change it to DJ-NAME YYYY-MM-DD.mp3. What's the easiest way to do this, for several year's worth of files?
move middle part of filename to front
shell;rename
cd to the directory then run the following (using perl-rename). This is a dry-run first.rename -n 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}) (.*)\.mp3$/$4 20$3-$1-$2.mp3/' *02.04.11 DJ Kilbot.mp3 -> DJ Kilbot 2011-02-04.mp3If you are happy with the output, then run it for real.rename 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}) (.*)\.mp3$/$4 20$3-$1-$2.mp3/' *Explanationrename -n: run a test dry-run.'s/FOO/BAR/' substitute the regex FOO and replace with BAR.^([0-9]{2})\.([0-9]{2})\.([0-9]{2}) (.*)\.mp3$: regex to capture. Match the start of the string ^, then three lots of [0-9]{2} (i.e. two consecutive numbers) separated by a dot (\. when escaped). Then a space and (.*)\.mp3$. Parens () capture the contents for use in the replacement.$4 20$3-$1-$2.mp3: replace with the DJ name the fourth capturing group ($4), or (.*) above, then the rest of the string as specified (i.e. the third, first and second groups).*: act on all files in the directory.SimplifyThis regex has a bit of error checking built in. If you are sure that all files are named consistently, you can simplify it slightly to the following.rename 's/^(..)\.(..)\.(..) (.*)\.mp3$/$4 20$3-$1-$2.mp3/' *