Python3 Os Lchown
# Python3.x Python3 os.lchown() Method
[ Python3 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/python3import 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 user ID of the file owner os.lchown( path, 500, -1)# Set the group ID of the file owner os.lchown( path, -1, 500)print ("Permissions modified successfully!!")
Executing the above program outputs the following result:
Permissions modified successfully!!
[ Python3 OS File/Directory Methods](#)
YouTip