Python os.lchmod () method
Python OS file / directory methods
Outline
os.lchmod () method is used to modify the connection file permissions.
Supported only under Unix.
grammar
lchmod () method syntax is as follows:
os.lchmod(path, mode)
parameter
path - set the mark file path
mode - can be one or more components, multiple use "|" separated:
stat.S_ISUID: set UID bit
stat.S_ISGID: set group ID bits
stat.S_ENFMT: system file locking enforcement action
stat.S_ISVTX: After the save text and images
stat.S_IREAD: read access for the owner
stat.S_IWRITE: write permissions for the owner
stat.S_IEXEC: execute permissions for the owner of
stat.S_IRWXU: For the owner to read, write, and execute permissions
stat.S_IRUSR: read access for the owner
stat.S_IWUSR: write permissions for the owner
stat.S_IXUSR: execute permissions for the owner of
stat.S_IRWXG: for the same group of people permission to perform read and write
stat.S_IRGRP: For the same group read access
stat.S_IWGRP: write permissions for the same group
stat.S_IXGRP: execute permissions for the same group of
stat.S_IRWXO: read and write permissions for the other groups performed
stat.S_IROTH: read access for other groups
stat.S_IWOTH: write privileges for other groups
stat.S_IXOTH: permission to other groups by the
return value
This method has no return value.
Examples
The following example demonstrates lchmod () method of use:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT ) # 关闭文件 os.close( fd ) # 修改文件权限 # 设置文件可以通过组执行 os.lchmod( path, stat.S_IXGRP) # 设置文件可以被其他用户写入 os.lchmod("/tmp/foo.txt", stat.S_IWOTH) print "修改权限成功!!"
The above program output is:
修改权限成功!!