stat文本编辑器我们知道touch是创建文件,其实touch是用来修改文件的时间戳,同时 ,文件是有三个时间访问时间记录最近一次文件被访问时间,只要一个文件被打开,就意味着背后有一个相应的IO,打开是一个写IO(写访问时间到磁盘属性中)
touch命令:
[root@docker-node1 ~]# touch linuxea
[root@docker-node1 ~]# file linuxea
linuxea: empty
[root@docker-node1 ~]#
touch一个文件后,file其实是无法判断这个文件类型的,在touch一个不存在的文件时,默认是创建一个空文件,很多时候touch就被哪来用作创建空文件命令,这种默认是可以修改的,文件如果有则改时间戳,如果没有也不会创建文件
[root@docker-node1 ~]# touch -c linuxea1
[root@docker-node1 ~]# ll linuxea1
ls: cannot access linuxea1: No such file or directory
[root@docker-node1 ~]#
因此,如果仅仅只是修改时间戳,则可以使用-c选项
stat命令:显示文件系统和文件的源或者说是属性信息
[root@docker-node1 ~]# stat linuxea
File: ‘linuxea’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 71359973 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-07-12 14:23:31.396999492 -0400
Modify: 2016-07-12 14:23:31.396999492 -0400
Change: 2016-07-12 14:23:31.396999492 -0400
Birth: -
size:大小blocks:占据的磁盘块io block:一次io传递大小regular empty file:文件类型Device:存放的设备Inode: 71359973 inode号Links: 1 :链接次数Access: (0644/-rw-r--r--) :访问权限 Uid: ( 0/ root):UID 属主 Gid: ( 0/ root):GID 属组 三个时间戳Access: 2016-07-12 14:23:31.396999492 -0400 访问时间Modify: 2016-07-12 14:23:31.396999492 -0400 修改Change: 2016-07-12 14:23:31.396999492 -0400 状态改变时间
stat查看修改时间戳:源时间
[root@docker-node1 ~]# stat in.sh
File: ‘in.sh’
Size: 134 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 68352533 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-07-05 08:51:01.280561305 -0400
Modify: 2016-06-30 14:29:48.428395106 -0400
Change: 2016-06-30 14:29:52.828395524 -0400
Birth: -
[root@docker-node1 ~]#
touch一次后,修改为当下时间:
[root@docker-node1 ~]# touch in.sh
[root@docker-node1 ~]# stat in.sh
File: ‘in.sh’
Size: 134 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 68352533 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-07-12 14:39:33.524091028 -0400
Modify: 2016-07-12 14:39:33.524091028 -0400
Change: 2016-07-12 14:39:33.524091028 -0400
Birth: -
[root@docker-node1 ~]#
touch也可以指定时间:-t格式为:年月日小时分钟修改为2020年12月20号20时.20秒
[root@docker-node1 ~]# touch -t 202012202020.20 in.sh
[root@docker-node1 ~]# stat in.sh
File: ‘in.sh’
Size: 134 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 68352533 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2020-12-20 20:20:20.000000000 -0500
Modify: 2020-12-20 20:20:20.000000000 -0500
Change: 2016-07-12 14:45:23.777124351 -0400
Birth: -
[root@docker-node1 ~]#
如上所示:由此可见,stat查看只能修改访问时间和修改时间,状态改变时间和系统当前时间一样[root@docker-node1 ~]# dateTue Jul 12 14:45:25 EDT 2016[root@docker-node1 ~]#
如果只想修改访问时间添加-a -t即可
[root@docker-node1 ~]# touch -a -t 203012202020.20 in.sh
[root@docker-node1 ~]# stat in.sh
File: ‘in.sh’
Size: 134 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 68352533 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2030-12-20 20:20:20.000000000 -0500
Modify: 2020-12-20 20:20:20.000000000 -0500
Change: 2016-07-12 14:47:46.772137955 -0400
Birth: -
[root@docker-node1 ~]#
如果只想修改修改时间,-m -t即可
[root@docker-node1 ~]# touch -m -t 204012202020.20 in.sh
[root@docker-node1 ~]# stat in.sh
File: ‘in.sh’
Size: 134 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 68352533 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2030-12-20 20:20:20.000000000 -0500
Modify: 2040-12-20 20:20:20.000000000 -0500
Change: 2016-07-12 14:51:58.534161908 -0400
Birth: -
[root@docker-node1 ~]#
只要你修改源数据,不管你修的是访问时间还是修改时间,状态改变时间都会变成当下修改那一刻的时间
nano,vim
linux编辑器从界面来讲有两种,行编辑器,一次操作几行,sed流编辑器,第二种全屏编辑器,如nano,vim,vi
nano FILEnano常用操作ctrl+G 帮助ctrl+O 保存ctrl+R 读ctrl+Y 向上翻一页 ctrl+X 退出ctrl+W 查找ctrl+V 向下翻一页ctrl+K 剪切ctrl+U 取消