brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: setw synchronize-panes on types into every pane at once

Tmux
~/tips/tip-tmux-synchronize-panes

setw synchronize-panes on

Sends everything you type to all panes in the tmux window, handy for the same command on several servers.

Four SSH sessions to four machines and one command to run on all of them: this is what the option is for.

Ctrl-b :
setw synchronize-panes on
# when you are done
setw synchronize-panes off

Everything you type now goes to every pane in the window. A common pattern is one pane per server, then one sudo apt update for all.

The typical use is a handful of servers that need the same maintenance. Open one pane per server, log in on each, turn synchronization on and type the command once. Every pane receives the keys, so all of them run the same thing at once.

It is a window option, so it only affects the window you set it in. To make it a toggle you can bind a key, for example bind S setw synchronize-panes. A pane title or colour change that shows when it is on is worth setting up if you use it often, because forgetting it is on is the main way to get into trouble.

It types into every pane, including the ones you forgot about. Turn it off before you do anything you cannot undo.

Try it without risk: start a throwaway session with tmux new -s scratch, use the shortcut or command above there, look at what changes, and close the session again with tmux kill-session -t scratch. Nothing else on your machine is touched.

Further reading: tmux manual page (OpenBSD, official), tmux wiki: Getting Started (official), On this site: tmux send-keys types into a pane you are not looking at, On this site: Ctrl-b Alt-arrow resizes a tmux pane five cells at a time

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link