persistent screen sessions

A number of tools allow you to set up persistent bash sessions on a server (or another computer) that can continue to run when you log off / disconnect from them and that can have multiple windows (shell sessions / terminals) open at once. Thus, commands (and terminal session histories) will be kept alive even when logged out, and you can easily re-attach to a session that is still running. Here we introduce some that are commonly used.

screen

screen is one such tool for persisten shell sessions that you can detach from, and reattach to later, keeping it running in the background.

Essential instructions

The bare essentials are described in this guide:

And the most important command line arguments and keystrokes can be found in this reference:

And if you are looking for a more detailed intro, check out the Getting Started section of screen's online documentation.

tmux

tmux stands for 'terminal multiplexer'. It is also meant for running commands and workflows in persistent terminal sessions that you can log out of.

Essential instructions

  1. Create a new session with a name:
tmux new -s test
  1. Detach the session that is created with Ctrl+B and release Ctrl and B, then quickly D, so it's basically Ctrl+B and D. The release of Ctrl and B is important to not kill the session instead of detaching (yes, it happens). The message should indicate:
[detached (from session test)]
  1. List the session that is created:
tmux ls
  1. Then, to be able to reach the newly created session back again:
tmux attach -t test

Other shortcuts that can be useful

CTRL - B - [ //scroll mode
q //exit scroll mode