如何通过stat获取目录或文件的权限的数字形式

man stat 查看帮助。

-c --format=FORMAT use the specified FORMAT instead of the default; output a new line after each use of FORMAT 使用特殊格式代替默认输出;

常用的参数有如下:

%a Access rights in octal 8进制显示访问权限,0644

%A Access rights in human readable form 以人类可读的形式输出,drwxrwxr-t

%F File type 文件的类型

%g Group ID of owner 所属组gid的号码

%G Group name of owner 所属组的名称

%h Number of hard links 硬连接的数量

linux-zpycfm:~ # stat /var/run/libalarm
  File: ‘/var/run/libalarm’
  Size: 80              Blocks: 0          IO Block: 4096   directory
Device: 12h/18d Inode: 159827066   Links: 2
Access: (1775/drwxrwxr-t)  Uid: (    0/    root)   Gid: ( 1001/uvpalarm)
Access: 2018-05-03 18:09:31.883333421 +0800
Modify: 2018-05-03 17:57:24.997312107 +0800
Change: 2018-05-03 17:57:24.997312107 +0800
linux-zpycfm:~ # stat -c %a /var/run/libalarm/
1775
linux-zpycfm:~ # stat -c %A /var/run/libalarm/
drwxrwxr-t

 

posted @ 2018-05-07 16:29  行木辛  阅读(495)  评论(0编辑  收藏  举报