linux系统中如何使用touch命令
这篇文章给大家分享的是有关linux系统中如何使用touch命令的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件。
如果创建一个新文件有很多种方法,比如:
vifilecat>fileecho"hello,world">filetouchfiletouch命令不仅可以创建新文件,而且可以修改文件的时间属性;
格式: touch [option] [file]
备注:
\1) -t选项的时间格式[[CC]YY]MMDDhhmm[.ss]说明:\2) touch命令的几点说明:
1,同时创建一个或者多个空文件linuxidc@linuxidc:~/linux/mkdir$lslinuxidc@linuxidc:~/linux/mkdir$toucha.txtlinuxidc@linuxidc:~/linux/mkdir$lsa.txtlinuxidc@linuxidc:~/linux/mkdir$touchb.txtc.txtlinuxidc@linuxidc:~/linux/mkdir$lsa.txtb.txtc.txtlinuxidc@linuxidc:~/linux/mkdir$touch{1..5}.txtlinuxidc@linuxidc:~/linux/mkdir$ls1.txt2.txt3.txt4.txt5.txta.txtb.txtc.txt2,创建文件,并用stat查看文件的属性状态信息
linuxidc@linuxidc:~/linux/mkdir$touchlinuxidc.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc.txtFile:'linuxidc.txt'Size:0Blocks:0IOBlock:4096regularemptyfilelinuxidcice:807h/2055dInode:9569451Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:25:16.439856937+0800Modify:2018-05-0117:25:16.439856937+0800Change:2018-05-0117:25:16.439856937+0800Birth:-最后有3个时间Accesstime:最后访问时间,查看文件的内容时,这个时间会改变,使用cat命令查看文件时,可以看出Accesstime已经变了linuxidc@linuxidc:~/linux/mkdir$statlinuxidc.txtFile:'linuxidc.txt'Size:0Blocks:0IOBlock:4096regularemptyfilelinuxidcice:807h/2055dInode:9569451Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:25:16.439856937+0800Modify:2018-05-0117:25:16.439856937+0800Change:2018-05-0117:25:16.439856937+0800Birth:-linuxidc@linuxidc:~/linux/mkdir$catlinuxidc.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc.txtFile:'linuxidc.txt'Size:0Blocks:0IOBlock:4096regularemptyfilelinuxidcice:807h/2055dInode:9569451Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:27:51.887215139+0800Modify:2018-05-0117:25:16.439856937+0800Change:2018-05-0117:25:16.439856937+0800Birth:-Modifytime:最后修改时间,修改文件内容,文件的修改时间会改变。访问时间和状态改变时间也发生变化linuxidc@linuxidc:~/linux/mkdir$statlinuxidc.txtFile:'linuxidc.txt'Size:0Blocks:0IOBlock:4096regularemptyfilelinuxidcice:807h/2055dInode:9569451Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:27:51.887215139+0800Modify:2018-05-0117:25:16.439856937+0800Change:2018-05-0117:25:16.439856937+0800Birth:-linuxidc@linuxidc:~/linux/mkdir$vimlinuxidc.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc.txtFile:'linuxidc.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:29:34.982228802+0800Change:2018-05-0117:29:35.018231392+0800Birth:-Changetime:状态改变时间,修改文件内容,移动文件,或者改变文件属性等,文件的changetime会发生改变.1,移动文件(重命名),changetime发生改变:linuxidc@linuxidc:~/linux/mkdir$statlinuxidc.txtFile:'linuxidc.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:29:34.982228802+0800Change:2018-05-0117:29:35.018231392+0800Birth:-linuxidc@linuxidc:~/linux/mkdir$mvlinuxidc.txtlinuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc2.txtFile:'linuxidc2.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:29:34.982228802+0800Change:2018-05-0117:32:25.392863791+08003,修改文件的权限,change time发生了改变
linuxidc@linuxidc:~/linux/mkdir$statlinuxidc2.txtFile:'linuxidc2.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0664/-rw-rw-r--)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:29:34.982228802+0800Change:2018-05-0117:32:25.392863791+0800Birth:-linuxidc@linuxidc:~/linux/mkdir$chmod777linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc2.txtFile:'linuxidc2.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0777/-rwxrwxrwx)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:29:34.982228802+0800Change:2018-05-0117:33:31.602584110+0800Birth:-touch-m修改文件的modify和change时间linuxidc@linuxidc:~/linux/mkdir$statlinuxidc2.txtFile:'linuxidc2.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0777/-rwxrwxrwx)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:29:34.982228802+0800Change:2018-05-0117:33:31.602584110+0800Birth:-linuxidc@linuxidc:~/linux/mkdir$touch-mlinuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc2.txtFile:'linuxidc2.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0777/-rwxrwxrwx)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2018-05-0117:29:34.982228802+0800Modify:2018-05-0117:34:31.678864985+0800Change:2018-05-0117:34:31.678864985+0800touch-d修改创建后的文件的修改时间linuxidc@linuxidc:~/linux/mkdir$ls-lhlinuxidc2.txt-rwxrwxrwx1linuxidclinuxidc55月117:34linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$touch-d20190218linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$ls-lhlinuxidc2.txt-rwxrwxrwx1linuxidclinuxidc52月182019linuxidc2.txtlinuxidc@linuxidc:~/linux/mkdir$statlinuxidc2.txtFile:'linuxidc2.txt'Size:5Blocks:8IOBlock:4096regularfilelinuxidcice:807h/2055dInode:9569550Links:1Access:(0777/-rwxrwxrwx)Uid:(1000/linuxidc)Gid:(1000/linuxidc)Access:2019-02-1800:00:00.000000000+0800Modify:2019-02-1800:00:00.000000000+0800Change:2018-05-0117:37:13.031347481+0800Birth:-
感谢各位的阅读!关于“linux系统中如何使用touch命令”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。