4

[This continues my previous question How do I know I'm running inside a linux "screen" or not? ]

As title, can I?

I tried screen -S mysess but it creates a new screen instead of changing the name of current screen.

I also tried screen -X 'sessionname haha' , but no effect. It just display a inverse-color bar at terminal bottom saying

-X: unknown command 'sessionname haha'

enter image description here enter image description here

Jimm Chen
  • 1,709
  • 5
  • 17
  • 32

1 Answers1

19

Use Ctrl-a: to get to command mode for the session and then use the sessionname command

sessionname session1

EDIT:

Using your example above:

If you are detached from a session you can change it's session name with

screen -r 25278.pts-15.linux-ic37 -X sessionname YourSessionName

If you are attached to the session then you can change it's session name with

screen -d -r 25134.pts-3.linux-ic37 -X sessionname YourSessionName
user9517
  • 114,104
  • 20
  • 206
  • 289
  • Iain, you're like Wikipedia with added mod privileges. That's my cool-thing-I-did-not-know-but-will-use-often-now-I-do for the day, and it's not even 9am yet. Thanks! – MadHatter Apr 06 '12 at 07:50
  • Thank. But I'd like it to be done programmably so to be run from a shell script, not interactively. – Jimm Chen Apr 06 '12 at 08:02
  • 2
    @JunChen: you should have said that in your question then ! – user9517 Apr 06 '12 at 08:09
  • Thank you. I got it now. The single quotes in my command caused the problem. Anyway, I think I have made it clear from the beginning, because from my screenshot, you can see I tried to change the session name via command line. – Jimm Chen Apr 07 '12 at 00:54
  • And I found that, in order to change *current* session name, just typing ``screen -X sessionname haha`` does not always work. On second execution, it will inevitably fail with message like ``/var/run/uscreens/S-chj2/16218.pts-9.linux-ic37: No such file or directory`` --still a pending question. – Jimm Chen Apr 07 '12 at 02:04