這道題考察的內容是怎么查看文件的權限,以及對權限對應數字的過濾
首先查看權限對應的數字內容使用stat命令來查看
[root@zhang ~]# stat /etc/hosts
File: ‘/etc/hosts’
Size: 158 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 16826902 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-03-27 19:30:01.140839849 +0800
Modify: 2013-06-07 22:31:32.000000000 +0800
Change: 2019-03-27 19:27:19.304832132 +0800
Birth: -
然后對644進行過濾(方法有多種)
1 awk先取行 再取列
[root@zhang ~]# stat /etc/hosts|awk 'NR==4'
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
[root@zhang~]# stat /etc/hosts|awk -F "[0/]" 'NR==4{print $2}'
644
2 sed 先取行 再去掉開頭 去掉結尾
(1)[root@zhang ~]# stat /etc/hosts|sed -n 4p
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
[root@zhang ~]# stat /etc/hosts|sed -nr '4s#^.(0(.)/-.*$#\1#gp'
644
[root@zhang ~]# stat /etc/hosts|sed -n 's#^.*0\(.*\)/-r.*$#\1#gp'
644
[root@zhang ~]# stat /etc/hosts|grep '644'
644