I want to run a command foo on one terminal and pass the result to another terminal. Is it possible to do this ?

  • 4
    Also look into tmux and screen, both of which allow you to take over, mirror, or just execute commands on, other sessions.
    – Kevin
    Jul 12, 2014 at 18:32

2 Answers 2


Yes, it is. A picture worth a thousand words:

radu's terminal

So, you have to redirect the output of your command using > operator to /dev/pts/#. You can find # using who or w command. If tou want to redirect and the errors, use:

<command> >& /dev/pts/#
  • thanks. but if the another terminal does not exist. what we should do? Or better to say pass it to newer one? Jul 12, 2014 at 17:07
  • 5
    You will need probably a script to do that: the script will take as argument your command then should open a new gnome-terminal and detect the tty (using tty command) of the new terminal and finally send the output to it. Jul 12, 2014 at 17:25

Something like this for your $HOME/.bashrc :

ng() { gnome-terminal -x sh -c "$*; bash"; }

This will run a command and shows the result on a new terminal window.


ng ls -l
ng echo foo

Edit: To consider aliases from the $HOME/.bashrc use this instead:

ng() { gnome-terminal -x bash -ic "$*; bash"; }

then the output of ls should be colored (thanks to Radu Rădeanu for this hint).

  • This will run the command directly in the new terminal. Jul 12, 2014 at 17:42
  • Yes but what is the advantage to run it first in the old terminal ?
    – TuKsn
    Jul 12, 2014 at 17:46
  • No advantage..., but in fact this answer to this comment. Jul 12, 2014 at 17:53
  • 4
    You will understand if you will run type ls and then ng type ls :) Jul 12, 2014 at 18:01
  • 1
    if write function in one line in bashrc, maybe need a semicolon to end it, or you will meet an "unexpected end of file" error. so ng() { gnome-terminal -x sh -c "$*; bash" ;} should be better. And if you are using xfce(xfce4-terminal as default emulator): ng() { xfce4-terminal -x sh -c "$*; bash" ;} or you can simply run by any default emulator ng() { x-terminal-emulator -x sh -c "$*; bash";}
    – user305925
    Jul 16, 2014 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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