230

I know how to start a screen, and how to list different screens:

screen -ls

or to attach:

There are screens on:
        2477.pts-0.server1      (Detached)
        2522.pts-0.server1      (Detached)
2 Sockets in /var/run/screen/S-root.

$ screen -r 2477.pts-0.server1

But what is the key combination to detach from a screen session and keep it running?

5 Answers 5

284

Ctrl+a followed by d. Note the lower case. The [screen manpage] has a long list of these shortcuts under "DEFAULT KEY BINDINGS".

2
  • 15
    I think that you mean <kbd>Ctrl-A<kbd> <kbd>d</kbd> (lowercase). The upper case (D) is 'powerdetach'.
    – Arcege
    Apr 25, 2012 at 0:23
  • 1
    yes, as @Arcege proposes, <Ctrl-A> <d> detaches from current screen session. Which worked for me. <Ctrl-A> <D> seemed to wait something else and received "detach aborted" message as soon as I pressed any other Key. If <Ctrl-A> <D><D> pressed you're detached and logout from ssh.
    – theme
    Jul 7, 2017 at 10:51
75

To list your sessions, run:

screen -list

You can run any command under screen command like:

screen myscript.sh

Then press Ctrl+a (release) and then d to detach the process/screen (so it'll continue to run).


To resume detached process, use:

screen -r

If you have multiple, then add the session number after that.


You can also re-attach to already Attached screen by screen -x. Useful to investigate why it's attached, share terminal with someone or to watch/check somebody what they're doing.


For more help, either run man screen or within the screen press Ctrl+a, release and then hit ? to see more shortcuts.

See also:

12

You'll probably see it listed like this in the screen man page:

^a - d

It's important the note the case of the letters as uppercase and lowercase will do different functions.

7

Create screen using this command: screen -S testscreen

List the screen using this command: screen -ls

Attache the screen using this command: screen -r testscreen

Attache the multipurpose screen using this command (if already others are attached with the same screen): screen -x testscreen

Detach the screen using this command: screen -X detach OR Ctrl+a+d

Kill the screen using this command: screen -XS testscreen kill

Terminate the attached screen using: Ctrl+d

5

Some systems remove certain bindings by default. So it is best to look at the online keybinding page: Ctrl-a ?. You can also use the command prompt in screen: Ctrl-a :detach. Myself, I generally remove the key bindings for 'detach' and 'powerdetach', except on remote systems.

1
  • "Some systems remove certain bindings by default" <- worth the upvote! Jan 15, 2021 at 1:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .