如何用UTC中的时间戳"触摸"文件?

Dim*_*nek 1 unix shell time touch

在我的系统上,我必须运行touch -t '197001010100' filename以获得0秒的统计时间戳.

我假设1小时的偏移是由于我的时区,是否有一种跨Unix方式来触摸文件并获得零tiemstamp,就像Unix Epoch一样?

anu*_*ava 5

您可以TZ=UTC在这些命令之前使用以确保使用UTC时区:

TZ=UTC touch -t '197001010000' filename
TZ=UTC stat -c '%y %n' filename
1970-01-01 00:00:00.000000000 +0000 filename
Run Code Online (Sandbox Code Playgroud)

PS:你也需要使用时间戳197001010000而不是197001010100.

  • [POSIX规范](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html#tag_20_130_08)规定`touch`应尊重`TZ`. (2认同)