Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Apr 28 '11 at 16:52

This question came from our site for professional and enthusiast programmers.

    
Not a programming question. Should go to SuperUser or Unix. –  0xC0000022L Apr 27 '11 at 22:13

5 Answers 5

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
#/bin/bash
echo -ne '\ek${0}\e\\'

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

I hope this helps.

share|improve this answer
    
Thanks, this helps a lot. Is there anyway to rename an already existent screen session? –  Charlotte Apr 27 '11 at 21:19
    
@Charlotte : see edits. Thanks for the votes! –  shellter Apr 27 '11 at 21:44

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 from 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 t 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.

share|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

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, :sessionname name. You can view running screen sessions with screen -ls, and connect to one by name with screen -xS name.

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.

share|improve this answer

While running screen:

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

share|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.

example:

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.

share|improve this answer

Your Answer

 
discard

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.