如何在Linux下使用Python获取目录的所有者和组ID?
使用os.stat()获得的UID和GID的文件。然后,使用pwd.getpwuid()和grp.getgrgid()分别获取用户名和组名。
os.stat()
pwd.getpwuid()
grp.getgrgid()
import grp import pwd import os stat_info = os.stat('/path') uid = stat_info.st_uid gid = stat_info.st_gid print uid, gid user = pwd.getpwuid(uid)[0] group = grp.getgrgid(gid)[0] print user, group