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: tmux link-window shows the same window in two sessions

Tmux
~/tips/tip-tmux-link-window

tmux link-window -s work:logs -t home:

Puts one running tmux window in a second session, without starting it twice.

I like one tmux session per project, but some windows belong to all of them: the one with htop, or the one tailing a log on the server. You don’t have to open that window twice. tmux can link one window into several sessions, and every session then shows the same window, with the same panes and the same output.

Say the window is called logs in the session work and you also want it in the session home:

tmux link-window -s work:logs -t home:

-s is the window you have, -t is where it should appear. The colon after home with nothing behind it means “the next free window number in that session”. You can also give a number, like home:9. Add -d if you don’t want tmux to switch to the linked window straight away.

Now switch to home with Ctrl-b s and the logs window is there, still running, and anything you type in it shows up in work as well. It is the same window, not a copy, so you also only run that tail -f once.

The thing to remember is what closing does. kill-window (or Ctrl-b &) destroys the window and removes it from every session it is linked to. To take it out of just one session, use unlink-window instead:

tmux unlink-window -t home:logs

That only works while the window is still linked somewhere else, because tmux won’t leave a window without a session. I’d reach for this for windows that watch something, not for a shell you work in, because two sessions typing into one pane gets confusing quickly.

Further reading: tmux manual page

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