I am just fooling around on my terminal (Gnome terminal). I was wondering is there a way to send output of one terminal to another without having to make a new file or pipe.
for example: on first terminal I run ls and want its output to be displayed on second terminal (with or without using any command on second)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If both terminals belong to the same user, you can send your output to the virtual device that is used as the particular terminal’s tty.
So you can use the output from w, which includes the TTY information, and write directly to that device.
ls > /dev/pts/7
(If the device mentioned by w was pts/7)
Another option is to use the number of a process that is connected to that device. Send your output to /proc/<process number>/fd/1.
ls > /proc/5555/fd/1
Assuming the process number that you found that runs in that terminal is 5555.
Note that this direct write is only allowed if the user that attempts to write is the same user that owns the other terminal.
Method 2
You can use write command.
As @MelBurslan commented, if write permission is off, first execute:
$ mesg y
From man mesg
OPTIONS
y Allow write access to your terminal.
Usage of write:
$ write username tty
e.g. Send ls output to other terminal.
$ w USER TTY FROM <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="165a59515f5856">[email protected]</a> IDLE JCPU PCPU WHAT user :0 :0 08:15 ?xdm? 7:37 0.25s init --user user pts/0 :0 08:19 1.00s 0.09s 0.01s w user pts/12 :0 08:50 54.00s 0.03s 0.03s bash $ ls | write username pts/12
Method 3
I found a similar method.
On first terminal:
$ tty /dev/pts/0 $ <no need to run any command here, just see the output>
On second terminal:
$ ls > /dev/pts/0
Now you get the output on first terminal
Method 4
you can write to the terminal’s TTY; for example:
in terminal 1:
$ tty ttys000
in terminal 2:
$ tty ttys029 $ exec &> >(tee >(cat >&/dev/ttys000)) ls
Output will show in both terminals in real-time even as you type.
Works on linux and macOS. The macOS TTY path is /dev/{number} while on Linux it’s /dev/pts/{number}
Method 5
You can use wall also:
$ wall "Message here"
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0