file operations
Think of a file as a notebook in a drawer. You cannot do anything with it until you take it out and open it to a page; then you can read lines, write new lines, flip to a different page, and finally put it away. Files work the same way through a small, fixed set of operations the operating system offers, and you ask for them with system calls.
The core operations are: create (make a new, empty file and an entry for it in a directory), open (look the file up, set up the bookkeeping the OS needs, and hand back a handle you will use from now on), read (copy some bytes from the file's current position into your program's memory), write (copy bytes from your program into the file at the current position), seek or reposition (move the current position to a chosen offset without reading or writing, so you can jump around), close (tell the OS you are finished, so it can flush buffers and release the handle), delete (remove the file and reclaim its space), and truncate (cut a file down to a chosen length, often zero, while keeping its attributes). Almost everything you do to a file is built out of these few verbs. A typical session is: open, then a series of reads and writes with the position moving along, then close.
Why it matters: this tiny vocabulary is the entire contract between programs and stored data, and its uniformity is a triumph. The very same read and write calls move bytes whether the target is a file, a keyboard, a network connection, or a printer, because the OS makes them all look like files. A common beginner mistake is forgetting to close a file: until you close (or the program exits), buffered writes may not be safely on disk, and each open file ties up a limited slot in the OS's tables.
To append one line to a log: fd = open("log.txt"), seek to the end, write(fd, "done\n", 5), then close(fd). The open returns a handle, the write moves the position forward five bytes, and the close makes sure the line is actually saved.
Open, then read or write while the position moves, then close.
These same read and write calls work on far more than files, terminals, pipes, and sockets all behave like files. And until you close (or flush), writes may sit in a buffer and not yet be safe on disk.