$ tty



in user-space, cat process waits on it's stdin to receive input from /dev/tty0 file.

On listing non-existent file fff,

  ls /fff > file1
   ls cannot find file :file1 Access denied

Despite redirection of stdout to file1 instead of /dev/tty0, the error about, file does not exist, will display on /dev/tty0 through stderr file descriptor.


If stderr writes to /dev/tty0 similar to stdout, what is the purpose of stderr?

What was the idea behind, UNIX/Linux maintaining one more file descriptor stderr for writing error to /dev/tty0 ?

  • You asked the stdout to be redirected to a file AND not the stderr. Meaning, stderr is still going to the terminal, /dev/tty0. So what's the issue here?
    – user218374
    Commented May 7, 2017 at 4:38
  • @RakeshSharma I did not get you. My question is not about knowing the mechanics in usage of stdout/stderr, but try knowing why do we need stderr, because it is also writing to /dev/tty0 Commented May 7, 2017 at 4:41
  • Demonstrably it isn't in your example... Commented May 7, 2017 at 4:49
  • @MichaelHomer ok updated query. Bit lazy today Commented May 7, 2017 at 4:58
  • Deeply related, possible duplicate Commented May 7, 2017 at 5:00

2 Answers 2


We need STDERR (file descriptor 2) to separate the output stream (STDOUT, file descriptor 1) from the error stream.

Without the separation, you can not distinguish the valid outputs from errors.

As you can see in your case, both streams are being attached to the terminal, and you can easily distinguish or operate on them (dup(2) et al.) by simple file descriptor operations from userspace.

Just an an example, to send STDOUT to a file and STDERR to a different file:

my_command >stdout.log 2>stderr.log

stdoout is expected to be opened in a write-only state for every unix process from launch, stdin as read-only (as i think), and stderr as non-blocking read/write deploying - at maximum - a line out-buffer.

stderr is primarily for getting output to a consumer immediately, and is heavily relied upon in terminal user interface applications; have a look at more.

  • 1
    Both Read/write from stderr? Commented May 7, 2017 at 6:07
  • According to the manpage on Arch Linux, stderr is unbuffered, while stdout is line-buffered. Further, I am almost completely certain that there is no system where by default stderr is RW but stdout is write-only. I'm open to learning otherwise though — any chance you could cite some sources on this?
    – Fox
    Commented May 7, 2017 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .