What is GNU Screen?
-
1I prefer just to open up a few tabs instead of conflating the same terminal – Scott Stensland Aug 27 '18 at 23:16
1 Answers
What is GNU Screen? Great!
Erm, a slightly more useful answer: it allows you to run multiple console applications, or commands, in one terminal. Kind of like a tabbed terminal emulator. In fact, that's exactly what it is (just not done with the regular GUI toolkits)
Why is it so great? Simple, you can run a program in a screen session (Run screen
and it runs your default shell, run screen myapp
and it runs myapp in the session), hit ctrl+a (the screen control sequence) and then press d (ctrl+a,d) to detach.
The program keeps running in the background, but, unlike doing mycmd &
, you can run screen -r
to reattach the session, and everything is as you left it. You can send input to the command, if it's a curses UI, everything still works just like if it were a "real" terminal.
It's very popular with console IRC clients - you can run (say) screen irssi
and reattach the session from anywhere you can SSH from.
A few useful commands:
- ctrl+a, c to make a new virtual terminal (or "window") in the session
- ctrl+a, n and ctrl+a, p to cycle through multiple windows
- ctrl+a, 1 to select window 1, ctrl+a, 4 to select window 4 and so on
- ctrl+a, ctrl+a to flick between the last two active windows
- ctrl+a, shift+a (upper-case a) allows you to rename the current window
- ctrl+a, ` (for me, that's shift+2 - the quote mark) lists windows, you can use the arrows and select one. Also useful with the "tab bar" setting I'll list in a second
A few other useful things I've stumbled across:
- Use the
-U
flag when you launch screen so it supports Unicode (for example,screen -xU
) - The
-x
flag allows you to reattach the same session multiple times. (-r
disconnects existing connections) - You can do interesting stuff with the status bar. I have my setup to display
[ hostname ][ 0-$ bash (1*$ irssi) ][16/09 9:32]
(Running on hostname, it has two windows. This is set by the hardstatus lines in my .screenrc (at the end of the answer)
startup_message off
vbell off
hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}]%{=y C}[%d/%m %c]%{W}'
-
1*"unlike doing `mycmd &`"* - actually, you can use `fg` to get a process back from the background (where it is sent with `&`), and `ctrl+z` to put it back there. – naught101 Oct 22 '14 at 11:29
-
2@naught101: Sure, that puts it in the background, *but it is still attached to the terminal*. Close the terminal window, or break the connection to the server, and the process also gets closed. `screen` avoids this, by separating the part where the process runs from the part where user interaction happens. – Piskvor left the building Jun 18 '19 at 10:01