Please note that I am not asking how to change the creation date of a bunch of files to a given date. I want to shift the date by a given amount of time, for example 47732400 seconds.
Can I accomplish this using touch
or something else in BASH?
touch only changes the creation time if the target modification time is before the original creation time.
for f in ~/Desktop/*; do
old=$(stat -f %B -t %s "$f")
touch -t $(date -r $(($old - 1234567)) +%Y%m%d%H%M%S) "$f"
done
SetFile always changes the creation time. It comes with the command line tools package that can be downloaded from Xcode's preferences or Apple's website.
for f in ~/Desktop/*; do
old=$(stat -f %B -t %s "$f")
new=$(date -r $(($old + 1234567)) '+%m/%d/%Y %H:%M:%S')
SetFile -d "$new" -m "$new" "$f"
done
stat -f %B -t %s
: format birth time, time format seconds since epoch
date -r
: reformat seconds since epoch
touch -t
: change access and modification times
SetFile -d
: change creation time
old=$(stat -c %Y "$f")
and touch -t $(date -d @$(($old - 47732400)) +%Y%m%d%H%M.%S) "$f"
.
Reusing and enhancing a previous answer to shift files dates with a reference file/date (the old GoPro always reset its time to 2009..)
ref_file=GOPR3440.MP4
new_time_for_that_file=0327160015 #date's format: 27th March 2015, 16:00
ref_file_timestamp=`stat -f %B -t %s "$ref_file"`
new_time_timestamp=`date -j $new_time_for_that_file +%s`
time_diff=$[$new_time_timestamp - $ref_file_timestamp]
for f in *; do
old=$(stat -f %B -t %s "$f")
new=$(date -r $(($old + $time_diff)) '+%m/%d/%Y %H:%M:%S')
SetFile -d "$new" -m "$new" "$f"
done