Why does open() create my file with the wrong permissions?

前端 未结 7 1692
天涯浪人
天涯浪人 2020-11-29 23:47

I am trying to read some text from a file and write it to another using open(), read() and write().

This is my open()

相关标签:
7条回答
  • 2020-11-30 00:23

    Not strictly relevant to the question, but the accepted answer could use this clarifying point:

    There is a relationship between rwx and its numerical representation that can be seen by treating the presence of a letter as a binary 1, and its absence as a binary 0.

    e.g.

    rwx  <-->  111 (binary) <-->  7 (octal)
    
    r--  <-->  100 (binary) <-->  4 (octal)
    
    -wx  <-->  011 (binary) <-->  3 (octal) 
    

    As a further addendum, you may now consider the chmod command:

    chmod 777 filename.extension --> rwxrwxrwx permissions

    777 <--> 111 111 111 <--> rwx rwx rwx
    

    or: chmod 654 filename.extension --> rw-r-x-r--

    654 <--> 110 101 100 <--> rw- r-x r--
    

    Hope this is informative!

    0 讨论(0)
提交回复
热议问题