<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>pane on
A Scripter's Notes</title><link>https://scripter.co/tags/pane/</link><description>Recent content in pane
on A Scripter's Notes</description><language>en-us</language><managingEditor>kaushal.modi@gmail.com (Kaushal Modi)</managingEditor><webMaster>kaushal.modi@gmail.com (Kaushal Modi)</webMaster><lastBuildDate>Wed, 22 Apr 2026 08:24:58 -0400</lastBuildDate><generator>Hugo -- gohugo.io</generator><docs>https://validator.w3.org/feed/docs/rss2.html</docs><atom:link href="https://scripter.co/tags/pane/index.xml" rel="self" type="application/rss+xml"/><item><title>Send a command to every pane/window/session in tmux</title><link>https://scripter.co/command-to-every-pane-window-session-in-tmux/</link><description>&lt;blockquote>Faster way to send the same command to each and every &lt;em>pane&lt;/em> in your
tmux &lt;em>session&lt;/em>.&lt;/blockquote>&lt;div class="ox-hugo-toc toc">
&lt;div class="heading">Table of Contents&lt;/div>
&lt;ul>
&lt;li>&lt;a href="#send-command-to-all-panes-in-all-sessions">Send command to all panes in &lt;strong>all&lt;/strong> sessions&lt;/a>
&lt;ul>
&lt;li>&lt;a href="#usage">Usage&lt;/a>&lt;/li>
&lt;li>&lt;a href="#about-the-double-hashes">About the &lt;code>##&lt;/code>&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;a href="#send-command-to-all-panes-in-current-session">Send command to all panes in &lt;strong>current&lt;/strong> session&lt;/a>&lt;/li>
&lt;li>&lt;a href="#tmux-send-cmd-to-all-panes-old">Older version (circa 2014)&lt;/a>&lt;/li>
&lt;/ul>
&lt;/div>
&lt;!--endtoc-->
&lt;p>Ever wondered how you would send the &lt;code>clear&lt;/code> command to &lt;em>each pane&lt;/em>,
in &lt;em>each window&lt;/em>, in &lt;em>each session&lt;/em> in &lt;code>tmux&lt;/code>, or how you would do
source your shell config file in each after each tweak?&lt;/p>
&lt;p>Here are few excerpts from my &lt;a href="https://github.com/kaushalmodi/dotfiles/blob/master/tmux/dot-tmux.conf">&lt;code>.tmux.conf&lt;/code>&lt;/a> that allow doing just
that.&lt;/p>
&lt;h2 id="send-command-to-all-panes-in-all-sessions">Send command to all panes in &lt;strong>all&lt;/strong> sessions&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#send-command-to-all-panes-in-all-sessions">#&lt;/a>&lt;/h2>
&lt;p>Thanks to the tip in comments from &lt;em>Bob Fleming&lt;/em>, I learned that &lt;code>tmux&lt;/code> has a &lt;code>-a&lt;/code>
switch for the &lt;code>list-panes&lt;/code> command.&lt;/p>
&lt;p>From &lt;code>man tmux&lt;/code>,&lt;/p>
&lt;blockquote>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">list-panes [-as] [-F format] [-t target]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> (alias: lsp)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> If -a is given, target is ignored and all panes on the server
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> are listed. If -s is given, target is a session (or the
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> current session). If neither is given, target is a window (or
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> the current window). For the meaning of the -F flag, see the
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> FORMATS section.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/blockquote>
&lt;p>With that knowledge, the &lt;a href="#tmux-send-cmd-to-all-panes-old">older version&lt;/a> of the &lt;kbd>E&lt;/kbd> binding now reduces
to,&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-docker" data-lang="docker">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Send the same command to all panes/windows/sessions&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="nb">bind&lt;/span> E command-prompt -p &lt;span class="s2">&amp;#34;Command:&amp;#34;&lt;/span> &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> &lt;span class="s2">&amp;#34;run \&amp;#34;tmux list-panes -a -F &amp;#39;##{session_name}:##{window_index}.##{pane_index}&amp;#39; \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> | xargs -I PANE tmux send-keys -t PANE &amp;#39;%1&amp;#39; Enter\&amp;#34;&amp;#34;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h3 id="usage">Usage&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#usage">#&lt;/a>&lt;/h3>
&lt;ul>
&lt;li>Type the following binding in any &lt;code>tmux&lt;/code> pane: &lt;kbd>C-z E&lt;/kbd>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>&lt;/li>
&lt;li>Enter a command that you would want to send to all the panes, like
&lt;code>source ~/.alias; clear&lt;/code> &lt;em>(this is entered in the tmux command
prompt)&lt;/em>.&lt;/li>
&lt;li>That will source the &lt;code>~/.alias&lt;/code> in &lt;strong>all&lt;/strong> panes, and then clear the
terminals as well.&lt;/li>
&lt;/ul>
&lt;h3 id="about-the-double-hashes">About the &lt;code>##&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#about-the-double-hashes">#&lt;/a>&lt;/h3>
&lt;div class="note">
&lt;p>The &lt;code>#&lt;/code> character needs to be escaped by another &lt;code>#&lt;/code> and typed as
&lt;code>##&lt;/code>, only when used inside the &lt;code>run-shell&lt;/code> command.&lt;/p>
&lt;/div>
&lt;p>.. because otherwise, &lt;code>tmux run-shell&lt;/code> command will replace the
unescaped &lt;code>#{session_name}&lt;/code>, &lt;code>#{window_index}&lt;/code> and &lt;code>#{pane_index}&lt;/code> with
their current values &lt;strong>before&lt;/strong> executing the command.&lt;/p>
&lt;p>With the hashes escaped, those variables will be evaluated &lt;em>at run
time&lt;/em>.&lt;/p>
&lt;p>But if you were to type the above command directly in the terminal,
without the &lt;code>run-shell&lt;/code> command wrapper, you would use only single
&lt;code>#&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">tmux list-panes -s -F &amp;#34;#{session_name}:#{window_index}.#{pane_index}&amp;#34;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="send-command-to-all-panes-in-current-session">Send command to all panes in &lt;strong>current&lt;/strong> session&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#send-command-to-all-panes-in-current-session">#&lt;/a>&lt;/h2>
&lt;p>The &lt;code>list-panes&lt;/code> command has another useful switch: &lt;code>-s&lt;/code>, which takes
an optional argument, a &lt;em>session name&lt;/em>. If that argument is not
supplied, it takes the current session name by default.&lt;/p>
&lt;p>Below &lt;kbd>C-e&lt;/kbd> binding is used to send a command to all panes, in all
windows, but &lt;strong>only in the current session&lt;/strong>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-docker" data-lang="docker">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">bind&lt;/span> C-e command-prompt -p &lt;span class="s2">&amp;#34;Command:&amp;#34;&lt;/span> &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> &lt;span class="s2">&amp;#34;run \&amp;#34;tmux list-panes -s -F &amp;#39;##{session_name}:##{window_index}.##{pane_index}&amp;#39; \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> | xargs -I PANE tmux send-keys -t PANE &amp;#39;%1&amp;#39; Enter\&amp;#34;&amp;#34;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="tmux-send-cmd-to-all-panes-old">Older version (circa 2014)&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#tmux-send-cmd-to-all-panes-old">#&lt;/a>&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-docker" data-lang="docker">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Send the same command to all panes/windows/sessions&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="nb">bind&lt;/span> E command-prompt -p &lt;span class="s2">&amp;#34;Command:&amp;#34;&lt;/span> &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> &lt;span class="s2">&amp;#34;run \&amp;#34;tmux list-sessions -F &amp;#39;##{session_name}&amp;#39; \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> | xargs -I SESS tmux list-windows -t SESS -F &amp;#39;SESS:##{window_index}&amp;#39; \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> | xargs -I SESS_WIN tmux list-panes -t SESS_WIN -F &amp;#39;SESS_WIN.##{pane_index}&amp;#39; \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> | xargs -I SESS_WIN_PANE tmux send-keys -t SESS_WIN_PANE &amp;#39;%1&amp;#39; Enter\&amp;#34;&amp;#34;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>I have set my tmux prefix to &lt;kbd>C-z&lt;/kbd>.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description><author>Kaushal.Modi@fakeEmailToMakeValidatorHappy.com (Kaushal Modi)</author><category domain="https://scripter.co/categories/unix">unix</category><category domain="https://scripter.co/tags/tmux">tmux</category><category domain="https://scripter.co/tags/pane">pane</category><category domain="https://scripter.co/tags/window">window</category><category domain="https://scripter.co/tags/session">session</category><guid>https://scripter.co/command-to-every-pane-window-session-in-tmux/</guid><pubDate>Thu, 06 Mar 2014 09:50:21 -0500</pubDate></item></channel></rss>