Python os.fchmod() Method
os.fchmod() Overview
The os.fchmod() method is used to change the access rights of a file specified by the parameter fd, and the parameter mode is the access rights of the file under Unix.
Available on Unix.
os.fchmod() Syntax
The syntax format of the fchmod() method is as follows:
os.fchmod(fd, mode);
os.fchmod() Parameters
- fd – file descriptor
- 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, the Unix V7 version of stat.
- stat.S_IWRITE: For owner write permissions, the Unix V7 version of stat.
- stat.S_IEXEC: S_IXUSR is synonymous with stat in the Unix V7 version for owner-executed permissions
- 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.fchmod() Return Value
This method has no return value.
os.fchmod() Demo
The following example demonstrates the use of the fchmod() method:
#!/usr/bin/python3
import os, sys, stat
# Open the file "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )
# The settings file can be executed through the group
os.fchmod( fd, stat.S_IXGRP)
# Settings file can be written by other users
os.fchmod(fd, stat.S_IWOTH)
print ("Modify permission successfully!!!")
# Close file
os.close( fd )
The output of executing the above program is:
Modify permission successfully!!!