问题: 过滤出stat /etc/hosts的权限值
法1:
[[email protected] ~]# stat /etc/hosts|sed -n ‘4p‘|awk -F ‘[0/]‘ ‘{print $2}‘
644
注:
Awk里的[0/]表示
Access: (0644/-rw-r--r--)
法2:
[[email protected] ~]# stat /etc/hosts|awk -F ‘[0/]‘ ‘NR==4 {print $2}‘
644
法3:
[[email protected] ~]# 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--)
[[email protected] ~]# stat /etc/hosts|sed -nr ‘4s#^.*\(0(.*)/-.*$#\1#gp‘
644
Access: (0644/-rw-r--r--)
时间: 2024-12-29 12:09:31