Skip to content
shellhacks.dev
Tooling

List sessions

List tmux sessions with list-sessions -F for output a script can parse. With no server running the command prints an error and exits 1.

1 min read
Summarize in AI

A script needs the names of the running tmux sessions, and the default listing has a timestamp and a status in it.

Shell
tmux list-sessions; echo "no server: $?"
tmux new-session -d -s one
tmux new-session -d -s two
tmux ls
echo ---
tmux ls -F '#{session_name}' | sort
Text
no server running on /tmp/tmux-0/default
no server: 1
one: 1 windows (created Fri Nov  6 14:07:08 2026)
two: 1 windows (created Fri Nov  6 14:07:08 2026)
---
one
two

list-sessions (alias ls) prints one line per session, and -F takes a format with #{...} variables, listed in the tmux manual. #{session_name} is all a script needs. The first command shows what happens before any session exists: tmux has no server process, says so on standard error and exits 1.

The default listing includes the creation time, which varies, so do not parse it. Treat exit status 1 as "none", but not necessarily as an error, when the server may be down. Running tmux ls inside the session it lists works the same.

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.