GNU Screen reminder
id : qb1vt73c20
category : computer
blog : unixlinux
created : 04/04/10 - 19:41:24

Listing
# screen -list

or
# screen -ls

or
# screen -r

  • Magic command line to launch screen :
# screen -a -T xterm -U

Attaching
  • Attach detached screen
# screen -r [[pid.]tty[.host]]

  • Attach to a not detached screen session
# screen -rx [[pid.]tty[.host]]

Locking
  • C-a X or C-a C-x : Lock your screen
  • Archlinux Gnu/Screen manual tells to use C-a C-x for locking, it doesnt work for me, i use C-a X to lock my screen session
  • C-a : password : Protect your session with passwd password

Regions
  • C-a S : Create a new region
  • C-a Tab : Go to next region
  • C-a Q : Delete all regions excepted current one
  • C-a X : Close current region
  • Resize regions :
    • C-a : resize +N : add N line to region
    • C-a : resize -N : remove line from region
    • C-a : resize = : make all regions equals
    • C-a : resize max : maximize a region
    • C-a : resize min : minimize a region
  • Binding :
    • C-a : bind k focus up : bink k to focus up
    • C-a : bind j focus down : bind j to focus down
    • C-a j : go to next region
    • C-a k : go to previous region

Selections
  • C-a ' : Prompt for window name or window number
  • C-a " : Prompt windows list
  • C-a 0..9 : Go to window number
  • C-a C-a : Go to previous selected window
  • C-a C-n or C-a n: Go to next window
  • C-a C-p C-a p : Go to previous region

Naming
  • C-a A : Rename current window

Creation
  • C-a C-a or C-a c : Create a new window

Detaching
  • C-a d or C-a C-d : Detaching screen
  • C-a D D : Detaching screen and logout (known as POWER detach)
  • In command line :
# screen -d [[pid.]tty[.host]]

or (for POWER detach)
# screen -D [[pid.]tty[.host]]

Copy/History
  • C-a C-[ : Enter copy mode
  • Space : Select first and second mark (move like in VI)
  • C-a C-] : Paste what was selected

Monitoring
  • C-a H : Enter monitoring mode
  • C-a M : Leave monitoring mode

Informations
  • C-a i : Get window informations

Scrollback
  • C-a : defscrollback 99999 : Set 99999 line scrollback
  • C-a [ : Enter copy mode, use vi command to navigate in scrollback
    • h : Move the cursor left by one character
    • j : Move the cursor down by one line
    • k : Move the cursor up by one line
    • l : Move the cursor right by one character
    • 0 : Move to the beginning of the current line
    • $ : Move to the end of the current line.
    • G : Moves to the specified line (defaults to the end of the buffer).
    • C-u : Scrolls a half page up.
    • C-b : Scrolls a full page up.
    • C-d : Scrolls a half page down.
    • C-f : Scrolls the full page down.
    • / : Search forward
    • ? : Search backward

Bonus
  • Want to rename your screen's tabs when connecting to a distant host, use this little script like ssh :
.01#!/bin/bash
.02
.03# Get local and distant hostname
.04DISTANT_HOST=$1
.05LOCAL_HOST=`hostname`
.06
.07#Set current tab title to DISTANT_HOST name
.08echo -ne "\033k${DISTANT_HOST}\033\\"
.09/usr/bin/ssh ${DISTANT_HOST};
.10
.11#Reset current tab title LOCAL_HOST name when leaving DISTANT_HOST
.12echo -ne "\033k${LOCAL_HOST}\033\\"