When I execute a command like:

echo "Hello" > tty/pts/2

It will print the message on that terminal. Is it redirected to stdout or stderr of that tty?


Presumably your command is not right; As it stands it will save the string "Hello" to a file named 2 i.e. tty/pts/2 (if the intermediate directories exist).

Perhaps you meant:

echo "Hello" > /dev/pts/2

which will send the string "Hello" to the 2nd pseudo terminal.

Now, the STDIN, STDOUT and STDERR of the process running inside the terminal are bound to the pseudo terminal itself, so it is not really possible to single out the file descriptor of the process running within the terminal.

You can check that in /proc, by reading the file descriptor the shell that is running within a terminal, you will see that the standard streams are actually symlinked to the pseudo terminal.

For my zsh runing on pseudo terminal /dev/pts/46:

/proc/self/fd% tty

/proc/self/fd% ls -l           
lrwx------ 1 foobar foobar 64 Jun 13 15:07 0 -> /dev/pts/46
lrwx------ 1 foobar foobar 64 Jun 13 15:07 1 -> /dev/pts/46
lrwx------ 1 foobar foobar 64 Jun 13 15:07 2 -> /dev/pts/46

Simple test would be redirect stdout and then stderr of the command to /dev/null and see what happens.

adminx@L455D:~$ echo "hello" > /dev/pts/22
adminx@L455D:~$ echo "hello" > /dev/pts/22  > /dev/null # no output , stdout gone
adminx@L455D:~$ echo "hello" > /dev/pts/22  2> /dev/null # stderr gone, but stdout shows up

Thus , stdout is what you see.


Neither. stdin, stdout and stderr have meaning only when bound to processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.