您的位置:首页 > 运维架构 > Linux

linux中如何取得一个文件的权限?

2017-08-03 22:07 169 查看

例:如何取得/etc/hosts文件的权限对应的数字内容,如-rw-r--r-- 为 644,要求使用命令取得644这样的数字

方法1:sed
[root@ZHOUQIZHONG ~]# stat /etc/hosts | sed -nr'4s#.*\(0|/-.*##gp'
644
[root@ZHOUQIZHONG ~]#
方法2:sed 反向引用
[root@ZHOUQIZHONG tmp]# stat /etc/hosts |sed -nr '4s#.*\(0(.*)\/-.*#\1#gp'
644
[root@ZHOUQIZHONG tmp]#
方法3:awk
[root@ZHOUQIZHONG ~]# stat /etc/hosts |awk -F'[/0]' 'NR==4{print $2}'
644
[root@ZHOUQIZHONG ~]#
方法4:stat
[root@ZHOUQIZHONG ~]# stat -c%a /etc/hosts
644
[root@ZHOUQIZHONG ~]#
>>>>>>>>刚学的这些方法,方法还有很多,linux魅力无穷啊<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 学习