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: set destroy-unattached on makes a tmux session vanish when you detach

Tmux
~/tips/tip-tmux-destroy-unattached

tmux new -s scratch \; set destroy-unattached on

Cleans up throwaway sessions as soon as you leave them.

Not every session needs to survive. For a quick scratch session I’d rather it disappears when I detach, instead of showing up in tmux ls for weeks.

tmux new -s scratch \; set destroy-unattached on

The \; runs the second command right after the first, so the option is set only on the session scratch. Detach with Ctrl-b d and tmux destroys the session, with everything running in it.

Since tmux 3.5 there are two more values for grouped sessions: keep-last destroys a session only if others in its group remain, and keep-group keeps the last session of a group alive.

Be careful where you set it. In ~/.tmux.conf with -g it applies to every session, including the ones you use to keep jobs running after you log out. That is the whole point of tmux for most people.

Also note that it acts on sessions without a client right away. On a test server with no one attached, set -g destroy-unattached on ended every session on the spot, and the server with them. Set it per session, from inside the session you are attached to.

Further reading: tmux manual page (OpenBSD)

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