Unix learning tips from Miguel de Icaza

Miguel de Icaza – a very well known programmer in Linux circles – shares a few tips to having a better experience in Unix environments.  Here is a summary of what he recommends:

  • Read, learn, and memorize the “Unix Programming Environment” book by Kernighan and Pike.
  • Read and learn the “Unix for the impatient” book by Abrahams and Larson.
  • Learn Emacs.
  • Use Midnight Commander, which Miguel is the author of.  Here is a handy manual.
  • Keep a copy of the “Unix Power Tools” book nearby.
  • Learn touch typing.

These are all solid recommendations.  I’d suggest to use Vim instead of Emacs, but that’s more of a personal preference – learn one or the other.  And I can’t agree more on the touch typing.  That is indeed the most important skill that you will ever learn.  Right next to the camp fire starting.

At this point you might be thinking “I am awesome”, “the world is my oyster” and “Avatar 3D was not such a bad movie”.

But unless you touch-type, you are neither awesome, nor you are in a position to judge the qualities of the world as an oyster or any James Cameron movies.

You have to face the fact that not only you are a slow typist, you do look a little bit ridiculous. You are typing with two maybe three fingers on each hand and you move your head like a chicken as you look at you alternate looking at your keyboard and looking at your screen.

Do humanity a favor and learn to touch type.

Best shell alias ever

I came across the best shell alias ever:

alias up="cd .."

This is one of those things that make me go “Why didn’t I thought of it earlier? And myself?”.

In order to add some value to this post, here are my two mostly used aliases:

alias pd="perldoc"
alias pdf="perldoc -f"

Working with named pipes in Perl

The collegue of mine came across a problem that developed into an interesting solution that I decided to share with the world. Actually, I think the world is pretty much aware of the solution, but just in case that I will ever be looking for this solution again, I’ll have it handy here.

The task at hand was to do some processing of the logs on the fly. The syslog was configured to filter the appropriate logs into a named pipe and a Perl script was written to read from the said pipe and do all the processing.

The original piece of code looked something like this:

open (SYSLOG, "<$named_pipe") 
  or die "Couldn't open $named_pipe: $!\n";

while () {
  do_processing($_);
}

close(SYSLOG);

The problem came with syslog daemon restarts. Every time the syslog was stopped, the EOF was sent to the pipe and the script stopped reading it.

Continue reading Working with named pipes in Perl

Analysis of two perl lines

Today I saw these two lines in one backup script that was written in perl:

my $d = (localtime())[6];
$d = $d=~/[067]/ ? 0 : $d % 2 + 1;

Does this look cryptic to you? Probably not. But I wanted to write something and thought that these two lines won’t be that obvious for everyone out there. So I decided to explain exactly what goes on.

Before I start, I have to say that these are not just any two random lines of perl code. These are very useful lines that provide a short and elegant solution to a rather common problem. Read on if you interested.

Continue reading Analysis of two perl lines

Learn UNIX shell

There is a very nice shell tutorial at LinuxCommand.Org.

Not only it covers all the stuff like conditions, loops, and functions, but it also provides a list of resources to continue your education on the matter. The language is simple and the examples are clear.

There is also a nice explanation on how to start writing scripts once you feel more or less comfortable with the command line itself. And, of course, you can find few ready made scripts in the script library over there.

Strongly recommended for shell beginners.