标签:
问题: 过滤出stat /etc/hosts的权限值
法1:
[root@lanny ~]# stat /etc/hosts|sed -n ‘4p‘|awk -F ‘[0/]‘ ‘{print $2}‘
644
注:
Awk里的[0/]表示
Access: (0644/-rw-r--r--)
法2:
[root@lanny ~]# stat /etc/hosts|awk -F ‘[0/]‘ ‘NR==4 {print $2}‘
644
法3:
[root@lanny ~]# stat /etc/hosts|sed -n ‘4p‘
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
stat /etc/hosts|sed -rn ‘4s###gp‘
stat /etc/hosts|sed -rn ‘4s#^.*##gp‘
Access: (0644/-rw-r--r--)
stat /etc/hosts|sed -rn ‘4s#^.*\(0##gp‘
Access: (0644/-rw-r--r--)
[root@lanny ~]# stat /etc/hosts|sed -nr ‘4s#^.*\(0(.*)/-.*$#\1#gp‘
644
Access: (0644/-rw-r--r--)
标签:
原文地址:http://www.cnblogs.com/iiiiher/p/5573158.html