Yes, however the terminal file is not a regular file.
If you list the extended properties of a terminal file, you'll see:
$ ls /dev/tty1 -lah
crw--w---- 1 root tty 4, 0 Apr 6 13:07 /dev/tty1
notice the first character in the permission section is a letter "c", this indicates that the file is a character special device. In contrast, a regular file would have a "-" in there, a directory a "d", a block special device a "b", a symbolic link an "l", and a unix domain socket an "s".
It's important to note that in Unix systems like Linux, a filesystem is actually more like a namespace for interactions with kernel object, where you can name for various kernel object so they can be referred to unambiguously by various parts of the system. These kernel objects are not just regular files that are backed by persistent storage, but also things like hardware device, or sockets, etc.
A character special device is a kernel object that interface with the userspace by reading and writing streams of characters, they are accessed by doing read()
and write()
system call.
For example, in my machine with Ctrl+Alt+F1 (which is /dev/tty1 in my machine, not tty0), I could read off whatever being typed to the virtual console using a program that uses the read()
syscall like cat
:
- In graphical emulator,
sudo cat /dev/tty1
- Switch to virtual console emulator with Ctrl+Alt+F1
- Type something into the virtual console emulator
- Switch back to graphical UI with Ctrl+Alt+F7
- In the graphical emulator, I'd see whatever I typed in the virtual console emulator as the output of
cat
The other way around, I could also display characters in the virtual console using a program that uses write()
syscall like tee
:
- In graphical emulator,
echo "hello world" | sudo tee /dev/tty1
- Switch to virtual console emulator with Ctrl+Alt+F1
- In the virtual console emulator, I'd see "hello world"
Most regular text editors will refuse to actually open non-regular special files because they are programmed to check the file type and refuse to edit non-regular files. This is to prevent "accidents" because it makes little sense to edit special devices in regular text editors. Additionally, most regular text editors also doesn't actually just call write()
to the existing file, but instead they'd write to a new file and rename()
the swap file to replace the old file. Even when you have a text editor that supports writing in-place, they'd typically try to truncate the file first, which of course isn't supported in a special character device.