Skip to content

Instantly share code, notes, and snippets.

@NeuronQ
Last active August 17, 2017 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeuronQ/4697aef62307818693cc0fec83b0feaa to your computer and use it in GitHub Desktop.
Save NeuronQ/4697aef62307818693cc0fec83b0feaa to your computer and use it in GitHub Desktop.
UNIX Screen cheatheet
#!/bin/cat
# Intro to using UNIX Screen
## Basics
screen -list # LIST current screen sessions
screen -S myscreen1 # CREATE a new session named *myscreen1*
screen -r myscreen1 # RESUME an existing detached screen session
screen -D -r myscreen1 # RESUME an existing screen session, even if was left attaches (say by a dropped connection...)
screen -R "my screen 1" # RESUME or create a session named *my screen 1*
screen -X -S <session no.> quit # DESTROY session
`C-a d` # DETACH from current screen session
## Window Managing
`C-a "` # list menu of all windows (use number key then <kbd>Enter</kbd> to select one)
`C-a 0` # switch to window 0
`C-a '` + `part or all of window name` + [Enter] # switch to window by name
`C-a c` # create a new window
`C-a A` # give a name to current window
`C-a k` # kill current window (and detach session if this was the last one left)
## Shared Sessions
screen -S myshared1 # create a session named myshared1
# ...login from another terminal...
screen -x -r myshared1 # connect to session myshared1
## Other shortcuts
screen -S my1 -t one # create a session named *ms1* with a windows named *one*
screen -r my1 -p one # resume session *my1* and go directly to window *one*
## Status Bar
# You SHOULD use something like this to keep track of the window you are in.
# Add to your `~/.screenrc` this black magic:
# (from: http://www.ibm.com/developerworks/aix/library/au-gnu_screen/)
`
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
`
# ...or other suggested alternative:
# (from https://wiki.harvard.edu/confluence/display/USERDOCS/How+to+use+'screen'+for+remote+shell+sessions)
`
startup_message off # default: on
defscrollback 4096 # default: 100
shell -$SHELL
vbell off
crlf off # default: off
caption always "%{= kw} %H | %{kc}%?%-w%?%{kY}%n*%f %t%?(%u)%?%{= kc}%?%+w%? %=|%{kW} %l %{kw}| %{kc}%{-b}%D, %m/%d/%Y |%{kW}%{+b}%c:%s %{wk}"
termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
defhstatus "screen ^E (^Et) | $USER@^EH"
hardstatus off
`
---
## References:
#>> http://www.ibm.com/developerworks/aix/library/au-gnu_screen/ - recommended
man screen # read this after the intro above (also at: http://www.gnu.org/software/screen/manual/screen.html)
#>> https://wiki.harvard.edu/confluence/display/USERDOCS/How+to+use+'screen'+for+remote+shell+sessions - shorter and less explanations, but more to the point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment