【问题标题】:How can I modify the access timestamp of a file to seconds before using a shell command in unix?如何在 unix 中使用 shell 命令之前将文件的访问时间戳修改为秒?
【发布时间】:2015-07-16 19:40:13
【问题描述】:

我尝试将文件的访问时间更改为秒前,例如设置“1437082451”(07/16/2015 @ 9:34:11pm (UTC)) 到“1437082450”(07/16/2015 @ 9:34:10pm (UTC)) 所以我只是将当前访问时间减去一秒。 我必须只使用 shell 命令来执行此操作,我搜索了一段时间但什么也没找到。

【问题讨论】:

    标签: shell date unix timestamp touch


    【解决方案1】:
    touch -at $(date -d @$(( $(stat -c '%X' "$filename") - 1)) '+%Y%m%d%H%M.%S') "$filename"
    

    使用stat 检索文件的当前访问时间,使用bash 算法减去一秒,并使用date 格式化touch 命令的新时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      相关资源
      最近更新 更多