Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

screen

Create a Named Screen

screen -S something

List Screens

screen -ls
There are screens on:
        6355.flaskapp   (01/25/2021 07:23:32 AM)        (Attached)
        6346.sqlite     (01/25/2021 07:22:51 AM)        (Attached)

Reattach to Screen

screen -r   XXXXX

Basic Usage

Below are the most basic steps for getting started with screen:

  • On the command prompt, type screen.
  • Run the desired program.
  • Use the key sequence Ctrl-a + Ctrl-d to detach from the screen session.
  • Reattach to the screen session by typing screen -r.

Screen is a shell layer that allows you to use one shell session, detach from it, and then reattach from a different computer where you left off. It’s useful for long jobs, recording what commands were run, and bad connections that might drop your SSH shell in the middle of a work session.

$ which screen
/usr/bin/screen

Install Screen

For Debian-Based Linux, the command is:

$ sudo apt-get install screen

Start Screen

Start screen with the simple “screen” command and hit enter to begin using it.

Screen Commands

Here is the TLDR version that you probably are looking for:

  • screen -S something

  • screen -ls

  • screen -r xxxx.something -D

Everything Else besides TLDR:

Linux Screen uses ctrl + a to start commands and then a character to do a specific command. You can see all of the commands using ctrl-a ? Screen Help

Ctrl-a ?Show Help File
Ctrl-a HCreate or Stop Log of Session

A pwd will tell you what your working directory is, and you will have a screenlog.0 file in it with whatever commands you typed. If you Ctrl-a H again it will stop logging.

Ctrl-a MMonitor for output
Ctrl-a _Monitor for silence
Ctrl-a xLock Screen
Ctrl-a dDetach Screen
Ctrl-a cCreate new screen
screen -lsList all Screens
screen -r xxxxReattach to existing Screen xxxx
Ctrl-a nCycle to Next Screen
Ctrl-a pCycle to Previous Screen
Ctrl-a kStop Screen

When you finally type “exit” or ctrl-a k to kill a session you will see the [screen is terminating] message.

Check if Screen is Running

If screen isn’t running, you can verify using the pgrep utilitiy

$ pgrep screen

If screen is running, you will get 2 process IDs:

$ pgrep screen
13020
13021

Example of Using Screen

screenStart screen
ctrl a, HTurn on logging
ctrl a, cMake a New Screen
start some commandlong boring output
ctrl a, cMakes a new screen
do other commandsbleh bleh whatever
ctrl a, nCycle to the next screen
exitType exit, it will scroll through screens shutting them down each time.

Now you can review screenlog.0 file