linux中如何取得一個文件的權限?
阿新 • • 發佈:2017-08-04
linux學習 3:awk
例:如何取得/etc/hosts文件的權限對應的數字內容,如-rw-r--r-- 為 644,要求使用命令取得644這樣的數字
方法1:sed
[[email protected] ~]# stat /etc/hosts | sed -nr‘4s#.*\(0|/-.*##gp‘
644
[[email protected] ~]#
方法2:sed 反向引用
[[email protected] tmp]# stat /etc/hosts |sed -nr ‘4s#.*\(0(.*)\/-.*#\1#gp‘
644
[[email protected] tmp]#
方法
[[email protected] ~]# stat /etc/hosts |awk -F‘[/0]‘ ‘NR==4{print $2}‘
644
[[email protected] ~]#
方法4:stat
[[email protected] ~]# stat -c%a /etc/hosts
644
[[email protected] ~]#
>>>>>>>>剛學的這些方法,方法還有很多,linux魅力無窮啊<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
本文出自 “qizhong” 博客,請務必保留此出處http://qizhong.blog.51cto.com/12933988/1953445
linux中如何取得一個文件的權限?