Skip to content
shellhacks.dev
Tooling

Kill a session

Kill a tmux session with kill-session -t =name. A bare name also matches by prefix, so -t work can hit workshop, and the equals sign forces an exact match.

1 min read
Summarize in AI

Two sessions have similar names, and killing one by its name must not touch the other.

Shell
tmux new-session -d -s work
tmux new-session -d -s workshop
tmux kill-session -t =work
tmux ls -F '#{session_name}'
tmux kill-session -t wor; echo "kill -t wor: $?"
tmux ls; echo "ls: $?"
Text
workshop
kill -t wor: 0
no server running on /tmp/tmux-0/default
ls: 1

A tmux target such as work is matched against session names first as an exact string and then as a prefix, so -t wor finds workshop when it is the only session that starts that way, and kills it. The = form turns the prefix matching off, as the tmux manual explains under target sessions. In the run, =work removed only work, while the bare prefix removed workshop and left no server running.

When two sessions share the prefix the bare form is rejected as ambiguous, which is the safer failure. A script should therefore always use the equals sign with a name it built itself. kill-server ends every session and the server, which is a bigger hammer than most scripts need.

Share

More snippets

Tooling

Swap two panes in a window

Swap two panes in a window with swap-pane -s source -t target. The panes keep their IDs and running programs and trade positions, and prefix then braces do it.

2 min read
Tooling

Resize a pane

Resize a pane with resize-pane -x 30 for an exact width or -R 10 to move its edge. The keys are prefix then Ctrl and an arrow, one cell at a time.

1 min read
Tooling

Zoom a pane to full screen

Zoom one pane to fill the window with resize-pane -Z, or prefix then z, and call it again to restore. The window shows a Z flag while zoomed.

1 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.