doucongqian6644 2013-01-10 01:33
浏览 182
已采纳

os.MkDir和os.MkDirAll权限值?

I'm trying to create a log file at the start of my program.

I need to check if a "/log" directory exists if it doesn't create the directory then move on to creating the log file.

Well I tried to use os.Mkdir (as well as os.MkDirAll), but no matter what value I put into the second parameter I get a locked out folder with no permissions. What value should this be in order to get a read / write for user folder? I thought it would be 0x700 but it doesn't seem to work.

Thanks!

  • 写回答

2条回答 默认 最新

  • doucuo4413 2015-07-01 02:11
    关注

    You can use octal notation directly:

    os.Mkdir("dirname", 0700)
    


    Permission Bits

    +-----+---+--------------------------+
    | rwx | 7 | Read, write and execute  |
    | rw- | 6 | Read, write              |
    | r-x | 5 | Read, and execute        |
    | r-- | 4 | Read,                    |
    | -wx | 3 | Write and execute        |
    | -w- | 2 | Write                    |
    | --x | 1 | Execute                  |
    | --- | 0 | no permissions           |
    +------------------------------------+
    
    +------------+------+-------+
    | Permission | Octal| Field |
    +------------+------+-------+
    | rwx------  | 0700 | User  |
    | ---rwx---  | 0070 | Group |
    | ------rwx  | 0007 | Other |
    +------------+------+-------+
    

    A Unix Permission Primer


    Common Permission Usages

    0755 Commonly used on web servers. The owner can read, write, execute. Everyone else can read and execute but not modify the file.

    0777 Everyone can read write and execute. On a web server, it is not advisable to use ‘777’ permission for your files and folders, as it allows anyone to add malicious code to your server.

    0644 Only the owner can read and write. Everyone else can only read. No one can execute the file.

    0655 Only the owner can read and write, but not execute the file. Everyone else can read and execute, but cannot modify the file.

    www.maketecheasier.com/file-permissions-what-does-chmod-777-means/


    Directory Permissions on Linux

    When applying permissions to directories on Linux, the permission bits have different meanings than on regular files. (source)

    Read bit The user can read the file names contained in the directory.
    Write bit The user can {add,rename,delete} files names IF the execute bit is set too.
    Execute bit The user can enter the directory and access the files inside.

    https://unix.stackexchange.com/a/21252

    Permissions Calculator

    permissions calculator

    A handy permissions calculator.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题