Skip to content

Instantly share code, notes, and snippets.

@averagesecurityguy
Created November 16, 2020 23:55
Show Gist options
  • Save averagesecurityguy/9c853157da6394af15659ef1926ae157 to your computer and use it in GitHub Desktop.
Save averagesecurityguy/9c853157da6394af15659ef1926ae157 to your computer and use it in GitHub Desktop.
Extract the creation date from an image and add the date to the filename. Only works on Mac.
#!/bin/bash
#
# Extract the creation date from an image and add the date to the filename.
# Only works on Mac.
#
DUMP_DIR="/Users/family/pics/dump"
CP_DIR="/Users/family/pics/dated"
cd "$DUMP_DIR"
OLDIFS=$IFS
IFS=$'\n'
for file in $(ls); do
date=$(mdls "$file" | grep "kMDItemContentCreationDate " | cut -d '=' -f 2 | cut -d ' ' -f 2)
newfile=$(echo "$date-$file")
echo "cp $file $CP_DIR/$newfile"
cp "$file" "$CP_DIR/$newfile"
done
IFS=$OLDIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment