Screen

ref book

detailed man page
quick reference
good FAQ page

my .screenrc

mine is copied from here: http://linux.dsplabs.com.au/gnu-screen-screenrc-configuration-file-p13/
another sample : http://home.comcast.net/~bmsims1/screenrc.html

# C-a :source .screenrc

termcapinfo xterm* ti@:te@
startup_message off
vbell off
autodetach on
altscreen on
shelltitle "$ |bash"
defscrollback 10000
defutf8 on
nonblock on

#escape ``
#escape `e

# BIND ESCAPE TO F11!
# bindkey -k F1 command

hardstatus alwayslastline                                                                                                                          
#hardstatus alwaysfirstline

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
##    Explanation of hardstatus line    ##
# Ignore the ' marks if you use these examples for yourself

# Note that if you want to use the color brown under konsole
# You actually use bright yellow (%{Y}). 

# Note the embeded space after the colon, I feel 
#  it just looks nicer with a blank between the
#  text and console edge:
#   '%{=b}%{G} Screens: '

# This prints the window listing in blue:
#   '%{b}%w'

# This right-aligns what follows:
#   '%='

# This displays the time (hours and minutes) in 12hr format 
# and adds an AM/PM flag, in bold green:
#   '%{G}%C%A'

# This displays the day of the week:
#   '%D'

#This displays the date in Mon/day/year format:
# and again I embeded a space to give me one space
# between the text and console edge:
#  '%M/%d/%Y '

# The resultsing command give you a status line that 
#  looks like this: 
#   | Screens: 0* bash  <blanks zapped>         5:30PM  Fri, Jun/25/2004 |
#  (The pipes indicate the edges of the xterm/console).

# Green text, time, and date; windows in blue:
# hardstatus alwayslastline "%{=b}%{G} Screen(s): %{b}%w %=%{kG}%C%A  %D, %M/%d/%Y "
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #

#hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'
#hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
#hardstatus string '%{= kw}[ %{= kb}%H%{= kw} ][ %= %{= kw}%?%-Lw%?%{= kr}(%{= kW}%n*%f %t%?(%u)%?%{= kr})%{= kw}%?%+Lw%?%?%= %{w} ][ %{r}%l%{w} ]%{w}[%{r} %d/%m/%y %C %A %{w}]%{w}'

# 1. show [ hostname ],  %{= kw}[ %{= kb}%H%{= kw} ]
#   %{= kw} defines the next [ in background color black and fg in color white
#   %H defines host information
#   %{= kb} defines the host in background color black and fg in color blue
#   %{= kw} defines the next ] in background color black and fg in color white 

# 2. [%=    %{= kw} %? %-Lw %?   %{= kW}%n*%f %t   %{= kw} %? %+Lw %?   %= ]
# %= padding

# %{= kw} %?%-Lw  %?  all windows' numbers and names, which are prior to the current active window.
# those names and numbers are fg w in bg black

# %{= kW}%n*%f %t defines the current active window number, *, then flag, and then title in bright WHITE in bg black

# %+Lw  all windows' numbers and names, which are after to the current active window.

# 3. [ %{r}%l%{w} ] shows current load of the system
# % load information in fg red
# %l current system load
# %{w} next ] is fg color white
# %t window title

# %{w}[ %{r} %d/%m/%y %C %A %{w}] shows [ Day/Month/Year Hour:Minute AM/PM  ] in fg color red , and [ ] in fg color white
# %{w} defines fg white for [
# %{r} defines next is red fg

hardstatus string '%{= kw}[ %{= kb}%H%{= kw} ][%= %{= kw}%?%-Lw%?%{= kW}%n*%f %t%{= kw}%?%+Lw%?%= ][ %{r}%l%{w} ]%{w}[%{r} %d/%m/%y %C %A %{w}]%{w}'

#show an underline
caption always "%{=bu kb} %=  %= "

##    Keybindings    ##

# bind <F3> to split
# bind <F4> to un-split
# bind <F5> to split vertically
# bind <F7> to detach screen from this terminal
# bind <F8> to kill current session
# bind <F10> to create a new screen (This will break Midnight Commander)
# bind <F9> to rename an existing window
# bind <F11> to move to previous window
# bind <F12> to move to next window
bindkey -k k3 split
bindkey -k k4 only
bindkey -k k5 split -v 
bindkey -k k7 detach
bindkey -k k8 kill
# space in keyboard
bindkey -k k9 title
bindkey -k k; screen
bindkey -k F1 prev
bindkey -k F2 next

#bind 'R' screen ssh s1554463@sunfire16
#bind 'R' screen -t sunfire16 ssh s1554463@sunfire16
bind 'q' quit

#screen -t sunfire01 0
#screen -t sunfire16 2 ssh s1554463@sunfire16
#screen -t sunfire16 1 ssh s1554463@sunfire16

#chdir /hr
screen -t acer 0
screen -t kw64 1
screen -t spl2 2
screen -t sunfire 3
#screen -t kw64 1 ssh root@132.234.103.72 -t 'screen -d -RR kw64'
#screen -t spl2 2 ssh root@132.234.103.113 -t 'screen -d -RR spl2'
#screen -t sunfire 3 ssh s1554463@132.234.222.1 -t 'screen -d -RR spl'

how to get help

  • in run mode to show default key binding

Ctrl-A and then type :help or Ctrl-A ?

  • man screen

how to ?

  • quit

To quit the whole thing (screen), killing all the little virtual terminals:

Either type: Control-A and : and quit and Enter

or F8 in my .screenrc to exit each window one by one

  • to get beginning of command line since ctrl-a is used by screen

ctrl-a a

logging

screen has the ability to log its output to a file on the disk. To enable screen logging, press Ctrl+a H to enable it and
again to disable it. By default, the log file will be saved as $HOME/screenlog.1 .

split screen

To split the screen in two, press Ctrl+a S (capital "S") which will split the screen in half, or Control-A and type : split and Enter
now you have existing session on the top that you're already using and a blank session at the bottom.
If you ever type "CONTROL-a s" (lowercase "s") by mistake and suspend your shell, just type "CONTROL-a q" to unsuspend it.

To move to the bottom half, press Ctrl+a, then the TAB key.

Once in the blank half, you have to set this bottom half of the screen to use any existing session or create a new one there.

  • To use existing session:

- press Ctrl+a, then " You will be presented with a list of available screen sessions, pick one using the arrow keys (be careful not to pick the one already at the top or you'll have a mirror console), and activate it by pressing Enter.
- or you can use F11/F12 to recycle if my .screenrc is used.
- or press Control-A and : select 1 and Enter. 1 is the window number

  • To create a new session

- if a new screen session is needed, type Control-A and : screen and Enter or Ctrl+a c

To return to full size screen, switch to the half you want it to remain and press Ctrl+a Q. (that's the capital letter "Q")

sharing

sharing screen with other users

1. As root: sudo chmod u+s /usr/bin/screen (Screen has to be SUID if you want to share a term between two users.)
Note: SUID allows an executable to be run by the owner of that file, instead of with the user's own permission. There are some security concerns when doing this, so use this tip at your own discretion.
2. sudo chmod 755 /var/run/screen
3 Log out of root, and run Screen as the user who is going to share the session: screen
4. Press Ctrl+a, then type :multiuser on and press Enter.
5. Press Ctrl+a, then type :acladd steve (”steve” is the username of the person who will connect to your screen session).

working from another computer

Let's say you have a screen session open at work with X number of windows on it by starting screen like : screen -S screen_session_name
It's 5 p.m. and you have to go home and then You can simply SSH into your workstation at work and list your available screen sessions with the command:

screen -ls

And connect to the sessions you were running at work with the command:

screen -x screen_session_name

This way screen will let you pick things up exactly from where you left off.

status vs hardstatus

There are two types of status-bar you may have within a GNU Screen session:

  • "caption" line.
  • "hardstatus" line.

Whats the difference between them? Well the hardstatus line is used for status messages from screen - for example to alert you to activity, or other similar messages. The caption line is usually only shown if there is more than one window open, and allows you to view details of them.

resurrect

http://brainscraps.wikidot.com/resurrect

Good tutorial

A Guide to GNU Screen

FAQ of GNU screen

my quick list

  • change window title: Ctrl-a A
  • wipe sessions : screen -wipe
  • list sessions : screen -list
  • Ctrl-a K – Kills a window session
  • Ctrl-a c – Creates a new window

A stupid question. Can i reload the .screenrc when i run the screen already?

<Ctrl>+<a>+":" source $HOME/.screenrc<CR>

ctrl-a d detach screen

screen -S sessionname
screen -d -R sessionname will resume a session that you started in a different location.

Anyway, you may want to try to add those two options to your screenrc:

nonblock 1
defnonblock 1

One of them is completely useless (but i don't remember which one)
while the other allows you to reattach a dead session after 1 second,

Screen Logging

As a consultant, I find it important to keep track of what I do to someone's server. Fortunately, screen makes this easy. Using "Ctrl-A" "H", creates a running log of the session. Screen will keep appending data to the file through multiple sessions. Using the log function is very useful for capturing what you have done, especially if you are making a lot of changes. If something goes awry, you can look back through your logs.

Screen Monitor

Just wanted to mention to other cool tricks you can do with screen. Screen can monitor a window for activity or lack thereof. This is great if you are downloading large files, compiling, or watching for output. If you are downloading something or compiling, you can watch for silence. To start the monitor, go to the screen you want to monitor and use "Ctrl-A" "M" to look for activity or "Ctrl-A" "_" to monitor for silence. Then open or switch to a new window. When the monitor detects activity or silence, you will get an alert at the bottom with the window number. To quickly go to that window, use "Ctrl-A" " (thats a quote mark, ctrl-a then a "). After you do this, just type in the number of the window and enter. To stop monitoring, go to that window and undo the monitor with the same command. For example, to stop monitoring for activity you would use "Ctrl-A" "M" again.

To split a screen in screen, its ctrl+a S, then ctrl+a tab to jump between the screens, ctrl+a X ro unsplit;
In vim, its ctrl+w s to split the screen horizontally, ctrl+w v to split the screen vertically and then ctrl+w w to jump between the screens in vim.

http://aperiodic.net/screen/quick_reference

bash

ls directory color

If you run Terminal.app with a black background and a color 'ls' command, directories (in bold blue) can be hard to see. You can change the color of directories with an export LS_COLORS command. For example, to make all directories yellow, add this to ".bash_profile" in your home directory:

export LS_COLORS='di=01;33'

Other good colors for directories are bold white (01;37) and bold purple (01;35). You can find a complete table of ANSI colors in many places; The Linux Documentation Project's list is one such place.

alias ls 'ls —color=auto'

export PS1="\h@\u:\w% "

extra

ln -s /dir/src/src/abc.bin /dir/dest/abc.bin
ls -s /dir/src/src/abc.bin //will create a symbol link in current directory with name abc.bin

vim

colorscheme files : Place in your ~/.vim/colors/
http://www.jonlee.ca/tag/vimrc/

find

alias findany='find . -follow -type f -print0 | xargs --null grep $*'
alias findcode='find . -name "*.cpp" -name "*.h" -name "*.java" -name "*.c" -name "*.hpp" -follow -type f -print0 | xargs --null grep $*'
alias findfile='find . -follow -type f | grep $*'
alias findtext='find . -not -name "*.d" -not -name "*.o" -not -name "*.a" -follow -type f -print0 | xargs --null grep $*'
alias findweb='find . -name "*.aml" -name "*.xml" -name "*.xsd" -name "*.mdl" -name "*.sml" -follow -type f -print0 | xargs --null grep $*'
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License