Screen and rTorrent

tuxAfter some serious stuff about networking there is going to be a small article about some useful Linux thingies.

First of all small reminder about programmes and background processes.  If you want to run programme in background there is a very easy way how to do it. Just add & sign after the command. Like in this example with top.

tnk@charon:~$ top &
[1] 7440

[1]+ Stopped top

If you then need to return to this programme (i.e. run it in active shell again) you have to use the job number (in this case signed as [1]) as an argument for fg utility. If you don’t remember the job number just run “jobs” command for the list.

tnk@charon:~$ fg 1

After displaying the name of the job it will re-enter the programme. But there is one small problem. Quite big number of programmes (like the one used as an example) will stop working after being put to background and this is where screen utility comes to play. This utility will enable you to “detach” the running application so it will run in background and even after you log off. Which provides nice possibilities of running some apps remotely.

So how to use screen – it is quite easy. For running an application you want to run at the background just type the following (I am using top as an example).

tnk@charon:~$ screen  top

That’s all.  Now your application is running and you can work with it as you wish until the time will come to put it into the background when you have to press ctrl+a+d After that you will see following output.

tnk@charon:~$ screen top

Which will say to you that the app is running successfully in the background. OK that’s what we wanted. Now you can do whatever you want until the time will came to return to the app. Then you just hit the following command

tnk@charon:~$ screen -r

If you were running just one programme you will return immediately. If you put more to the background using screen the fallowing output will be shown.

tnk@charon:~$ screen -r
There are several suitable screens on:
7444.pts-0.charon (04/05/2009 11:59:38 PM) (Detached)
7327.pts-0.charon (04/05/2009 09:59:27 PM) (Detached)
Type “screen [-d] -r [pid.]” to resume one of them.

So it is obvious what you have to do you have to select the right one. Unfortunately I did not find any way how to identify the processes except for the time and date. So the command will look like this :

tnk@charon:~$ screen -r 7444.pts-0.charon

Update: There is a simple way how to change the the session name so you can get oriented in your detached sessions. The syntax is as in following example using -S parameter is for naming the sessions. So -S top names the session as top and then just type in the program name. The actual commands are below.

tnk@charon:~$ screen -S rtorrent rtorrent
tnk@charon:~$ screen -S top top

Now you have your detached sessions running and named so you can list them again with the same command as before but you will see the difference.

tnk@charon:~$ screen -r
There are several suitable screens on: (04/06/2009 04:00:00 PM) (Detached)
8763.rtorrent (04/06/2009 03:59:47 PM) (Detached)
Type “screen [-d] -r [pid.]” to resume one of them.

So for return to the right session just use the adequate command

tnk@charon:~$ screen -r 8763.rtorrent



This being said I’d like to proceed to why  did I bother to do all this.
And the answer is rTorrent – the cli BitTorrent client for Linux.

This client is one of the best in my opinion as I like light-weight functional stuff with rather simple user interface. If you know and like uTorrent from windows this client will be almost as good but not like uTorrent this can be run from bash.

So how to run rTorrent. Just download your favourite torrent and run command

tnk@charon:~$ rtorrent whatever_your_torent_is.torrent

This will add the torrent into the queue and open the main “window” of the app. There are few controls you would like to change/use.

main operations:
ctr+q                   exits the app
ctr+q ctr+q      forces the app to exit
ctrl+d                 on active torrent will stop the activity on it
ctrl+d ctrl+d   on active torrent will remove the torrent from queue
<enter>             adds new torrent – you can use for path completion

Speed throttling
asd/ASD            adds 1,5,10 KB to the limit in up/down direction
zxc/ZXC            removes 1,5,10 KB from the limit in up/down direction

for details and queue browsing use arrow keys
right arrow torrents details
left arrow main screen

These are just the basic controls but what makes the rTorrent such a powerful client is that it can be configured in way you are used to from clients like Azureus or uTorrent but in text file. What all you can set read on the developer’s pages (where is also a sample of the config so you do not need to reinvent the wheel)  or here. But things like scheduled check for new torrents in selected directories, port settings or various limits are there.

There is one minor warning the current version of rTorrent which is included in Debian Lenny is not supporting DHT. So you have to leave this part of rTorrent’s config commented.

So screen together with rTorrent is quite powerful and handy combination for downloads on a remote machines. If there will be some reason I will write more about this topic.

As a last thing I’d like to mention is that all these programmes are in standard Debian Lenny distribution so no need for compiling or packaging.

Update: Just recently I have found that very extensive article about this topic is on arch-linux wiki so if you are interested in more options look there

Leave a Reply

Your email address will not be published. Required fields are marked *