Skip to content

Instantly share code, notes, and snippets.

@zigmoo
Forked from kapitanluffy/screen_cheatsheet.markdown
Last active March 11, 2024 23:44
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save zigmoo/b67b11cd7bc8a5c66a44b91fcf37898e to your computer and use it in GitHub Desktop.
Save zigmoo/b67b11cd7bc8a5c66a44b91fcf37898e to your computer and use it in GitHub Desktop.
Screen Cheatsheet

Screen Quick Reference

Wait a minute, why would anyone use 'screen', and what is it anyway?

Well, because it's both AWESOME and FUN!!

It lets you keep your own session running on all the servers you already use, and chances are, it's probably already installed and waiting for you! (since 1987!)

Basic

Description Command
Start a named screen session screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r <session_name>
Detach a running session screen -d <session_name>
Enable/disable vertical scrolling mode* in a running session Ctrl-a ESC
  • The vertical scrolling mode works with mouse scrolling as well as up and down arrows. Press ESC to cancel out of this mode.

Escape Key

All screen commands are prefixed by an escape key, by default Ctrl-a (that's Control-a, sometimes written ^a). To send a literal Ctrl-a to the programs in screen, use Ctrl-a a. This is useful when when working with screen within screen. For example Ctrl-a a n will move screen to a new window on the screen within screen.

Getting Out

Description Command
detach Ctrl-a d
detach and logout (quick exit) Ctrl-a D D
exit screen Ctrl-a : quit or exit all of the programs in screen.
force-exit screen Ctrl-a C-\ (not recommended)

Spawn & Monitor Named Screen Session on Remote Server

REMOTE_USER="hiphopapotamus" ; USER="rhymenoceros; PRIV_KEY="/home/${USER}/.ssh/id_rsa" ; HOST="conchords.linode.com" ; SESSION_NAME="${HOST}_$(date +%Y%m%d_%H%M%S)" ; COMMAND="ssh -i ${PRIV_KEY} ${REMOTE_USER}@${HOST} 'htop' ; exec bash ;" ; screen -dmS ${SESSION_NAME} bash -c " ${COMMAND} " ; screen -r ${SESSION_NAME} ; screen -ls ;

  • Change the word "htop" above, leaving the single-quotes in place, to provide the remote command you intend to run.

Help

Description Command
See help Ctrl-a ? (Lists keybindings)

Window Management

Description Command
Create new window Ctrl-a c
Change to last-visited active window Ctrl-a Ctrl-a (commonly used to flip-flop between two windows)
Change to window by number Ctrl-a <number> (only for windows 0 to 9)
Change to window by number or name Ctrl-a ' <number or title>
Change to next window in list Ctrl-a n or Ctrl-a <space>
Change to previous window in list Ctrl-a p or Ctrl-a <backspace>
See window list Ctrl-a " (allows you to select a window to change to)
Show window bar Ctrl-a w (if you don't have window bar)
Kill current window Ctrl-a k (not recommended)
Kill all windows Ctrl-a \ (not recommended)
Rename current window Ctrl-a A

Split screen

Description Command
Split display horizontally Ctrl-a S
Split display vertically Ctrl-a | or Ctrl-a V (for the vanilla vertical screen patch)
Jump to next display region Ctrl-a tab
Remove current region Ctrl-a X
Remove all regions but the current one Ctrl-a Q

Misc

Description Command
Redraw window Ctrl-a C-l
Enter copy mode Ctrl-a [ or Ctrl-a <esc> (also used for viewing scrollback buffer)
Paste Ctrl-a ]
Monitor window for activity Ctrl-a M
Monitor window for silence Ctrl-a _
Enter digraph (for producing non-ASCII characters) Ctrl-a Ctrl-v
Lock (password protect) display Ctrl-a x
Enter screen command Ctrl-a :
Enable logging in the screen session Ctrl-a H
@zigmoo
Copy link
Author

zigmoo commented Jan 23, 2024

Can't believe yall let me misspell "rhymenoceros" for all these years... Thankfully that's fixed now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment