touch 命令详解
Linux -- touch 创建及修改文件时间
TOUCH(1) User Commands TOUCH(1)
NAME 名称
touch - change file timestamps 修改文件时间戳
SYNOPSIS 大纲(语法)
touch [OPTION]... FILE...
DESCRIPTION 说明
Update the access and modification times of each FILE to the current time.
更新每个文件的访问时间和修改时间为当前时间。
A FILE argument that does not exist is created empty, unless -c or -h is supplied.
除非指定-c或-h参数,否则当FILE参数所指向的文件不存在时,将创建一个空文件。
A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output.
Mandatory arguments to long options are mandatory for short options too.
对于长选项必须的参数,对于短选项也是必须的。
-a
change only the access time
只修改访问时间。
-c, --no-create
do not create any files
不创建任何文件。
-d, --date=STRING
parse STRING and use it instead of current time
解析STRING,并使用它代替当前时间。
-f (ignored)
-h, --no-dereference
affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink)
只影响符号连接文件本身,而不影响任何被引用的文件(通常只针对可以改变符号连接文件时间戳的系统)。
-m
change only the modification time
只修改'修改时间。
-r, --reference=FILE
use this file's times instead of current time
使用此文件的时间代替当前时间。
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
使用[[CC]YY]MMDDhhmm[.ss]格式字符串代替当前时间。
--time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a; WORD is modify or mtime: equivalent to -m
修改指定的时间:当WORD=access, atime, or use时,等价于-a;当WORD=modify or mtime时,等价于-m。
--help display this help and exit
显示此命令的帮助信息并退出。
--version
output version information and exit
显示版本信息并退出。
Note that the -d and -t options accept different time-date formats.
-d与-t选项所接受的日期时间格式不同。
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report touch translation bugs to <http://translationproject.org/team/>
DATE STRING
The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.
--date=STRING指定的字符串通常是人类能够轻易识别的绝大多数*格式的字符串。例如:"Sun, 29 Feb 2004 16:21:42 -0800"或"2004-02-29 16:21:42"甚至"next Thursday"。日期字符串可以包含日历日期、时间、时区、周、相对时间、相对日期、数字等项目。空字符串表示当前天的开始。日期字符串格式比这里容易记录的复杂得多,但在info文档中有完全描述。
AUTHOR
Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith.
COPYRIGHT
Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for touch is maintained as a Texinfo manual. If the info and touch programs are properly installed at your site, the command
info coreutils 'touch invocation'
should give you access to the complete manual.
touch的完整文档是以Texinfo手册形式维护的。如果info和touch程序都已经安装,那么执行命令:
info coreutils 'touch invocation'
应该会让你访问到整篇手册。
GNU coreutils 8.22 June 2014 TOUCH(1)
案例:
一、查看文件详细时间信息方式
[root@user test]# ll total 4 -rw-r--r-- 1 root root 3072 Mar 6 21:22 test [root@user test]# stat test File: 'test' Size: 3072 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 65556 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-03-06 21:22:44.693495766 +0800 Modify: 2017-03-06 21:22:44.693495766 +0800 Change: 2017-03-06 22:40:59.432269895 +0800 Birth: - [root@user test]#
二、修改test的访问时间为‘2017-03-06 20:00:00’
[root@user test]# touch -a -d '2017-03-06 20:00:00' test [root@user test]# stat test File: 'test' Size: 3072 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 65556 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-03-06 20:00:00.000000000 +0800 Modify: 2017-03-06 21:22:44.693495766 +0800 Change: 2017-03-06 22:43:48.309459980 +0800 Birth: - [root@user test]#
下一篇: more 命令详解