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

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条)

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B