文件权限st_mode
含义
八进制值
英文注记
s_irusr
用户读
4
read user
s_iwusr
用户写
2
write user
s_ixusr
用户执行
1
exec user
s_irgrp
组读
4
read group
s_iwgrp
组写
2
write group
s_ixgrp
组执行
1
exec group
s_iroth
其他用户读
4
read other
s_iwoth
其他用户写
2
write other
s_ixoth
其他用户执行
1
exec other
这也对应了我们常见的chmod 755, 上面的表格可以分成三组, 每组最大值为7,表示读写执行权限. 下面用c代码来看看具体值:
#include <stdio.h>#include <sys/stat.h>/*s_irusr: 使用者读权限, read user 4s_iwusr: 使用者写权限, write user 2s_irgrp: 组用户读权限, read group 4s_iroth: 其他用户读权限, read other 4*/int main(int argc, char const *argv[]) { printf( s_irusr, s_iwusr, s_irgrp, s_iroth=%o, %o, %o, %o, (s_irusr | s_iwusr | s_irgrp | s_iroth)=%o\n, s_irusr, s_iwusr, s_irgrp, s_iroth, (s_irusr | s_iwusr | s_irgrp | s_iroth)); return 0;}
结果:
s_irusr, s_iwusr, s_irgrp, s_iroth=400, 200, 40, 4, (s_irusr | s_iwusr | s_irgrp | s_iroth)=644
以上就是unix与linux文件权限的含义是什么的详细内容。