Python os.lchmod() Method
os.lchmod() Overview
The os.lchmod() method is used to modify the permissions of the connection file.
It is only supported for use under Unix.
os.lchmod() Syntax
The syntax format of the lchmod() method is as follows.
os.lchmod(path, mode)
os.lchmod() Parameters
- path – Sets the path to the tagged file
- mode – may consist of one or more of the following, with multiple separated by "|".
- stat.S_ISUID: Set UID bit
- stat.S_ISGID: Set the group ID bit
- stat.S_ENFMT: System file lock enforcement actions
- stat.S_ISVTX: Save text and images after execution
- stat.S_IREAD: For owner read access
- stat.S_IWRITE: For owner write permissions
- stat.S_IEXEC: For permissions executed by the owner
- stat.S_IRWXU:For owner’s read, write, and execute permissions
- stat.S_IRUSR: For owner read access
- stat.S_IWUSR: For owner write permissions
- stat.S_IXUSR: For permissions executed by the owner
- stat.S_IRWXG: For people in the same group read and write permission to execute
- stat.S_IRGRP: For read access to the same group
- stat.S_IWGRP:For same group write permissions
- stat.S_IXGRP: For permissions executed by the same group
- stat.S_IRWXO: Permissions for other groups to read, write, and execute
- stat.S_IROTH: For other group read permissions
- stat.S_IWOTH: For other group write permissions
- stat.S_IXOTH:For permissions executed by other groups
os.lchmod() Return Value
This method has no return value.
os.lchmod() Demo#1
The following example demonstrates the use of the lchmod() method.
#!/usr/bin/python3
import os, sys
# Open file
path = "/root/apidemos.com.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close file
os.close( fd )
# Modify file permissions, set files to be executable by group
os.lchmod( path, stat.S_IXGRP)
# Settings file can be written by other users
os.lchmod("/tmp/foo.txt", stat.S_IWOTH)
print ("Modify permission successfully!!!")
Output:
Modify permission successfully!!!