Leia Mais…
Wednesday, December 31, 2008
Perl 5.10 for People Who Aren't Totally Insane
It's enough to make you think that 5.10's changes are just for the hard-core perl hackers, but it couldn't be further from the truth! The new version of Perl is full of changes that are easy to use and pack lots of useful benefits for doing plain old every day Perl programming.
How to set up a home email server (without being spammed to death)
by RedHat Magazine Editorial Team
by Stuart Kirk
Why host your own mail?
There are many reasons to host your own email. Perhaps you don’t like the limits placed on you by your current ISP. Maybe they aren’t willing to host the domain you want, or give you the access you want. And if they do fit your needs, they want to charge a small fortune. Maybe you want complete privacy. Or perhaps you just want to access your email from anywhere using a web-based frontend. The list goes on and on…
There are several many ways to accomplish this task. Everyone has their preferred MTA program, but for the purposes of this article, we’ll use sendmail. The same can also be done using postfix, or exim. Each approach has its own merits.
Let’s get started.
Requirements
I’m going to assume that when setting up your email server, you’ll want to do so with your own personalized domain name. While I’m not going to explain how to register a domain name, if you’re unsure, you can always click here for an explanation on how to do so. The domain that I’ll refer to in this article will be mailjunkie.org, with the hostname of the machine being server1. I’m also going to assume, at least for now, that your IP address is static, and your inbound and outbound connections on port 25 are unrestricted.
The first thing you’ll need will be your physical infrastructure: a computer running Red Hat® Enterprise Linux®, a high-speed Internet connection, and a registered domain name. After you have installed Red Hat Enterprise Linux on your system you will want to make sure the following packages are installed:
- dovecot
- sendmail
- sendmail-cf
- squirrelmail
- perl
- gcc
There are other packages we will need later on.
Configuring your mail exchanger
After you’ve set up your domain name with your favorite registrar, you will need to configure your Mail Exchanger (MX) record. You will do this through your domain registrar. After you find the page that will allow you to set up your MX record, I recommend you do the following:
- Setup the MX record in the format mx.yourdomain.com. So, for our
example domain, we would choose “mx.mailjunkie.org” as our MX record. - Configure your mail exchanger with a priority of 0 (zero).
- Create a hostname/address (A RECORD) that associates mx.mailjunkie.org with the IP address that your ISP has assigned you.
After you’re done setting this up, you can test to see if it worked by dropping to a shell prompt and issuing the following command.
If your setup is correct, you should see some synthesis of:
[root@server1 ~]$ nslookup -query="MX" mailjunkie.org
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
mailjunkie.org mail exchanger = 0 mx.mailjunkie.org.
Authoritative answers can be found from:
mailjunkie.org nameserver = dns4.name-services.com.
mailjunkie.org nameserver = dns5.name-services.com.
mailjunkie.org nameserver = dns1.name-services.com.
mailjunkie.org nameserver = dns2.name-services.com.
mailjunkie.org nameserver = dns3.name-services.com.
mx.mailjunkie.org internet address = 1.2.3.4
dns1.name-services.com internet address = 69.25.142.1
dns2.name-services.com internet address = 216.52.184.230
dns3.name-services.com internet address = 63.251.92.193
dns4.name-services.com internet address = 64.74.96.242
dns5.name-services.com internet address = 70.42.37.1
Please note that it may take some time for the changes you have made to propagate through DNS. If you check immediately after you make these changes and do not see your settings reflected, try a few minutes later.
Configuring s`endmail
The next step will be setting up and configuring sendmail. The process for doing this is somewhat arduous, so please read all of the information presented before beginning.
The file /etc/mail/sendmail.cf is the main configuration file
for sendmail. This “cf file” contains the directives that sendmail will
operate under. Much more friendly, however, is the file /etc/mail/sendmail.mc.
This “mc file” should be the base that you use for making all changes
to sendmail’s operating parameters. Additionally, the “cf file” is
created from the parameters listed in this “mc file”. Red Hat has done
a wonderful job creating a template for your “mc file” and as such,
the bulk of the changes that need to be made are just editing
directives that are already present. Below are the directives that you
must search for within your “mc file” and change accordingly:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl - change to - DAEMON_OPTIONS(`Port=smtp, Name=MTA')
LOCAL_DOMAIN(`localhost.localdomain')dnl - change to - LOCAL_DOMAIN(`emailjunkie.org')
dnl MASQUERADE_AS(`mydomain.com')dnl - change to - MASQUERADE_AS(`emailjunkie.org')
dnl FEATURE(masquerade_envelope)dnl - change to - FEATURE(`masquerade_envelope')
dnl define(`SMART_HOST',`smtp.your.provider') - change to - define(`SMART_HOST',`your.trusted.smtp.relay')
Add in the line:
FEATURE(`allmasquerade')
Please note: You must replace “your.trusted.smtp.relay” with the name
of your ISP’s SMTP server. While omitting this change will not prevent
your e-mail server from operating properly, there are several filters
that are often employed that will block any “at home Cable, xDSL” port
25 connections for fear of spam.
After you have made these changes and are back in your server’s /etc/mail directory, run the command “make -C /etc/mail“. This compiles the “cf file” based on the instructions given in your “mc file”. Each time you make a change to your “mc file”, you must re-compile your “cf” file by issuing this command.
Edit your hosts file
Sendmail will make use of your /etc/hosts file, so you need to modify it so that mail is routed properly. Edit your /etc/hosts file and include a line that reads:
1.2.3.4 server1.mailjunkie.org
where 1.2.3.4 is the IP address that is assigned to you by your ISP.
Obtaining and installing MailScanner, SpamAssassin, and ClamAV
Out of the box, sendmail works to deliver mail only. As such,
you are quite vulnerable to spam and virus threats that will very
quickly become a problem if you do not take action early. These
three applications will process received mail and scan it for viruses
and spam before it is delivered. You can download the latest versions
of these applications from mailscanner.info.
Download the latest “for Red Hat, Fedora, and Mandrake Linux (and other
RPM-based Linux distributions)” release of MailScanner, as well as the
latest “ClamAV and SpamAssassin easy installation packages.”
The installation package for all of the applications is quite good; it
will resolve most of the dependencies that are required to gunzip, un-tar, and run both of these applications. As MailScanner checks for the presence of ClamAV when it installs, I recommend installing the SpamAssassin/ClamAV package first:
[root@server1 ~]# wget http://www.mailscanner.info/files/4/install-Clam-0.88.5-SA-3.1.7.tar.gz
[root@server1 ~]# tar zxvf install-Clam-0.88.5-SA-3.1.7.tar.gz
[root@server1 ~]# cd install-Clam-0.88.5-SA-3.1.7
[root@server1 install-Clam-0.88.5-SA-3.1.7]# ./install.sh
There will be significantly more output produced as ClamAV and
SpamAssassin are installed on your system. After they are installed,
you should see a message similar to this:
Now you need to install:
1) Razor-agents-sdk and Razor2 from http://razor.sourceforge.net/ and
2) DCC from http://www.rhyolite.com/anti-spam/dcc/
Follow the links above to download the three applications that will
assist SpamAssassin in processing your email. Below are the list of
commands I used to download and install them. For clarity, I have
removed all of the output that was produced for each command. You can
expect to see significantly more than what I have listed. What
is shown are the base commands to download, compile, and install the
helper applications.
[root@server1 ~]# wget http://umn.dl.sourceforge.net/sourceforge/razor/razor-agents-sdk-2.07.tar.bz2
[root@server1 ~]# wget http://umn.dl.sourceforge.net/sourceforge/razor/razor-agents-2.82.tar.bz2
[root@server1 ~]# wget http://www.rhyolite.com/anti-spam/dcc/source/dcc.tar.Z
[root@server1 ~]# bunzip2 razor-agents-sdk-2.07.tar.bz2
[root@server1 ~]# tar xvf razor-agents-sdk-2.07.tar
[root@server1 ~]# cd razor-agents-sdk-2.07
[root@server1 razor-agents-sdk-2.07]# perl Makefile.PL
[root@server1 razor-agents-sdk-2.07]# make
[root@server1 razor-agents-sdk-2.07]# make test
[root@server1 razor-agents-sdk-2.07]# make install
[root@server1 razor-agents-2.82]# cd ..
[root@server1 ~]# bunzip2 razor-agents-2.82.tar.bz2
[root@server1 ~]# tar xvf razor-agents-2.82.tar
[root@server1 ~]# cd razor-agents-2.82
[root@server1 razor-agents-2.82]# perl Makefile.PL
[root@server1 razor-agents-2.82]# make
[root@server1 razor-agents-2.82]# make test
[root@server1 razor-agents-2.82]# make install
[root@server1 razor-agents-2.82]# cd ..
[root@server1 ~]# tar zxvf dcc.tar.Z
[root@server1 ~]# cd dcc-1.3.42/
[root@server1 dcc-1.3.42]# ./configure
[root@server1 dcc-1.3.42]# make install
[root@server1 dcc-1.3.42]# cd ..
Now that these applications are installed, we can proceed to download, compile, and install MailScanner.
[root@server1 ~]# wget http://www.mailscanner.info/files/4/rpm/MailScanner-4.56.8-1.rpm.tar.gz
[root@server1 ~]# tar zxvf MailScanner-4.56.8-1.rpm.tar.gz
[root@server1 ~]# cd MailScanner-4.56.8-1
[root@server1 MailScanner-4.56.8-1]# ./install.sh
As with ClamAV and SpamAssassin, there will be a significant amount of output produced. You should, however, end up with:
Preparing... ########################################### [100%]
1:mailscanner ########################################### [100%]
Good, SpamAssassin site rules found in /etc/mail/spamassassin
To activate MailScanner run the following commands:
service sendmail stop
chkconfig sendmail off
chkconfig --level 2345 MailScanner on
service MailScanner start
Now, before we issue the commands to start MailScanner, please be sure within the /etc/MailScanner/MailScanner.conf file, the following lines exist:
- Virus Scanners = clamav
- Use SpamAssassin = yes
These directives tell MailScanner to use ClamAV to scan for
viruses, and SpamAssassin to process email for spam. From here we can
issue the commands below to start MailScanner and begin processing
email. I highly recommend you view the /var/log/maillog
file while starting MailScanner and scan the output for undesirable
actions, as well as to verify that Mail is being processed properly.
[root@server1 MailScanner-4.56.8-1]# service sendmail stop
[root@server1 MailScanner-4.56.8-1]# chkconfig sendmail off
[root@server1 MailScanner-4.56.8-1]# chkconfig --level 2345 MailScanner on
[root@server1 MailScanner-4.56.8-1]# service MailScanner start
Setting up web access to your email
I am going to assume that you have your apache server running.
If you don’t you should review the steps to install and configure apache.
After you have verified that your web server is running, execute the following commands at your shell prompt:
[root@server1 ~]# chkconfig dovecot onThese commands will start your IMAP server, which will be used by the Squirrel Mail package to access the mail stored on your server. With good luck, you should now have a fully functional, protected email server running. Keep in mind you may need to make changes to your /etc/mail/local-host-names file and /etc/mail/relay-domains file. Each case will be different, so I recommend you review your /var/log/maillog file and use the links provided to perform any final setting changes. Leia Mais…
[root@server1 ~]# service dovecot start
10 things every Perl hacker should know
As one of the easiest programming languages to use for whipping up quick, effective code for simple tasks, Perl attracts new users easily and has become an important and popular tool for getting things done. Before jumping fully into Perl programming, though, there are a few things you should know that will make your life easier, both when writing code and when asking for help from Perl experts.
1. Perl is not an acronym
Perl is sometimes known as the Practical Extraction and Report Language, because it's very practical, and it is very good at extracting data and creating reports using that data. It is also known humorously as the Pathologically Eclectic Rubbish Lister, for reasons that might become obvious after you've used it for a while. Both of these phrases are equally "official" and equally correct, but the language is not PERL. It was named Perl before either of those phrases was invented, and the language is in fact not technically an acronym at all. When speaking of the language, call it Perl, and when speaking of the parser (the interpreter/compiler), it is acceptable to call it perl, because that is how the command used to run it is spelled. One of the quickest ways to get identified as a know-nothing newbie when talking to Perl hackers is to call it PERL.
2. There is more than one way to do it
One of the main mottos of the Perl language and community is TIMTOWTDI, pronounced "Tim Toady". This one really is an acronym, and it stands for There Is More Than One Way To Do It. It's true of Perl on many levels, and is something important to keep in mind. While some ways to do something are often better than other ways to do the same thing, you can be sure that for pretty much everything you can do with Perl, there is more than one way to do it.
3. Use warnings and use strict
Warnings and the strict pragma are important weapons in the Perl hacker's arsenal for debugging code. Warnings will not prevent a program from executing, but will give helpful information on how the code can be fixed up.
The strict pragma will actually prevent the code from executing if a strict approach to programming style is not used, such as lexically scoping variables. Once in a while, a program might be better off without the strict pragma, but if you're new to Perl it will surely be a long time before you learn to recognize such situations, and until then you should just use it.
A Perl script with warnings turned on in the shebang line and the strict pragma used, on a standard UNIX system, would start like this:
#!/usr/bin/Perl -wuse strict;
Warnings can also be turned on with a use statement, like this:
#!/usr/bin/Perluse strict;
use warnings;
A pragma, in Perl, is a preprocessor directive. In other words, it's an instruction sent to the compiler before the code is compiled for execution. Pragmas change how the compiler parses code.
4. Use taint checking
With the -T option on the shebang line of your program, you explicitly turn on taint checking. This is a security measure that checks all input for your program for "tainted" data, to help ensure that incoming data will not allow arbitrary code execution if a malicious user is trying to crack security on the system running your code. This is especially important in circumstances where you are using Perl/CGI scripts to process data from an HTML form on the Web. It can be combined with the -w option as -wT.
5. Use lexically scoped variables
You can use the my() operator to create variables using lexical scoping. In brief, this means that the scope of the variable is limited to the current context: if you declare a variable using my() inside a subroutine, the variable only exists inside that subroutine. The value of lexical scoping is that it protects different parts of modular code from one another.
For instance, if you're using a Perl module or library without knowing exactly what the code inside it looks like, using lexical variables can help to prevent accidentally assigning new values to variables that need to remain unchanged until later. It is especially important to use lexical scoping for your variables when writing modules and libraries in Perl. For those coming to Perl from other languages, you may know of the concept of lexically scoped variables as "private variables".
6. How to name your programs
Perl programs should have the appropriate file extension in their names. Many lower-quality Perl howtos simply use the .pl extension for everything, naming Perl scripts something like foo.pl. Technically, the .pl extension should be used for Perl libraries, not for executable Perl programs. For executable files, you should either use .plx or, if your operating system will allow it, no file extension at all. Perl modules, meanwhile, should use the .pm file extension. It is also considered good practice to use only alphanumeric characters and underscores in Perl script filenames, and to start those filenames with a letter (or underscore), similar to how you would start variable names.
7. How to use CPAN
The Comprehensive Perl Archive Network (CPAN) is a rich resource for finding freely available, reusable code. In particular, CPAN is where you'll find legions of Perl modules that can be used to enhance the functionality of your programs and reduce the time you spend writing them. The options you have for using CPAN vary from one operating system and Perl parser implementation to the next, but you can always browse CPAN using your Web browser. Perl implementations generally come with at least a command-line tool for installing Perl modules from CPAN.
8. How to use Perldoc
The online documentation for Perl is extensive and comprehensive, in the form of Perldoc. With Perldoc installed on your system, you can use it to access documentation on any of the standard Perl functions, installed modules, variables, and a slew of other things -- even Perldoc itself! It's like having one of the most complete programming reference books available right at your fingertips, for free, and searchable since it's in electronic format.
On some systems, Perldoc will be installed by default with Perl itself, and on others the process for installation should be self-evident. If you have problems getting Perldoc installed, you can always access the online Perldoc Website. Make sure you know how to use Perldoc, because it can make you a more effective Perl hacker in ways that just might surprise you.
9. Don't reinvent the wheel
You should use subroutines, modules, and libraries often. The point is to help you write code faster and keep that code from becoming unmanageable if you need the same functionality in multiple programs, or more than once in the same program. This is accomplished by separating blocks of code from the rest of your source code using subroutines, modules, and libraries. You're better off using a design for the wheel that already exists, rather than reinventing the wheel from scratch, most of the time. In addition, when you're reusing code from a subroutine, module, or library, and you need to improve that code somehow, you only need to change it in one place.
The term "subroutine" in Perl means roughly the same thing as "function" in C.
10. Regular expressions are your friends
Perl's regular expression syntax can help to make your source code look intimidating to the uninitiated, and as a result sometimes people new to Perl programming avoid regexen. This is, really, a mistake. Regular expressions add a great deal of power to the Perl programming language, often allowing the programmer to do something in three lines that might otherwise take fifty lines of code. Regular expressions are expressions made up of abbreviations for matching patterns in strings that can be used to find and manipulate smaller strings inside larger strings. It behooves the Perl hacker to learn regex syntax and learn it well.
Often Perl hackers and other programmers who use regular expressions will refer to them as "regexen" or "regexes" in the plural ("regex" singular). An alternate version of "regex" is "regexp", though why anyone would want to add that extra letter, making it more difficult to pronounce clearly, is beyond me.
Leia Mais…Building custom subroutines in Perl
Every programming language comes with its own built-in functions or subroutines—every time you print() or join() something in Perl, you're actually using a built-in subroutine. But Perl also allows you to define your own custom subroutines, so that you can save yourself some time and effort when performing common tasks. I'll show you why subroutines are useful, and how to create your own.
Advantages of subroutines
Subroutines are convenient for three reasons:
- They let developers break up long procedural scripts into smaller, easier to understand fragments. This makes code easier to debug, and simplifies locating the source of errors.
- By identifying commonly-used tasks and then encapsulating those tasks into independent packages, subroutines make code reuse a reality. It's not uncommon for many Web developers to maintain their own library of commonly-used subroutines and import them whenever needed to quickly accomplish common tasks.
- A subroutine is created once but invoked many times. So if a code update is needed in the future, the changes can be done in one spot (the subroutine definition) while the subroutine invocations remain untouched.
Defining a subroutine
Here's a simple example of a subroutine:
# define subroutinesub makeJuice
{
print "Making lemon juice...";
}
Every subroutine follows a few basic rules:
- The subroutine definition begins with the "sub" keyword, followed by the name of the subroutine. This name is what you use to invoke the subroutine in your scripts. The name may optionally be followed by parentheses.
- The code that makes up the subroutine is enclosed within curly braces. This code is regular Perl code—you can use variables, loops, conditionals and all the usual Perl constructs inside it.
- Subroutines may appear anywhere in a Perl script, or may even be imported from external files.
To call a subroutine, invoke it by preceding its name with an ampersand (&):
# call subroutine&makeJuice();
When the Perl interpreter sees this call, it looks for the subroutine named makeJuice() and executes it. You can invoke the same subroutine as many times as you like. In this particular example, we call the makeJuice() subroutine four times:
#!/usr/bin/perl# define subroutine
sub makeJuice
{
print "Making lemon juice...\n";
}
# call subroutine
&makeJuice();
&makeJuice();
&makeJuice();
&makeJuice();
The above script produces the following output:
Making lemon juice...Making lemon juice...
Making lemon juice...
Making lemon juice...
Of course, there will come a time when you're fed up with all that lemon juice and would prefer something different. That's why subroutines can accept arguments, user-defined values passed to the subroutine when it is called and then processed by the code inside that subroutine. Let's see how to pass arguments to a subroutine.
Passing arguments to a Perl subroutine
Suppose I would like to give the makeJuice() subroutine more intelligence by telling it which flavor of juice to make:
&makeJuice("strawberry");Invoking a subroutine with an argument is the easy part—I still need to write the code that accepts the argument and does something with it:
sub makeJuice{
# retrieve the argument
my ($flavor) = shift (@_);
# and use it
print "Making $flavor juice...\n";
}
Perl has a somewhat unique way of handling subroutine arguments. All arguments passed to a subroutine are stored in a special @_ array. To retrieve the arguments, you have to look inside the array and extract them.
In the revised subroutine definition above, we use the shift() function to extract the first element of the array—the flavor—and assign it to a variable. This variable is then used in the call to print().
If you don't like the shift() syntax, you can also use "regular" array notation (indexing):
sub makeJuice{
# retrieve the argument
my ($flavor) = $_[0];
# and use it
print "Making $flavor juice...\n";
}
This next listing is another, slightly more useful example:
#!/bin/perl# define subroutine to convert between dollars and euros sub convertCurrency {
# get amount in $
my ($usd) = shift (@_);
# specify conversion rate
my $convRate = 0.82;
# print amount in euro
print "USD $usd = ", sprintf("%0.2f", $usd * $convRate), " EUR"; }
# invoke function with custom $ amount
&convertCurrency(100);
Here, the convertCurrency() subroutine performs the conversion between dollars and euros. The amount of USD to be converted is passed to the subroutine as an argument, and the output contains the corresponding amount in euros. Adding arguments to a subroutine thus immediately makes the subroutine more flexible and useful.
Sending back return values from a subroutine
Now, consider this variant on the convertCurrency subroutine from the previous example:
#!/usr/bin/perl# define subroutine
sub convertCurrency
{
# get amount in $
my ($usd) = shift (@_);
# specify conversion rate
my $convRate = 0.82;
# convert value
$euro = $usd * $convRate;
}
# invoke function with custom $ amount
print &convertCurrency(100);
Even though the subroutine does not print any output, it does return a value, which can be caught and used by the main script. By default, this value is the last expression evaluated by the subroutine.
If you like, you can override this return value by specifying your own with a "return" statement:
#!/usr/bin/perl# define subroutine to check file status
sub checkFileStatus {
# get file path
my ($file) = $_[0];
# test file status
# return 1 or 0
(-r $file) ? return 1 : return 0;
}
# invoke function with filename
# check return value and print appropriate message
$status = &checkFileStatus('/usr/local/mail.cf');
if ($status == 1)
{
print "File is readable\n";
} else {
print "File is not readable\n";
}
The "-r" test checks if the file is readable, and the subroutine sends back true or false to the caller depending on what it finds. The main script then checks this return value and prints an appropriate message.
You can also write a subroutine that returns an array instead of a scalar value:
#!/usr/bin/perl# define subroutine to
# split an email address into
# user and domain
sub breakEmailAddress
{
# get address
my ($address) = shift(@_);
# split address on the @ symbol into an array
@components = split('@', $address);
# return array
return @components;
}
# split email address
# print the components
@output = &breakEmailAddress('john@some.domain.com');
print "Username is ", $output[0], "\nDomain is ", $output[1]; [/code]
Here is the output:
Username is johnDomain is some.domain.com Leia Mais…
Saturday, December 27, 2008
The top 5 Linux myths: Why you shouldn’t fear the penguin
Now, what to the do with the old computer, or even with the netbook? Why not give your old computer a new life by running Linux on it? It may seem like a scary thought, but chances are you have a few misconceptions about Linux and that’s keeping you from making the jump.
Here is a list of five of the biggest Linux myths out there and how you can make Linux your friend.
5. It won’t connect to an iPod or MP3 player.
This might not apply to everyone, but to some people who only have one computer it could be a big deal. Most people now have some sort of MP3 player, and need a computer to put music on it, with special software on top of that, especially with the iPod.
Now, of course, you can’t use the App Store without iTunes (which has some problems installing with WINE), but you can easily buy songs from Amazon MP3 store, or rip them from CDs. Most music players for Linux support MP3 players, and even iPods, some like Songbird even look like iTunes if you’re almost too comfortable with the program.
4. Linux is not compatible with Mac/Windows files.
This seems to be a general misconception about computers in general. A lot of people seem to think that files from one operating system won’t work on any other one. This is true about applications, but not for the files they use or create.
If you’re working with a word processor, chance are it can export files to .doc files, which just about any program can use. Music is usually stored in MP3, AAC or FLAC files, all of which are easily usable on any platform. Having compatible files is easily avoided if you use cross-platform applications such as OpenOffice, that way you dont have to worry about exporting to other file types
3. Linux can’t play games.
This might not be important to everyone, but to some people games are the main reason why they stick with Windows. Even if all they play is World of Warcraft, they don’t want to give up their games just because thy switch to another OS.
There’s actually a lot of games that are native to Linux, though most aren’t as pretty as the newest games. There are ways to play those new games on Linux, however. There’s Codeweaver’s Crossover and Crossover Games, Cedega, and WINE (Crossover is essentially a more stable, paid version of WINE). Between these three, most popular games are easily played. I run WarCraft III on Ubuntu Eee using WINE, and it can easily handle WoW or even games liek Team Fortress 2, assuming your computer can handle it, of course.
2. Apps are hard to find.
Most Linux distros come with a lot of useful software, but sometimes you might want to replace them with something else or find something else you might want ot need. Unlike Windows, and to a lesser extent Mac, there aren’t many retail box copies of Linux software. However, with a quick Google search for “Linux apps” I was able to find Linux Online’s application page. Or, if you’re running Ubuntu, there’s Get Deb, which not only lists Ubuntu software, but also makes it really simple to install them.
1. You have to learn command line/terminal
I can’t tell you how many times I’ve told people that I’m running Linux, and they immediately cringe at the idea of the terminal. Somewhere along the line, Linux got the reputation that it’s only usable by coders, or those who know a decent bit of code.
The same people that cringe are the same people that are surprised when I show them Ubuntu Eee. It’s possibly even more simple than Windows with the netbook remix UI, but Linux is easy even without that.
Some distributions such as openSUSE have a Windows-like start menu, some, like Ubuntu, have an applications drop menu that lists all your applications, making for an environment that should be easy for anyone. Most also use GNOME or KDE file browsers which are just as easy to navigate as Windows Explorer.
If you can possibly get past these scary ideas, I would recommend Ubuntu, or Ubuntu Eee for your Eee PC (soon to be Easy Peasy, with more netbooks supported). Also look for my article on useful applications for Linux that can replace your Windows or Mac Apps.
Thursday, December 25, 2008
An A-Z Index of the Bash command line for Linux.
alias Create an alias
apropos Search Help manual pages (man -k)
apt-get Search for and install software packages (Debian)
aspell Spell Checker
awk Find and Replace text, database sort/validate/index
b
bash GNU Bourne-Again SHell
bc Arbitrary precision calculator language
bg Send to background
break Exit from a loop
builtin Run a shell builtin
bzip2 Compress or decompress named file(s)
c
cal Display a calendar
case Conditionally perform a command
cat Display the contents of a file
cd Change Directory
cfdisk Partition table manipulator for Linux
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
chroot Run a command with a different root directory
chkconfig System services (runlevel)
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
command Run a command - ignoring shell functions
continue Resume the next iteration of a loop
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
d
date Display or change the date & time
dc Desk Calculator
dd Convert and copy a file, write disk headers, boot records
ddrescue Data recovery tool
declare Declare variables and give them attributes
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dig DNS lookup
dir Briefly list directory contents
dircolors Colour setup for `ls'
dirname Convert a full pathname to just a path
dirs Display list of remembered directories
dmesg Print kernel & driver messages
du Estimate file space usage
e
echo Display message on screen
egrep Search file(s) for lines that match an extended expression
eject Eject removable media
enable Enable and disable builtin shell commands
env Environment variables
ethtool Ethernet card settings
eval Evaluate several commands/arguments
exec Execute a command
exit Exit the shell
expect Automate arbitrary applications accessed over a terminal
expand Convert tabs to spaces
export Set an environment variable
expr Evaluate expressions
f
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fg Send job to foreground
fgrep Search file(s) for lines that match a fixed string
file Determine file type
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width.
for Expand words, and execute commands
format Format disks or tapes
free Display memory usage
fsck File system consistency check and repair
ftp File Transfer Protocol
function Define Function Macros
g
gawk Find and Replace text within file(s)
getopts Parse positional parameters
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
h
hash Remember the full pathname of a name argument
head Output the first part of file(s)
history Command History
hostname Print or set system name
i
id Print user and group id's
if Conditionally perform a command
ifconfig Configure a network interface
ifdown Stop a network interface
ifup Start a network interface up
import Capture an X server screen and save the image to file
install Copy files and set attributes
j
join Join lines on a common field
k
kill Stop a process from running
killall Kill processes by name
l
less Display output one screen at a time
let Perform arithmetic on shell variables
ln Make links between files
local Create variables
locate Find files
logname Print current login name
logout Exit a login shell
look Display lines beginning with a given string
lpc Line printer control program
lpr Off line print
lprint Print a file
lprintd Abort a print job
lprintq List the print queue
lprm Remove jobs from the print queue
ls List information about file(s)
lsof List open files
m
make Recompile a group of programs
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mkisofs Create an hybrid ISO9660/JOLIET/HFS filesystem
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mtools Manipulate MS-DOS files
mv Move or rename files or directories
mmv Mass Move and rename (files)
n
netstat Networking information
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
nslookup Query Internet name servers interactively
o
open Open a file in its default application
op Operator access
p
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
ping Test a network connection
popd Restore the previous value of the current directory
pr Prepare files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pushd Save and then change the current directory
pwd Print Working Directory
q
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
r
ram ram disk device
rcp Copy files between two machines
read read a line from standard input
readonly Mark variables/functions as readonly
reboot Reboot the system
renice Alter priority of running processes
remsync Synchronize remote files via email
return Exit a shell function
rev Reverse lines of a file
rm Remove files
rmdir Remove folder(s)
rsync Remote file copy (Synchronize file trees)
s
screen Multiplex terminal, run remote shells via ssh
scp Secure copy (remote file copy)
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
set Manipulate shell variables and functions
sftp Secure File Transfer Program
shift Shift positional parameters
shopt Shell Options
shutdown Shutdown or restart linux
sleep Delay for a specified time
slocate Find files
sort Sort text files
source Run commands from a file `.'
split Split a file into fixed-size pieces
ssh Secure Shell client (remote login program)
strace Trace system calls and signals
su Substitute user identity
sudo Execute a command as another user
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
t
tail Output the last part of files
tar Tape ARchiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program running time
times User and system times
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
trap Run a command when a signal is set(bourne)
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
type Describe a command
u
ulimit Limit user resources
umask Users file creation mask
umount Unmount a device
unalias Remove an alias
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unset Remove variable or function names
unshar Unpack shell archive scripts
until Execute commands (until error)
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
v
v Verbosely list directory contents (`ls -l -b')
vdir Verbosely list directory contents (`ls -l -b')
vi Text Editor
vmstat Report virtual memory statistics
w
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user's path.
while Execute commands
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
Wget Retrieve web pages or files via HTTP, HTTPS or FTP
write Send a message to another user
x
xargs Execute utility, passing constructed argument list(s)
yes Print a string until interrupted
. Run a command script in the current shell
### Comment / Remark
Leia Mais…
Monday, December 22, 2008
A Beginner's Guide to Pointers
What Are Pointers?
Pointers are basically the same as any other variable. However, what is different about them is that instead of containing actual data, they contain a pointer to the memory location where information can be found. This is a very important concept. Many programs and ideas rely on pointers as the basis of their design, linked lists for example.
Getting Started
How do I define a pointer? Well, the same as any other variable, except you add an asterisk before its name. So, for example, the following code creates two pointers, both of which point to an integer:
int* pNumberOne;
int* pNumberTwo; Notice the "p" prefix in front of the two variable names? This is a convention used to indicate that the variable is a pointer. Now, let's make these pointers actually point to something:
pNumberOne = &some_number;
pNumberTwo = &some_other_number; The & (ampersand) sign should be read as "the address of" and causes the address in memory of a variable to be returned, instead of the variable itself. So, in this example, pNumberOne is set to equal the address of some_number, so pNumberOne now points to some_number.
Now if we want to refer to the address of some_number, we can use pNumberOne. If we want to refer to the value of some_number from pNumberOne, we would have to say *pNumberOne. The * dereferences the pointer and should be read as "the memory location pointed to by," unless in a declaration, as in the line int *pNumber.
What We've Learned So Far: An Example
Phew! That's a lot to take in. I'd recommend that if you don't understand any of those concepts, to give it another read through. Pointers are a complex subject and it can take a while to master them. Here is an example that demonstrates the ideas discussed above. It is written in C, without the C++ extensions.
#include <stdio.h>
void main()
{
// declare the variables:
int nNumber;
int *pPointer;
// now, give a value to them:
nNumber = 15;
pPointer = &nNumber;
// print out the value of nNumber:
printf("nNumber is equal to : %d\n", nNumber);
// now, alter nNumber through pPointer:
*pPointer = 25;
// prove that nNumber has changed as a result of the above by
// printing its value again:
printf("nNumber is equal to : %d\n", nNumber);
} Read through and compile the above code sample. Make sure you understand why it works. Then, when you are ready, read on!
A Trap!
See if you can spot the fault in the program below:
#include <stdio.h>
int *pPointer;
void SomeFunction();
{
int nNumber;
nNumber = 25;
// make pPointer point to nNumber:
pPointer = &nNumber;
}
void main()
{
SomeFunction(); // make pPointer point to something
// why does this fail?
printf("Value of *pPointer: %d\n", *pPointer);
} This program firstly calls the SomeFunction function, which creates a variable called nNumber and then makes the pPointer point to it. Then, however, is where the problem is. When the function leaves, nNumber is deleted because it is a local variable. Local variables are always deleted when execution leaves the block they were defined in. This means that when SomeFunction returns to main(), the variable is deleted. So pPointer is pointing at where the variable used to be, which no longer belongs to this program. If you do not understand this, it may be wise to read back over on local and global variables, and on scope. This concept is also important.
So, how can the problem be solved? The answer is by using a technique known as dynamic allocation. Please be aware that this is different between C and C++. Since most developers are now using C++, this is the dialect that the code below is using.
Dynamic Allocation
Dynamic allocation is perhaps the key to pointers. It is used to allocate memory without having to define variables and then make pointers point to them. Although the concept may appear confusing, it is really simple. The following code demonstrates how to allocate memory for an integer:
int *pNumber;
pNumber = new int; The first line declares the pointer, pNumber. The second line then allocates memory for an integer and then makes pNumber point to this new memory. Here is another example, this time using a double:
double *pDouble;
pDouble = new double; The formula is the same every time, so you can't really fail with this bit. What is different about dynamic allocation, however, is that the memory you allocate is not deleted when the function returns, or when execution leaves the current block. So, if we rewrite the above example using dynamic allocation, we can see that it works fine now:
#include <stdio.h>
int *pPointer;
void SomeFunction()
{
// make pPointer point to a new integer
pPointer = new int;
*pPointer = 25;
}
void main()
{
SomeFunction(); // make pPointer point to something
printf("Value of *pPointer: %d\n", *pPointer);
} Read through and compile the above code sample. Make sure you understand why it works. When SomeFunction is called, it allocates some memory and makes pPointer point to it. This time, when the function returns, the new memory is left intact, so pPointer still points to something useful. That's it for dynamic allocation! Make sure you understand this, and then read on to learn about the fly in the ointment, and why there is still a serious error in the code above.
Thursday, December 18, 2008
Run Windows applications on Linux
Most people who use Linux are familiar with the WINE program, which enables the use of Windows software on Linux without requiring Windows itself. WINE is still fairly immature. While it can run some applications, other applications can present a problem.
However, other programs exist that allow you to run more specialized applications. For example, CodeWeaver's CrossOver Office lets you run Windows business applications (such as Microsoft Office, Quicken, etc.) under Linux, and TransGaming's WineX allows you to play many popular Windows games under Linux.
CodeWeaver recently released CrossOver Office 2.1, which includes support for even more applications, most notably Macromedia's Dreamweaver MX and Flash MX. The ability to run these applications on Linux is a true benefit for professional Web developers, who often write Web applications on the Windows platform for deployment on Linux servers.
CrossOver Office is easy to install. You can download RPM packages or the Loki installer, which looks like a large bash script file. The Loki installer is the most portable option, enabling you to install CrossOver Office in a location of your choice and on any Linux distribution, including Debian and Slackware.
CrossOver Office is a commercial application, and it costs $59.95. However, you can download a 30-day trial version. When you download the Loki installer, start it by executing the following:
$ sh install-crossover-office-2.1.0.sh
This begins the installation program and allows you to choose the installation location or pick the existing location if you're upgrading.
Once the installation is complete, grab the installation CDs for the Windows applications you want to install, and use the easy-to-use configuration tool to launch the installation wizards for the respective programs.
Leia Mais…Friday, December 12, 2008
Use Cygwin when you can't use Linux
Linux fans would love to use Linux all of the time, but sometimes it just isn't possible. Maybe a certain application requires that you use Windows, or perhaps you're forced to use Windows at work. Regardless of the reason, if you've become attached to your Linux and open source applications, rest assured that you can use Cygwin to run most of those applications on Windows.
Cygwin is an environment for Windows, similar to Linux, that provides a Linux API emulation layer and a collection of tools that are normally only available on systems that use open source tools, such as Linux, the *BSD's, and Mac OS X.
To begin using this environment, visit the Cygwin Web site and download the installer--the setup.exe file. Once this component is downloaded, double-click it and choose the Install From Internet option, which will download only the packages you want to install. You'll need to specify the root environment of the installation, where packages will be downloaded to, and a mirror site from which to download packages.
After you've picked a mirror, the installer will download some base files and allow you to select packages from various categories. Here you can choose what shells, text-processing tools, databases, desktop applications, and other programs that you'd like to install. Since Cygwin comes with an X server, you can even install GNOME and KDE programs. Better yet, you can compile your own programs to run under Cygwin by installing gcc and friends.
Cygwin will dutifully download and install all of the packages that you select. When the download process is complete, you can fire up Cygwin and an initial bash shell by clicking the Cygwin icon on your desktop.
Leia Mais…Thursday, December 11, 2008
LINUX NEWBIE ADMINISTRATOR GUIDE
Intro. We are relative Linux newbies (with Linux since Summer 1998). We run mostly RedHat and Mandrake -> the solutions might not be directly applicable to other Linux distributions (although most of them probably will be). Hope this helps; we try to be as practical as possible. Of course, we provide no warranty whatsoever. If you spotted a bad error or would like to contribute a part on a topic of your choice, we would like to hear from you.
General description of this Guide. A complete reference for new Linux users who wish to set up and administer their own Linux home computer, workstation and/or their home or small office network. The answers are meant to be simple, with just sufficient detail, and always supported with a readily usable example. The work is still in progress, but we hope the Guide can be helpful already. We welcome your corrections, advice, criticism, links, translations, and CONTRIBUTIONS. Pls note that there are no ad banners on our pages.
Conventions:
<> = single special or function key on the keyboard. For example
italic = name of a file or variable you probably want to substitute with your own.
fixed width = commands and filenames.
Part 0: For the Undecided (Linux Benefits)
If you are wondering what the Linux pros and cons are, and whether Linux is for you.
Part 1: Before Linux Installation
What distribution should I use, how to obtain it, Linux hardware requirements, how to partition your hard drive, about dual boot, which packages to install, which graphical user interface (GUI) to install (gnome or kde?), and how to login for the very first time.
Part 2: Linux Resources, Help and Some Links
How to access the Linux documentation (from under MS Windows or Linux), what are Linux help commands, where to find the geek dictionary, + pointers to some Linux newsgroups and websites.
Part 3: Basic Operations FAQ
After you installed Linux, here are answers to some questions that Linux newbie users/administrators may have when trying to perform every-day tasks: what are the file name conventions, how to run a program, shut down my computer, set up the path, add users, remove users, make your passwords and system more secure, work with file permissions, schedule jobs with "at" and cron, change your shell prompt, print symbols in the text mode, use color in the text mode, redirect input/output, write a simple shell script, install a new program ...
Part 4.1: Boot-time issues
Some info on LILO and GRUB boot managers, how do I choose the operating system which boots on default, hints on configuration of the boot loaders, "uninstalling" Linux ...
Part 4.2: Drives
Where are my drives, how to access them, configure user access, get the zip drive recognized, set 32-bit hard drive IO, increase the limit on the number of opened files, add a new hardrive, manage the swap space ...
Part 4.3: X-windows
How to switch between text and graphical consoles, set up my video card, monitor and mouse for the X-server, setup a graphical login prompt, change a default desktop, have multiple sessions of Xwindows running at the same time, use Xwindow remotely, install TrueType fonts from my MS Windows partition to Linux, how to copy-paste under X and in the text mode, how to use VNC.
Part 4.4: Basic Configurations
Real basics on how to configure the printer and soundcard, bits about configuration files, daemons, and device files.
Part 4.5: Networking
Setting up a network, ppp (connection over the phone), remote access to your computer, ftp and html server, e-mail, how my computer can get hacked ...
Part 5: Linux Shortcuts and Commands
Maybe this should have come first. A practical selection of Linux shortcuts and commands in a concise form. Perhaps this is everything that a computer-literate newbie Linuxer really needs. Highly recommended.
Part 6: Linux applications (proprietary or not)
Essential and/or famous Linux applications with some hint/comments: word processing, spreadsheet, database, latex. Extensive info on how to set up and use a CD recorder to write data, audio, and mixed mode CDs.
Part 7: Learning with Linux (commands for more esoteric work or programming)
Review of some more advanced or less useful commands/tools to get you started with fancier text processing, encryption, digital signatures (gpg), simple programming plus some info on the Linux console tools that can help you learn about computers. Under development so perhaps not so good: grep, regular expressions, sed, gawk, sort, ascii codes, linux built-in c compiler and tools, perl, python, tcl/tk, "Reverse Polish Notation" (RPN) calculator, scilab, wine ... working on it.
Monday, December 8, 2008
Making waves with Linux: A few tips for trainers
Are you teaching Linux? Will you be teaching Linux soon? Are you thinking about catching the Linux wave in the future? If you can say “yes” to at least one of these questions, this article is for you. TechRepublic has published some excellent articles about Linux. We’d like to take this opportunity to highlight some of the Linux articles that trainers might find most useful.
Linux jargon
If you’re new to Linux, you might want to catch up on the terms by reading Jargon Watch: Open-source, kernel, and SMP , by Mary Ann Fitzharris.
Linux certification
Bruce Maples’ article The unsettled world of Linux certification uncovers a tsunami of information on the availability of Linux certification. If you are considering obtaining Linux certification, this article will serve as a quick reference guide to get you started.
Linux tips you can teach
Looking for some Linux tips or information on the Linux OS? We have several:
Jack Wallen, Jr.’s tip, titled Access remote Linux hosts with NFS discusses the benefits offered by NFS, including centralized data housing.
Linux systems are stable, but they aren't bombproof. In the article titled Do yourself a favor—create a Linux boot floppy , Wallen tells you how to save yourself from kernel panic by making a boot floppy for Linux.
Tuesday, December 2, 2008
Run Windows applications on Linux, BSD and Mac OS X
December 20, 2008
The Wine development release 1.1.11 is now available.
What's new in this release:
- Numerous fixes for IE7 support.
- Support for 64-bit cross-compile using Mingw64.
- User interface support for crypto certificates.
- Better support for MSI installation patches.
- Various Direct3D optimizations.
- Various bug fixes.
The source is available now. Binary packages are in the process of being built, and will appear soon at their respective download locations.

