Python Basics
Python Advanced
Python Useful References
Python Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Python os.lchown() Method
Description:
This method changes the owner and group id of path to the numeric uid and gid. This function will not follow symbolic links.
To leave one of the ids unchanged, set it to -1.
Syntax:
os.lchown(path, uid, gid).
|
Parameters:
Here is the detail of parameters:
path: This is the file path for which ownership to be set.
uid: Owner ID to be set for the file.
gid: Group ID to be set for the file.
Example:
#!/usr/bin/python
import os, sys
# Open a file
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close opened file
os.close( fd )
# Now change the file ownership.
# Set a file owner ID
os.lchown( path, 500, -1)
# Set a file group ID
os.lchown( path, -1, 500)
print "Changed ownership successfully!!"
|
This would produce following result:
print "Changed ownership successfully!!"
|
|
|
|