Python3 os.fchown() Method
os.fchown() Overview
The os.fchown() method is used to modify the ownership of a file. This function modifies the user ID and user group ID of a file, which is specified by the file descriptor fd.
Available on Unix.
os.fchown() Syntax
The syntax format of the fchown() method is as follows:
os.fchown(fd, uid, gid)
os.fchown() Parameters
- fd – file descriptor
- uid – the user id of the file owner
- gid – the user group id of the file owner
os.fchown() Return Value
This method has no return value.
os.fchown() Demo
The following example demonstrates the use of the fchown() method:
#!/usr/bin/python3
import os, sys, stat
# Open the file "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )
# Set the user id of the file to 100
os.fchown( fd, 100, -1)
# Set the user group id of the file to 50
os.fchown( fd, -1, 50)
print ("Modify permission successfully!!!")
# Close file
os.close( fd )
The output of executing the above program is:
Modify permission successfully!!!