I'm looking for a formal definition of file that does not only include storage but also abstractions like procfs or /dev/null (or any fuse-based file) that do not relate to storage.

So far I know that all files are abstractions that

  • can be identified
  • can have names (usually organized in hierarchical structures)
  • can be accessed as a byte stream
  • usually provide permissions and other (system specific) metadata

however I was unable to find any useful formal definition in any OS book I've read so far.

  • $\begingroup$ did you look into inodes? $\endgroup$
    – Bhaskar
    Commented Dec 20, 2016 at 21:24
  • 1
    $\begingroup$ I'd argue that things like /dev/null aren't files at all but, rather, are hacks allowing us to access non-file things as if they were files. Also, it's not clear to me what you mean by "formal". Within what formalism? $\endgroup$ Commented Dec 20, 2016 at 22:16
  • $\begingroup$ "A file is something that can be opened with fopen"? $\endgroup$
    – adrianN
    Commented Dec 21, 2016 at 10:42
  • $\begingroup$ @DavidRicherby any software abstraction that behaves exactly like a file is a file: we can only define software entities in term of their behavior. As for the formalism, I'm looking for something rigorous from a CS perspective. We have a formal definition of for turing machines for example. $\endgroup$ Commented Dec 21, 2016 at 15:53
  • $\begingroup$ Different OSes attribute different operations to files, see e.g. *nix vs Windows. One can try to find a common ground, but it will not be precise. Further, in CS one rarely speaks about files -- I think this is done only when designing an OS, a filesystem, maybe a DBMS, or in some on-disk algorithms (e.g. sort-merge). (and a few others) $\endgroup$
    – chi
    Commented Dec 21, 2016 at 16:08

2 Answers 2


According to Wikipedia, a computer file is simply a resource for storing information. The term appears to have originated in the punch card era, where a computer program was literally stored in a file (as in, a box used to store loose pages, see image below). As other forms of media were introduced, such as disks, the nomenclature followed.

From a *nix point of view, everything is a file: sockets, devices, terminals, screens/monitors, data files, pipes, and so on. Microsoft Windows, in contrast, tends to call permanent storage data "files", and volatile resources as whatever they are, such as named pipes, sockets, raster devices, etc. Other systems may have similar definitions somewhere between these two extremes.

Unfortunately, as I've just stated, there's no single definition of what a file is, because it is different things to different people, except that everyone tends to agree on the base-line definition that a file is a named resource that stores data on permanent media (permanent does not imply that it can never be modified, simply that it persists through power cycles).

Punch Card File] (Wikipedia)

  • $\begingroup$ I've read the wikipedia definition, but it's too focused on storage. As stated, I'm looking for a definition that cover files like /dev/null, that do not store data. $\endgroup$ Commented Dec 20, 2016 at 21:52
  • $\begingroup$ @GiacomoTesio The two points I was trying to make are (a) file means different things to different authors, although (b) files are at least universally defined as resources. NUL and /dev/null are special resources, because they don't actually store anything, but are resources nevertheless. A resource is simply something that can transmit or receive data (or both). A generic OS book's definition of a file will depend on the author's point of view. $\endgroup$
    – phyrfox
    Commented Dec 20, 2016 at 22:00

I think of a file as a sequence of bytes. Even after it loses its name (usually caused by a call to rm, which unlinks it), it still exists on the disk until its chunks get overwritten by other stuff. File formats are contexts for reading files. It all goes back to the principle that information is bytes plus context.

The previous poster is right that devices, whilst being treated as files, are not really files. This is a very useful hack.

So my definition of a file: a sequence of bytes stored in memory.

  • 2
    $\begingroup$ "So my definition of a file: a sequence of bytes." is a sequence of (let's say, UTF-8) bytes. Is it a file? $\endgroup$ Commented Dec 21, 2016 at 9:44
  • $\begingroup$ We are talking about software abstractions, anything that behave exactly like a file is a file. Actually we cannot define any software entity except from its behavior. $\endgroup$ Commented Dec 21, 2016 at 15:47
  • $\begingroup$ "I think of a file as a sequence of bytes." That's not the only definition of "filesystem". See, for example, en.wikipedia.org/wiki/Record-oriented_filesystem $\endgroup$
    – Pseudonym
    Commented Jan 6, 2017 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.