linux系统中如何使用touch命令
短信预约 -IT技能 免费直播动态提醒
这篇文章给大家分享的是有关linux系统中如何使用touch命令的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件。
适用场景:
如果创建一个新文件有很多种方法,比如:
vi filecat > fileecho "hello,world" > filetouch filetouch命令不仅可以创建新文件,而且可以修改文件的时间属性;
格式: touch [option] [file]
备注:
\1) -t选项的时间格式[[CC]YY]MMDDhhmm[.ss]说明:\2) touch命令的几点说明:
1,同时创建一个或者多个空文件
linuxidc@linuxidc:~/linux/mkdir$ lslinuxidc@linuxidc:~/linux/mkdir$ touch a.txtlinuxidc@linuxidc:~/linux/mkdir$ lsa.txtlinuxidc@linuxidc:~/linux/mkdir$ touch b.txt c.txtlinuxidc@linuxidc:~/linux/mkdir$ lsa.txt b.txt c.txtlinuxidc@linuxidc:~/linux/mkdir$ touch {1..5}.txtlinuxidc@linuxidc:~/linux/mkdir$ ls1.txt 2.txt 3.txt 4.txt 5.txt a.txt b.txt c.txt
2,创建文件,并用stat查看文件的属性状态信息
linuxidc@linuxidc:~/linux/mkdir$ touch linuxidc.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt File: 'linuxidc.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty filelinuxidcice: 807h/2055d Inode: 9569451 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:25:16.439856937 +0800Modify: 2018-05-01 17:25:16.439856937 +0800Change: 2018-05-01 17:25:16.439856937 +0800Birth: -最后有3个时间Access time: 最后访问时间,查看文件的内容时,这个时间会改变,使用cat命令查看文件时,可以看出Access time已经变了linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt File: 'linuxidc.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty filelinuxidcice: 807h/2055d Inode: 9569451 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:25:16.439856937 +0800Modify: 2018-05-01 17:25:16.439856937 +0800Change: 2018-05-01 17:25:16.439856937 +0800Birth: -linuxidc@linuxidc:~/linux/mkdir$ cat linuxidc.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt File: 'linuxidc.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty filelinuxidcice: 807h/2055d Inode: 9569451 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:27:51.887215139 +0800Modify: 2018-05-01 17:25:16.439856937 +0800Change: 2018-05-01 17:25:16.439856937 +0800Birth: -Modify time:最后修改时间,修改文件内容,文件的修改时间会改变。访问时间和状态改变时间 也发生变化linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt File: 'linuxidc.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty filelinuxidcice: 807h/2055d Inode: 9569451 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:27:51.887215139 +0800Modify: 2018-05-01 17:25:16.439856937 +0800Change: 2018-05-01 17:25:16.439856937 +0800Birth: -linuxidc@linuxidc:~/linux/mkdir$ vim linuxidc.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt File: 'linuxidc.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:29:34.982228802 +0800Change: 2018-05-01 17:29:35.018231392 +0800Birth: -Change time:状态改变时间,修改文件内容,移动文件,或者改变文件属性等,文件的change time会发生改变.1,移动文件( 重命名 ), change time 发生改变:linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt File: 'linuxidc.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:29:34.982228802 +0800Change: 2018-05-01 17:29:35.018231392 +0800Birth: -linuxidc@linuxidc:~/linux/mkdir$ mv linuxidc.txt linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt File: 'linuxidc2.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:29:34.982228802 +0800Change: 2018-05-01 17:32:25.392863791 +0800
3,修改文件的权限,change time发生了改变
linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt File: 'linuxidc2.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:29:34.982228802 +0800Change: 2018-05-01 17:32:25.392863791 +0800Birth: -linuxidc@linuxidc:~/linux/mkdir$ chmod 777 linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt File: 'linuxidc2.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0777/-rwxrwxrwx) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:29:34.982228802 +0800Change: 2018-05-01 17:33:31.602584110 +0800Birth: -touch -m修改文件的modify和change时间linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt File: 'linuxidc2.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0777/-rwxrwxrwx) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:29:34.982228802 +0800Change: 2018-05-01 17:33:31.602584110 +0800Birth: -linuxidc@linuxidc:~/linux/mkdir$ touch -m linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt File: 'linuxidc2.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0777/-rwxrwxrwx) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2018-05-01 17:29:34.982228802 +0800Modify: 2018-05-01 17:34:31.678864985 +0800Change: 2018-05-01 17:34:31.678864985 +0800touch -d修改创建后的文件的修改时间linuxidc@linuxidc:~/linux/mkdir$ ls -lh linuxidc2.txt-rwxrwxrwx 1 linuxidc linuxidc 5 5月 1 17:34 linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ touch -d 20190218 linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ ls -lh linuxidc2.txt-rwxrwxrwx 1 linuxidc linuxidc 5 2月 18 2019 linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt File: 'linuxidc2.txt' Size: 5 Blocks: 8 IO Block: 4096 regular filelinuxidcice: 807h/2055d Inode: 9569550 Links: 1Access: (0777/-rwxrwxrwx) Uid: ( 1000/ linuxidc) Gid: ( 1000/ linuxidc)Access: 2019-02-18 00:00:00.000000000 +0800Modify: 2019-02-18 00:00:00.000000000 +0800Change: 2018-05-01 17:37:13.031347481 +0800Birth: -
感谢各位的阅读!关于“linux系统中如何使用touch命令”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341