Os Lchown
# Python2.x Python os.lchown() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.lchown() method is used to change the owner of a file, similar to chown, but does not follow symbolic links.
It is only supported on Unix systems.
### Syntax
The syntax for the **lchown()** method is as follows:
os.lchown(path, uid, gid)
### Parameters
* **path** -- The file path for which to set permissions.
* **uid** -- The user ID of the owner.
* **gid** -- The group ID of the owner.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the lchown() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open a file path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT )# Close the opened file os.close( fd )# Modify file permissions# Set the file's owner user ID os.lchown( path, 500, -1)# Set the file's owner group ID os.lchown( path, -1, 500)print "Permission modification successful!!"
The output of executing the above program is:
Permission modification successful!!
[ Python OS File/Directory Methods](#)
YouTip