Screen is a must known GNU console tool, this small piece of software comes really handy when you are working on a console or sending long processes on a remote host.
When you start screen, you simply get a terminal prompt, but then, many features are given to you. Most users don't even know about it, but you will soon love it.
From GNU:
Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.
Along this tutorial, we are going to start a screen session and start different windows. Then we will see how to use the some essential features from screen, such as naming windows, navigating from window to window.
Mind that key binding will be written in bold and that it is case sensitive, where Ctrl-x y means pression Control and x simultaneously.
Installation:
As usual, before using softwares, you need it to be install on your system. In order to install screen on a debian based system, you need to:
$sudo apt-get install screen
Starting a screen session, dettaching and reattaching it:
Now that everything is up, let's start your first screen instance giving it the name screen-session:
$screen -S screen-session
As you can see, you get a new prompt inside the previous terminal. Let's start a program inside this shell, irssi -c irc.debian.org for instance.
$irssi -c irc.debian.org
Okie, once logged in, join a channel (/j #debian) and detached the session (Ctrl-a d). You are getting back to your previous shell and told that the session is [detached].
You can go back to your screen session by attaching the session back:
$screen -x screen-session
As you can see, the irc session is still running on :) .
Creating more windows:
screen can actually handle more than one window per session. In order to create a new window, type Ctrl-a c keybinding, you then get a new prompt, let start top in that window:
$top
And again a new window, Ctrl-a c where you will start for instance nload (a network traffic analysis software):
$nload
Navigating through windows:
There is a lot of things you can do now:
Example:
Now, let's see how it goes using the windows we created. We are going to give them all a name, and switch windows.
First, we are going back to the first window we created when we launched screen. So, let's go by typing Ctrl-a 0 and as we are running irssi on debian channel, we we call it "irc debian". In order to do this, we need to use the keybinding Ctrl-a A and then remove the elder name and type "irc debian" instead.
Going back to the windows list Ctrl-a " will now show window 0 called debian irc and windows 1 and 2 named bash. Go to the last one (#2) and select it Enter. This window is running nload, so let's call it "nload" [Ctrl-a A].
Now, switch to the previous window [Ctrl-a p], and rename it "top" [Ctrl-a A], back to the windows list [Ctrl-a "], this is now much easier to find the window you started ;) .
Conclusion:
screen allow system administrators and console fans to get more from their terminal as you can easily start windows are find them back by giving them appropriate names.
Another usefull feature of screen is to be able to connect to a remote server, start a screen session, detach the session and then close the ssh connection. Later on, you can connect back to the remote host and attach back the screen session you started earlier on.
People who want to know more about screen my refer to man screen or Ctrl-a ? from within a screen session.
Enjoy it ;)