-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