screen
Start a screen session. Then hit space to get past the intro screen. (If you want to use screen on a remote server, SSH to the server before running screen.) Now you have a shell open in screen. Do stuff, whatever. When you want another "window"...
CTRL-a c
Create a new shell instance. Maybe you want to name the current window?
CTRL-a A
Triggers a prompt to enter a name for the window. Do stuff in your current window. Then...
CTRL-a CTRL-a
Switch back to last screen window.
CTRL-a "
Display list of screen windows. Use arrows and enter to select.
CTRL-a p
Switch to the previous screen window.
CTRL-a n
Switch to the next screen window. Now, suppose you want to shut down your laptop but not lose all the windows in your session. (Or perhaps you've SSH'ed into a server somewhere and are running screen there but now you want to close the connection.)
CTRL-a CTRL-d
Detach from screen. (If you set "autodetach on" in .screenrc, this will happen automatically when you close your terminal.) And when you want to come back and reattach to all your screen sessions?
screen -d -r
Start up screen and reattach to existing windows. If you want to close a screen window, 'exit' like you would normally. When you exit the last window, screen will close.
Note: This is how I solve the "I need to use the bathroom at this coffee shop and take the MBP with me so no one steals it but I don't want to lose all my sessions by closing my laptop" problem... :)
And to see a list of open sessions on a machine...
screen -ls
You can create a ~/.screenrc file to specify settings and default behaviors for screen. Do a web search for examples.
My .screenrc
# Screen command settings.
autodetach on
startup_message off
defscrollback 5000
vbell_msg "* ding *"
# Fix scrolling, in case we don't want to use CTRL+a [
# Assumes xterm or a variant like OSX's xterm-color
termcapinfo xterm* ti@:te@
# Statusline (should be one-line)
hardstatus alwayslastline '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}[%{W}%n%f %t%?(%u)%?%{=b kR}]%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %D %m/%d %C%a ]%{W}'
0 comments:
Post a Comment