dev/tty
is a file system object that represents the current console. Copying files into this "directory" from the command line prints out the content of these files to your console:
cp myfile.txt /dev/tty
is equivalent to
cat myfile.txt
These objects are there to let you use the familiar file APIs to interact with console. It is a clever way to unify console API with file API. You can usefopen
, fprintf
, etc. to interact with the console in the same way that you interact with regular files.
This example writes "Hello, world\n"
to the terminal:
#include <stdio.h>
int main (int argc, const char * argv[]) {
FILE *f = fopen("/dev/tty", "w");
fprintf(f, "Hello, world!\n");
return 0;
}