Last modified on 13 Sep 2020.

Keep the running tasks on the remote host continue after turning off the local caller.

Install

sudo apt install screen # ubuntu

Basic command lines

# check screen version
screen -v
# start new session (with name)
screen -S <name>
# list running sessions
screen -ls
# attach to a running session (without name)
screen -x
# attach to a running session (with name)
screen -rx <name>
# -x for an interactive (scrolling)
# detach a running session
screen -d <name> # or Ctrl + A, D
# kill a session
screen -X -S <name> quit

Delete sessions

  1. Reattach first: screen -r <name>
  2. Ctrl + A, K then Y
# kill ALL auto-created sesssions
screen -ls | grep pts | cut -d. -f1 | awk '{print $1}' | xargs kill

# kill all detached sessions
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill

Create a screen + list of command lines

screen -S 'dat' -dm bash -c 'cd /jekyll-site; bundle exec jekyll serve -I; exec sh'

Hotkeys

  • Detach: Ctrl + A, D
  • Reattach: Ctrl + A, R
  • Kill current session: Ctrl + A, K then Y

Reference