Ubuntu – How to send terminal command to a TTY terminal

command linetty

I am looking for a way to send an executed command to a TTY terminal. For example, let us say that I open the gnome-terminal and on the window I type sudo aptitude update && sudo aptitude upgrade.

How can I send this to a TTY terminal instead of working with it in the TTY7 GUI environment?

Best Answer

I would recommend not doing that directly, but use a terminal multiplexer, such as tmux, as an in-between.

In the terminal that should receive the command start tmux with an identifier:

tmux new-session -s MYSES

Send commands to it with:

tmux send-keys -t MYSES "sudo aptitude update && sudo aptitude upgrade"$'\n'
Related Question