Getting started with Screen in Linux

If you are a level 10 geek, you know this already and just skip this post and read something else on my blog. But if you are one of those that long to be more geeky, read on.

Screen

Screen is an excellent tool to to more in one terminal window. Not just doing more, but you are able to stop working, close the window and reopen all your work at a later point. Screen is a “screen manager with VT100/ANSI terminal emulation” according to its man-page.

Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.


Start using screen

To start, you must have Screen installed on your linux computer, use the package manager to install it, if its not already there. (ie. sudo apt-get install screen in ubuntu/debian/easy peasy, yum install screen in fedora/moblin)

Open screens config file with nano:

orjanv:-$ nano ~/.screenrc

Add the following two lines and save using CTRL + X, then Y and ENTER. (i have used capital letters here, but use lower case when you do this tutorial)

vbell on
caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c"

(Thanks to Åsmund G. for .screenrc tips)

Now run screen and name the screen-session for something of your choice:

orjanv:-$ screen S somethingname

Now you are inside screen, and the bottom of the terminal should look something like this:

Now you can start by pressing CTRL + A and then | (pipe), to split the screen in two. In order to switch between them, think of browser tabs, and use CTRL + A, then TAB key. The cursor indicates what pane is active. Now run a command like ls -l to see what happens.

Multiple virtual terminals and multiple panes

Next, we are to run multiple virtual terminals and use different panes to show each virtual terminal. For example if you want to always show output from a logfile using tail -f /var/log/apache.log and also want to have your favorite IRC channel visible at all times, you can now do this using two panes and two virtual terminals in screen. To switch between virtual terminals, use CTRL + A and then numeric keys 0 or 1 or 2 (depends on how many virtual terminals you have created using CTRL + A, then C). If you use two virtuals terminals more frequently, you can swap easier by using CTRL + A, then A to swap between the two (like P->P on a TVs remote controller).

Suspend and resume

By pressing CTRL + A, then D you can detach your work and close the terminal window, log out and go home. Now, next day you can log into your computer, open up a terminal and type

orjanv:-$ screen -rd somethingname

to reopen your work just where you left it.

Read the man page for screen to deepen your knowledge and strengthen your unixpowers.

About Ørjan Hoyd Vøllestad

Etter å ha undersøkt det litt, kom jeg til samme konklusjonen som C. S. Lewis gjorde i 1929: “Christianity, if false, is of no importance, and if true, of infinite importance. The only thing it cannot be is moderately important."
This entry was posted in Featured and tagged , , , , , , , , , . Bookmark the permalink.

Comments are closed.