Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the bunch of files that have names like MOV001.mpg, MOV002.mpg etc. They all have different date-time.

How can I rename them so they turn into 2012 08 05 13 45 33 MOV001.mpg, 2012 09 02 23 45 07 MOV002.mpg etc.?

In other words, how can I extract the date and time information from the files I rename?

Thank you much in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Untested:

for f in *.mpg; do
  mv "$f" "$(stat -f "%m" -t "%Y %m %d %H %M %S" "$f") $f"
done

stat -f "%m" should produce the last modified date of the file, -t "%Y %m %d %H %M %S" should format the date according to your requirements.

share|improve this answer
    
Thank you. Helped when using stat -f "%Sm" instead of stat -f "%m" –  Sunny Reborn Pony Nov 15 '12 at 9:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.