Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a script. I really want to know this. I hope tmux executable can tell me this.

I find

tmux rename <newname>

can rename current session. But I can't find a command to fetch its own name.

Thank you.

share|improve this question
up vote 17 down vote accepted

With tmux 1.2 (and later), you can use the -p option of display-message to output a message to stdout (instead of displaying it to an attached client):

tmux display-message -p '#S'

#S is formatted as the session name (see the description of the status-left option in the man page).

share|improve this answer
+1, much better than my answer. – chepner Apr 9 '12 at 12:52
I really appreciate that you point out it require tmux 1.2, which is exactly the version available for openSUSE 11.3 auto online update. – Jimm Chen Apr 10 '12 at 1:19

Not ideal, but you can extract the name of the attached session with awk:

tmux list-sessions -F '#{session_name} #{session_attached,yes,}' | awk '$2=="yes" {print $1}'

The custom format is a little easier to parse than the default.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.