touch

touch – change file timestamps

更新文件时间戳。

更新文件的访问时间和修改时间为当前时间,默认情况下若该文件不存在则创建该文件。

语法

touch [OPTION]... FILE...

[选项]

-a : 只更新文件的访问时间。

-c, –no-create : 即使文件不存在也不创建文件。

-d, –date=STRING : 使用指定的时间替换当前的时间。

-h, –no-dereference : 只更新软链接的时间戳。

-m : 只更新修改时间戳。

-r, –reference=FILE : 使用指定文件的时间戳来更新该文件的时间戳。

-t STAMP : 使用 [[CC]YY]MMDDhhmm[.ss] 替换当前的时间。

–time=WORD : 只更新指定的时间戳如 访问时间 access 修改时间 atime。

[参数]

要更新时间戳的文件名。

[实例]

[root@z-dig ~]# stat tools
  File: `tools'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 32468       Links: 4
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-07-30 10:05:50.717250974 +0800
Modify: 2015-07-21 22:43:02.803539704 +0800
Change: 2015-07-21 22:43:02.803539704 +0800
[root@z-dig ~]# touch tools
[root@z-dig ~]# stat tools 
  File: `tools'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 32468       Links: 4
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-08-05 12:14:46.223082051 +0800
Modify: 2015-08-05 12:14:46.223082051 +0800
Change: 2015-08-05 12:14:46.223082051 +0800
[root@z-dig ~]# 
[root@z-dig ~]# stat anaconda-ks.cfg 
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-07-13 22:06:44.995549970 +0800
Modify: 2015-06-17 22:36:03.322999728 +0800
Change: 2015-06-17 22:36:05.978999725 +0800
[root@z-dig ~]# touch -a anaconda-ks.cfg 
[root@z-dig ~]# stat anaconda-ks.cfg     
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-08-05 12:15:51.528094269 +0800
Modify: 2015-06-17 22:36:03.322999728 +0800
Change: 2015-08-05 12:15:51.528094269 +0800
[root@z-dig ~]# 
[root@z-dig ~]# ls -l touchtest_1
ls: cannot access touchtest_1: No such file or directory
[root@z-dig ~]# touch touchtest_1
[root@z-dig ~]# ls -l touchtest_1
-rw-r--r-- 1 root root 0 Aug  5 12:17 touchtest_1
[root@z-dig ~]# ls -l touchtest_2
ls: cannot access touchtest_2: No such file or directory
[root@z-dig ~]# touch -c touchtest_2
[root@z-dig ~]# ls -l touchtest_2   
ls: cannot access touchtest_2: No such file or directory
[root@z-dig ~]# 
[root@z-dig ~]# stat anaconda-ks.cfg 
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-08-05 12:15:51.528094269 +0800
Modify: 2015-06-17 22:36:03.322999728 +0800
Change: 2015-08-05 12:15:51.528094269 +0800
[root@z-dig ~]# touch -d "2018-08-08" anaconda-ks.cfg 
[root@z-dig ~]# stat anaconda-ks.cfg                  
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2018-08-08 00:00:00.000000000 +0800
Change: 2015-08-05 12:18:47.073092676 +0800
[root@z-dig ~]# 
[root@z-dig ~]# stat src
  File: `src'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 32466       Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-08-05 12:11:27.017095967 +0800
Modify: 2015-08-05 12:11:27.017095967 +0800
Change: 2015-08-05 12:11:27.017095967 +0800
[root@z-dig ~]# ln -s src src_link
[root@z-dig ~]# stat src_link
  File: `src_link' -> `src'
  Size: 3               Blocks: 0          IO Block: 4096   symbolic link
Device: 803h/2051d      Inode: 51188       Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-08-05 12:20:12.049089821 +0800
Modify: 2015-08-05 12:20:12.049089821 +0800
Change: 2015-08-05 12:20:12.049089821 +0800
[root@z-dig ~]# touch -h -d "2018-08-08" src_link
[root@z-dig ~]# stat src_link                    
  File: `src_link' -> `src'
  Size: 3               Blocks: 0          IO Block: 4096   symbolic link
Device: 803h/2051d      Inode: 51188       Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2018-08-08 00:00:00.000000000 +0800
Change: 2015-08-05 12:22:36.470094847 +0800
[root@z-dig ~]# stat src
  File: `src'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 32466       Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-08-05 12:11:27.017095967 +0800
Modify: 2015-08-05 12:11:27.017095967 +0800
Change: 2015-08-05 12:11:27.017095967 +0800
[root@z-dig ~]# 


[root@z-dig ~]# touch -d "2018-08-08" src_link   
[root@z-dig ~]# stat src
  File: `src'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 32466       Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2018-08-08 00:00:00.000000000 +0800
Change: 2015-08-05 12:23:24.297089219 +0800
[root@z-dig ~]# 
[root@z-dig ~]# stat anaconda-ks.cfg 
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2018-08-08 00:00:00.000000000 +0800
Change: 2015-08-05 12:18:47.073092676 +0800
[root@z-dig ~]# touch -m anaconda-ks.cfg 
[root@z-dig ~]# stat anaconda-ks.cfg     
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2015-08-05 12:24:24.214096261 +0800
Change: 2015-08-05 12:24:24.214096261 +0800
[root@z-dig ~]# 
[root@z-dig ~]# stat anaconda-ks.cfg 
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2015-08-05 12:24:24.214096261 +0800
Change: 2015-08-05 12:24:24.214096261 +0800
[root@z-dig ~]# stat src
  File: `src'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 32466       Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2018-08-08 00:00:00.000000000 +0800
Change: 2015-08-05 12:23:24.297089219 +0800
[root@z-dig ~]# touch -r src anaconda-ks.cfg 
[root@z-dig ~]# stat anaconda-ks.cfg 
  File: `anaconda-ks.cfg'
  Size: 1057            Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 28084       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-08 00:00:00.000000000 +0800
Modify: 2018-08-08 00:00:00.000000000 +0800
Change: 2015-08-05 12:25:48.329068629 +0800
[root@z-dig ~]# 


正文部分到此结束

转载请注明原文链接 http://www.z-dig.com/touch.html