Last active
October 5, 2019 23:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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