Frequently Asked Question

Why is everything a file in Linux?

Inherited from Unix: most things you talk to, regular files, directories, terminals, pipes, sockets, block devices, character devices, even some kernel knobs, are represented by file descriptors. The same six syscalls (open, read, write, close, lseek, ioctl) work on all of them. That means a program that copies from one file to another also copies between sockets, terminals, and pipes with no extra code.

The unification isn't perfect, networking has its own socket, bind, accept family; some devices need ioctl to do anything interesting, but it's a strong enough abstraction that shell pipelines, dd, and tee work on everything from /dev/sda to /dev/random to a USB serial port.

Video

Further reading and video