There are a few of these, but none have all the answers that I want (e.g. how to scroll back up the terminal while attached to a screen session) or are in a format I like. So, I’ve prepared my own.
This is a cheatsheet of how to do the things I typically need to do with Linux (unix)’s
$ screen -S [name]
Name is just an alias for the screen session so that it can easily be distinguished what’s happening in that session when looking at a list of all screen sessions via
In order to detach from a screen session hold the control key and press “a”. Then press the “d” key.
You’ll be back a command prompt like the below after doing so.
[detached from 28882.db-dump] $
$ screen -ls
As mentioned above
screen -ls will list running screen sessions. Here’s a sample of the output
$ screen -ls There are screens on: 28882.db-dump (Detached) 46174.mw-scan (Detached) 2 Sockets in /var/run/screen/S-mchadwick.
screen -r [name-or-pid]
screen -r will allow you to re-attach to a running screen session. You can use the id or name of the screen session.
While attached to a screen session, hold the control key and press “a”. Then press escape. At this point you’ll be able to scroll up and down within the screen session.
Press escape again to regain the ability to enter commands.
While attached to a screen session, hold the control key and press “a”, then press “k”. You’ll need to then press “y” to confirm you’d really like to kill the screen session.
$ screen -d -r [name]
You may have to do this if you unexpectedly lost an SSH connection while attached to a screen session. In this case the
screen session may still think it’s connected to that SSH connection (e.g. orphaned). The above command will detach it from that terminal and re-attach it to the current terminal.
Hi, I'm Max!
If you'd like to get in touch with me the best way is on Twitter.