【请教】用stat得到文件权限?
时间:2011-07-01
来源:互联网
python里执行命令:
>>>stat.S_IMODE(os.stat('/root/test').st_mode)
420
如何根据420这个值 得到 /root/test 的权限呢 ?
请大牛指教
>>>stat.S_IMODE(os.stat('/root/test').st_mode)
420
如何根据420这个值 得到 /root/test 的权限呢 ?
请大牛指教
作者: 清潼止水 发布时间: 2011-07-01
在线等。。。。
作者: 清潼止水 发布时间: 2011-07-01
自己摸索出来了:
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IRUSR
256
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IWUSR
128
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IXUSR
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IRGRP
32
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IWGRP
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IXGRP
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IROTH
4
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IWOTH
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IXOTH
0
非0 表示有权限 0 表示没权限
[root@rhel_server ~]# ls -l test
-rw-r--r-- 1 root root 0 Jul 1 15:14 test
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IRUSR
256
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IWUSR
128
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IXUSR
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IRGRP
32
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IWGRP
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IXGRP
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IROTH
4
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IWOTH
0
>>> stat.S_IMODE(os.stat('/root/test').st_mode) & stat.S_IXOTH
0
非0 表示有权限 0 表示没权限
[root@rhel_server ~]# ls -l test
-rw-r--r-- 1 root root 0 Jul 1 15:14 test

作者: 清潼止水 发布时间: 2011-07-01
回复 清潼止水
420 =>100 010 000 =>r-- -w- ---
420 =>100 010 000 =>r-- -w- ---
作者: 106033177 发布时间: 2011-07-01
回复 106033177
貌似不是这样(⊙o⊙)…,看看这个:
>>> stat.S_IMODE(os.stat('/root/test').st_mode)
420
>>> commands.getoutput('ls -l /root/test')
'-rw-r--r-- 1 root root 0 Jul 1 15:34 /root/test'
貌似不是这样(⊙o⊙)…,看看这个:
>>> stat.S_IMODE(os.stat('/root/test').st_mode)
420
>>> commands.getoutput('ls -l /root/test')
'-rw-r--r-- 1 root root 0 Jul 1 15:34 /root/test'
作者: 清潼止水 发布时间: 2011-07-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28