Is there a way to give a particular name to a unix screen session? For instance, say I'm running the same program multiple times, each with different parameters and I want to tell which one is which.


You can name a session when starting it with the -S name option. From within a running screen, you can change it by typing

Ctrl+A,: followed by sessionname name(1).

You can view running screen sessions with screen -ls, and connect to one by name with

screen -xS name

(1):name is and an arbitrary string which will become the new session name. If the session name contains whitespace, quote it with single or double quotes.

Within a single screen session, you can also name each window. Do this by typing Ctrl+A, A then the name you want. You can view an interactive list of named windows by typing Ctrl+A, ", and select the one you want to switch to from that list.

Naming both screens and terminals within screens is really helpful for remembering what they are and why you started them in the first place.

| improve this answer | |

There are two concepts here, and I'm not sure which one you have in mind:

  • You can have multiple screen windows. Each window runs a shell or other program. All the windows are hosted by the same process. C-a c creates a window, C-a n and C-a p switch to the next/previous window, and so on.
  • You can have multiple screen sessions. Each session is hosted by its own process and is independent of all other sessions. Starting screen without any reattach (-r or -R) option creates a new session.

Windows have titles, which can be set through the -t command line option, the C-a A key binding, the title command, or the \ek escape sequence. See shellter's answer for more details.

Sessions can have names. You'd typically set the name on the command line with the -S option; if you don't specify a name, screen makes one up. If you use multiple screen sessions, you'd typically give them different session names. You can list the running screen session with screen -ls; the first word on each session line is 12345.sessionname where 12345 is the screen process ID. Use screen -r sessionname or screen -r 12345 to resume a session indicated through its name or process ID.

| improve this answer | |
  • 1
    In the default key bindings, to change title you have to use C-a A. – enzotib Dec 21 '11 at 6:49

Ah... Screen, it takes me back ;-)

For one window

-t name
    sets the title (a.k.a.) for the default shell or specified program. 
    See also the "shelltitle" .screenrc command.

For mutliple sessions started from your .screenrc

screen -t top 2 nice top
screen -t ....

Here's a link to one on-line copy of the man-page for screen.

Edit : added

To change the current screens name, make a shell script tool like

cat scrnTitle.sh
echo -ne '\ek${0}\e\\'

Untested, I don't have screen available on the system I am working on.

| improve this answer | |
  • Thanks, this helps a lot. Is there anyway to rename an already existent screen session? – well actually Apr 27 '11 at 21:19
  • @Charlotte : see edits. Thanks for the votes! – shellter Apr 27 '11 at 21:44
  • Nice answer @shellter! I'm curious, did you say "takes me back" to mean you use something else these days (e.g tmux), or just that it's over 32 years old? – tutuDajuju May 17 '19 at 7:27
  • 1
    @tutuDajuju : Gulp, now that I think about it, I've used screen at least 25 years. Takes me back, because now it is a special use case that would take me to screen. Normally I just keep opening X-Terms, but I remember when it seemed impossible to run X on a 486 PC ;-) Cheers! – shellter May 17 '19 at 13:49
  • @shellter FYI, I ran X on a 486 PC with 8Mb RAM back in 1992... – Eno Oct 16 '19 at 16:01

While running screen:

Ctrl+a (or whatever your screen escape sequence is) A

| improve this answer | |

The answers above already tell you how to name a screen when you start it. They also point out that a screen can't be renamed after it has been started. The window title can be set but the name used to attach to the screen remains pid.pty.host.

However, to achieve a useful effect I've found that using alias work pretty well. If I forget to name a screen or find myself in a session with a bunch of screens up that have naturally become screens for particular tasks I simply set an alias for the command to attach to them.


alias goncompile='screen -r 2354'

Issuing the alias command by itself will remind you what screens you have up and command you have set to attach to them.

Use unalias to remove them.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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