Add modified date to filename in bash

Quick little bash snippet: I needed to prepend all files in a directory with their respective modified times. This was to make sorting in various applications easier. This is what I came up with.

for file in *.mp3; do mv "$file" $(date +%Y%m%d-%H%M%S -r $file")_"$file"; done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.