如何使 screen -R 附加到最年轻的分离会话?

Wim*_*nen 19 gnu-screen

我在 debian lenny 上使用screen,我想使用该-R选项。来自man screen

   -R   attempts  to  resume  the  youngest  (in  terms  of creation time)
        detached screen session it finds.  If successful, all  other  com?
        mand-line  options  are  ignored.   If no detached session exists,
        starts a new session using the specified options, just  as  if  -R
        had  not been specified.
Run Code Online (Sandbox Code Playgroud)

但是,当我运行screen -R它时,它实际上并没有附加到最年轻的分离会话。相反,它抱怨有“几个合适的屏幕”,我需要选择其中之一。

我错过了什么吗?我如何使这项工作如宣传的那样?

Dav*_*yan 23

尝试使用screen -RR.

例子:

$ screen -ls
There are screens on:
    5958.pts-3.sys01    (08/26/2010 11:40:43 PM)    (Detached)
    5850.pts-1.sys01    (08/26/2010 11:40:35 PM)    (Detached)
2 Sockets in /var/run/screen/S-sdn.
Run Code Online (Sandbox Code Playgroud)

请注意,屏幕 5958 是最年轻的。使用screen -RR连接到屏幕 5958。这些-RR选项在-d -RR.

   -d -RR  Reattach a session and if necessary detach or  create  it.  Use
           the first session if more than one session is available.
Run Code Online (Sandbox Code Playgroud)

我经常使用的另一个技巧是-S给屏幕一个标签/标签。然后您可以使用该标签重新附加,而无需记住每个屏幕中发生的事情,如果列表变得笨拙。

示例(vim 和 curl 的启动屏幕):

$ screen -dm -S curl
$ screen -dm -S vim 
$ screen -list

There are screens on:  
    11292.vim       (08/27/2010 12:02:53 AM)        (Detached)
    11273.curl      (08/27/2010 12:01:42 AM)        (Detached)
Run Code Online (Sandbox Code Playgroud)

注意:该-dm选项仅用于启动分离屏幕

然后,在以后,您可以使用标签轻松地重新连接curl

# screen -R curl
Run Code Online (Sandbox Code Playgroud)