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).
More Articles by Anthony Lawrence - Find me on Google+ 2013-07-30
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments - no registration needed!
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar