linux命令之touch
linux命令
linux命令之touch
touch
格式:touch (选项) (参数)
作用:
一、是用来创建新的空文件
二、是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;
选项:
r -a: 只更改存取时间
r -c: 不建立任何文件
r -d: <时间日期> 使用指定的日期时间,而非现在的时间
r -f: 此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题
r -m: 只更该变动时间
r -r: <参考文件或目录> 把指定文件或目录的日期时间,统统设成和参考文件或目录的日期时间相同
r -t: <日期时间> 使用指定的日期时间,而非现在的时间;
参数:
一、指定要创建的空文件名称
二、指定要设置时间属性的文件名称
示例:
1
在目录/mnt下创建空文件 a.txt b.txt
[root@localhost mnt]# touch a.txt b.txt
[root@localhost mnt]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 7 16:59 a.txt
-rw-r--r-- 1 root root 0 Nov 7 16:59 b.txt
2
复制/etc/passwd文件到/mnt目录下,使用 touch –a 修改文件passwd的存取时间
[root@localhost mnt]# cp -a /etc/passwd .
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2016-11-07 18:36:43.441999782 +0800
Modify: 2016-10-21 18:15:07.082976185 +0800
Change: 2016-11-07 17:03:09.395040011 +0800
Birth: -
[root@localhost mnt]# touch -a passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2016-11-07 17:04:09.175035587 +0800
Modify: 2016-10-21 18:15:07.082976185 +0800
Change: 2016-11-07 17:04:09.175035587 +0800
Birth: -
3
使用touch –d 修改文件passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2016-11-07 17:04:09.175035587 +0800
Modify: 2016-10-21 18:15:07.082976185 +0800
Change: 2016-11-07 17:04:09.175035587 +0800
Birth: -
[root@localhost mnt]# touch -d
2018-10-12 passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2018-10-12 00:00:00.000000000 +0800
Modify: 2018-10-12 00:00:00.000000000 +0800
Change: 2016-11-07 17:04:35.739033621 +0800
Birth: -
4
使用touch –m 修改文件passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2018-10-12 00:00:00.000000000 +0800
Modify: 2018-10-12 00:00:00.000000000 +0800
Change: 2016-11-07 17:04:35.739033621 +0800
Birth: -
[root@localhost mnt]# touch -m passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2018-10-12 00:00:00.000000000 +0800
Modify: 2016-11-07 17:05:07.385031279 +0800
Change: 2016-11-07 17:05:07.385031279 +0800
Birth: -
5
使用touch –r修改文件passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2018-10-12 00:00:00.000000000 +0800
Modify: 2016-11-07 17:05:07.385031279 +0800
Change: 2016-11-07 17:05:07.385031279 +0800
Birth: -
[root@localhost mnt]# touch -r /etc/passwd passwd
[root@localhost mnt]# stat passwd
File: ‘passwd’
Size: 2264 Blocks:
8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4558657 Links: 1
Access: (0644/-rw-r--r--) Uid: (
0/ root) Gid: (
0/ root)
Access: 2016-11-07 18:36:43.441999782 +0800
Modify: 2016-10-21 18:15:07.082976185 +0800
Change: 2016-11-07 17:06:45.478024019 +0800
Birth: -
◆Time 使用指定时间而不是当前时间。Time 变量以十进制形[[CC]YY]MMDDhhmm[.SS] 指定
文章来源: zmedu.blog.csdn.net,作者:互联网老辛,版权归原作者所有,如需转载,请联系作者。
原文链接:zmedu.blog.csdn.net/article/details/103259515
- 点赞
- 收藏
- 关注作者
评论(0)