Sunday, January 18, 2009

Installing and using Screen

The GNU Screen Homepage description for screen is :

"Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells."
It is a very useful tool for slug IMO. For example sometimes it takes too much time to install something on slug. You can easily open a screen page. Make the installation process in there and you can close the terminal screen. You won't loose any data. As you get familiar with it you can use it for many other purposes. You should first install it if you still don't have.
apt-get install screen

After installing screen, it is time to learn some of the basic screen commands. If you run screen

You will see some text, ending with "Press Space or Return to end". Press space and you will be presented with a clean shell window. Test it with
ls /var

The fun part begins when you first hit ctrl+a then d. You will return to the main session with a line saying that detached. You can return to the screen session by writing screen -R anytime. Even after closing the terminal window and coming back. So you can also use this technique to run shell scripts(I am running my shell script that I mentioned two post ago with screen). Anyway, you can find the list of some useful commands below. Just try an learn.
screen - To start screen
screen -R - To return to the detached screen session
In the screen session
ctrl+a then d - To detach from screen(Still working on the background)
Ctrl + a then c - To create another session in screen (multiple windows).
Ctrl + a then Ctrl + a - Toggle between multiple shells
Ctrl + a then A - To rename the current window (Capital A)
Ctrl + a then " - To see the list of windows and select which you want
Ctrl + a and S - To split your window into two (Capital S)
Ctrl + a and TAB - To move between the two halves of the split windows
Ctrl + a then k - To kill the current window (you can also use exit)

Tip of the day :)
You can setup a small status bar across the bottom of the window which show you how many windows you have open, and which one you are working with.
First backup the original config file in case of a problem
cp /etc/screenrc /etc/screenrc.backup

then edit the config file
nano /etc/screenrc

Find and change the lines to
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
That is all, restart screen and you will see a blue bar at the bottom. Cheers...
Link to the original article.

1 comment: