需求
获取/etc/hosts的0644
[root@ecm tmp]# stat /etc/hosts
File: /etc/hosts
Size: 158 Blocks: 8 IO Block: 4096 regular file
Device: 253,1 Inode: 33564206 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-04-29 01:46:07.056141136 +0800
Modify: 2021-07-16 16:35:49.000000000 +0800
Change: 2023-09-08 14:46:54.008000000 +0800
Birth: 2023-09-08 14:46:53.964000000 +0800
方法1
[root@ecm tmp]# stat /etc/hosts | awk 'NR==4' |awk -F '/' '{print $1}' | awk -F '(' '{print $2}'
0644
方法2(利用正则)
[root@ecm tmp]# stat /etc/hosts | awk 'NR==4' | awk -F '[/(]' '{print $2}'
0644