touch :更新文件时间或创建空白文件
1.命令格式
touch [选项] 文件
2.命令功能
原意是用来更新文件的时间戳,现在多数用来创建空白文件。
3.命令参数
-a :只更改存取时间
-m :只更改修改时间
-c :不创建任何文件
-t :使用指定的日期和时间,而非现在的时间
4.命令实例
例子1:创建不存在的空白文件
[root@bogon ~]# touch file1
[root@bogon ~]# ls
aa abc anaconda-ks.cfg Desktop file1 gg install.log install.log.syslog
例子2:更改存取时间
[root@bogon ~]# stat file1
File: `file1‘
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 2709265 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-21 17:02:49.000000000 +0800
Modify: 2014-12-21 17:02:49.000000000 +0800
Change: 2014-12-21 17:02:49.000000000 +0800
[root@bogon ~]# touch -a file1
[root@bogon ~]# stat file1
File: `file1‘
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 2709265 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-21 17:05:37.000000000 +0800
Modify: 2014-12-21 17:02:49.000000000 +0800
Change: 2014-12-21 17:05:37.000000000 +0800
例子3:更改修改时间
[root@bogon ~]# stat file1
File: `file1‘
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 2709265 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-21 17:05:37.000000000 +0800
Modify: 2014-12-21 17:02:49.000000000 +0800
Change: 2014-12-21 17:05:37.000000000 +0800
[root@bogon ~]# touch -m file1
[root@bogon ~]# stat file1
File: `file1‘
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 2709265 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-21 17:05:37.000000000 +0800
Modify: 2014-12-21 17:07:48.000000000 +0800
Change: 2014-12-21 17:07:48.000000000 +0800
例子4:不创建任何文件
[root@bogon ~]# ls
aa abc anaconda-ks.cfg Desktop file1 gg install.log install.log.syslog
[root@bogon ~]# touch -c file2
[root@bogon ~]# ls
aa abc anaconda-ks.cfg Desktop file1 gg install.log install.log.syslog
例子5:使用指定时间
[root@bogon ~]# touch -t 201412211712.30 file2
[root@bogon ~]# stat file2
File: `file2‘
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 2709266 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-21 17:12:30.000000000 +0800
Modify: 2014-12-21 17:12:30.000000000 +0800
Change: 2014-12-21 17:13:20.000000000 +0800
本文出自 “冷血杀手” 博客,请务必保留此出处http://deathkiller.blog.51cto.com/9130248/1592314
原文地址:http://deathkiller.blog.51cto.com/9130248/1592314