TransWikia.com

Execute command as if in another open terminal window

Unix & Linux Asked by falky on October 14, 2020

Let’s say I have three Terminal windows open:

  1. ttys001: the current terminal I am in. Current directory is ~
  2. ttys002: current directory is ~/Desktop
  3. ttys003: a terminal where I’ve SSH’d into a remote machine. The current directory on local machine is ~/test. The current directory of the remote machine is ~/abcdef

Is it possible to execute a command that runs as if it were in one of the other open terminals, but prints the output in my currently active terminal.

For instance, from ttys001, can I get the output of ls as if it were run in ttys002 and have it print in ttys001.

Can I also do the same for the remote machine I am connected to in ttys003 (ie get the output of ls ~/abcdef not ls ~/test.

Would be interesting in hearing how this would work for macOS and Linux.

Edit:
I am aware I am asking about "terminal windows" as opposed to the processes that are running in them. This is deliberate. The aim is to write a tool that can get the list of files/folders available to a user for each terminal window they have open. If a terminal window is actively SSH’d into another machine, then I’d like to get the files/folders in the working directory of the remote machine.

One Answer

Have a look at tmux or screen.

You can attach multiple times to a "session", locally, remotely via ssh, or in any other way you can start a shell on the machine in question.

Everything that happens in one session will be displayed on all attached terminals.

It is available for MacOS and Linux.

Correct answer by dirkt on October 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP