OpenFile contants meanings

f, err := os.OpenFile("text.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

What is 0644 here?
How to understand O_WRONLY i.e. “Open the file write-only”? So it opens the file only for writing? And we can’t use the file for reading?

Check the os docs for more details, but in summary it is passing flags to OpenFile by or'ing them that state the file is to be created if it doesn’t exist (os.O_CREATE), it should be appended to if it does exist (os.O_APPEND, meaning not rewritten) and it’s opened as write only (os.O_WRONLY).

As for 0644, those are the file permissions. Check the Numeric notation section at if you’re not familiar with numeric permissions.


This calculator, along with the Info and Code Examples tabs, might help:

0644 is a very common setting. It allows read/write permissions for the owner of the file, and read-only for everyone else.

Search on “unix permissions” to find many pages that explain how it works. For example:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.