None of the above answers worked for me (tmux v2.3), but this did, from the bash command line:
for _pane in $(tmux list-panes -a -F '#{pane_id}'); do
tmux clear-history -t ${_pane}
done
A more generalized script, for tmux commands other than 'clear-history' would just replace that element with a parameter, eg. $1. Do be careful if you intend to write a script to handle a series of tmux commands, as "-t ${_pane}" will need to be applied to each.
Note that the -a
parameter to tmux list-panes
is required to cover all panes in all windows in all sessions. Without that, only panes in your current tmux window will be affected. If you have more than one tmux session open and only want to apply the command to panes within the current session, replace -a
with -s
(It's all in the tmux man page).
I haven't the mod points to comment directly on each of the above answers, so here's why they weren't working for me:
The problem that I had with @shailesh-garg 's answer was that the sync affected only commands issued within the panes, not tmux commands issued using Ctrl-B :
which are outside the panes.
The three problems that I had with @kshenoy 's answer were that:
- it sends keystrokes to within a pane, not to the tmux operation
of that pane, so for instance, if one had a bash shell running in
the pane and one used the script to send "clear-history", those
would be the keystrokes that would appear in the bash command-line.
A work-around would be to send "tmux clear-history" or to pre-pend
"tmux " to "$@", but I haven't edited the answer because of my other
problems with the answer;
- I couldn't figure out how to send a
new-line character without literally breaking the line;
- Even when I did that, sending "tmux clear-history" had no effect.