os.chown 正是我想要的,但我想要按名称指定用户和组,而不是 ID(我不知道它们是什么).我该怎么做?
os.chown is exactly what I want, but I want to specify the user and group by name, not ID (I don't know what they are). How can I do that?
import pwd
import grp
import os
uid = pwd.getpwnam("nobody").pw_uid
gid = grp.getgrnam("nogroup").gr_gid
path = '/tmp/f.txt'
os.chown(path, uid, gid)
这篇关于如何按名称更改目录的用户和组权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!