Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adamrosloniec/d74b1e4265c4bbbdcbd13e03e91dca15 to your computer and use it in GitHub Desktop.
Save adamrosloniec/d74b1e4265c4bbbdcbd13e03e91dca15 to your computer and use it in GitHub Desktop.
Command Line Bash - Change file date modified to date taken/created - For each file in directory - Linux/Mac
# Command Line Bash - Change file date modified to date taken/created - For each file in directory - Linux/Mac
# 1. Best method, find file with .jpg extension, and do function:
find . -iname \*.jpg -exec sh -c 'for f in "$@";do m="$(GetFileInfo -d "$f")";SetFile -m "$m" -d "$m" "$f";done' sh {} +
# 2. My old method - Example with all files in current directory:
for f in $(ls .);do touch -t $(date -r $(stat -f%B $f) +%Y%m%d%H%M) $f;done
# 3. My old method - Example with all files in specific directory:
# specific directory is for example:
# /Users/adamrosloniec/Downloads/BACKUP-PHOTOS/
for f in $(ls /Users/adamrosloniec/Downloads/BACKUP-PHOTOS/);do touch -t $(date -r $(stat -f%B $f) +%Y%m%d%H%M) $f;done
# 4. My old method - Example with only .jpg files in specific directory:
for f in $(ls /Users/adamrosloniec/Downloads/BACKUP-PHOTOS/*.jpg);do touch -t $(date -r $(stat -f%B $f) +%Y%m%d%H%M) $f;done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment