Skip to content

Instantly share code, notes, and snippets.

@gfxhacks
Created July 4, 2020 04:16
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 gfxhacks/cf22de9b016bb4c23a117611fef9255a to your computer and use it in GitHub Desktop.
Save gfxhacks/cf22de9b016bb4c23a117611fef9255a to your computer and use it in GitHub Desktop.
Rename files by creation date in OSX. More info: https://gfxhacks.com/renaming-files-by-date-from-metadata
#-- Make sure to specify your own filename.ext and all .ext instances.
#-- To overwrite the file, swap cp with mv.
# copy and rename file
cp filename.ext "newFileName-$(mdls -name kMDItemContentCreationDate filename.ext | sed 's/[^0-9]//g' | cut -c 3-14).ext"
# copy and rename all files in folder with specified extension.
for i in folder/*.ext; do cp "$i" "SomeTextHere-$(mdls -name kMDItemContentCreationDate "$i" | sed -e 's/[^0-9]//g' | cut -c 3-8)-someMoreTextHere.ext"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment