Advertisement
cmurillo

Batch shift the creation date of files on Mac OS

Feb 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.61 KB | None | 0 0
  1. # Batch shift the creation date of files on Mac OS
  2. # Source: https://superuser.com/a/894991/105418
  3. # to shift files dates with a reference file/date (the old GoPro always reset its time to 2009..)
  4.  
  5. ref_file=GOPR3440.MP4
  6. new_time_for_that_file=0327160015 #date's format: 27th March 2015, 16:00
  7.  
  8. ref_file_timestamp=`stat -f %B -t %s "$ref_file"`
  9. new_time_timestamp=`date -j $new_time_for_that_file +%s`
  10. time_diff=$[$new_time_timestamp - $ref_file_timestamp]
  11.  
  12. for f in *; do
  13.     old=$(stat -f %B -t %s "$f")
  14.     new=$(date -r $(($old + $time_diff)) '+%m/%d/%Y %H:%M:%S')
  15.     SetFile -d "$new" -m "$new" "$f"
  16. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement