Os Fchown
# Python2.x Python os.fchown() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.fchown() method is used to change 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 systems.
### Syntax
The syntax for the **fchown()** 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 does not return any value.
### Example
The following example demonstrates the use of the fchown() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys, stat # Open file "/tmp/foo.txt" fd = os.open( "/tmp", os.O_RDONLY )# Set file user id to 100 os.fchown( fd, 100, -1)# Set file group id to 100 os.fchown( fd, -1, 50)print "Permission modification successful!!"# Close file os.close( fd )
Executing the above program outputs the following result:
Permission modification successful!!
[ Python OS File/Directory Methods](#)
YouTip