Although you'll hear the "everything is a file" is a Unix design philosophy, as Wikipedia notes it is
really more accurate to say that in Unix "Everything is a file descriptor".
I've said similar things myself, usually explaining that it's an abstraction, that everything *looks like* a file
to a programmer. That is realistic. It's a programmers reality; outside
of programming, this abstraction doesn't really matter.
It's also true that it depends on how you look at things. Linus Torvalds opined a slightly different take in this thread:
What do you think "a file" is?
In UNIX, a file descriptor is pretty much
anything. You could say that sockets aren't
remotely file-like, and you'd be right. What's
your point? If you can read on it, it's a file.
See what I mean? Programmer's reality.
Still other people prefer other terms. In The Art of Unix Programming, Eric Raymond expresses it this way:
More generally, everything is a byte stream; even hardware devices are byte streams. This metaphor was a tremendous success of early Unix, and a real advance over a world in which (for example) compiled programs could not produce output that could be fed back to the compiler. Pipes and shell programming sprang from this metaphor.
In earlier operating systems, devices were very special thing. If you wanted to write to a printer or a tape, you had to ask the operating system to do that in your program. There was no concept of a "device" that you could just open and read or write at will.
Naming is an important part of that ability, of course. See The Hideous Name by Rob Pike and P.J. Weinberger and Ghosts of Unix Past: a historical search for design patterns for more on that.
Some people get downright angry about "everything is a file". Here's a rant from 10 Things I Hate About (U)NIX:
The often stated advantage of this paradigm is that you can connect programs to devices and they'll just work, without being specially designed to interface with the device. This was almost true at one point. Writing to a text-only line printer was exactly the same as writing to a text-only terminal or writing to a text file. Now, however, most people tend to deal in a little more than just plain text. If I have a program that outputs an image, can I just send that image to a terminal and have it display? Can I send it to the printer in the same way?
He's obviously misunderstood the meaning; learning the limits of abstractions is often the hardest part of understanding anything. And of course you CAN send an image to a terminal and display the bytes with "od" - and which is the proper representation: the visual on a graphics screen or the raw bytes? Both are legitimate. The artist would say it's the screen display, the programmer would insist it is the bytes.
Again, it's just a programmers view of their reality. Everything in Unix looks like a file to a programmer and that's where this expression came from. It's not meant to be taken literally outside of programming (and yes, of course
scripting and creating pipes at the command line is programming).
Got something to add? Send me email.
Increase ad revenue 50-250% with Ezoic
More Articles by Anthony Lawrence
Find me on Google+
© 2013-07-30 Anthony Lawrence