【问题标题】:Changing the change timestamp on a file Linux更改文件 Linux 上的更改时间戳
【发布时间】:2018-11-08 18:22:13
【问题描述】:

所以我正在尝试使用从这里获得的脚本更改文件的更改时间戳:Setting/changing the ctime or "Change time" attribute on a file

#!/bin/sh
now=$(date)
echo $now
sudo date --set="qui nov 7 21:05:56 WET 2018"
chmod 777 $1
sudo date --set="$now"

这是输出:

qui nov 8 18:19:39 WET 2018
date: invalid date ‘qui nov 7 21:05:56 WET 2018’
date: invalid date ‘qui nov  8 18:19:39 WET 2018’

这是怎么回事? date 的输出不是有效日期?我尝试了对我链接的答案的评论中建议的修复,但它也不起作用。

【问题讨论】:

  • touch 是一种比更改系统时间更容易修改文件时间戳的方法。

标签: linux date sh


【解决方案1】:

AFAIK 论据不同的原因:

$ info date

   Invoking 'date' with no FORMAT argument is equivalent to invoking it
with a default format that depends on the 'LC_TIME' locale category.  

Setting the time下:

If given an argument that does not start with '+', 'date' sets the
system clock to the date and time specified by that argument (as
described below).  You must have appropriate privileges to set the
system clock.  Note for changes to persist across a reboot, the hardware
clock may need to be updated from the system clock, which might not
happen automatically on your system.

   The argument must consist entirely of digits, which have the
following meaning:

'MM'
     month
'DD'
     day within month
'hh'
     hour
'mm'
     minute
'CC'
     first two digits of year (optional)
'YY'
     last two digits of year (optional)
'ss'
     second (optional)

   Note, the '--date' and '--set' options may not be used with an
argument in the above format.  The '--universal' option may be used with
such an argument to indicate that the specified date and time are
relative to Coordinated Universal Time rather than to the local time
zone.

【讨论】:

  • 你试过这种格式吗? now=$(date "+%Y%m%d%H%M%S")
猜你喜欢
  • 2016-01-09
  • 1970-01-01
  • 2018-11-27
  • 1970-01-01
  • 2017-05-09
  • 2017-03-30
  • 1970-01-01
  • 1970-01-01
  • 2019-02-14
相关资源
最近更新 更多