Everything may be a file, but not everything is real.
Consider the contents of
/proc. On my Linux system, there is a file
/proc/uptime, whose current contents are:
If I were to
cat the file again, it would contain different numbers. My hard drive is mounted read-only, so it can't possibly be the case that something is writing these numbers to disk every fraction of a second.
In fact, nothing under
/proc is on disk. Each interaction with a file in that directory simply runs kernel code, due to the nature of
Then there are temporary files. Chances are, your
/tmp is mounted
tmpfs, meaning its contents are stored in RAM instead of on disk.
Another interesting place is
/dev/tcp, for communicating with the network. On some systems, this only even exists under
bash but not other shells, so it can't possibly be on-disk in those systems.
These examples all show that the filesystem and the hard drive are separate, and the "Everything is a file" philosophy does not impact performance on account of I/O speed.