Code-Memo

File modes and permissions

Unix-style permission bits

os.FileMode includes permission bits 0o755, 0o644, etc. (octal). Readable shorthand:

Creating files

f, err := os.OpenFile("out.txt", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)

Open flags (common)

Flag Meaning
O_RDONLY read-only
O_WRONLY write-only
O_RDWR read and write
O_APPEND write at end
O_CREATE create if missing
O_EXCL error if O_CREATE and exists
O_TRUNC truncate on open for write
O_SYNC sync writes (platform-dependent)

Combine with |:

os.O_CREATE | os.O_WRONLY | os.O_TRUNC

os.Mkdir / MkdirAll

err := os.MkdirAll("path/to/dir", 0o755)

Windows note

Permission bits are mapped to ACLs; Go APIs still accept Unix-style modes where applicable.

fs.FileMode and types

os.ModeDir, os.ModeSymlink, etc. distinguish special file kinds in addition to permissions.