[root@localhost ~]# stat /etc
File: `/etc'
Size: 12288 Blocks: 24 IO Block: 4096 directory
Device: fd00h/64768d Inode: 9961473 Links: 122
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-07-07 10:14:18.596307668 +0800
Modify: 2016-07-05 10:12:54.554048038 +0800
Change: 2016-07-05 10:12:54.554048038 +0800
[root@localhost ~]# stat /etc | sed -n 's#^.*s: (\([0-9].*\)/dr.*$#\1#gp'
0755
[root@localhost ~]# stat /etc/ | sed -n 's#^.*(\(.*\)/d.*#\1#gp'
0755
[root@localhost ~]# stat /etc/ | sed -n 4p | sed 's#^.*Access:(##g'
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
[root@localhost ~]# stat /etc/ | sed -n 4p | sed 's#^.*Access: (##g'
0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
[root@localhost ~]# stat /etc/ | sed -n 4p | sed 's#^.*Access: (##g'|sed 's#/.*$##g'
0755
[root@localhost ~]# stat /etc| sed -n '4p'
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
[root@localhost ~]# stat /etc| sed -n '4p'|cut -d "/" -f1
Access: (0755
[root@localhost ~]# stat /etc| sed -n '4p'|cut -d "/" -f1|cut -d "(" -f2
0755
[root@localhost ~]# ls -dl /etc | cut -c 2-10| tr rwx- 4210
421401401
[root@localhost ~]# ls -dl /etc | cut -c 2-10| tr rwx- 4210| awk -F "" '{print $1+$2+$3}'
7
[root@localhost ~]# ls -dl /etc | cut -c 2-10| tr rwx- 4210| awk -F "" '{print $1+$2+$3 $4+$5+$6 $7+$8+$9}'
755
[root@localhost ~]# stat -c %a /etc
755
[root@localhost ~]# stat -c %A /etc
drwxr-xr-x
[root@localhost ~]# stat -c %b /etc
24
[root@localhost ~]# stat -c %C /etc
system_u:object_r:etc_t:s0
经上思考过程:
当命令结果包含我们需要的内容的时候,我们要想到命令的参数是否有具体的参数能够一步达到我们需要的结果呢,这样就会去man stat
思路:
1.通过stat输出包含的目标内容
2.通过head,tail,sed,awk,grep定位到单行
3.通过cut,awk等设置分隔符取出需要段内容
2016-11-16
取出权限位
评论
发表评论
姓 名: