Wim Peeters
apt-get install screen
When you start screen by typing "screen" on the command line, it seems as if you just get your bash again. Before really working with it you should configure it a bit.
# $HOME/.screenrc # Wim Peeters <www.lubby.org> # Defines the time a message is displayed # if screen is not disturbed by other activity. msgwait 2 # Print the version and the compile date in the status line. version # Same as the login command except that the # default setting for new windows is changed. deflogin off # Same as the scrollback command except that # the default setting for new windows is changed. defscrollback 500 # If set to "on", screen will append to the "hardcopy.n" # files created by the command "C-a h", otherwise these # files are overwritten each time. hardcopy_append on # This command configures the use and emulation of the # terminal's hardstatus line hardstatus on # When you are familiar with the game "nethack", # you may enjoy the nethack-style messages which will # often blur the facts a little, but are much funnier to read. nethack on # Select whether you want to see the copyright notice during # startup startup_message off # Sets the visual bell setting for this window. vbell off # If you prepend the word "always" to the type (e.g., # "alwayslastline"), screen will use the type even if the # terminal supports a hardstatus. hardstatus alwayslastline "%{= dR} %-Lw%50>%{= dG}%n%f* %{= dW}%t%{= dR}%+Lw%<" # # Change the way screen does highlighting for text marking # and printing messages. # # explanation about color codes: # # sorendition <attribute> <color> # sorendition ab cd // a,c=bg b,d=fg # # ab c&d c&d # 00 normal 0 black 4 blue # 1- invert 1 red 5 magenta # 25 bright 2 green 6 cyan # 3- 1+2 3 brown 7 silver # # * attributes are cumulative, so a=3 is invert+bright # * colors use the same codes for bg & fg colors, # so cd=22 all you get is green, text unreadable # # examples: # 00 02 - black bg (0), green fg (2), no attributes (00) # 20 30 - brown bg (3), black fg (0), bright bg (2) -> turns yellow # 35 74 - silver bg (7), blue fg (4), invert, bright bg (3) # bright fg (5) # # # Coloring: #sorendition 10 49 # Blue on White #sorendition 05 46 # Cyan on Blue #sorendition 05 42 # Green on Blue #sorendition 05 70 sorendition 25 70 # The message specified here is output # whenever a `Power detach' was performed. pow_detach_msg "BYE" # Keybindings bind ~ activity "activity in %n (%t) [%w:%s]~" bind * activity "activity in %n (%t) [%w:%s]" bind m screen -t 'mutt' mutt bind v screen -t 'vim' vim bind w screen -t 'w3m' env TERM=xterm w3m -B bind y screen -t 'mc' env PAGER=less.sh mc -c bind z screen -t 'ROOT' su bind L screen -t 'LOGFILE' sudo /usr/bin/tail -f /var/log/messages # bindkey -k F1 prev # bindkey -k F2 nextYou can copy and paste this in a ".screenrc" file and safe it in your home directory. The program will find it automatically. You are now ready for the next step.
wpeeters@kubuntu:~$ ls -la .screenrc -rw-r--r-- 1 wpeeters wpeeters 2867 2007-11-10 15:26 .screenrc wpeeters@kubuntu:~$
The following table shows a few (not all of them) of the interesting key bindings which I use the most:
command | Function | Explication |
C-a 0 | select 0 | Selects screen 0 |
C-a 1 | select 1 | Selects screen 1 |
C-a n | select n | Selects screen n |
C-a 9 | select 9 | Selects screen 9 |
C-a A | title | Allow the user to enter a name |
for the current window. | ||
C-a c | screen | Create a new window with a shell |
and switch to that window. | ||
C-a C | clear | Clear the screen. |
C-a d | ||
C-a C-d | detach | Detach screen from this terminal. |
C-a D D | pow detach | Detach and logout. |
C-a space | ||
C-a n | ||
C-a C-n | next | Switch to the next window. |
C-a N | number | Show the number (and title) |
of the current window. | ||
C-a backspace | ||
C-a h | prev | |
C-a p | ||
C-a C-p | Switch to the previous window | |
(opposite of C-a n). | ||
C-a ? | help | Show key bindings. |
C-a C- | quit | Kill all windows and terminate screen. |
C-a : | colon | Enter command line mode. |
C-a [ | ||
C-a C-[ | ||
C-a esc | copy | Enter copy/scrollback mode. |
C-a ] | paste | Write the contents of the paste buffer to the |
stdin queue of the current window. | ||
C-a R | attach | Re-attach to a running session and if none |
exists create one | ||
C-a R | attach | Re-attach to a running session and if none |
tell me without creating a session. | ||
C-a x | multi user | Attach to a running session for |
for looking at it in multi screen mode. | ||
You can use it for attaching to! |
This might be boring. Therefore I took the following screenshot which is a bit more interesting.
Here you see 5 sessions. Session 1 is active at the moment. The Session are "0 bash 1* bash 2- mutt 3 ROOT 4 vim". These sessions can run on different systems. In the case of rootserver administration, the screen session normally runs on the rootserver.
Please try out the following. Start Screen, it should look like the startup session above and then type Ctrl-A c to create a new session. Do this until you have 5 sessions. on the last session you type ls -la followed by <enter>. You screen should look like the following.
Cycle through your windows with Ctrl-A n for next and Ctrl-A p for previous. Cycle till you get your session with the ls -la text on it. Jump immediately to session 2 with Ctrl-A 2. If you think you could do this with diffent session form the local system, I agree. Now you should just close the terminal window (yes, without closing the sessions first) and reopen a new terminal. You type the command "screen -list". You should see a detached session. If you compiled some sources in one of the sessions, the compilation goes on. Your monitoring session will not sleep either. You can detach the hard way (which you did) or properly with the detach command Ctrl-A d. You can Re-attach with the "screen -R" command.
This exercise already explained the basic usage of screen but we have still more to offer.
One very interesting feature of screen is the possibility to detach from a session and to attach it again later. The process is not effected in that time and stays running. This makes is ideal for long running jobs. To detach a screen we use C-a - d. To see if you still have a session running you can use screen -ls. The reattachment is done with screen -R.