Python3 os.lchown () method
Python3 OS file / directory methods
Outline
os.lchown () method is used to change the owner of a file, similar to chown, but do not follow links.
Supported only under Unix.
grammar
lchown () method syntax is as follows:
os.lchown(path, uid, gid)
parameter
path - set the permissions of the file path
uid - their user ID
gid - user group ID
return value
This method has no return value.
Examples
The following example demonstrates lchown () method of use:
#!/usr/bin/python3 import os, sys # 打开文件 path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT ) # 关闭打开的文件 os.close( fd ) # 修改文件权限 # 设置文件所属用户 ID os.lchown( path, 500, -1) # 设置文件所属用户组 ID os.lchown( path, -1, 500) print ("修改权限成功!!")
The above program output is:
修改权限成功!!