The tmux send-keys
command allows you to send keystrokes to a tmux pane or window. This is useful for automating tasks, running commands in multiple panes simultaneously, or controlling remote sessions. Use it with tmux send-keys -t target "command" Enter
.
$ tmux send-keys -t session:window.pane "echo hello" Enter
The send-keys
command is a powerful tmux feature that lets you programmatically send keystrokes to any pane or window, even if it's not currently active or visible.
tmux send-keys -t TARGET "TEXT" [KEY ...]
-t target
- Specifies which session, window, or pane to send keys to-l
- Send literally (don't interpret special key names)-R
- Reset terminal state before sendingsession
- Send to active pane of specified sessionsession:window
- Send to active pane of specified windowsession:window.pane
- Send to specific pane:window.pane
- Send to pane in current session.pane
- Send to pane in current windowtmux send-keys -t mysession "ls -la" Enter
- Run ls commandtmux send-keys -t 0:1.2 "cd /home/user" Enter
- Change directory in session 0, window 1, pane 2tmux send-keys -t dev Up Enter
- Send Up arrow key and Entertmux send-keys -t all "echo synced command" Enter
- Send to all panes (with proper setup)You can send special keys by name:
Enter
Escape
or Esc
Tab
Space
BSpace
or BackSpace
Up
, Down
, Left
, Right
DC
(Delete)Home
, End
F1
through F12
To send the same command to all panes in a window, you can use the synchronize-panes feature:
# Enable synchronize-panes tmux set-window-option synchronize-panes on # Type commands (will go to all panes) # ... # Disable when done tmux set-window-option synchronize-panes off