This question already has an answer here:

Suppose there are two terminals, pts/0 and pts/1.

In pts/0, I have fired a command:


Then, we only get the output of the ls command in pts/1, but I want to run a command as well as its output both on pts/1.

I tried "echo ls">/dev/pts/1, but instead the output of the ls command, "ls", is printed on pts/1.

How can I do it?

What I tried

marked as duplicate by muru, Archemar, Isaac, G-Man, schily Oct 29 '18 at 17:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Copy and paste this code on ttyecho.c

Compile it using gcc -O3 -o ttyecho ttyecho.c

Use it ./ttyecho -n /dev/pts/1 ls

  • 1
    @Tiger Be aware that the command string will first be parsed in the current terminal's shell but executed in the environment of the target's. You can see the difference with ttyecho -n /dev/pts1 ls $$ and ttyecho -n /dev/pts1 ls '$$' – Otheus Feb 7 '16 at 7:47

Depends on your terminal environment:

  • In Linux with the console: openvt _command_
  • Within a terminal in screen: screen _command_
  • Within X Windows (Mac as well): xterm -e "_command_"

It's not clear to me why you want to do this; depending on the exact reason, the clusterssh package may do what you want.

The idea of clusterssh is that you start several ssh commands to several machines (or possibly the same machine multiple times). You then get a terminal window for each ssh session, plus one entry window of clusterssh. If you type something into one of the terminal windows, it gets sent only to that ssh session; if you type it into the main entry window, however, it gets sent to all sessions.

If that's not what you need, it might be useful if you could explain why you want to do this.

  • Yeah, clusterssh is a nice tool for working with a small set of hosts in parallel. – Otheus Feb 7 '16 at 8:13

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