touch命令的作用linux中touch命令的功能与格式linux touch命令详解




touch命令的作用linux中touch命令的功能与格式linux touch命令详解

2022-07-20 19:31:03 网络知识 官方管理员

如果创建一个新文件有很多种方法,比如:

vifilecat>fileecho"hello,world">filetouchfiletouch命令不仅可以创建新文件,而且可以修改文件的时间属性;

touch命令的作用(linux中touch命令的功能与格式)(1)

格式:touch[option][file]

备注:

1)-t选项的时间格式[[CC]YY]MMDDhhmm[.ss]说明:

touch命令的作用(linux中touch命令的功能与格式)(2)

2)touch命令的几点说明:

touch命令的作用(linux中touch命令的功能与格式)(3)

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.txt

2,创建文件,并用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.4398569370800Modify:2018-05-0117:25:16.4398569370800Change:2018-05-0117:25:16.4398569370800Birth:-最后有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.4398569370800Modify:2018-05-0117:25:16.4398569370800Change:2018-05-0117:25:16.4398569370800Birth:-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.8872151390800Modify:2018-05-0117:25:16.4398569370800Change:2018-05-0117:25:16.4398569370800Birth:-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.8872151390800Modify:2018-05-0117:25:16.4398569370800Change:2018-05-0117:25:16.4398569370800Birth:-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.9822288020800Modify:2018-05-0117:29:34.9822288020800Change:2018-05-0117:29:35.0182313920800Birth:-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.9822288020800Modify:2018-05-0117:29:34.9822288020800Change:2018-05-0117:29:35.0182313920800Birth:-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.9822288020800Modify:2018-05-0117:29:34.9822288020800Change:2018-05-0117:32:25.3928637910800

2,修改文件的权限,changetime发生了改变

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.9822288020800Modify:2018-05-0117:29:34.9822288020800Change:2018-05-0117:32:25.3928637910800Birth:-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.9822288020800Modify:2018-05-0117:29:34.9822288020800Change:2018-05-0117:33:31.6025841100800Birth:-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.9822288020800Modify:2018-05-0117:29:34.9822288020800Change:2018-05-0117:33:31.6025841100800Birth:-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.9822288020800Modify:2018-05-0117:34:31.6788649850800Change:2018-05-0117:34:31.6788649850800touch-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.0000000000800Modify:2019-02-1800:00:00.0000000000800Change:2018-05-0117:37:13.0313474810800Birth:-


发表评论:

最近发表
网站分类
标签列表