How to Manage tmux Sessions Using the Commands on tmuxcheatsheet.com

Updated

Use tmux new -s mysession to start a named session, Ctrl+b d to detach from it, tmux ls to list sessions, tmux attach -t mysession to reattach, and tmux kill-session -t mysession to delete it. These commands come from the Sessions section of the tmuxcheatsheet.com quick reference and cover the full start–detach–reattach–cleanup cycle. They apply to any standard tmux install; the cheat sheet also includes an Install page if tmux is not yet on your machine.

Start a session

Goal Command
Start an unnamed session tmux or tmux new or tmux new-session
Start a named session tmux new -s mysession (also : new -s mysession from inside tmux)
Start a named session or attach if it already exists tmux new-session -A -s mysession
Start a session with a named first window tmux new -s mysession -n mywindow

The -A form is the one to remember for repeat use: running it again attaches you to the existing mysession instead of failing because the name is taken.

Detach and reattach

  • Detach: press Ctrl+b, release, then press d. The session keeps running in the background.
  • Attach to the last session: tmux a, tmux at, tmux attach, or tmux attach-session.
  • Attach by name: tmux a -t mysession (the cheat sheet lists a, at, attach, and attach-session as equivalent forms).
  • Detach other clients: : attach -d detaches everyone else on the session, which the cheat sheet describes as maximizing the window by detaching other clients.

Expected result: after Ctrl+b d you return to your normal shell prompt; after attaching you see the session's windows and panes exactly as you left them.

List and navigate sessions

  • tmux ls or tmux list-sessions prints all running sessions.
  • Ctrl+b s shows all sessions in an interactive picker.
  • Ctrl+b w opens a session and window preview.
  • Ctrl+b ( moves to the previous session; Ctrl+b ) moves to the next.
  • Ctrl+b $ renames the current session.

A common snag: tmux ls reports "no server running" when no session exists — start one with tmux new -s mysession first.

Kill sessions

Goal Command
Kill the current session from inside tmux : kill-session
Kill a named session tmux kill-session -t mysession (also tmux kill-ses -t mysession)
Kill all sessions except the current one tmux kill-session -a
Kill all sessions except a named one tmux kill-session -a -t mysession

Verify with tmux ls afterward: the killed session should no longer appear. If you are inside the session you kill, tmux drops you back to the shell.

Where sessions, windows, and panes fit

A session is the top-level container; each session holds one or more windows (like tabs), and each window can be split into panes. That is why session commands use -t with a session name, while window commands use shortcuts such as Ctrl+b c (create window) and pane commands use Ctrl+b % or Ctrl+b " (split). The cheat sheet's Windows and Panes sections list those separately, so keep the session commands above for the outer layer and switch sections when you need to split or rearrange inside a session.