GNU Screen |
GNU Screen is a GNU fullscreen console multiplexer which permits a user to multiplex one Computer terminal into multiple terminals. Thus screen allows the user to perform several additional tasks over a normal terminal.
= Reasons for use =
On Unix-like Operating System, GUI terminal emulators like Gnome Terminal and Konsole provide the ability to open multiple terminals. There are many reasons to use screen over these terminals.
# It is terminal agnostic, for terminals that were implemented correctly. # The session can be detached and reattached, making migration between locations like work and home simple, without requiring bandwidth-hogging remote desktop protocols, like Virtual Network Computing. # It can notify the user of activity or inactivity in terminals, permitting notification of events like the end of a compilation, or activity in an Internet Relay Chat application. # It has scrollback capabilities that are set independently from the terminal, ensuring that your preferences work regardless of the terminal you are using at each location. # Multiple users can join into one screen session, with read-only or full access, permitting collaboration in many forms. # It can split the screen, again regardless of the compliant terminal. # It provides these features with or without the X Window System being available.
= Tiny GNU Screen tutorial =
This is a tiny GNU Screen tutorial to show how to use programs like irssi and Lynx (web browser) in one terminal - under screen. First, start irssi running inside a screen session by typing:
screen irssi
This will start irssi in its own virtual window - inside a screen session. It looks just like you ran irssi, but - importantly - irssi is running inside screen. Now, in this irssi window of this screen session, as with any window inside screen, you can type:
Ctrl+A, c (Type Ctrl+a then c )
This will give you a new shell in a new window in the current screen session; irssi continues to run in the background in the other window. Now you can start lynx (or any other program) in the new shell by typing:
Now you can cycle between these two windows by pressing:
Ctrl+A, space
or toggle between them using
Ctrl+A, Ctrl+A (hold down Ctrl, hit A twice)
Now if you want to log out and you want these programs to continue running in the background, you type:
Ctrl+A, d
This will detach your screen session, leaving it in the background. You are back in the shell which you used to start screen. irssi and lynx will continue running in the screen session - but you can log out from the shell. Say you then change locations, and login again from somewhere else, like moving between work and home. When you login, you can view any existing screen sessions with
screen -ls
You should see output like this:
$ screen -ls There is a screen on: 4619.pts-3.tigger (Attached) 1 Socket in /tmp/screens/S-msoulier.
If you want to explicitely reattach to the session you see here, you would then type:
screen -r 4619.pts-3.tigger
If the session was detached, that would work, but it s still attached. I get this instead.
$ screen -r 4619.pts-3.tigger There is a screen on: 4619.pts-3.tigger (Attached) There is no screen to be resumed matching 4619.pts-3.tigger.
I forgot to detach it before leaving work. That s ok, I own it, and I can tell screen to forcibly detach it.
screen -d -r 4619.pts-3.tigger
Or, you can just tell screen to grab the first session it finds.
screen -d -R
Or, you can access an elsewhere-attached screen in multi-display mode (i.e. several displays attached to the same session):
screen -rx
When you want to quit irssi or lynx, just exit them normally. When the last window inside a screen session exits, the screen session exits.
= Customization =
Customization is accomplished using your ~/.screenrc file. The screen (1) manpage has all of the reference information that you ll ever need, but pulling together a really good set of preferences can still be very tough considering the sometimes cryptic syntax required. It s probably best to Google for some sample .screenrc files, and take what you like from them. I ll include an annotated sample here.
== Sample .screenrc file ==
# The command prefix, rebind to C-z to make Emacs keybindings easier escape ^zz #escape ^jj
# Customize options sorendition kG # black on bold green activity activity in %n (%t) [%w:%s]~ ^G bell bell in %n (%t) [%w:%s]~ ^G pow_detach_msg BYE vbell_msg *beep* defmonitor off nethack on startup_message off defscrollback 1024
# The status line hardstatus on hardstatus alwayslastline
# Hostname, datetime prefix hardstatus string %{rk}%H %{gk}%c %{yk}%M%d %{wk}%%-Lw%%{bw}%n*%f%t%(%u)%%{wk}%%+Lw%
# Hostname, datetime suffix #hardstatus string %{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a
# Basic display #hardstatus string %{= kc} %%-Lw%%{= kY}%n*%f %t%(%u)%%{= kc}%%+Lw%
# Can use caption if the terminal doesn t support hs #caption always %{= kc} %%-Lw%%{= kY}%n*%f %t%(%u)%%{= kc}%%+Lw%
# Custom bindings. bind j focus down bind k focus up # Might need this on Debian systems. #bindkey -k kb stuff 177
# Default screens on startup #screen -M 0 mutt #screen -t irssi 1 irssi --connect=irc.oftc.net #screen -t emacs 2 emacs #screen -t mail 3 pine #screen -t slashdot 4 lynx http://www.slashdot.org/ #screen -t k5 5 lynx http://www.kuro5hin.org/ #screen -t bar 6 ssh
=External links=
*[http://www.gnu.org/software/screen GNU Screen] *[http://freshmeat.net/projects/screenie Screenie - a screen session handler (frontend)] *[http://www.kuro5hin.org/story/2004/3/9/16838/14935 GNU Screen: an introduction and beginner s tutorial] *[http://deadman.org/sshscreen.html SSH-Agent forwarding and GNU Screen] *[http://lizzie.spod.cx/screenirssi.shtml A guide to using irssi in screen] *[http://aperiodic.net/phil/archives/Geekery/ode-to-screen.html An Ode to screen]|
|