Posted under » Ubuntu » Linux on 14 January 2010

GNU Screen is a terminal multiplexer program for Linux. It allows you to turn one terminal into many, and run processes even after logging out. A typical use is for Jupyter notebook.

To run screen, simply execute the command

# screen

You will see a flash, then be at a blank terminal. While it may seem that nothing has happened, what you're looking at is actually a new terminal within screen. You can continue as normal, but sooner or later you will wish to run a new terminal.

Pressing the control and a keys simultaneously (which we'll denote with Ctrl-a from now on) signals screen to interpret the next command. So if you press Ctrl-a and let go, then press 'c' for "create," (Ctrl-a c) you will be in a new terminal window. You've created a new window within screen. You can view the list of windows with Ctrl-a w. If you exit your shell in the new window, screen will automatically destroy the window and you'll be back to the first. Create a few more and type some random commands in each (different ones in each). You can now press Ctrl-a then SPACE to move to the next window. If you press Ctrl-a a you will return to the previous window. Also, you can select windows directly by typing the number after Ctrl-a.

Lastly, you need to know how to detach and reattach to screen. Press Ctrl-a d and screen will exit. You are back at the single terminal you started with, without screen. You can see what screen sessions you have running in the background with 'screen -ls.' Now, to reattach to your screen session,

# screen -x

We use the -x command to reattach so that it can be done multiple times. From your laptop, home computer, and work computer, are the most common. For the rest of the basics, see the screen man page or Ctrl-a ?.

# screen -ls // List your running screen sessions
# screen -x // reattach to your screen session
# screen -r // If there is only one session to be resumed, it will be resumed automatically; 
# screen -r [pid].[tty].[host]. // If there are more than one, you need to specify which screen session you want to resume by typing
# Ctrl-a c // Create a new screen window
# Ctrl-a w // View a list of windows
# Ctrl-a SPACE // Move to the next window
# Ctrl-a d // Detach from your screen session
# exit  // To close a screen session

Sometimes the screen hangs and you want it to quit. Here is what you do.

screen -s 4603.pts-11.ubuntu -X quit

More commands.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS IOT