You could use a combination of date
and touch
, here GNU coreutils.
If I read you correctly you want a specific date and keep file time, as in HMS. Not set each file say 300 days prior to the current value.
You can create that time by combining the string 2014-05-25
with the extracted time from the files by using date
, for example:
$ date +"2014-05-25 %T.%N" -r file.jpg
2014-05-25 18:06:28.277679656
Then combine by doing something like:
for f in *.jpg; do touch -d "$(date +"2014-05-25 %T.%N" -r "$f")" "$f"; done
Note that this can mess with DST and timezone.
An alternative might be to add %z
at end of date string, or add -u
to date
options.
TZ=UTC0 touch -d "$(date -u +"2014-05-25 %T.%N" -r "$f")"
Test
Test, test, test before action. Check with ls --full-time
, echo instead of touch etc. find ... -printf
also have time/date options.
You could even do a backup of times to a text file.
Notes:
From Q:
- 1969 days ago is 29 Sep 2010.
- 1969 days into the future is Jul 11 2021 (at least in my time zone).
- To get May 25 2014 from
"-1969 days ago"
current date has to be 15 Oct 2019.
The issue with "-1969 days ago"
is that you have a minus in front of the time.
Minus + minus = plus
Either remove the minus sign, or remove the ago
part.
1969 days ago
is 29 Sep 2010, as is -1969 days
for f in *.jpg; do TZ=UTC0 touch -d "$(date -u +"2014-05-25 %T.%N" -r "$f")" "$f"; done
worked perfectly for me. – iembry Feb 20 '16 at 04:16