I exported pictures from mac's iPhoto. The directories are named with the date in local naming ("Day. MONTH YYYY"):

8. Mai 2013/
13. Juli 2013/
31. Oktober 2014/

and some of them with GPS data:

Capdepera, 2. Juli 2013/
Stuttgart, 13. Februar 2013/
Marsa Alam, 31. Dezember 2011/

I would like to have the directory names like YYYY-MM-DD<.GPS-Data-if-exists> = 2013-07-02.Capdepera

I would separate with cut -d',' -f1 the GPS-data and with -f2 the date part (to $DatePart). In a second step, I would split with the dot '.' the date part to day and moth+year and then take the last 4 digits as Year. After that I'll get

DAY=02      # fill leading zero is no issue.

Now, to map month to number, I would create an array like


and with echo -e $Monate | grep $MONTH| cut -d'=' -f2 I got 07 as result. Now I can concat all them to the final directory name to rename it.

My question now is: is there an easier way as I described above? I mean after having with -f2 the date part in the first step, a date convert like SQL function convert() would give me the result without splitting and array as step between:

convert("$DatePart", +%Y-%m-%d) => 2013-07-02

Thanks, Celal

1 Answer 1


With the perl-based rename utitlity, and given a suitably recent version of perl (in particular, older versions of Time::Piece don't provide the use_locale method that enables parsing of non-English month and day names):

$ LC_TIME=de_DE.UTF-8 rename -n -- '
    BEGIN{use Time::Piece; Time::Piece->use_locale()};
    s/(.*?), (\d+\. \w+ \d+)/Time::Piece->strptime($2,"%d. %B %Y")->strftime("%Y-%m-%d.$1")/e
  ' *,\ */
rename(Capdepera, 2. Juli 2013/, 2013-07-02.Capdepera/)
rename(Marsa Alam, 31. Dezember 2011/, 2011-12-31.Marsa Alam/)
rename(Stuttgart, 13. Februar 2013/, 2013-02-13.Stuttgart/)

You can omit the LC_TIME=de_DE.UTF-8 assignment if your locale already uses German datetimes. The simpler case (with no GPS data string) is left as an exercise.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .