How to Use GNU Screen
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.
|Commands||What It Does|
|Ctrl-a ? (question mark)||
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.
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.
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)||
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)||
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”).|
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 ]||
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.