(Almost) everything is a file but not everything is a regular file. It doesn't make sense to call a text editor on something that is a special file such as a directory, a network socket, a serial port, etc.
The file /dev/stdout
can be one of several things depending on the unix variant:
- a “special” file, typically a character device;
- a “magic” symbolic link that points to the file that the process accessing it has open on this descriptor;
- a symbolic link to one of the above.
In any case, opening /dev/stdout
and similar files creates a new file descriptor that's associated with the same file that the application already has open on file descriptor 1. “Standard output” means file descriptor 1, and it's only a convention that this file descriptor is used for output — the kernel doesn't care.
When you run a program in a terminal, all three standard descriptors (0 = standard input, 1 = standard output, 2 = standard error) are opened on the terminal device. Reading from that device returns characters typed by the user, and writing to that device displays text in the terminal window. (There's no standard way, given a terminal device, to read the output that it displays or to inject input into it.)
When you run cat /dev/stdout
, that does exactly the same thing as cat /dev/stdin
or cat /dev/stderr
, because these three file descriptors are connected to the same file: it tells cat
to read from the terminal. That's what cat
with no argument does too.
If you ran cat /dev/stdout >foo
, then /dev/stdout
would refer to the file foo
— that command is equivalent to cat foo >foo
. Depending on the cat
implementation, it might either error out (the GNU version complains that “input file is output file”), or it might do nothing because it reads from the file foo
which is empty (>foo
just truncated it). With a version of cat
that doesn't detect this special case, if foo
is not empty, then cat /dev/stdout >>foo
or the equivalent cat foo >>foo
would append the content of the file to itself indefinitely.
When you run vim /dev/stdout
, it complains because it doesn't know how to edit a terminal (that just doesn't make sense).