Python os.fchown() Method
Python OS File/Directory Methods
Overview
The os.fchown() method is used to modify the ownership of a file. This function changes the user ID and group ID of a file specified by the file descriptor fd.
Available on Unix.
Syntax
fchown()The syntax of the method is as follows:
os.fchown(fd, uid, gid)
Parameters
fd-- file descriptor
uid-- user id of the file owner
gid-- group id of the file owner
Return Value
This method has no return value.
Example
The following example demonstrates the use of the fchown() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys, stat # 打开文件 "/tmp/foo.txt" fd = os.open( "/tmp", os.O_RDONLY ) # 设置文件的用户 id 为 100 os.fchown( fd, 100, -1) # 设置文件的用户组 id 为 100 os.fchown( fd, -1, 50) print "修改权限成功!!" # 关闭文件 os.close( fd )
The output of the above program is:
Permission modification successful!!Other Extensions