问题描述
我正在尝试更改文件访问权限:
I am trying to change permission of a file access:
os.chmod(path, mode)
我要将其设置为只读:
os.chmod(path, 0444)
还有其他方法可以将文件设为只读吗?
Is there any other way make a file read-only?
推荐答案
os.chmod(path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
stat.S_ISUID
设置UID位.
stat.S_ISGID
设置组ID位.该位有几种特殊用途.为了 它指示将使用BSD语义的目录 目录:在此创建的文件会从 目录,而不是创建过程的有效组ID中的目录, 并且在那里创建的目录也将设置S_ISGID位.为一个 没有设置组执行位(S_IXGRP)的文件, set-group-ID位指示强制性文件/记录锁定(另请参见 S_ENFMT).
stat.S_ISGID
Set-group-ID bit. This bit has several special uses. For a directory it indicates that BSD semantics is to be used for that directory: files created there inherit their group ID from the directory, not from the effective group ID of the creating process, and directories created there will also get the S_ISGID bit set. For a file that does not have the group execution bit (S_IXGRP) set, the set-group-ID bit indicates mandatory file/record locking (see also S_ENFMT).
stat.S_ISVTX
粘性位.当此位在目录上设置时,表示 该目录中的文件只能由 文件的所有者,目录的所有者或特权用户 过程.
stat.S_ISVTX
Sticky bit. When this bit is set on a directory it means that a file in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, or by a privileged process.
stat.S_IRWXU
文件所有者权限的掩码.
stat.S_IRWXU
Mask for file owner permissions.
stat.S_IRUSR
所有者具有读取权限.
stat.S_IRUSR
Owner has read permission.
stat.S_IWUSR
所有者具有写权限.
stat.S_IXUSR
所有者具有执行权限.
stat.S_IXUSR
Owner has execute permission.
stat.S_IRWXG
屏蔽组权限.
stat.S_IRGRP
组具有读取权限.
stat.S_IWGRP
组具有写权限.
stat.S_IXGRP
组具有执行权限.
stat.S_IRWXO
屏蔽其他人(不在组中)的权限.
stat.S_IRWXO
Mask for permissions for others (not in group).
stat.S_IROTH
其他人具有阅读权限.
stat.S_IROTH
Others have read permission.
stat.S_IWOTH
其他人具有写权限.
stat.S_IXOTH
其他人具有执行权限.
stat.S_IXOTH
Others have execute permission.
stat.S_ENFMT
系统V文件锁定实施.该标志是共享的 带有S_ISGID的文件:文件/记录锁定在没有 设置了组执行位(S_IXGRP).
stat.S_ENFMT
System V file locking enforcement. This flag is shared with S_ISGID: file/record locking is enforced on files that do not have the group execution bit (S_IXGRP) set.
stat.S_IREAD
S_IRUSR的Unix V7同义词.
stat.S_IREAD
Unix V7 synonym for S_IRUSR.
stat.S_IWRITE
S_IWUSR的Unix V7同义词.
stat.S_IWRITE
Unix V7 synonym for S_IWUSR.
stat.S_IEXEC
S_IXUSR的Unix V7同义词.
stat.S_IEXEC
Unix V7 synonym for S_IXUSR.
这篇关于在Python中更改文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!