Published on

Send commands to all panes in Tmux

Send commands to all panes in Tmux

Tmux is one of the most useful tool when it comes to using using a linux terminal.

Tmux is a terminal multiplexer, it allows a user to access multiple terminals (or windows), each running a separate program, while providing a single screen to work on. Tmux is useful for running more than one command-line program at the same time, increasing productivity and the way you work.

Tmux is one of the "terminal multiplexer", it enables a number of terminals (or windows) to be accessed and controlled from a single terminal. It allows you to create a session on a remote box, run applications in that remote session, "detach" from the session, and re-"attach" when desired. It also has advanced features such as multiple windows and split views. Using tmux is recommend when running an interactive CLI program remotely. If you get disconnected from your session, you can re-attach as though nothing happened.

Let's consider a case where you have to send a command to all the panes in a window, for example - an ssh command to connect to a remote host, across all panes or another example is to clear history in all your panes).

Using prefix synchronize-panes command

You can use <prefix> :setw synchronize-panes on to set the ability to send commands to all panes. All panes in the given window are all now synchronized to receive the same command.

Here, let's assume that your <prefix> is Ctrl-B, which is the default prefix.

Let's take an example, let's say you want to clear history across all panes in a window. You can do the follow set of commands-

setw synchronize-panes on

To disable the synchronize-panes state, you can use the following command-

setw synchronize-panes off

Using on or off is optional. The command can also be used to toggle between the on and off states. So, the below command can be used to toggle states-

setw synchronize-panes

Shortcut Ctrl-B, then, Ctrl-S

The default shortcut to synchronize panes is-


Custom Shortcut in ~/.tmux.conf

You can create a custom shortcut if Ctrl-S is confusing. You can unbind the Ctrl-S and add a new binding to another keypair, like Ctrl-Y.

You can create a custom shortcut in your ~/.tmux.conf -

unbind C-S
bind C-Y set-window-option synchronize-panes

You have to reload changes in tmux config tmux.conf so that it reflects-

tmux source-file ~/.tmux.conf

So, the new shortcut to synchronize panes is-


I hope you found this article useful, glad that you found it easy to send commands to all panes in a window in Tmux.