- 1 Screen
- 2 installation
- 3 Command Line Options
- 4 Screen Command Keys
- 5 Scrollback
- 6 Monitor Window Activity
- 7 Exit Screen
- 8 Log to file
- 9 nested screen
- 10 .screenrc
- 11 Screen articles to read
- 12 The Dungeon Collapses
- 13 Issues
- 14 keywords
screen - A screen manager that supports multiple logins on one terminal.
$ yum info screen Summary: A screen manager that supports multiple logins on one terminal. Description: The screen utility allows you to have multiple logins on just one terminal. Screen is useful for users who telnet into a machine or are connected via a dumb terminal, but want to use more than just one login.
To install screen:
yum install screen
To start screen:
Command Line Options
To create an unamed session:
To create a named session
screen -S [SESSION_NAME]
To reattach as the controlling terminal (only one can be the controlling terminal):
screen -r screen -r [[pid.]tty[.host]] screen -r [SESSION_NAME]
When wanting to connect to a specific session, you can generally use just the 'pid' (instead of the full '[[pid.]tty[.host]]' format).
To attach to current session (multi view mode):
screen -x screen -x [[pid.]tty[.host]] screen -x [SESSION_NAME] # join a named session screen -x -p [WINDOW#] [SESSION_NAME] # join a named session on WINDOW#
To list screen sessions:
# Sessions marked ‘detached’ can be resumed with "screen -r". Those marked # ‘attached’ are running and have a controlling terminal. If the session runs # in multiuser mode, it is marked ‘multi’. screen -ls screen -list
Start a screen session in detached mode:
# Start screen in "detached" mode. This creates a new session but doesn’t attach # to it. This is useful for system startup scripts. screen -d -m screen -d -m [INITIAL_COMMAND] screen -d -m -S [SESSION_NAME] [INITIAL_COMMAND]
To stuff a string into a running session: (does not join session) 
screen -x [SESSION_NAME] -X stuff "[COMMAND]" screen -x [SESSION_NAME] -p [WINDOW#] -X stuff "[STRING]" screen -x [SESSION_NAME] -p [WINDOW#] -X stuff "[STRING]"`echo -ne '\015'`
To execute a command in a running session
screen -x [SESSION_NAME] -p [WINDOW#] -X exec "[COMMAND]" [PARAM1] [PARAM...]
To change the currently selected the current window: (does not join session)
screen -x [SESSION_NAME] -X select [WINDOW#]
Screen Command Keys
Enter command-line mode. (colon) (Command Summary):
Pass 'ctrl-a' through to application:
- "You can also detach just by closing the terminal emulator that contains the session. All of the programs you started running within screen are still running."
To kill a session, (or window if exists):
Ctrl+a K exit
To quit screen and kill all windows:
Ctrl-a c (mnemonic: create window)
List windows interactive:
- "to get a full-screen list of windows. You can navigate this list with the arrow keys (or vi-style, with j and k), and pick a window to activate by pressing Enter when it's highlighted."
Switch between current window and previous window:
Ctrl-a Ctrl-a (mnemonic: alternate window)
Switch next/previous window:
Ctrl-a n (mnemonic: next window) Ctrl-a p (mnemonic: previous window)
Switch to window # (0 is first screen):
Ctrl-a [0-9] (mnemonic: window #)
List windows (with number and name):
- "will give you a small, non-interactive list of windows"
Show the number (and title) of the current window
Name a window:
Ctrl-a A <name>
Switch to a window by name or number:
Ctrl-a ' <name_or_number>
To kill a window:
Ctrl+a K (mnemonic: kill window) exit
Renumber a window (switch if already exist):
Ctrl-a :number [number][enter]
Pass Ctrl-a to application: (good for screen in screen)
Ctrl-a a ...
"Ctlr-A U" allows me to change CR/LF mode
"Screen remembers a configurable number of scrollback lines, and you'll need them because you won't be able to use your terminal emulator's scroll features while running screen" 
To scroll back through screen's history, first enable the copy mode by pressing Ctrl+a [ . Now, use either one of the arrow keys, page up, page down, home and end keys to scroll through screen's history.
Pressing Enter will start marking text for copying. Pressing Enter again will copy the selected text into the clipboard. Now, to paste that text, press Ctrl+a ].
# Scroll back Ctrl+a [ # Move around [Arrow Keys] # Mark begin Enter # Copy text from begin to here Enter # Paste text Ctrl+a ] # Search forward /[TEXT] # Search backwards ?[TEXT] # Search again (in same previous direction) n # Dump current window scrollback to a file Ctrl+a :hardcopy -h <filename> # Set copy buffer file: Ctrl+a :bufferfile <filename> # ... # Write copy buffer to file: Ctrl+a >
Clear scrollback (per window): 
Ctrl+a :scrollback 0 Ctrl+a :scrollback 15000 # or bind this to a key, such as Ctrl+a C, as that is a useless clear screen key! bind C eval "scrollback 0" "scrollback 15000"
By default, the scrollback buffer only keeps the last 100 lines of text, which is not enough for a typical interaction with Screen. I’ve found a setting of 5000 lines to be more than adequate for my usage. The number of scrollback lines can be configured in your $HOME/.screenrc file, by adding the following line:
# $HOME/.screenrc defscrollback 5000
- Copying GNU screen scrollback buffer to file (extended hardcopy)? - Stack Overflow - http://stackoverflow.com/questions/4807474/copying-gnu-screen-scrollback-buffer-to-file-extended-hardcopy
- Screen - Copy and Paste - http://stuff.mit.edu/afs/athena.mit.edu/project/gnu/doc/html/screen_11.html#SEC72
Monitor Window Activity
Monitor the current window for 30 seconds of silence:
To start or stop monitoring a window for activity
- "As you've seen from the section on detaching and reattaching, screen is not easy to kill. You can't just close its containing terminal. (Actually, you can, but then all those processes are still running on your system, ready to be reattached.) There's no "quit" key.
- How do you fully exit screen?
- To my knowledge, the only way to do this nicely (i.e. without sending nasty signals to processes that don't deserve it) is to close each of your screen windows. Exit whatever programs or shells each is running, and they will go away. When the last program running inside screen is exited, screen itself will go away." 
According to the screen man page (version 4.00.03):
C-a C-\ (quit) Kill all windows and terminate screen.
The "C-a C-\" character does not appear to be captured. Another solution is to send the 'quit' command.
To send a command:
C-a : <command>
C-a : quit
Log to file
C-a H # start/stop logging to screenlog.N
- "You can also use Control-a + H to save loggings into screenlog.n file. One more Control-a + H to turn off. C-a H: Begins/ends logging of the current window to the file "screenlog.n"."
logging - Save "Screen" (program) output to a file - Stack Overflow - http://stackoverflow.com/questions/14208001/save-screen-program-output-to-a-file
To control a screen within a screen, just append the following:
[ctrl]+[a] [a] ... # sends a [ctrl]+[a]
Create new window:
[ctrl]+[a] [a] c
- Same as the scrollback command except that the default setting for new windows is changed. Initial setting is 100.
# Kenneth's Screen Configuration - $HOME/.screenrc # Auto detach on terminal close - default setting is on autodetach on # Hide startup copyright screen startup_message off # 10,000 lines of scrollback! defscrollback 10000 # flash screen on bell vbell on # clear scrollback with '[ctrl]+a c' bind C eval "scrollback 0" "scrollback 15000" # set default terminal - default is screen.xterm # alternative # term xterm term linux # default windows screen -t local # run 'mutt' program #screen -t mail mutt # default push #screen -t root #stuff "sudo su -\015 cd /\015" #screen -t 'my tasks' #stuff "cd /esx\015"
Screen articles to read
The Dungeon Collapses
If you kill screen:
$ kill [pid]
Suddenly the Dungeon collapses!! - You die...
Must be connected to a terminal
When trying to start screen from a startup script, or non login session:
Must be connected to a terminal.
ssh email@example.com screen "tail -f /var/log/messages"
"ssh -t ..." will force pseudo-tty allocation.
"screen -d -m" will start in detached mode
- terminal - How can I launch a screen session with a command over ssh on a remote server from my desktop? - Server Fault - http://serverfault.com/questions/21806/how-can-i-launch-a-screen-session-with-a-command-over-ssh-on-a-remote-server-fro