GNU screen, most commonly just called screen, is one of couple of tools which allows you to multiplex multiple "virtual consoles". In layman's terms, it allows you to start into a virtual terminal session which you can detach from and then reattach without loosing what's going on inside of that terminal session. This is ideal for when you are connecting to a machine over SSH and you are at risk of loosing your connection. That way after you have been disconnected you can just attach to exactly the same state you has disconnected from. No matter if you are in the middle of running a copy, top, irssi or sitting at a blank terminal. Everything is just like it was before you disconnected.
Screen has some basic, yet important to remember keyboard shortcuts. The most important one is CTRL+a then tap d. This will disconnect your current session.
To start a new screen, just type screen.
Your terminal will go blank signaling that you have entered a new terminal session inside of a new screen. Lets start a command like top.
madmaze@spork:~$ < you are now inside of a "screen" > madmaze@spork:~$ top
Then to detach from this screen hit CTRL & a, then tap d.
< hit CTRL+a then d to detach > [detached from 20041.pts-4.sp0rk] madmaze@spork:~$
Now to see which screens are running, run screen -ls
madmaze@spork:~$ screen -ls There is a screen on: 20041.pts-4.sp0rk (02/22/2014 09:44:35 PM) (Detached) 1 Socket in /var/run/screen/S-madmaze.
That means you currently have one screen open and you are detached from this screen. To reconnect, run screen -dr 20041
madmaze@spork:~$ screen -dr 20041
.. and now you should be back to top which had been running in the background while you were detached.
s): 9.8 us, 5.3 sy, 0.0 ni, 84.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 3105556 total, 2364832 used, 740724 free, 36460 buffers KiB Swap: 2572284 total, 362828 used, 2209456 free, 532236 cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2189 root 20 0 98.6m 23m 11m S 8.0 0.8 492:18.82 Xorg 27255 madmaze 20 0 538m 246m 27m S 6.3 8.1 117:39.77 chrome 2824 madmaze 20 0 265m 12m 5820 S 3.3 0.4 6:31.73 guake 8479 madmaze 20 0 518m 103m 20m S 3.0 3.4 63:45.22 chrome 2893 madmaze 20 0 30724 3236 548 S 1.0 0.1 47:08.06 compton 9733 madmaze 20 0 318m 115m 26m S 1.0 3.8 12:56.18 chrome
Easy as that. Also when reconnecting, you don't have to type out the full name of the screen, only enough to differentiate it from other ones. In the case that you just have one screen running,
screen -dr without a name will do the trick.