1. 程式人生 > >linux中如何取得一個文件的權限?

linux中如何取得一個文件的權限?

linux學習

例:如何取得/etc/hosts文件的權限對應的數字內容,如-rw-r--r-- 644,要求使用命令取644這樣的數字

方法1sed

[[email protected] ~]# stat /etc/hosts | sed -nr‘4s#.*\(0|/-.*##gp‘

644

[[email protected] ~]#

方法2sed 反向引用

[[email protected] tmp]# stat /etc/hosts |sed -nr ‘4s#.*\(0(.*)\/-.*#\1#gp‘

644

[[email protected] tmp]#

方法

3awk

[[email protected] ~]# stat /etc/hosts |awk -F‘[/0]‘ ‘NR==4{print $2}‘

644

[[email protected] ~]#

方法4stat

[[email protected] ~]# stat -c%a /etc/hosts

644

[[email protected] ~]#

>>>>>>>>剛學的這些方法,方法還有很多,linux魅力無窮啊<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

本文出自 “qizhong” 博客,請務必保留此出處http://qizhong.blog.51cto.com/12933988/1953445

linux中如何取得一個文件的權限?