The classic terminal multiplexer.
- horizontal and vertical screen splitting
- built-in serial and telnet support which tmux lacks
- status bar requires config
- dynamic term titles requires config
Several Linux distributions are moving to Tmux which is another newer alternative.
You can run one terminal multiplexer inside another.
eg. on a remote SSH session inside another multiplexer on your local machine.
By using screen at one layer and tmux at another, you can avoid embedded keybindings clashes and having to double escape keybindings all the time to send them through to the embedded multiplexer.
Start a basic screen session:
screenCtrl-a w after this command to show the status bar to see you're inside screen.
List running screens:
screen -ls- Start screen with options:
-D- detaching it from another terminal-R- and reattaching it here-A- adjusting the height and width to the current terminal
screen -DRAMulti-attach to an already attached screen (useful to screen your screen with colleagues' terminals to follow along):
screen -xOpen new screen pane at number $num or next highest available:
screen $num$HOME/.screenrc
Screen requires a good configuration to make it more usable, such as:
- showing a permanent status bar along the bottom to see which screen terminal number you're in
- dynamic term titles (what command each term is running)
- custom keybindings
(Tmux has this by default).
See my advanced screen config here:
HariSekhon/DevOps-Bash-tools - configs/.screenrc
Ctrl-a is the default primary keybinding action key prefix, followed by the next key.
Escape the shell key of Ctrl-a to jump to the start of the line by doing Ctrl-a , a.
| Action | Keystrokes |
|---|---|
| Create a new screen | Ctrl-a , c |
| Switch to the next screen | Ctrl-a , n |
| Switch to the previous screen | Ctrl-a , p |
| Jump to screen number | Ctrl-a , <num> |
| Jump to screen number greater than 9 | Ctrl-a , ', <num> |
| Jump to last screen number | Ctrl-a , Ctrl-a |
| List screens and jump to menu selected one | Ctrl-a , " |
| Rename screen | Ctrl-a , A |
| Renumber screen (will swap position with the other screen if already on of that number) |
Ctrl-a , :number <num> |
| Detach from the current screen (shells stay running, can reattach later using command below) |
Ctrl-a , d |
| Reattach to a detached screen | screen -r |
| Split the terminal horizontally | Ctrl-a , S |
| Split the terminal vertically (requires patching, only Mac / Debian / Ubuntu seem to have this) |
Ctrl-a , | |
| Switch between split screens | Ctrl-a , Tab |
| Unify on current split | Ctrl-a , Q |
| Remove the current split | Ctrl-a , X |
| Resize the current split region | Ctrl-a , :resize <number> |
| Enter Scroll / Copy mode | Ctrl-a , [ |
| Search backwards in the scrollback buffer | ? |
| Search forwards in the scrollback buffer | / |
| Next search match | n |
| Copy text in scrollback mode to buffer - Start / Stop copy section | Space to begin marker, select text, Space to end marker to copy to buffer |
| Paste text from buffer | Ctrl-a , ] |
| Jump backwards one screen in scrollback buffer (or use arrow keys) | Ctrl-b |
| Jump forwards one screen in scrollback buffer | Ctrl-f |
| Jump to top line in current screen of scrollback buffer | H |
| Jump to middle line in current screent of scrollback buffer | M |
| Jump to bottom line in current screent of scrollback buffer | L |
Send a literal Ctrl-a |
Ctrl-a , a |
Text Screenshot to ~/hardcopy.$WINDOWOverwrites this same text file each time called |
Ctrl-a , h |
Append Start / Stop screen log to ~/screenlog.$WINDOW |
Ctrl-a , H |
From DevOps-Bash-tools repo:
screen_terminal_to_stdout.sh # screen args such as window numberRetains the temp file if this environment variable is set to any value:
export SCREEN_TERMINAL_NO_DELETE_TEMPFILE=1You can pass screen options as args such as:
-S <session_name>
-p <window_number>
See window numbers using your Ctrl-A + w hotkey combo or in stdout via this command:
screen -S [<session_name>] -Q windowsUses the above script screen_terminal_to_stdout.sh combined with the copy_to_clipboard.sh portable script for
Mac and Linux to send the terminal output straight into the clipboard ready to paste out to AI.
screen_terminal_to_clipboard.sh # screen args such as window numberThis one is quicker and convenient to use for quickly pasting your terminal results back to an AI LLM or if you want to share the file as it automatically retains the tempfile.
Ported from private Knowledge Base page 2012+ (should have had earlier notes)