72

I am running a screen session and I'd like to change it's name. I know that when starting a new screen session I can use the '-S' option to give it a name. How do I change that name once the session has already started?

BenMorel
  • 4,587
chaimp
  • 831

5 Answers5

79

There is a screen command to do this. From the manual:

Command: sessionname [name]

(none)

Rename the current session. Note that for screen -list the name shows up with the process-id prepended. If the argument name is omitted, the name of this session is displayed.

Caution: The $STY environment variable still reflects the old name. This may result in confusion. The default is constructed from the tty and host names.

To access the screen command line, use Prefix:, where Prefix is typically Ctrl-a.

So you will most likely have to do so: Ctrl-a:sessionname [name]

reg
  • 1,143
jw013
  • 51,212
43

To rename the window title within a screen session:

  • press and release Ctrl+a and then press Shift+a

To rename the actual session name (displayed with screen -ls) use:

ccpizza
  • 1,723
14
# screen -S old_session_name -X sessionname new_session_name
  • 1
    This didn't work for me on Fedora 29 (Screen version 4.06.02 (GNU) 23-Oct-17), I had to use Ctrl a followed by :sessionname <new-session-name>. It did, however, work on OS X with Screen version 4.00.03 (FAU) 23-Oct-06 – adamc Nov 21 '18 at 23:06
2

Don't forget to update the contents of the $STY variable with the new name:

$ session -S OldName -X sessionname NewName

$ echo $STY

PID.OldName  <- Where PID is the actual Process ID on your system

Note: If you tried a screen top at this point, it'll fail with a message about not being able to find the old session in /run/uscreens/S-username.

$ export STY=PID.NewName <- Where PID is the actual Process ID on your system

$ screen top

This will now work, since the $STY variable is being used (along with other purposes) to find the location in /run/uscreens/S-username of the session file.

RossMan
  • 21
0

May not be answering this exact question, but to change the name displayed at the bottom like (0 bash), you can use

  • Ctrl-a then :title <newtitle> to change the bash part
  • Ctrl-a then :number <newnumber> to change the number (which will also change relative order of your session instances).