• os.chmod()--更改目录授权权限


    用法:os.chmod() 方法用于更改文件或目录的权限

    语法:os.chmod(path, mode)  

    参数:只需要2个参数,一个是路径,一个是说明路径的模式。

      path -- 文件名路径或目录路径。

      mode:

    • stat.S_ISUID: Set user ID on execution.                      不常用

    • stat.S_ISGID: Set group ID on execution.                    不常用

    • stat.S_ENFMT: Record locking enforced.                                          不常用

    • stat.S_ISVTX: Save text image after execution.                                在执行之后保存文字和图片

    • stat.S_IREAD: Read by owner.                                                           对于拥有者读的权限

    • stat.S_IWRITE: Write by owner.                                                         对于拥有者写的权限

    • stat.S_IEXEC: Execute by owner.                                                       对于拥有者执行的权限

    • stat.S_IRWXU: Read, write, and execute by owner.                          对于拥有者读写执行的权限

    • stat.S_IRUSR: Read by owner.                                                            对于拥有者读的权限

    • stat.S_IWUSR: Write by owner.                                                          对于拥有者写的权限

    • stat.S_IXUSR: Execute by owner.                                                       对于拥有者执行的权限

    • stat.S_IRWXG: Read, write, and execute by group.                           对于同组的人读写执行的权限

    • stat.S_IRGRP: Read by group.                                                             对于同组读的权限

    • stat.S_IWGRP: Write by group.                                                           对于同组写的权限

    • stat.S_IXGRP: Execute by group.                                                        对于同组执行的权限

    • stat.S_IRWXO: Read, write, and execute by others.                          对于其他组读写执行的权限

    • stat.S_IROTH: Read by others.                                                           对于其他组读的权限

    • stat.S_IWOTH: Write by others.                                                         对于其他组写的权限

    • stat.S_IXOTH: Execute by others.                                                      对于其他组执行的权限

    示例:

    # -*- coding: UTF-8 -*-
     
    import os, stat
     
    # 假定 /tmp/test.txt 文件存在,设置文件可以通过用户组执行
     
    os.chmod("/tmp/test.txt", stat.S_IXGRP)
     
    # 设置文件可以被其他用户写入
    os.chmod("/tmp/test.txt", stat.S_IWOTH)
     
    print("修改成功!!")

    结果:

    
    
  • 相关阅读:
    Mina入门:mina版之HelloWorld
    Mina入门:Java NIO基础概念
    Activity与Service进行数据交互
    Android 6.0权限全面详细分析和解决方案
    查看Android系统是User模式还是Eng模式
    修改 Android 5.x 系统默认音量大小
    Android执行程序或脚本的方法
    Android Launcher 3 简单分析
    将Android系统源码导入ecplise
    Scrum三大角色特点
  • 原文地址:https://www.cnblogs.com/liangmingshen/p/10216168.html
Copyright © 2020-2023  润新知