456

When I first started using tmux, I didn't give my first session a name. Then, as I started creating different sessions for different tasks (work, play, etc), I started naming my sessions.

Now I have a bunch of different sessions, but the first one doesn't have a name. How can I name (or rename) it, both from within tmux and from a shell prompt?

Mateusz Piotrowski
  • 4,016
  • 4
  • 28
  • 53
Richard Jones
  • 5,468
  • 3
  • 18
  • 14

2 Answers2

698

From within tmux

Short way: prefix, then dollar sign:

Ctrl + B, $

or

Long way: prefix, then colon:

Ctrl + B, :

Then type this command at the prompt:

rename-session [-t current-name] [new-name]

If the current session name (-t current-name) is not specified, the currently attached session will be renamed.

By default the session name will be in brackets in the lower left corner of tmux. You can list all sessions and switch between them with:

Ctrl + B, s

From shell prompt

You can rename tmux sessions with

tmux rename-session [-t current-name] [new-name]

To find your session names, do tmux list-sessions -- it will be in the left-most column.

If the current session name (-t current-name) is not specified, the most recently used session will be renamed.

David Oliver
  • 115
  • 1
  • 7
skrblr
  • 7,151
  • 1
  • 14
  • 5
  • 1
    I'm trying to create a canonical answer. Can you also tell me how to do this from within tmux? And also how I would find out what my session is currently named? – Richard Jones May 23 '12 at 17:35
  • The default key binding for `rename-session` is `Ctrl-b $`. Actually, it uses `command-prompt` to provide a minimal interface to `rename-session`. The prompt uses the current session name as the default value, which you can delete and replace with the new name. If you haven't changed your status bar from the default, the session name should be displayed on the left-hand side. – chepner May 23 '12 at 17:44
  • 2
    Hmm.. `C-b $` doesn't seem to be set by default in my tmux on Ubuntu 10.04. At any rate, you can find the name of your current session with `tmux list-sessions`, it'll be the left-most item. Will probably be '0' if it was the first session you created. Then `tmux rename-session -t 0 renamed_session`. Both commands should work from within tmux. – skrblr May 23 '12 at 18:15
  • 1
    It'd be better if you flesh out your answer with a comprehensive edit instead of back and forth comments – random May 23 '12 at 18:54
  • 8
    Note that `rename-session [new-name]` is enough if you want to rename current session within tmux. – Matvey Aksenov Nov 07 '12 at 19:13
  • 10
    `tmux new -s myname` to start a new named session. so you don't run into this predicament next time. – Danny Nov 29 '14 at 18:34
  • if you get at `rename-session` a "command not found" you forgot to press `^B` + `:` – rubo77 Jun 21 '16 at 11:06
  • The long way is a bit shorter if you use `rename` (an alias) instead of `rename-session`. – rrd Jan 30 '23 at 18:31
20

From within tmux you can also edit the name of the current window (one of many within the session) with:

  • Prefix, then comma sign:

Ctrl + B, ,

(This does not rename the "session", but the window inside a session, which many users that land here are searching for)

rubo77
  • 4,680
  • 11
  • 45
  • 79