//
You are reading..
Productivity

How to use linux screen


If you are using linux you have probably sumbled across screen. It is a great tool to run some processes that take a long time and detach them from the console.

In our example we are collecting tweets, since this process can go on for a while or actually forever unless we stop it, we will use screen to start our collecting program and then let it continue for some days. Normally closing your console also closes your program unless you don’t deamonize it. Screen is an easy alternative to do that.

Step 1.

If you are using debian just type

apt-get install screen 

and you are ready to go

Step 2:

To start using screen simply type screen and you will be greeted with a welcome screen. Now you are inside screen and everything looks the same apart that you can do a few cool tricks:

Shortcuts

The following are some of the most used shortcuts that lets you
navigate through your screen environment. Note that unless modified by
your .screenrc, by default every screen shortcut is preceded by Ctrl+a.
Note that these shortcuts are case-sensitive.

  • 0 through 9 – Switches between windows
  • Ctrl+n – Switches to the next available window
  • Backspace – Switches to the previous available
  • Ctrl+a – Switches back to the last window you were on
  • A – Changes window session name
  • K – Kills a window session
  • c – Creates a new window
  • [ – Then use arrows to scroll up and down terminal

Find out about more shortcuts in Screen’s man pages. In your terminal, run: man screen.

You will find great tutorials on the web on screen like this or this. They will explain screen in much more detail to you.

Step 3:

What we will do is start the collecting process and then detach the window. This is pretty easy:

Type

ruby collect_tweets.rb 

to start collecting the tweets, you will see them popping up in your console.

Now to detach the window simply press

ctrl+ a + d

and you are back in your console. Notice that screen is still running your tweet collection.

To go back to screen and see what it is doing simply type:

screen -ls

It will provide you with the instances of screen that you are running now. You should find one entry. To connect to that session simply type:

screen -r and the pid number for example

screen -r 27699

And voila you are back in watching your ruby program collecting those tweets.

Sweet isn’t it?

Step 4:

Extra goodies:

You can have multiple consoles in screen to create a new one simply press

ctrl + a + c

and you have a new console inside screen. To cycle between those consoles press

ctrl + a + n 

to flip to the next window.

Now you are able to start those collecting processes and safely disconnect from your box while it is still preforming the collection process.

In the next tutorial I will show you how to monitor what is going on from the browser.

Cheers
Thomas

Advertisements

About plotti2k1

Thomas Plotkowiak is working at the MCM Institute in the Social Media and Mobile communication group which belongs to the University of St. Gallen. His PhD research in Social Media is researching how the structure of social networks like Facebook and Twitter influences the diffusion of information. His main focus of work is Twitter, since it allows public access (and has a nice API). Make sure to also have a look at his recent publications. Thomas majored 2008 in Computer Science and Economics at the University of Mannheim and was involved at the computer science institutes for software development and multimedia technoIogy: SWT and PI4. During his studies I focused on Artificial Intelligence, Multimedia Technology, Logistics and Business Informatics. In his diploma/master thesis he developed an adhoc p2p audio engine for 3D Games. Thomas was also a researcher for a year at the University of Waterloo in Canada and in the Macquarie University in Sydney. He was part of the CSIRO ICT researcher group. In his freetime thomas likes to swim in his houselake (drei weiher) and run and enjoy hiking in the Appenzell region. Otherwise you will find him coding ideas he recently had or enjoying a beer with colleagues in the MeetingPoint or Schwarzer Engel.

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: