Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question
    
what do you have? Did you try something? Can you give some examples? – tachomi Feb 11 at 14:53
    
@tachomi on first terminal I run ls and want its output to be displayed on second terminal (with or without using any command on second) – edward torvalds Feb 11 at 14:55
up vote 22 down vote accepted

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.

share|improve this answer
    
I dont get /dev/pts/7 or similar with w command, but second way works for me – edward torvalds Feb 11 at 15:07
2  
@edwardtorvalds The /proc/XXX/fd/1 is generally a soft link to the base device. Try using ls -l /proc/XXXX/fd/1 and see what it is pointing to. Does it have any relation to what appeared in the w command? – RealSkeptic Feb 11 at 15:22
    
I am not relating w command with /proc/XXX/fd/0 I am relating w command with /dev/pts/7 – edward torvalds Feb 11 at 15:26
4  
@edwardtorvalds I am saying that they are connected as /proc/XXX/fd/1 is supposed to be a soft link to whatever device the w command displays. What is the output of ls -l on it? – RealSkeptic Feb 11 at 15:27
    
TTY information can also be found in the output from tty (only current) or who (all). – Nick Volynkin Mar 3 at 5:53

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             LOGIN@   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
share|improve this answer
    
on arch linux, in gnome terminal, output of w command is edward tty2 19:53 6:05 2:48 23.12s firefox and if I write ls | write edward tty2 I get no output but a beep sound – edward torvalds Feb 11 at 15:00
    
@edwardtorvalds You released you typed edwardd instead of edward? – tachomi Feb 11 at 15:04
    
also if I try it on tty5 (ctrl + alt + 5) I get error you have turned write permission off – edward torvalds Feb 11 at 15:04
    
that was typing error on this site – edward torvalds Feb 11 at 15:04
    
try mesg y command on the target terminal, before you run the command – MelBurslan Feb 11 at 15:07

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

share|improve this answer
1  
tail -f instead of cat could be useful – tachomi Feb 11 at 15:37
3  
@tachomi actually there is no need of any command to read the output – edward torvalds Feb 11 at 17:37

You can use wall also:

$ wall "Message here"
share|improve this answer
    
you might wanna describe it in detail. I don't understand anything from this – edward torvalds Feb 11 at 15:08
3  
You definitely do not want to use wall (short for "write all"), as it writes to every logged-in tty session, including the one you're sending from. Instead, using write allows a specific tty to be declared. – Monty Harder Feb 11 at 19:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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