Skip to content

Instantly share code, notes, and snippets.

@Phlow
Created October 11, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phlow/6c05ce9681e91a7be3fb to your computer and use it in GitHub Desktop.
Save Phlow/6c05ce9681e91a7be3fb to your computer and use it in GitHub Desktop.
Rename files and use their date
#!/bin/bash
# Copy MP3 files in a directory to a new name based solely on creation date
# FROM: foo.mp3 Created on: 2012-04-18 18:51:44
# TO: 20120418_185144.mp3
for i in *.mp3
do
# mod_date=$(stat -c "%y" "$i"|sed 's/\..*$//')
# mod_date=$(stat -c "%y" "$i"|awk '{print $1"_"$2}'|sed 's/\..*$//')
mod_date=$(stat --format %y "$i"|awk '{print $1"_"$2}'|cut -f1 -d'.'|sed 's/[: -]//g')
cp "$i" "$mod_date".mp3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment