In short, I would say:
A flag is a predefined bit or bit sequence that holds a binary value.
A mode is a distinct setting.
So it's not always possible to replace the term "mode" by "flag". This is only possible if it's about a binary value. I got confused by these terms when reading:
The argument flags must include one of the following access modes:
O_RDONLY, O_WRONLY, or O_RDWR.
The file creation flags are O_CLOEXEC,
O_CREAT, O_DIRECTORY, O_EXCL, O_NOCTTY, O_NOFOLLOW, O_TMPFILE, and
The file status flags are all of the remaining flags listed
Why they just don't say:
The file access flags are O_RDONLY, O_WRONLY, and O_RDWR.
Why they suddenly use a different term when it's about "access"? Probably behind the scenes it's also just about a binary value, right? Probably all O_VARIABLE's above are 0 or 1.
And see: https://en.wikipedia.org/wiki/File_descriptor
This table records the mode with which the file (or other resource) has been opened: for reading, writing, appending, and possibly other modes.
So Wikipedia uses the term "mode" only (and not flag). At least they are consistent, because they call them all "modes".
Is there a specific reason why sometimes mode is used and something flag (while it's about the same thing)? I would stay, be at least consistent to avoid confusion.