From Christoph's Personal Wiki
Jump to: navigation, search

screen provides you with an ANSI/vt100 terminal emulator, which can multiplex up to 10 pseudo-terminals. On startup, it executes $SHELL in window 0. Then it reads $HOME/.screenrc to learn configuration, keybindings, and possibly open more windows.


  • Start a named session:
$ screen -S session_name
  • Detach from Linux screen session:
Ctrl+a d

The program running in the screen session will continue to run after you detach from the session.

  • Reattach to a specific detached session. The terminal emulator reconfigures according to your $TERMCAP or $TERM settings. When you have multiple screens detached, you must supply the session name:
$ screen -r [|]
  • Reattach to a detached session or (if none) create a new session:
$ screen -R
  • Detach a screen session remotely. Has the same effect as typing "C-a d" on the controlling terminal. `screen -D` will power-detach:
$ screen -d [|]
  • Show all available sessions and their status. Use -wipe to remove DEAD sessions:
$ screen -list
$ screen -ls
$ screen -wipe

If sockets are missing, you may send a SIGCHLD to its "SCREEN" process and the process will re-establish the socket (think of someone cleaning /tmp thoroughly).

  • Start a new screen session and set the number of lines in the scrollback buffer to 200 (the default is 100 lines):
$ screen -h 200

Keyboard shortcuts

  C-a ?		(help)		Show all keybindings.

  C-a c		(screen)	Create new windows.

  C-a SPACE	(next)		Advance to next window (with wraparound).

  C-a C-a	(other)		Toggle between the current and previously
				displayed windows.

  C-a 0		(select n)	Switch to window n=0 ... 9.
  C-a 9		

  C-a w		(windows)	Show a list of window names in the status line.

  C-a a		(meta)		Send a literal C-a/C-s/C-q to the
  C-a s		(xoff)		process in the window.
  C-a q		(xon)		For instance, emacs uses C-a and C-s.

  C-a l		(redisplay)	Redraw this window.

  C-a W		(width)		Toggle between 80 & 132 columns mode. 

  C-a L		(login)		Try to toggle the window's utmp-slot.

  C-a z		(suspend)	Suspend the whole screen session.

  C-a x		(lockscreen)	Execute /usr/bin/lock, $LOCKCMD or a 
				built-in terminal lock.

  C-a H		(log)		Log stdout of window n to screenlog.n.

  C-a C-[	(copy)		Start copy mode.  Move cursor with h,j,k,l.
				Set 2 marks with SPACE or y.  Abort with ESC.
				(C-[ is ESC.)  Preceeding second mark with
				an a appends the text to the copy buffer.

  C-a C-]	(paste)		Output copy buffer to current window's stdin.

  C-a <		(readbuf) 	Read the copy buffer from /tmp/screen-exchange.
  C-a >		(writebuf)	Write the copy buffer to /tmp/screen-exchange.

  C-a d		(detach)	Detach screen. All processes continue and may
				spool output to their pty's, but screen
				disconnects from your terminal.  

  C-a D D	(pow_detach)	Power detach.  Disconnect like C-a d but also
				kill the parent shell.

  C-a K		(kill)		Kill a window and send SIGHUP to its process
				group.  Per default this would be C-a C-k,
				but it is redefined in the demo .screenrc
				(think of killing a whole line in emacs).

  C-a : 	(colon)		Online configuration change.
Ctrl+a c       Create a new window (with shell)
Ctrl+a "       List all window
Ctrl+a 0       Switch to window 0 (by number )
Ctrl+a A       Rename the current window
Ctrl+a S       Split current region horizontally into two regions
Ctrl+a |       Split current region vertically into two regions
Ctrl+a tab     Switch the input focus to the next region
Ctrl+a Ctrl+a  Toggle between the current and previous region
Ctrl+a Q       Close all regions but the current one
Ctrl+a X       Close the current region

See the man page or TeXinfo manual for many more keybindings and commands.

Customize Linux screen

When screen is started, it reads its configuration parameters from /etc/screenrc and ~/.screenrc, if the file(s) is/are present. We can modify the default Screen settings according to our preferences using the .screenrc file.

  • Example .screenrc:
# Turn off the welcome message
startup_message off

# Disable visual bell
vbell off

# Set scrollback buffer to 10000
defscrollback 10000

# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

External links