screen - open multiple "windows" in one session, detach, reattach later.


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?


Triggers a prompt to enter a name for the window.

Do stuff in your current window. Then...


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.)


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

Hat tip: (thanks!)

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}'

Find Me Around

User login