qarma qarma - 1 month ago 8
Bash Question

How to "touch" a file with timestamp in UTC?

On my system I have to run

touch -t '197001010100' filename
to get stat timestamp of 0 seconds.

I assume the 1 hour offset is due to my timezone, is there a cross-Unix way to touch a file and get zero tiemstamp, as in Unix Epoch?

Answer

You can use TZ=UTC before these commands to make sure to use UTC timezone:

TZ=UTC touch -t '197001010000' filename
TZ=UTC stat -c '%y %n' filename
1970-01-01 00:00:00.000000000 +0000 filename

PS: Also you need use timestamp as 197001010000 instead of 197001010100.

Comments