3

as you know "wall" command sends a message to all terminals:

wall message

now my question is this: is there any command that can send a "command" to be run in all terminals?
for example sending clear command to all terminals , so then all terminals will be cleared.

3
  • KDE's konsole can send input to all tabs (Edit->Copy Input to), but that of course can't work for virtual terminals. Commented Jul 5, 2012 at 12:58
  • 1
    Possible duplicate of Execute command in remote active terminal
    – George M
    Commented Jul 5, 2012 at 13:26
  • What do you want to do with this and why?
    – Nils
    Commented Jul 8, 2012 at 21:53

3 Answers 3

6

That would be somewhat frightening, but you can send the output of any command to multiple "terminals". For instance, to clear all TTYs that you have access to:

for tty in /dev/ttys00*; do clear > "$tty"; done # OS X (local)
for tty in /dev/pts/*; do clear > "$tty"; done # Linux (Ubuntu, via SSH)
2
  • For the purpose of the user's example (clearing all terminals), that's enough.
    – Random832
    Commented Jul 5, 2012 at 14:26
  • The subtlety of this is that one has to get the TERM environment variable right for each individual terminal, especially if one is doing more than clearing the screen. But even clearing the screen varies by terminal type. For real serial terminals, and for pseudo-terminals, this is quite the challenge, because there is no way to reliably tell what TERM should be set to, programmatically. Then there are the terminal emulators that do not actually really clear their screens. unix.stackexchange.com/a/375784/5132
    – JdeBP
    Commented Feb 27, 2020 at 14:35
1

Using George M command on Ubuntu gave me returned the following error

bash: /dev/pts/ptmx: Permission denied
$ ls /dev/pts/
0  1  10  4  5  6  8  ptmx

So adding to it, I exclude ptmx in my alias in ~/.bash_aliases by simply allowing 0-9.

alias clearall='for tty in /dev/pts/[0-9]; do clear > "$tty"; done'
-2

Cluster SSH.

yum install cssh after activating rpmforge.

5
  • This isn't even wrong, it has nothing to do with the question. Commented Jul 5, 2012 at 23:20
  • @Gilles I'm not sure what's wrong with it; it seems fine Commented Jul 6, 2012 at 0:17
  • @MichaelMrozek What does coordinating multiple ssh sessions have to do with executing commands in multiple terminals? Commented Jul 6, 2012 at 0:22
  • @Gilles The description says "ClusterSSH controls a number of xterm windows via a single graphical console window" Commented Jul 6, 2012 at 0:25
  • @Gilles to issue actual commands you have to be owner of that terminal. I do not think that the question is about putting text onto a number of terminals. I suspect the questioner wants to do something on a number of machines with a single place to type the according commands. This is what Cluster-SSH is all about. Sadly the questioner has not answered the request for clarification.
    – Nils
    Commented Jul 11, 2012 at 21:17

This site is temporarily in read-only mode and not accepting new answers.

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