Tuesday, August 26, 2008

Display your Arch Linux theme information automatically

Often when you come across a desktop screenshot in the forums/websites a myriad of question flows through your mind. "What theme is that? Lovely icon, if only I knew its name. Wow, but is it openbox or fluxbox or something else?" Now while its possible to mention all the details while posting the picture, its a hassle everytime you post a screenie in the monthly screenshot thread.

Instead, wouldn't it be better if we could somehow automatically include all the details in the screenshot itself? Yes, it would be and its possible just by using these two small scripts.




Edit the path to the logos.pl file here in the info.pl file
require '/home/sujoy/bin/logos.pl';


Now all you have to do is put the two files in the same directory and make the info.pl file readable and executable
$ chmod 500 info.pl

and make the logos.pl file readable
$ chmod 400 logos.pl


You can run the script from inside the directory as
$ ./info.pl


Here is a picture of the script in action


While the logos.pl file given here is for Arch Linux only, you can modify it to suit your distro and use the info.pl script along with it.

note: the scripts are not mine, the name of the author is mentioned in the script itself

Tuesday, August 19, 2008

10+ essential programs for the terminal junkie

The command line in a Linux system is one area that a new user despises and a long time pro seeks to master. While the shell is powerfull in itself, there are still some tasks that requires a separate program, for instance playing music, IMs, browsing the web, etc.

Lets take a look at some command line applications that does the job and does it well.


screen


Simply put, screen is a window manager that allows you to run multiple terminals from a single terminal process. It allows session-sharing, persistence and multiple windows. One can simple detach a session and then later attach it to continue a previous work without starting all over again. Specially usefull without a Xession as it allows more than 6 terminals, by multiplexing.


vim


Vim, though not the most intuitive of all, is a power packed text editor that is ideal for programming as well as for general text editing. Vim is modal in nature and includes no menus or mouse features. All the features are accessible via commands and keybindings. Vim also supports autocompletion for various programming languages via add-on scripts called omnifunc. A built in tutorial vimtutor is included, that helps in getting started. While the age old war between vim and emacs continues, both are well accepted in the Linux community.


Latex


Latex is a proffessional typesetting system designed for technical, scientific, mathematical documentaion. It is however a language that accesses the power of Tex, hence a suitable text editor is needed along with it. Latex, used mostly for desktop publishing and word processing, can also be used to create raster graphics.


elinks


Complete with table and frame rendering,tab support,color support,multiple items download in the background, elinks is a powerpacked web browser. The arrow keys can be used to browse through the links, and by using the "." key, one can also just type in the link number to open it. Great for browsing over ssh or just for a low bandwidth connection.See this list for other text based web-browsers


alpine


Alpine, based on the old pine mail client and licensed under the apache license, is a simple yet efficient text-based mail client. Unlike mutt, it doesn't need any external program to fetch mails and with its context-sensitive help, is very easy to use. Mutt is another viable alternative to alpine.
According to an interview published in Lifehacker, Linus Torvalds himself uses alpine.


irssi


Supports add-on perl scripts, auto logging and can also be themed. It has highly configurable keybindgins that ensures maximum customizeability. Also while irssi is specifically targeted towards IRC, when combined with bitlbee, it adds IM functionality also. One point for bitlbee users though, its better not to use public servers for security reasons. WeeChat is a viable alternative to irssi, you may also want to have a look at it.


ncmpc + mpd


Music Player Daemon (MPD) is based on the client-server architecture. The daemon stays in background and actually plays the tracks while the client(ncmpc) is used to control the playlist, sounds etc. The real advantage of mpd over other console based players like cmus, moc, etc is that it allows remote access, that is, the daemon can run in one computer while the client connects to it from a remote computer to control it. Combined with icecast, mpd can be converted into a audio streaming server. These are the other clients supporting mpd.


mplayer


MPlayer supports a wide range of supported output drivers, Xv,X11,DirectFB,etc. It plays most audio and video file types and can be used with or without a GUI frontend. Enabling framebuffer allows one to watch videos on mplayer without even starting a X session. Also included in the mencoder which is a video filtering, decoding, and encoding tool that works from the command line.


rTorrent


rTorrent, as is obvious from its name, is a bittorrent client with ncurses interface. It can watch a directory for torrent files and automatically download them, and if required move them to a separate directory. It supports session control,DHT along with other features and allows the user to select the files to download if the torrent consists of more than one file. rTorrent can be operated over ssh and thus can be used in a torrent slave. For instructions on setting up rTorrent follow K.Mandla’s article.


midnight commander


Midnight Commander is a two-panel file manager, that can open RPM or other archive packages without extracting, serve as a FTP or FISH client and rename multiple files. It has a ncurses based interfaces and is useful for file manegment in a console or via ssh.

I left out those that are shipped with most distros like nmap, htop, etc. Other console applications that maybe of interest include the fbida project, bandwidth monitor, youtube-dl, MS word reader.

Did I miss your favourite application? Tell me about it.

note: images taken from wikipedia or the application's home page

Monday, August 18, 2008

Moving on with python... get rid of any file

Ok this might look pretty silly,but I feel compelled to delete every Thumbs.db file that I tend to recieve from my friends. The file is generated in windows systems when one views the contents of a directory in "Thumbnail" or "Filmstrip" mode. The idea is to store the settings with regard to thumbnail and filmstrip view, as well as to keep a cache of the thumbnail of image and video files.

Whenever I borrow some pics or movies from my friends' DVDs, etc, these tiny little files also gets copied over. Now these are completely harmless as far as I know, but since they are of no use in Linux, I dont want them in my system.

Now, deleting a particular file inside every directory is a pretty troublesome task. Hence, I wrote myself a neat little python program that searches directories, passed to it as the absolute path, for the file mentioned and prompts for its removal.

Here goes my first ever self-written-useful-program.


#!/usr/bin/env python
import os
import sys

def del_thumbs_db (start_path):
for i in os.listdir (start_path):
if i=="Thumbs.db": # change to whatever file you want to remove
del_file = os.path.join (start_path, i)
print """
FILE : %s
""" % del_file
#comment out next two lines to removing prompting for each file
ch = raw_input("\nDelete the file ? ")
if ch == "y" or ch == "Y":
os.unlink (del_file)
i = os.path.join (start_path, i)
if os.path.isdir (i):
del_thumbs_db (i)

if len (sys.argv) != 2:
print """thumbs needs an argument..!!
Usage: thumbs [absolute path]"""
quit ()
path = os.path.abspath (sys.argv[1])
if os.path.isdir (path):
del_thumbs_db (path)
else:
print "path is not a directory ..."


Usage is pretty simple, save the program in a file (say, delete) and make it executable by
# chmod +x /path/to/delete

then run the program like this,

$ delete /absolute/path/to/directory/

The program starts searching for the file mentioned, from the directory passed as argument and goes on recursively to search in subdirectories.

Now a simple bash script like this one
rm `find /home/user/path -name 'pattern_to_search_for'`

would have been easier and better suitable for this task, however, that way I was never going to really get on with python. Hoping for some python expert to come along and provide some insight on this code.

Your comments are welcome. :)

Sunday, August 17, 2008

New to Linux? Make sure you bookmark these

New users in the Linux/Unix land are often confused and overwhelmed by the marked differences between the OS they come from and Linux. It takes some time gettting used to the new environment and the new way of doing things. Now while you are at it, take a look at these websites that are there to help you make the smooth transition, these provide extensive documentation to step-by-step howtos, and also community support.

Now while there are scores of material worthy of a mention, in the internet, I list the ones that every new user must bookmark (or atleast take a look at).


Distrowatch.com

Image Hosted by ImageShack.us

Here, you can find reviews and news about the most popular Linux/Unix distributions as well the new ones that just came in. Regularly updated upon each new version release of the distributions and also ranks them based on page views. Overall, this is the place to be in if you are trying to find a new distro to try out.

The Linux Documentation Project
Image Hosted by ImageShack.us

This site contains tons of materials to get you started or help you if you get stuck in the middle. From HowTos, guides, manpages, to Linux Gazette, an online magazine, this site is so full of information that its almost overwhelming in itself.

The Gentoo Wiki
Image Hosted by ImageShack.us

While the name might indicate that its specifically for the gentoo users, its not. The guides and howtos here can be related to most of the distributions with minor modifications like the actual download process involving the package managers, etc. Here one can find guides for a broad range of topic covering almost all aspect of Linux, from kernel configurations to wine and cedega, the gentoo wiki is for all linux users, irrespective of the choice of distribution.

The Ubuntuforums
Image Hosted by ImageShack.us

Once again I mention something attached to a particular distribution. However, ubuntuforums, as all of its members knows, isn't just a place for ubuntu users. The sub forums in the other OS sections exists as well, although the real charm is the sheer number of people active here and the awesome community section. Nice place to get to know fellow linux users while engaging in some non-technical chat. Offcourse, you can also take a peep and find yourself comfortable in the programming section solving challenges. Its just a fun place to be here, even for the non-ubuntu users.


Linux Manpages

Image Hosted by ImageShack.us

As the name suggests this site is dedicated to the manpages. No distraction at all as you dive into man to find that lost option or switch. Specially beneficial for the ones who dislikes reading from the terminal. The ability to search and click also adds charm to the whole man page reading thing.


Other than these, you may also register to the forum or mailing lists of the distro you are using. IRCs are again a good place for support and discussion. Thats it fellows, read the FAQs, learn how to google and soon you will have a wealth of information at your disposal to make computing fun and comfortable.
Your comments are welcome. :)

Friday, August 15, 2008

Diving into python and projecteuler

While solving a trivial problem presented at ProjectEuler, I went for python instead of C, which is my usual language of preference. I am quite new in python programming though, hence the interest in applying my newly accuired skills.

The problem was pretty straightforward,
What is the largest prime factor of the number 600851475143 ?

Now considering the number being too big and my new found interest in python, it was an obvious choice. So, here is my solution,

#!/usr/bin/env python
import math

NUMBER = 600851475143
i=int(math.sqrt(NUMBER))

while i>1:
if not (NUMBER%i): # so i is a factor of NUMBER
# checking if i is prime
flag = 0
if not ((i+1)%6) or not ((i-1)%6):
for j in range (2,int(math.sqrt(i))+1):
if not (i%j):
flag = 1
break
else:
flag = 1
if not flag: # i is prime, so i is the answer
break
i -= 1
print "The largest prime factor is %d" % i


All this while, when I was reading about python, I kept stumbling into language purists who would say that interpreted languages are no good and that they take up too much time. Hence I put my code to the time test and this is the result,

[ProjectEuler]$ time python 003_problem.py
The largest prime factor is 6857

real 0m0.827s
user 0m0.816s
sys 0m0.006s
[ProjectEuler]$


I think, considering the hassle of computing big numbers like this one in other languages, specially ones like C, and the fact that it still gets interpreted in about 0.827 seconds speaks volumes about its power. For all I know, experienced python programmers might still be able to improve the solutions.

Monday, August 11, 2008

Iptables and TruStealth

I saw a thread in ubuntuforums.org yesterday, its been there since a week now, but somehow I missed it earlier. Anyways, its about the Shields UP test in Gibson Research Corporation's website.

Testing for all service ports, got me nowhere near true stealth. This is what I got after the first test,

Solicited TCP Packets: RECEIVED (FAILED) — As detailed in the port report below, one or more of your system's ports actively responded to our deliberate attempts to establish a connection. It is generally possible to increase your system's security by hiding it from the probes of potentially hostile hackers. Please see the details presented by the specific port links below, as well as the various resources on this site, and in our extremely helpful and active user community


Unsolicited Packets: PASSED — No Internet packets of any sort were received from your system as a side-effect of our attempts to elicit some response from any of the ports listed above. Some questionable personal security systems expose their users by attempting to "counter-probe the prober", thus revealing themselves. But your system remained wisely silent. (Except for the fact that not all of its ports are completely stealthed as shown below.)


Ping Reply: RECEIVED (FAILED) — Your system REPLIED to our Ping (ICMP Echo) requests, making it visible on the Internet. Most personal firewalls can be configured to block, drop, and ignore such ping requests in order to better hide systems from hackers. This is highly recommended since "Ping" is among the oldest and most common methods used to locate systems prior to further exploitation.



It was only after that, did I realise that I had no active firewall running! Iptables was not running at all. So I scoured the internet for some iptables guide. An hour and half later of reading tutorials and man-pages, it seemed quite interesting. Hence, instead of going for some already-available scripts, I set up my own rules.


# Generated by iptables-save v1.4.0 on Mon Aug 11 21:32:50 2008
*mangle
:PREROUTING ACCEPT [8311:783078]
:INPUT ACCEPT [8311:783078]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4155:229785]
:POSTROUTING ACCEPT [4167:230625]
COMMIT
# Completed on Mon Aug 11 21:32:50 2008
# Generated by iptables-save v1.4.0 on Mon Aug 11 21:32:50 2008
*nat
:PREROUTING ACCEPT [4219:185647]
:POSTROUTING ACCEPT [1808:81444]
:OUTPUT ACCEPT [1808:81444]
COMMIT
# Completed on Mon Aug 11 21:32:50 2008
# Generated by iptables-save v1.4.0 on Mon Aug 11 21:32:50 2008
*filter
:INPUT DROP [6:336]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [19:1289]
:OPEN - [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -j OPEN
-A INPUT -i lo -j ACCEPT
-A OPEN -s 192.168.1.0/24 -i eth0 -p tcp -m multiport --dports 21,22,23,3306 -j ACCEPT
-A OPEN -s 192.168.1.0/24 -i eth0 -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A OPEN -p tcp -m tcp --dport 65000:65010 -j ACCEPT
-A OPEN -p udp -m udp --dport 65000:65010 -j ACCEPT
COMMIT
# Completed on Mon Aug 11 21:32:50 2008


I opened the ports for ping, ftp, ssh, telnet and mysql server only for my local network and that 65000:65010 port range is for torrents. Other than that everything else is blocked unless its already established or related to an established connection, or if the interface in question is the loopback. And as I wished for, this time around I got a perfect "TruStealth" rating. Here is the complete summary,

Your system has achieved a perfect "TruStealth" rating. Not a single packet — solicited or otherwise — was received from your system as a result of our security probing tests. Your system ignored and refused to reply to repeated Pings (ICMP Echo Requests). From the standpoint of the passing probes of any hacker, this machine does not exist on the Internet. Some questionable personal security systems expose their users by attempting to "counter-probe the prober", thus revealing themselves. But your system wisely remained silent in every way. Very nice.

Thursday, August 7, 2008

Debian Lenny frozen!

Debian Lenny (Debian 5.0) has been frozen, meaning automatic transition of new version of packages from the unstable branch (Debian Sid) has been stopped. So a stable release is near. The Debian mailing list puts is this way, "Lenny is still scheduled to be released in September 2008."

I am currently using Debian as a dual boot with Zenwalk on my desktop PC. Its Debian Testing (Lenny), so I am beginning to wonder, if I should just stay with Lenny since everything is just working perfectly, or should I upgrade to the latest Testing branch after Lenny becomes stable.
As for people using Debian Etch, there has been another upgrade, called "etch and a half", once again from the mailing list,

While this update mainly includes security fixes and fixes for severe bugs,the Debian project has for the first time also added support for newer hardware by adding new drivers with updated Linux kernel and X.org packages. The new drivers are optional and the old versions will still be supported.


Personally, I am of the opinion that Debian Stable packages gets too old for desktop usage, hence I use the Testing branch. However, this time around I am going to stick around with Lenny to see if Debian Stable gets too old too quickly. Now, if things work, then there shouldn't be a problem.

Tuesday, August 5, 2008

Reasons not to use Linux

Now while scouring the internet you will find billions of posts as why to use linux and finally make the shift from your closed source OS, two of which I have written myself. However, this time around let me tell you or rather convince you "why NOT to install linux in your PC".

1. Please do refrain from installing linux in your PC if you are used to spoonfeeding. While its perfectly acceptable if a new user asks about whats KDE and Gnome, it gets irritating if after telling you to edit xorg.conf in your third month into linux, you ask where that file is!

2. Are you afraid of text files? No matter its opened in vim or gedit? Then I am sorry to say, you are better off with your fancy drop-down-menu GUI system. Spare us the trouble of porting every console app or configuration method into clumsy GUI subsystems.

3. If you think having too many choices is confusing and that the linux community has to justify why there are hundreds of distributions to confuse you, besides around 20 different window managers, then either make an informed decision or ask for help in choosing one, but please do not whine about how confusing it all is. Otherwise think thrice before switching.

4. "OMG! there is no real flow of money behind linux projects. So they must be trash!!" - if this is what you believe, then kindly do some web-research on GNU, FOSS, and opensource (you know like wikipedia, google ...). Come back later when you are convinced that free doesn't necessarily means bad.

Just my views though, however, seeing the same whining posts in different forums and communities, I wonder, if people trying out a different OS really wants to do that. They just seem to expect the same things done in the same way from a different system! Its like asking why streets in Norway are any different from the ones in China.

Sunday, August 3, 2008

Zenwalk 5.0 .. yes a bit old but..

I just found that old (well not that old) Zenwalk 5.0 CD lying around and hence took it for a spin. Some 20 minutes or so later I am starring at a XFCE desktop. Not bad, but its the same old blue color everywhere. Now while I have been using Linux for a while now, it was mostly awesome, xmonad or openbox, with Gnome in the earlier days. The first time I used XFCE, and I was impressed.

Zenwalk brings smoothness to the desktop. Apps are well integrated and the choice of apps are good too. No more bulky open-office or evolution. Instead I get abiword, gnumeric, ice-dove (thunderbird without the brand name) and gmusic-browser, which I must say is gtk's best answer to amarok.

Some quirks are there like the package-management for instance, dont even try to compare it with pacman or apt! But then anyone trying a slack or its derivative already knows that. It may even be a plus point since every thing is under manual control. Gslapt was ok but not upto the mark. Netpkg comes default, and while it does the job, I find manual control to be much better in zenwalk.

Stability is something I cannot really report on in a weeks time, so I will post on that later. However, it does feel really smooth amd fast and is good in resource management. Also solves the hal issues with slackware 12 (which got rectified in 12.1 I heard).

I already posted some screenshots in the screenshot gallery in deviantart. So let me know what you think of it, if you are using Zenwalk or are planning to use it. Offcourse you should go for the 5.2 version, I used the old one because I didn't feel like downloading again.