Tuesday, October 30, 2007

GNU Screen utility

Screen, this command might not be well known to many people but its one of those programs that you just can’t stop using once you’ve started. Previously I used VNC to connect the remote servers, but now i have stopped using it and use SCREEN on a regular daily basis and it’s really easy to use.
Screen program provides the following functionality:
  • Remote terminal session management (detaching or sharing terminal sessions)
  • Unlimited windows (unlike the hardcoded number of Linux virtual consoles)
  • Scrollback buffer (not limited to video memory like Linux virtual consoles)
  • Copy/paste between windows
  • Split terminal (horizontally) into multiple regions
  • Locking other users out of terminal
  • Screen is an easy way to allow processes to continue running after the session is terminated, if you lose connection screen will save your spot
Following is the content of my ~/.screenrc file
************************************************************
startup_message off
vbell off
caption always “%{= bb}%{+b w}%n %h %=%t %c”
hardstatus alwayslastline “%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<” activity “Activity in %t(%n)” shell -/bin/bash
************************************************************
Screen Commands
(screen) Start screen
(screen -S vishnu) Create a screen session with the name vishnu
(screen -r vishnu) reconnect to the session with the name vishnu
(screen -x ) Connect to an existing screen session
(screen -d ) detaching a screen session
(screen -r) reattaching the screen session
(Ctrl+a c ) New window
(Ctrl+a n ) Next Window
(Ctrl+a p ) Previous Window
(Ctrl+a ” ) Select window from list
(Ctrl+a Ctrl+a) Previous window viewed
(Ctrl+a <0-9> ) Select the numbered window
(Ctrl+a A ) Set window title
(Ctrl+a K ) Kill window
(Ctrl+a d ) Detach screen from terminal
(Ctrl+a x ) Lock Session
(Ctrl+a : ) Goto screen command prompt
(Ctrl+a ? ) Show key binding/command names
(Ctrl+s ) Pause the output on screen
(Ctrl+q ) Resume the output on screen
(Ctrl+a :escape ^Ww) Change key binding to w character
(Ctrl-a * ) List all currently attached displays. (displays)
(Ctrl-a Ctrl\) Kill all windows and terminate screen. (quit)
(Ctrl-a w ) List all windows. (windows)
(Ctrl-a h ) Write contents of the current window to the file hardcopy.n. (hardcopy)
(Ctrl-a H ) Begin/end logging of the current window to the file screenlog.n. (log)
(Ctrl-a ' ) Prompt for window name or number to switch to. (select)