linux touch 修改时间,linux – 使用touch命令将文件的修改时间设...

-t不接受纪元时间,-d确实如此

-d, --date=STRING

parse STRING and use it instead of current time

-t STAMP

use [[CC]YY]MMDDhhmm[.ss] instead of current time

您需要使用-d或–date而不是-t,并且需要在使用epochtime格式之前放置@,如日期联机帮助页中所述:

EXAMPLES

Convert seconds since the epoch (1970-01-01 UTC) to a date

$date --date='@2147483647'

例:

touch --date=@1442968132 test.txt

如果您只想更改修改时间,请使用-m或–time modify或–time mtime,如果没有,则修改和访问时间都会更改.

-m change only the modification time

--time=WORD

change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m

例子:

$touch --date=@1442968132 test

$stat test

File: test

Size: 0 Blocks: 0 IO Block: 4096 regular empty file

Device: fd03h/64771d Inode: 43266017 Links: 1

Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2015-09-23 02:28:52.000000000 +0200

Modify: 2015-09-23 02:28:52.000000000 +0200

Change: 2018-11-23 11:34:59.893888360 +0100

Birth: -

$touch --date=@1542968132 test

$stat test

File: test

Size: 0 Blocks: 0 IO Block: 4096 regular empty file

Device: fd03h/64771d Inode: 43266017 Links: 1

Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2018-11-23 11:15:32.000000000 +0100

Modify: 2018-11-23 11:15:32.000000000 +0100

Change: 2018-11-23 11:35:06.893888073 +0100

Birth: -

$touch -m --date=@1342968132 test

$stat test

File: test

Size: 0 Blocks: 0 IO Block: 4096 regular empty file

Device: fd03h/64771d Inode: 43266017 Links: 1

Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2018-11-23 11:15:32.000000000 +0100

Modify: 2012-07-22 16:42:12.000000000 +0200

Change: 2018-11-23 11:35:22.300887441 +0100

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值