424

I screen -r'd into a Django server that's running and I can't simply Ctrl + C and exit out of it.

Are there any alternative ways to get out of screen?

Currently, I manually close the tab on my local PC and ssh back in, but that's becoming tiresome.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
meder omuraliev
  • 177,923
  • 69
  • 381
  • 426

6 Answers6

734

Ctrl-a d or Ctrl-a Ctrl-d. See the screen manual # Detach.

ephemient
  • 189,938
  • 36
  • 271
  • 385
  • 14
    yes, you generally do have a tl;dr moment with the `man` command. so when you have a tl;dr when doing `man command_name`, in this case `man screen`, you can generally access a shorter & pretty helpful version of the docs by `--help` option, `command_name --help`, this case `screen --help`. – Ashish Sep 13 '14 at 06:42
  • 3
    Here's a [screen quick reference](http://aperiodic.net/screen/quick_reference) and a [combined screen & tmux cheat sheet](http://www.mechanicalkeys.com/files/os/notes/tm.html) you may find handy. – Trutane May 28 '15 at 22:03
  • 3
    `tmux --help` gives me new tmux session, so I'm like: "Oh sh~ why" – St.Shadow Feb 22 '17 at 09:36
  • 3
    This does not work when using screen for connecting to a serial device. – josch May 16 '17 at 09:41
  • 4
    @josch You should be able to use ctrl-a + k or ctrl-a + ctrl-k to kill the current screen window. Ashish - The --help output only talks about command line options, it does not talk about the key bindings – Aner Oct 06 '17 at 19:21
  • While for most people, this answer seems like the easy escape, it isn't the correct answer as it doesn't "exit" the screen session. Ctrl+A,K does, as mentioned by @Aner – Janos Aug 02 '18 at 15:55
  • @Trutane the old link is dead, did it look like this one: [combined screen & tmux cheat sheet](http://www.dayid.org/comp/tm.html) – Colin Feb 09 '19 at 06:06
  • @Colin yes, with some differences at the bottom of the table. The [last archive of that mechanicalkeys.com page](https://web.archive.org/web/20150822091205/http://www.mechanicalkeys.com/files/os/notes/tm.html) is from 2015, and it includes links to a couple other resources, one of which is still alive – Trutane Feb 21 '19 at 05:26
167
  • Ctrl + A, Ctrl + \ - Exit screen and terminate all programs in this screen. It is helpful, for example, if you need to close a tty connection.

  • Ctrl + D, D or - Ctrl + A, Ctrl + D - "minimize" screen and screen -r to restore it.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
fandyushin
  • 2,261
  • 2
  • 16
  • 31
  • 19
    I'm just clarifying for future readers. That's Ctrl-A followed by Ctrl-\, and Ctrl-A followed by Ctrl-D. – Julian Nov 07 '16 at 10:53
  • 2
    @Julian Detaching doesn't need Ctrl on both, just on ctrl+a. Works for me and if you do "ctrl+a" and then write ":help" you can see that it says that both ctrl+d and d works. – Johan Bjäreholt Dec 09 '16 at 11:09
  • 1
    This should be the accepted answer, as it specifies both detaching and exiting. – miguelmorin Mar 31 '19 at 15:51
  • Ctrl-A -> Ctrl-D just exits from the session for me, leaving it running in the background. Ctrl-A -> \ will exit the session completely (on Oracle Linux 6). – Andrew Brennan Apr 01 '19 at 16:03
  • 10
    To quit, it's `Ctrl-a` + `\ `, not `Ctrl-a` + `Ctrl-\ ` ! The key bindings can be viewed by pressing: `Ctrl-a` + `?` – feklee Aug 09 '19 at 09:49
  • Any hint on how to get to use `C-a` + `C-\ ` on keyboards where `\ ` is not on the 'standard' position but under some `alt-[key]` combination (Spanish keyboard in my case?) Trying `Ctrl-Alt-[key]` does not work :( – DavSanchez Jan 19 '20 at 03:45
103
  • Ctrl + A and then Ctrl+D. Doing this will detach you from the screen session which you can later resume by doing screen -r.

  • You can also do: Ctrl+A then type :. This will put you in screen command mode. Type the command detach to be detached from the running screen session.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
gsbabil
  • 7,097
  • 3
  • 23
  • 27
  • 16
    It's simply "Ctrl-a" then "d" – Kostyantyn May 20 '13 at 11:40
  • 5
    @Kostyantyn It works (as the man pages says 'For your convenience') both with and without the Ctrl for the d - so "Ctrl-a" "Ctrl-d" works, and so does "Ctrl-a" "d". Take your pick. – Eborbob Nov 21 '16 at 15:44
47

Ctrl+a followed by k will "kill" the current screen session.

user674669
  • 8,624
  • 10
  • 67
  • 92
8

In addition to the previous answers, you can also do Ctrl + A, and then enter colon (:), and you will notice a little input box at the bottom left. Type 'quit' and Enter to leave the current screen session. Note that this will remove your screen session.

Ctrl + A and then K will only kill the current window in the current session, not the whole session. A screen session consists of windows, which can be created using subsequent Ctrl + A followed by C. These windows can be viewed in a list using Ctrl + A + ".

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Ng Ju Ping
  • 157
  • 1
  • 2
2

To terminate the screen session use

Ctrl + a followed by k

To detach session and restore later use

Ctrl + a followed by d
RKM
  • 665
  • 1
  • 4
  • 17