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.

M0εiπ
  • 1,257

3 Answers3

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)
George M
  • 13,959
janmoesen
  • 2,710
  • For the purpose of the user's example (clearing all terminals), that's enough. – Random832 Jul 05 '12 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. https://unix.stackexchange.com/a/375784/5132 – JdeBP Feb 27 '20 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'
Paulo Tomé
  • 3,782
-2

Cluster SSH.

yum install cssh after activating rpmforge.

Nils
  • 18,492
  • This isn't even wrong, it has nothing to do with the question. – Gilles 'SO- stop being evil' Jul 05 '12 at 23:20
  • @Gilles I'm not sure what's wrong with it; it seems fine – Michael Mrozek Jul 06 '12 at 00:17
  • @MichaelMrozek What does coordinating multiple ssh sessions have to do with executing commands in multiple terminals? – Gilles 'SO- stop being evil' Jul 06 '12 at 00:22
  • @Gilles The description says "ClusterSSH controls a number of xterm windows via a single graphical console window" – Michael Mrozek Jul 06 '12 at 00: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 Jul 11 '12 at 21:17