How to Use GNU Screen

// May 21st, 2011 // Posted in Linux, OS X // Tagged as ,

On UNIX, GNU Screen is a utility that I cannot live without. I know many console users share the same point of view with me.

What is GNU Screen? it is a terminal multiplexer and you can run multiple console-based applications simultaneously. The best part of it is that you can leave it running on remote machines and come back to pick up your console sessions. It’s like VNC or Remote Desktop but for UNIX console. As you know that on UNIX if you run something on a shell and you got disconnected from it then your sessions will also stop. All work will be gone.

With that feature GNU Screen is indispensable when it comes to do console sessions on low speed connection. If you got disconnected then all you have to do is reconnect and continue with your work. Or if you do something that takes a long time to finish, say maybe archiving and backing up many files, then simply launch it from your GNU Screen session then detach from it and disconnect. Later on you can come back and reattach again to check the progress.

Anyway, here are some most useful features of GNU Screen that I use most of the time.

GNU Screen Most Used Commands
Commands What It Does
Ctrl-a ? (question mark)
GNU Screen's help pagehelp page

Open the help page. Also remember that “man” and “info” is your friend. By typing “man screen” and “info screen” you’ll get a lot of informations regarding Screen.

Ctrl-a d
resuming GNU Screen's sessionresuming session

Detach from the current Screen session and leave the process running in the background. Use “screen -r” to resume the session. If there are several Screen sessions running then add the session ID to the end of it. Ex: “screen -r 1088“. What really nice is that means you can login from anywhere to start your Screen session then later on continue the session again from different place.

Ctrl-a k
trying to kill a window in gnu screenkill a window

Kill current window. If you have another window active then Screen will move on to that window. If this is the only window to it then Screen will kill the window and exit, therefore ended the session.

Ctrl-a c Create a new window. By default it creates a new shell instance according your system setup (usually 90% of the time this is either bash or tcsh).
Ctrl-a A (capital A)
set title of current window in gnu screenset title

Rename current window. If you have so many windows running then I would suggest you name them so you won’t be lost.

Ctrl-a ” (double quote)
gnu screen showing list of active windows in current sessionlist of active windows

Show list of active windows in the current session.

Ctrl-a n, Ctrl-a p If you have multiple windows running then this command will do the flipping between the next window (using “Ctrl-a n”) and the previous window (using “Ctrl-a p”).
Ctrl-a h
gnu screen telling that it's logging to a file01. logging to a file
log file from a gnu screen window02. the log file

Create a running log (history). It will says “Screen image written to …” (see image 01). The file actually resides in your home directory (see image 02)

Ctrl-a ESC, Ctrl-a ]
entering gnu screen's copy modeA. entering copy mode
highlight the selection before copy it into gnu screen's bufferB. highlight the selection
gnu screen copied text into bufferC. copied into buffer
pasting text from gnu screen's bufferD. pasting text

Press “Ctrl-a ESC” will makes you temporary enter the copy buffer mode (see image A). You can tell when it says “Copy Mode …”.

In copy buffer mode you can move the cursor freely using directional keys. In this example I’m “cat”-ing the content of the Message of the Day (/etc/motd) in my Ubuntu machine. Next step is to highlight the block that you want to copy to the buffer. Move your cursor to the beginning of the block that you want to copy then press enter. That will mark the start point of the block. Then move your cursor toward the end of the block that you want to copy (see image B). In this example I’m copying the text “System Information …” from Ubuntu’s MOTD

Press enter again to copy the highlighted block into the buffer. This will end the “Copy Mode” and put you back to the active screen. You can tell when it says “Copied # characters into buffer” (see image C)

Use “Ctrl-a ]” to paste whatever is in the buffer (see image D). As you can see I’m pasting the text “System Information …” from the Screen’s copy buffer.

Please share this journal with others:

7 Responses to “How to Use GNU Screen”

  1. Great information! I’ve been looking for something like this for a while now. Thanks!

  2. bob says:

    bobby was here.great stuff.permission t use it for techops on Tuesday.

  3. Edward says:

    Thank you Pietra, for the info on gnu screen.

    When I invoke screen, it does not inherit PATH from my original shell. Have you encountered this before?

    • pietra says:

      Hi Edward,

      That is unusual. I’ve never experienced it before. Did you run the same shell as your main shell? running Screen with bash while your main is csh might cause issue i assume? how did you set your PATH? was it in /etc/environment or in your .bashrc ?

Leave a Reply