35

This is probably simple, but I really can't find out how you do it. I have read the man pages and googled without results.

Problem: How do I run a command in a detached tmux window?

Example: I want my detached window 'foo' to run 'ls', but I want to do it from another terminal.

I've tried stuff like: 'tmux -t foo ls' without results.

Accatyyc
  • 455
  • 1
  • 4
  • 6

1 Answers1

53

The command is send. send is a key sequence, so treat it accordingly (e.g. you'll probably want ENTER). The target is specified with -t. You may want foo.0 or foo.1 depending on the pane you wish to hit.

tmux send -t foo.0 ls ENTER

send is short for send-keys, which is located in the man pages, but perhaps a bit difficult to find in that mile of text.

84104
  • 12,698
  • 6
  • 43
  • 75
  • Great answer. Very informative and works a charm. Thanks! – Accatyyc Dec 10 '11 at 15:10
  • The most majestic solution for this issue! Massive thanks! – 3bdalla Feb 15 '17 at 06:21
  • 3
    Note that to target a specific window in a specific session, you separate them with a colon => `tmux send-keys -t foosession:foo.0 ls ENTER` – nickspoon Mar 17 '17 at 01:16
  • 3
    If you want to send spaces between words, you should surround the command with two apostrophes. The ENTER command should still be outside. This works for me on UBUNTU 16.04: `tmux send -t session_name 'echo durp'` ENTER – TrollAxeThrower Mar 21 '18 at 16:40