What is Linux
So, you've heard a lot about this Linux thing, and decided
to check it out. If you're new to Linux, or just new to computing in general,
it might be a bit confusing at first. Don't worry about it. It's actually
pretty simple. Get relaxed and read on, and we'll explain what all the fuss is
about.
Depending on the
context, the word "Linux" describes a couple of things. Most
accurately, the word "Linux" describes an operating system kernel --
that is, the low-level part of an operating system that does all the hard work
of talking to the computer's hardware, managing memory and devices, and
generally doing the grunt work. Unless you are an advanced user, or you run
into some sort of hardware or software problem, you'll almost never interact or
even need to think about the kernel itself.
While it's a very important part of the system, it's not
something that users interact with directly. Instead, you'll be working with
what are referred to as "user-space" programs -- so called because
users actually work with the programs directly. When a vendor or project
bundles the Linux kernel and a bunch of user-space programs together in a way
that's useful to end users, that's called a Linux distribution, often just
"Linux" for short -- because Linux is at the heart of the whole thing
to begin with, and saying "Linux distribution" every time is a bit
long winded. Generally speaking, when people say something like "I use
Linux," or "have you tried Linux?" they're not just talking
about the kernel, they're talking about a Linux distribution.
What's a distribution, and which one should I
use?
Speaking of Linux distributions, you might be wondering what
the heck a distribution actually is. It's pretty simple, really. As we've
already discussed, the Linux kernel itself isn't terribly useful for end users
on its own. You can't play Tetris, write a document, serve Web pages, or send
an email with the Linux kernel itself -- and what use is a computer if you
can't do those things?
So, lots of vendors and projects have decided to put the
Linux kernel together with useful software so that folks like you can get
things done. They also provide installation routines, so you can install Linux
on a computer, and management utilities so you can do things like add and
manage devices, or manage users, without having to know low-level commands or
do the grunt work with a text editor and the command line. When you put the
Linux kernel together with useful software, an installer, and management
utilities, you have a Linux distribution.
The next logical question is, which distribution -- or
distro -- should you use? Unfortunately, this isn't as simple as explaining
what a distribution is. We can't really tell you which distribution you should
be using, for a couple of reasons; it really all depends on your personal
preferences, and what you want to get done.
Some distros, like Red Hat Enterprise Linux and SUSE Linux
Enterprise Server are
designed primarily for companies that use Linux on servers. Some distros, like Fedora Core, Ubuntu, andopenSUSE have different profiles that are
suitable for use on the desktop or on the server.
If you ask 20 Linux users which distro you should use,
you're likely to get several different answers -- and they're all right, at
least for those users.
The nice thing is that
most Linux distributions are free, and you can download each one and test them
to see if they fit your needs. See our distro center for
descriptions and more information about the most popular Linux distros.
This is all free?
It sounds too good to be true, doesn't it? Microsoft, Apple,
and other companies charge for their software, so it sounds a bit odd that
you'd be able to download software that's equivalent to Windows or Mac OS X
free of charge. What's up with that?
The short answer is that
some people think that software should be distributed under free and open
source licenses that allow the software to be freely shared -- and even
modified! This has been going on a very long time; the GNU Project was formed
in 1984
by Richard Stallman, before Microsoft shipped the first version of
Windows, and the same year Apple shipped the first version of its
"classic" Mac OS.
It took a while to
gather steam, and it wasn't until 1991 that Linus Torvalds put out the first public release of Linux. Torvalds had
also ported the Bash shell and GCC to Linux, to make it worth using.
Eventually, Torvalds settled on the GNU General Public License (GPL) as the
kernel's license.
The GPL, which was developed by the GNU Project, allows you
to share software under the GPL with anyone you want. You can even modify the
software you get under the GPL, and distribute the new version, as long as you
share your changes under the same terms (the GPL) that you received the
software under.
What's all this about GNU/Linux?
Some folks refer to
Linux as GNU/Linux, because they want to emphasize the importance of the GNU
Project's contribution to Linux distributions. While the Linux kernel plays a
big part of any Linux distro, so does the software contributed by the GNU Project.
For example, without the GNU Compiler Collection (GCC), how would you compile the
kernel and other programs that run on Linux? Most Linux distros default to GNU
Bash for the shell,
and GNU
glib is used by GNOME,
GTK+, and many other programs that you would use all the time on Linux.
Without listing all of
the software used in Linux from the GNU Project, suffice it to say it's
a lot. Without GNU, we'd be missing a lot of wonderful software.
So the GNU Project has made
an effort to get
recognition for its contribution to Linux distributions. But, the GNU Project
isn't the only major contributor. It should be noted that Linux distros are
comprised of software from many other projects too -- like GNOME, KDE, X.org,
OpenOffice.org, the Mozilla Foundation, and too many others to mention.
Whether you call it Linux or GNU/Linux is up to you.
The difference between free software and open
source software
There is a difference
between free software and open source software. Specifically, all free software
is also open source software -- because it fits within the Open Source
Initiative (OSI) definition of open
source (often called
the OSD for short).
However, not all open
source software fits the definition of free
software as defined by
the GNU Project or the Debian
Project. What's the difference? Primarily, it's one of philosophy.
The free software philosophy is centered on the idea that, in the words of the
GNU Project, free software "is
a matter of liberty, not price."
Open source, on the other hand, is primarily centered around
the development model. The idea is that the open source model -- distributed
development, a transparent development process, and peer review of code -- is
better than the proprietary development model. Thus, open source licenses may
restrict users in ways that free software licenses may not.
Not all software that runs on Linux is free in either sense
of the word. Lots of companies make proprietary software for Linux, and charge
a pretty penny for it, too. For example, Oracle's products run on Linux, and
they don't give them away -- they have turned quite a profit running the Oracle
database and other products on top of Linux.
While the GPL and other licenses require that derivative
works carry the same license terms, they don't require that non-derivative
products carry the same licensing terms, so companies can and do sell software
that runs on Linux without breaking any rules or violating the licenses.
In fact, a few companies actually sell Linux and support it,
and do pretty well at that. Red Hat's distribution, Red Hat Enterprise Linux,
is comprised of free and open source software (FOSS) and they've been turning a
profit for some time doing so. Instead of making its money on the sale of
licenses, Red Hat makes its revenue on selling support for the distribution
because lots of companies are willing to pay to have someone to turn to if and
when they have problems or need new features.
Can I run my Windows programs under Linux?
If you're coming from a Windows background, and most people
are, you might have some Windows programs that you really want to keep using
even when you're using Linux. Windows programs will not run natively on Linux,
but you can find a few solutions to run Windows apps under Linux or within a
Linux session if you really need to do so.
Wine is one option for running Windows apps
under Linux. Wine is an open source implementation of the Windows API for Linux
and Unix operating systems. It's a compatibility layer for Windows apps, so
that they can run unmodified on top of Linux. Another option is CodeWeavers CrossOver, which is based on Wine,
but not entirely open source. CodeWeavers includes features not in Wine to make
it easier to set up and run Windows programs under Linux.
Virtualization is
another option for running your Windows applications under Linux.
Virtualization software like VMware Server and VMware Workstation, Parallels, and Qemu will allow you to run a full instance
of Windows under Linux -- so you can run almost any Windows program unmodified
on top of Linux, within the Windows environment. (Some applications that
require 3D support may not run under virtualization because virtual machines
typically do not provide 3D graphics.)
In the long run, however, you might prefer to find a native
Linux program as a substitute for your Windows applications. The next section
will discuss how to find software for Linux, and how to install it.
All about StarOffice and OpenOffice.org
StarOffice (SO) and OpenOffice.org (OOo) are the leading
rivals of Microsoft Office. Despite the difference in names, the two are mostly
variations on the same program. Both are developed largely by engineers at Sun
Microsystems, but OOo is free software, and SO is proprietary.
Functionally,however, the two programs are nearly identical. Each shares the
same general characteristics and has features that compare favorably with MS
Office's, and which you use depends largely on your philosophy rather than any
difference in functionality.
SO and OOo are the
modern descendants of a program developed by a German company called
StarDivision. Sun Microsystems bought StarDivision in 1999, and released the StarOffice
code under a dual license, with OpenOffice.org under the GNU Lesser General
Public License (LGPL) and StarOffice first under the SISSL license and later
under a proprietary license of its own. Today, the code base for the two
programs is developed largely together, with packaged versions of SO being a
snapshot of the code at a particular time plus a few extras.
SO and OOo consist of five main applications:
§
Writer: A word processor and intermediate
desktop publishing program
§
Calc: A spreadsheet program
§
Impress: A slide show program
§
Draw: A scalable vector graphics program
§
Base: A database
Unlike MS Office, these programs are not a suite of
originally independent programs, but applications that share much of the same
code. This design explains why SO and OOo occupy about two-thirds of the disk
space that MS Office does -- and why just installing the applications you need
won't save you as much space as you might expect.
It also means that the applications share several
sub-systems, including the ones for charting and drawing, and have a high
degree of inter-operability that allows data to be easily shared between
programs, or for a file for one application to be embedded in another
application. In addition, many of the windows and dialogs are the same in each
program -- Draw and Impress in particular have similar editing windows --
making the applications as a whole easy to learn.
General characteristics
The interface of the two programs is heavily dependent on
floating windows. Some of these, like the toolbar for lists, are
context-dependent, popping up when the mouse cursor is in an appropriate
position. Others floating windows open only when you choose.
Some, like the Gallery of clipart or the Function List in
Calc, open docked to one side of the editing windows. Others, like the
Navigator and Styles and Format window, are free floating. The Navigator is
particularly useful for moving around a long document, as well for rearranging
blocks of texts or obtaining an outline view of a document.
Another characteristic that makes SO and OOo stand out from
most office programs is the heavy emphasis on styles: format settings that are
defined in one location, then applied as needed, making it easier to make
global changes than if all formatting was done manually.
Almost every word processor offers character and paragraph
styles, but SO and OOo also include page, frame, and list styles. Moreover,
they also extend the concept of styles to the other applications, something
that other office programs either never do, or else do very weakly. You do not
have to use styles in SO and OOo, but, if you don't, advanced features -- for
instance, multiple header or footer styles in a text document -- may be
unavailable to you.
SO and OOo also have
extensive support for macros or scripts, as well as add-ons written in such
languages as Java and Python. Writers of macros are well-enough organized to
have their owndownload
page, but writers of add-ons are fewer and less organized, making
them harder to find. However, perhaps the best-known add-on is extendedPDF,
which gives enhanced control over exporting to PDF format. Wherever you find
them, you can quickly add both macros and add-ons to your SO or OOo
installation to get extra functionality.
In fact, some have been so successful that they have
eventually been added to the basic program. Java add-ons are especially
popular, so if you do not already have Java installed, you may want to check
the box on the OpenOffice.org download page to include it, or, in StarOffice,
to make sure that you select Java when running the installation program.
Otherwise, you may not be able to use some bits of the program, such as some of
the template wizards in Writer.
Interacting with Microsoft Office
As rivals to MS Office, StarOffice and OpenOffice.org have
to support Microsoft's formats and offer similar functionality. Their list of
options include a number of items designed to help you share files with MS
Office, including the option to save files in MS Office-compatible formats by
default. Files moving back and forth between MS Office and these programs can
fail to maintain complex formatting, but, the simpler the document is, the more
likely the transfer will avoid problems.
In another nod to MS Office, the two programs have many
tools in the same position as in MS Office. At the most, you may have to watch
for occasional changes in names. For instance, Calc uses the term
"datapilot" for "pivot tables." But, for the most part, you
can move between MS Office and SO or OOo and transfer much of your knowledge.
So which set of office features is superior? That depends
very much on your purposes and work habits. Writer is much stabler than MS
Word, especially for long documents, crashes less often, and recovers more readily
the few times that it does crash. It also features a more dependable master
document feature than MS Word and lists in which items can be moved about or
lists nested in each other without disrupting the number sequence.
The jury is still out on the differences between Base and
Access, Base's ability to connect with a wide variety of database formats
probably gives it an edge. Draw, of course, has no direct equivalent in MS
Office, but, in addition to being a general graphics program, it also contains
elements similar to those of MS Publisher and Visio, two applications available
in some versions of MS Office.
By contrast, a comparison between Impress and PowerPoint is
more mixed, with Impress having a better set of drawing features and PowerPoint
having the advantage in its ability to work with sound files. Similarly,
although advanced users complain that Calc can be much slower than Excel in
calculating complex formulas, average users are unlikely to notice any great
difference. Other considerations include the fact that SO and OOo lack a
grammar checker (although several are available as add-ons if you search for
them) and some of MS Office's collaboration tools, but include export to PDF
format, which MS Office lacks.
As for HTML editing, MS FrontPage easily wins the features
race over the limited HTML support in Writer. However, neither produces very
clean code, and therefore should probably be avoided, especially for
professional work.
In the end, probably the most accurate overall statement
that can be made is that, for most kinds of work, you can expect SO and OOo to
be functionally equivalent to MS Office, with only small pluses and minuses
either way.
Which to choose
Although SO and OOo are in many ways identical, they do have
some differences. Some of these, like SO's use of some proprietary code for its
spellchecker and thesaurus, matter very little because they do little to affect
functionality.
However, other differences will probably have a larger
effect on your choice:
§
OOo is released under the GNU Lesser General
Public License, and can be installed on any number of systems. SO is released
under a proprietary license that restricts installation to five computers for
the purchaser's use. In other words, you could install SO on your home and office
workstations and your lap top, but not use the same copy to setup a small
office for five people.
§
SO releases periodic patches and includes an
online updater. OOo does not release patches, and most experienced users
suggest backing up the configuration files in the .openoffice.org2 folder in
your home directory, doing a clean install for each new release, then copying
the configuration files back to their original position.
§
SO includes proprietary import and export
filters for a number of different formats, including SO versions 3.0-5.0.
§
OOo includes support for more than 90 languages
in various stages of completion, including many minority languages worldwide,
such as Slovenian and Welsh. For many languages, OOo is the first office
application available for it. SO supports 10 European languages.
§
SO has versions that run on Linux, Windows, and
Solaris. OOo supports these operating systems, as well as Mac OS X, FreeBSD,
and several other varieties of Unix. Note that, instead of the OS X version of
OOo, which runs under X, many people prefer NeoOffice, a fork of the project
that runs natively on Mac OS X using Aqua.
§
SO includes extensive templates and clipart, as
well as a number of fonts, including Arial, Garamond, Helvetica, and New
Century Schoolbook. Its collection of slide backgrounds is especially useful.
OOo lacks all these extras, although you can gather many templates, clipart,
and fonts online and install them yourself.
§
SO includes 60 days free technical support for
registered users, and paid support is available after that. The commercial box
set also includes a printed manual. Although Sun's technical support will also
assist OOo users, most OOo support comes from mailing lists, or from documents
posted by volunteers, many of whom have extensive experience with both OOo and
with helping volunteers.
Which of these differences matter most will depend very much
on your circumstances. On the one hand, if the free price and freedom from
proprietary license constraints count the most with you, then you will probably
find that OOo is worth the effort of scouting around for extras to set it up
exactly as you like.
On the other hand, in a more traditional corporate
environment, SO's patches and technical support may seem easier. In still other
cases, the languages or operating system you are using may determine your
choice.
Given that OOo is free for the download, consider exploring
it first and seeing how you cope. Then, if you decide that you need the
conveniences available in SO, you can easily make the switch. After all, no
matter which one you use, you'll be working with much the same code and
functionality.
Get started developing Web applications in Linux
A Linux distribution is a popular environment for developing
applications for the web. Whether you are designing a personal Web page or a
multi-page, database-driven, AJAX-enabled Web site, Linux has tools to make the
task easier.
Any article on Web
development warrants mention of the Linux, Apache, MySQL, and PHP, Perl, or Python (LAMP) platform. LAMP is the
culmination of a Linux distribution, together with the Apache Web server, the MySQL
database, and one (or more) of the scripting languages.
The components of the LAMP platform offer developers a
complete environment for developing and hosting complex Web apps. Scripting
languages are the glue between the Web servers and databases. They ensure that
all requests for information received by Web servers are transfered to the
databases.
PHP
PHP is an object-oriented, server-side
scripting language used to build dynamic Web sites. It's often compared to Microsoft's
ASP.NET, but can run on several Web servers and can talk to popular databases,
across all major operating systems. According to Netcraft, in April 2007, about
20 million domains were on servers with PHP installed. The TIOBE programming community index lists PHP as the forth most popular
programming language after Java, C, and C++. WordPress, a popular blogging
engine, and MediaWiki -- which drives Wikipedia -- are both written in PHP.
PHP is a pre-processor, which means it reads a file with
specific instructions written in PHP, processes the page and outputs another
page to the Web browser. Here's a simple example of a PHP program:
<b>
<?php
echo 'Hello, World!';
?>
</b>
A page with these lines will go through PHP, which converts
the echo statement into normal text. A normal page will contain a mixture of
HTML tags and PHP syntax, enclosed within the <?php and ?> delimiters.
Anything not contained in php delimiters is not processed.
When you decide to write
an application in PHP, you may find the PHP Extension and
Application Repository (PEAR) project
particularly useful. PEAR is a repository of libraries and components that you
can use for PHP development to add functionality like parsing RSS, connect to
an IMAP server, or generate images on the fly. PHP's
Wikipedia page has a
lot of details about PEAR's features and a comprehensive list of its libraries.
PHP doesn't have an
in-built debugger. But PHP programmers have two very powerful debuggers to
choose from: The Advanced PHP
Debugger (ADP) and Xdebug. Once included in a script, both APD
and Xdebug can profile and analyze the scripts execution. Xdebug can also plug
into development environments like Eclipse.
PHP is also useful for
writing template engines. A Web template system produces Web pages by
manipulating data in a database with the template. Smarty is
a popular template system written in PHP.
PHP has a comprehensive
manual, which covers everything from installation and PHP basics
right up to using several functions and PHP internals. New users should also
read the PHP FAQ and subscribe to the appropriate mailing
list. There's also a manual for
Smarty which covers
installation and usage.
Perl
Perl is an object-oriented, cross platform
language known for its text extraction capabilities. Web developers and others
took to Perl since it had features not available in other languages at the time
of its introduction in 1987. For example, it could process large amounts of
text and generate easy to read reports in no time.
Part of Perl's
popularity stems from its extensive add-on modules from Comprehensive Perl Archive Network (CPAN), which houses over 11,000 modules.
CPAN helps programmers locate modules and scripts that aren't included in the
standard Perl distribution.
Perl borrows several
features and syntax from other languages like C, sed, and Lisp. Perl includes a
special syntax for writing regular
expressions, which is now being used by several other languages,
like PHP, through the Perl Compatible Regular
Expression library. Perl is also the most popular language for
writing Common Gateway Interface (CGI) scripts. CGI is a standard that
defines how information is exchanged between a script and a Web server.
Here's the sample "Hello, World" program in perl:
#!/usr/bin/perl
print '<b>Hello, World!</b>';
This produces the same result as in PHP, the "Hello,
World", in bold font. Again, this is just a very simple demo.
Perl has an in-built debugger. Perl's -d switch makes the
script run under the Perl source debugger. Within the environment you can do
common debugging tasks, like setting breakpoints and changing variable values.
Perl also has the -w option, which warns of any questionable code it encounters
while running the program.
Perl's documentation Web site hosts a FAQ and tutorials to covers
everything from installation to regular expressions to using Perl's
objected-oriented features. You'll also find the Perl Beginner's Web site useful. It has links to a number of
online Perl tutorials, Perl book reviews, articles, mailing lists, forum
boards, wikis, and IRC channels that revolve around Perl.
Popular blogging software, Slash, which runs Slashdot, is
written in Perl. So is the software that runs LiveJournal.
Ruby
Ruby is another powerful and popular
scripting language that has a syntax similar to Perl. The Ruby FAQ suggests
that Perl developers will feel at home with Ruby's syntax. Ruby also supports
Perl-like regular expressions. Ruby's object-oriented features are similar to
Smalltalk.
A sample Ruby program to print the "Hello, World"
message:
#!/usr/bin/ruby
puts 'Hello, World!'
Like the other scripting
languages we've covered, Ruby is cross-platform. Similarly Ruby too has
repositories of libraries and applications. The Ruby Application Archive (RAA) is home to several libraries and also
hosts some documentation.
Though RAA also hosts
some applications built on Ruby, like games, the real place to find them is RubyForge. RubyForge hosts over 2500 projects.
Ruby has a package manager, calledRubyGems, that defines the format for
distributing Ruby programs and libraries. It also acts as a download manager
and its usage is similar to apt-get.
Ruby has a built-in
debugger that can be called with the -rdebug option. But there's a more popular
debugger, ruby-debug. Like other debuggers, it can set
catch points and breakpoints as well as display the contents of the stack.
The easiest way to learn
Ruby is to use the interactive
tutorial. The Ruby Web site also has lots
of tutorials for
absolute beginners to programming as well as programmers migrating from other
languages. Also on the site are a few in-depth manuals and books. The Ruby On-Page Web site, lists snippets of Ruby
code along with an explanation to help users get familiar with Ruby's syntax.
Python
The Python programming
language is popular with first time programmers since it focuses on
readability. Python is object-oriented and multi-platform. Google and YouTube
both use Python, which speaks a lot about the language's usability.
Python achieves the high levels of readability by using
English keywords and in its use of white space. In programming languages,
blocks of codes have traditionally been enclosed in braces ({}) and punctuation
(;). Python relies on indentation.
For example, a function in C that calls other functions
depending on the type of user would look like:
void foo(int x) {
if (newuser == 0) {
welcome();
help ();
} else {
welcome_back();
goodbye();
}
}
The same function in Python would look like this:
def foo(x):
if newuser == 0:
welcome()
help()
else:
welcome_back()
goodbye()
Notice the difference in the Python version? Some developers
criticize Python for forcing them to stick with strict syntax, because if the
Python program isn't properly indented, it would misbehave or fail to run.
Other developers prefer Python's strict syntax.
Python has a debugger, pdb,
which available as a module. It can set breakpoints and also be invoked as a
script to debug other scripts.
Like all popular
languages, there's no dearth of Python
documentation. If you are new to Python, the detailed official
tutorial, along with the online edition of Dive
Into Python book and How
to Think Like a Computer Scientist: Learning Python, have enough
information to get you started.
.Net
Novell's Mono project provides
a set of tools that can run code written in .Net. The Mono tools are compliant
with the Ecma
International standard and
can run on several platforms.
The Mono tools are under heavy development and the latest
version provides the core API of .NET Framework 2.0. Mono also bundles a Visual
Basic component to allow VB apps to run under Linux, even those that have been
compiled under Windows. There's also a VB compiler that can allow .Net
programmers to write and compile .Net code just like they would under Windows.
The best way to get
started with Mono is
by using its
VMware image that
contains everything a developer needs to get started migrating Windows
applications to Linux. The Mono
Migration Analyzer (MoMA)
tool helps identify issues that programmers may have when porting their .Net
application to Mono. There's a guide to using MoMA on its home page.
Mono's
FAQ answers several
questions regarding the project and its capabilities. We have a quick tutorial
for people interested in running .Net application with Mono. Mono also
has a number
of mailing lists that
discuss various aspects of Mono and its tools.
Java
Java applications,
either standalone or Web applets that run in a Web browser, need a special
environment to run. The Java Runtime Environment (JRE) packages provides such an
environment and includes a Java Virtual Machine (JVM) to translate Java code into a
form that's executable by the host machine.
Sun has made available
JREs for Linux, which allow you to run standalone code as well as Web applets.
Since Java wasn't open sourced until recently, free software enthusiasts
depended on the free (as in freedom) GNU Compiler for
Java (GCJ) to compile
their Java code. GCJ has a detailed
manual and several
tutorials for
compiling and debugging Java programs.
To allow developers to
add dynamic content to a Web site, Sun developed the Java
Servlet API. Servlets are scripts like PHP. To generate these
servlets Sun wrote the JavaServer
Pages (JSP)specification. To run these servlets, the Apache
foundation developed Apache Tomcat.
Tomcat is a runtime environment for Web applications in Java.
Application servers and frameworks
Depending on the language you're developing on Linux offers
several application servers and Web frameworks for quick deployment and
control. An application server is a centralized piece of software responsible
for delivering Web applications to client computers or devices.
JBoss is a cross-platform Java based
application server. To help developers get started using JBoss, the project has
loads of documentation in the wiki. You
can also get help on the forum
boardand several mailing
lists.
Another popular
application server is Zope,
written in Python. Zope has several components available that can be plugged
into the application server to extend its Web site building capability. Zope
includes its own Web server but can also be used with the Apache Web server.
Another good thing about Zope is that it can be managed from a Web browser.
Lots of documentation is available including HOWTOs and a free Zope book.
Web developers also rely on Web application frameworks to
assist them in the process of creating Web sites. A Web application framework
provides libraries for several common tasks like accessing databases, managing
sessions, etc. Using frameworks a Web developer can save a lot of time since
many frameworks also encourage code reuse.
Ruby on Rails
(RoR) is a Web
application framework written in Ruby. RoR helps developers in reusing code and
avoiding unnecessary repetition. The Ruby Web site has
lots of documentation
laced with examples. The RoR Web site also hosts several screencasts
that demo its Web site creation speed. For example, there's a demo
that creates a Weblog from scratch in 15 minutes.
Django is another Web
application framework that's gaining in popularity. Django is
written in Python and bundles a light-weight Web server for development and
testing, a templating system, tools for generating syndication feeds and
sitemaps, and several other components. Django can run under many Web servers
including Apache with the mod_python module and supports MySQL, PostgreSQL and
SQLite databases. Django has an under development
book available online
for free.
Then there's the Zend framework based on PHP. It provides several
coponents and modules for developing PHP based applications. The modules in the
Zend framework can do authentication, manage sessions, handle internationalization,
and use several PHP core and Web services introduced in PHP 5. The Zend
programmer's manual covers
these modules and their usage in detail.
Web development apps
If you are putting
together a simple Web page or are new to writing Web scripts, you can choose
from several "what you see is what you get" (WYSIWYG) programs for
HTML. Here's a brief look at some of them, which we've also covered in detail.
Quanta Plus is a Web development environment based
on KDE, but it works well under GNOME and other desktop environments too.
Quanta features a set of buttons for HTML tags that you'd use often, and
wizards for creating forms, tables, and other items.
Depending on what type of page you're creating, Quanta
offers several default templates. These templates are skeleton structures of an
HTML document, PHP script, and other document types supported by Quanta. Quanta
can access files remotely using FTP, SSH, SMB, NFS, WebDAV, and other
protocols.
If you want to maintain
older versions of the projects you've created with Quanta, it can hook up with Cervisia. Cervisia is a frontend to Concurrent Versions System (CVS), a popular revision
control program. To
compare and review changes in two versions of a Web page created with Quanta,
it can also work with Kompare,
a frontend to the diff utility which compares two files and outputs differences
between the two.
Another popular choice
is the Bluefish
editor, which can be used for writing HTML pages or scripts in many
languages. It supports PHP, Perl, Python, C, SQL, and several others. You can
edit multiple documents in Bluefish at a time, each document in its own tab.
Bluefish also includes several toolbars and a function browser for PHP, Python,
CSS, and formatting HTML. The function browser helps you find various tags and
insert them into the document. If the tag requires attributes, Bluefish will
pop up a dialog with the possible attributes so you can fill them in.
You also get wizards for creating tables, frames, forms, and
a user customizable 'Quick Bar' that allows users to add their most frequently
used buttons. Bluefish can also generates a page of thumbnails from a directory
of pictures and links the images to the thumbnails. It can run in both GNOME
and KDE.
Conclusion
If you've got Web development on your mind, there's no
better development platform than Linux. There are several choices of Web
scripting languages to choose from. Select the language depending on the type
of application you project. If you are new to Web scripting every language has
lots of well-categorized documentation that steps you through the various
stages of learning.
You still get several choices, even if you want to deploy
applications written in languages not native to Linux. .Net and Java are two
examples of popular languages that can be written and hosted using Linux as a
platform. Several languages also have Web frameworks that speed up the process
of Web site creation. Also available are application servers that assist in
putting together the various components required in a Web site. Finally if you
need help with some HTML, you've got options there as well.
Putting Linux on your computer
You've heard about all the benefits of using Linux: it's
fast, stable, secure, and it really is easy to use. If you're ready to give Linux
a try on your own computer, you have several options. Some require less
commitment than others.
Live CDs
For example, you might want to try running Linux from a
"live CD." This option loads the operating system into RAM, and
doesn't write files to the hard drive, which is one of the main benefits of
using a live CD: it makes no permanent changes to your computer, and
uninstalling it is as simple as removing the CD.
Another advantage for live CD distributions is that you can
use them almost anywhere. Take the CD or DVD with you and pop it into just
about any computer, and you'll have Linux at your fingertips without having to
install anything.
Using a live CD has its drawbacks, too. It runs slower
because the operating system is running from the CD instead of the hard drive.
Since CD-ROM/DVD drives are much slower than hard drives, running off a live CD
won't give you the same sort of speed that a hard drive install will.
Another problem is that any changes you make, such as custom
configurations, will disappear every time you shut down the live CD. Some live
CDs compensate for this by allowing you to write data and configurations to the
hard drive or a USB drive, but it requires some special setup.
Despite these drawbacks, a live CD is probably the best way
to test drive Linux. There's no risk in using the live CD, if you don't like
it, just pop the CD out and go back to what you were using before. If you like
the OS, though, you may want to go further and put Linux on your hard drive.
Installing on a partition
Installing Linux on a partition of your hard drive is easier
than ever. All you have to do is put the Linux CD in your drive and follow the
instructions. The vast majority of Linux distributions will recognize that you
have Windows installed and will help you set up a new partition just for Linux,
using some or all of the free space on your drive. This is called dual-booting.
When you reboot your
computer, instead of booting straight into Windows, the computer will display a
menu for you to select your operating system. If you make no selection, the
computer will boot into the default operating system, usually Linux, so if you
want to boot into Windows, you'll either have to pay attention, or change the default settings.
Books
If you prefer the dead tree study method, make
sure you get a book specifically designed for desktop Linux users. We have a
few recommendations, but be sure to look around, this isn't a comprehensive
list:
§
Linux for Non-Geeks by Rickford Grant, from No Starch
Press.
§
Linux Pocket Guide by Daniel J. Barrett, from O'Reilly
Media.
§
Linux for Dummies by Dee-Ann LeBlanc, from Wiley.
§
Point and Click Linux by Robin 'Roblimo' Miller, from
Prentice Hall PTR.
§
Linux All-In-One Desk Reference for Dummies by Naba Barkakati, from Wiley.
Removing Microsoft Windows
If you want to try Linux out all by itself, you can tell
Linux to take over the hard drive and use all the space for itself. Once this
operation is completed, you cannot change your mind and get Windows back unless
you have a restore disk, and even that will only restore the factory default
settings.
We're all about Linux here, of course, but we do recommend
that you make a full backup of your data before taking this route in case you
decide you need to revist Windows at a later date -- or just need access to
your data. Many people have removed Windows from their computers and report
great success in using only Linux for their day-to-day activities.
Buying Linux pre-installed
If you're not averse to
spending some money, and you'd rather skip the "do-it-yourself"
routine, you can buy a computer with Linux
pre-installed. The biggest advantage of doing it this way is that
you know the computer is configured correctly and that Linux will work the way
it is supposed to. Your computer is under warranty, and most companies provide
technical support for a certain period after purchase.
Companies that sell
desktop PCs and laptops with Linux pre-installed range from large OEMs like Dell to
smaller Linux-specific vendors like System 76, Koobox, Emperor Linux,
and many others.
If you need help
One of the nice things
about using open source software is that there is no shortage of help
available, should you need it. The first place to go is online. Search to see
if your question has already been answered somewhere. You might find the answer
in a discussion
forum, or in a Linux HOWTO.
If you have searched
diligently and haven't been able to solve your problem, then trying asking a
question in one of the discussion forums. You have a better chance of receiving useful answers if you document your question fully,
including a description of the hardware you are using, the distribution, the
exact nature of the problem/question, any error messages you received, and the
steps leading up to the error.
Most IRC networks have Linux
help channels if you
would like to try some realtime assistance. The same etiquette rules apply, and
don't expect immediate answers.
If it is hands-on help
you need, consider visiting a meeting of your local Linux
Users Group (LUG).
Many LUGs set aside time at each meeting specifically to answer questions or
help install Linux. LUGs also usually have a mailing list, so you can ask your
question before the meeting.
What's a desktop environment?
You'll hear a lot about the command line in Linux, but the
truth is, you rarely (if ever) need to see a command line. Just like Microsoft
Windows and Mac OS X, you can do all of your computing using an attractive
graphical user interface (GUI) with very little reason to use the command line
interface (CLI) unless you want to.
Linux users have a wide variety of desktop environments to
choose from, which may seem odd since you don't need to think about that with
Windows or Mac OS X. For the most part, you won't need to think about it on
Linux, either -- every major distribution has a default environment. For
example, the default desktop environment for Fedora and Ubuntu is GNOME. The
default for openSUSE, Slackware, and Mandriva is KDE. However, most distros
also offer choice between the desktop environment or window managers.
What's the difference between a desktop
environment and window manager?
You might see some GUIs for Linux described as desktop
environments and others described as window managers. What gives? Aren't they
the same thing? Well, not quite.
A window manager is the
application that controls things like the placement of windows within X, icons,
and the appearance of the windows. A window manager doesn't provide things like drag and drop
protocols between applications, suites of applications, and other features
you've probably come to expect from a GUI desktop.
True to its name, a
desktop environment provides a full environment You can expect to see something like
the equivalent of the Windows "Start" button, as well as a
customizable task bar, quick launch buttons, program menu, and desktop icons.
Some desktop environments also have help systems, screensavers, and
interchangeable skins or themes.
The desktop environments also come bundled with window
managers. The two most popular (and arguably more full-featured) for Linux are
K Desktop Environment (KDE) and the GNU Network Object Model Environment
(GNOME). Note that GNOME and KDE run on other operating systems as well.
Both of these are completely open source/free software,
which means that you can access the source code and make and distribute any
modifications you desire, just like you can with Linux itself. KDE uses the
KWin window manager, and GNOME utilizes Metacity as their default window
managers, respectively. Not to confuse things too much, but you can opt to
switch out the default window managers for GNOME and KDE if you choose. For
example, GNOME utilizes Compiz for users who opt for 3D desktop effects. For
the most part, you'll probably want to stick with the defaults here unless you
really enjoy tweaking your computer.
The anatomy of a GUI
The desktop environment
and window managers don't get all the credit for providing a GUI for Linux,
though. The actual work of drawing windows and accepting input is done by the X
Window System, usually just called X. The most popular implementation of X is X.org, an open source implementation of the
protocols that make up the X Window System.
Several years ago, XFree86 was
the most commonly used implementation of X, but most Linux distros moved away
from XFree86 after a controversial licensing change and complaints about the XFree86
project's development processes.
X handles the basics, but the desktop environments and
window managers provide the actual user interface that you see. The buttons,
widgets, title bars, mouse cursor, and so forth are all courtesy of the window
manager and desktop environment toolkits.
The X Window System
differs from other GUI implementations in a few key ways. The most obvious
difference is that X separates the client and server -- so it is possible to
run an X application on a remote system, but display the application on a local
computer. For example, you could run OpenOffice.org on a department server, but
display it on your local computer. This is used by projects like the Linux Terminal Server Project (LTSP) to enable thin
client computing.
Popular desktop environments and window managers
for Linux
Let's talk about some of the popular desktop
environments/window managers that you're likely to use with Linux.
KDE, which
started development in 1996, is a complete desktop environment that includes
its own combination Web browser/file manager (Konqueror),
office suite (KOffice),
and dozens of productivity applications, games, educational programs,
utilities, multimedia applications, and much more.
GNOME, like
KDE, provides a full desktop environment. GNOME has its own file manager
(Nautilus), Web browser (Epiphany), mail client (Evolution) and a bevy of
supporting applications. Like KDE, GNOME also has a number of applications that
are built on the GNOME platform, like AbiWord, the GIMP, Gnumeric, and many
others.
Note that Linux distributors often modify GNOME and KDE (and
other desktop environments/window managers) to some extent, so the application
selection and some features will vary depending on whether you're using Fedora,
Ubuntu, openSUSE, or any other distro.
Both KDE and GNOME are
surrounded by very loyal developer and user communities that each have strong opinions about why "their" desktop
environment is better. However, the rivalry is often overstated, and both GNOME
and KDE developers have made efforts to cooperate with one another (and other
projects) to help ensure interoperability on the Linux desktop.
While KDE and GNOME are
the most widely used projects, you'll find there are a number of quality
alternatives. For example, Xfce is a lightweight desktop environment
that is preferred by many users who want a full-featured, but
resource-friendly, desktop environment. Xfce is the default desktop for the Xubuntu distribution,
and Xfce packages are available for most major Linux distros.
The Window Maker window
manager is another popular choice. It emulates the NeXT operating system's interface. Window
Maker's look and feel is fairly different from Microsoft Windows and Mac OS X.
Window Maker is very lightweight, and is a good choice for lower-end hardware.
The Blackbox window manager is another lightweight
alternative for Linux desktops. Blackbox is minimalist in nature, and only
handles window management. It doesn't offer desktop icons, shortcuts, a
taskbar, menus, and so forth on its own. However, Blackbox does have 3rd party
applications (often integrated by Linux distributors) that provide some of
these features.
The Damn Small
Linux distribution
ships with two window managers -- FluxBox and a modified Joe's
Window Manager (JWM).
FluxBox is originally based on the Blackbox code, but also
offers an icon bar, configurable titlebar, support for KDE and GNOME sessions,
shortcuts, themes, and more. Many users enjoy FluxBox's clean design and its
low resource requirements.
JWM is another lightweight desktop alternative. It will look
a bit more familiar to Windows users, as it sports a Windows-like look for
title bars and its task bar. This is a fairly simple window manager with modest
features, but it's a good choice for older computers and Linux live CD distros.
Enlightenment is a window manager with big plans.
Enlightenment is slow in development, the most recent major release (0.16) took
place more than six years ago, and the 0.17 release has been in the works since
then -- with the occasional maintenance release for 0.16. According to the
Enlightenment Web site, the team is hard at work on "the next generation
of the window manager" which will include a bevy of interesting new
features, if it's ever released.
Don't let the wide selection of desktop environments and
window managers confuse you. We recommend that you begin by simply using the
default environment that comes with your Linux distribution. Once you become
more comfortable with Linux, try the others and come up with your own opinion
about which one is the best.
Using Samba to share files between Linux and
Windows
Your home network might
have a few Windows machines on the ground floor, a Mac in an upstairs bedroom,
a PocketPC on a nightstand, and a Linux box or two in the basement, all
networked with a generic router. For all the devices in this familiar family setup,
or even a scenario with thousands of users, the Samba suite
is an ideal solution for file and print sharing.
Several cross-platform file and print-sharing solutions
exist, but Samba and the SMB/CIFS protocol may be the easiest to implement in a
home networking environment. Windows machines and Macs come with the
functionality to work with with Samba out of the box, and you should only need
to install a single Samba package for Linux machines. GNOME and KDE offer Samba
client functionality built in to their default file managers, Nautilus and
Konqueror, respectively.
We'll focus on
configuring and using Samba for file and print-sharing in a typical home
network with Linux and Windows machines. You can choose from several
Samba configuration GUIs, but we'll go the old-fashioned route and
point our text editors to smb.conf. The configuration file is commonly found at
/etc/samba/smb.conf or /usr/local/samba/lib/smb.conf. Note that you will need
to be root to edit these, or use sudo.
Samba will run on nearly any Unix-like system and can be
found in the repositories of just about every Linux distribution. Begin by
using your distribution's package manager to make sure it is installed.
Configuring Samba
Samba is a very mature
and complex package, so its configuration file can be long and complicated. You
will have to trust that your distribution supplied you with a reasonably sound
default configuration and focus on changing just a few lines in smb.conf to
make sure they are appropriate for the purposes of a home network. If you want
to know more about any line, consult
man smb.conf.
Remember that any line in the configuration file preceded by
a semicolon (;) or hash mark (#) is a comment and will not be recognized as an
active setting. To activate the line, remove the semicolon or hash. It's a good
idea to add your own comments preceded by one of these characters so that you
will remember the logic behind your configuration the next time you load
smb.conf.
The first option to
consider is Samba's security level. This line will appear under the
[global] section of smb.conf,
where all Samba-wide configuration is done. The other sections, addressed later
in this article, relate to specific Samba services (shared resources). The
security level will most likely be set to the value user and look like this:security = user
For a home network, you
may want to consider setting this to
share. The main difference is that with the user setting you will be
required to log into the Samba server before you can browse its resources. This
is a wise precaution on untrusted networks, but will be inconvenient when using
resources you would like your entire household to have access to, such as a
printer. With shareenabled, you can still require users to
authenticate themselves with a password to access particular resources.
While still in the [global] section, let's move on
to printers. If you use the Common UNIX Printing
System (CUPS) (which
most distributions default to), the only thing you need to do to have Samba
recognize your printers is set the following lines accordingly:
printing = cups
printcap
name = cups
Since you may be
configuring these printers (and perhaps other resources) to be accessible
without user authentication, it is very important that you restrict access to
only known and trusted hosts - the computers in your household. Consult your
router's manual for instructions on assigning specific IP addresses to each
computer in your home network. Once you have a list of trusted hosts, enter
them into the following lines in the
[global] section:
hosts allow = computer1 computer2
computerN
hosts
deny = ALL
Although you have
specified that
ALL hosts be denied, any host listed on the hosts allow line will still be given
access. The format of the IP addresses assigned to each computer by your router
will vary. For instance, if machines on your local network are given addresses
of the format 192.168.0.x, the following lines
will restrict Samba access to local hosts:
hosts allow = 192.168.0.
hosts
deny = ALL
Note that the final
digit of the IP address was left off on the
hosts allow line. This specifies that any IP address in that range be
allowed. For additional security against external access, look into blocking Samba ports with a firewall.
Sharing directories and printers
It's time to move beyond
[global] and configure specific
shared resources. Begin with the [homes] section. By default, your distribution may have this section
configured to allow users to access their home directory on the machine running
the Samba server.
If you have
security = share set, this feature may not work as expected and users may be
presented with home directories without logging in. If you are the only one
with a home directory on the machine running the Samba server anyway, which is
likely in a home network environment, it is advisable to remove or comment out
(using hash marks or semicolons) the [homes] section and add any useful directories as shared resources
individually later on.
Now you can begin sharing specific directories. Use this as
a template for a publicly shared folder for which it is not necessary for users
to be authenticated:
[Share Name]
path =
/location/of/directory
guest ok
= yes
browseable
= yes
read only
= no
Share Name is whatever title you choose (to the client accessing your
server, this will appear to be the name of the shared directory). The guest ok = yes line is what specifies this share as publicly accessible.
The browseable = yes line will make the share appear available to all users. Set browseable = no to force users to manually type in the share name to access
it. Of course, you can set read only = yes to restrict users from make changes to the directory
remotely.
Use this as a template for private shares that users must
enter a password to access:
[Share Name]
path = /location/of/directoryvalid
users = user
read only
= yes
browseable
= no
Here, user is the user name on the
machine running the Samba server of the person with access privileges to the
share. Use these two templates to add shares for all the files users may want
to access from the server machine.
Your server should be
fully configured now. With what you added to the defaults provided by your
distribution, your completed smb.conf should look something like this:
[global]
security = share
workgroup = HOME
server string = %h server
log file = /var/log/samba/log.%m
max log size = 1000
dns proxy = No
hosts allow = 192.168.0.
hosts deny = ALL
printing = cups
printcap name = cups
[printers]
path = /var/spool/samba
printable = Yes
browseable = No
[print$]
path = /var/lib/samba/printers
[Public Directory]
path = /Public/Files
guest ok = yes
read only = no
browseable = yes
[Private Directory]
path = /private/files/
valid users = me
read only = yes
browseable = no
Before you leave the server machine you have a few more
quick chores. First, enter any users that will be accessing the Samba server
into the following command:
smbpasswd -a user
You will be prompted to
enter a Samba password for each user. You can change the password at any time
by logging in as the desired user and running
smbpasswd. Now restart your Samba
server using this command:/etc/init.d/samba restart
Accessing Samba shares from Windows clients
Head over to a Windows machine to try out your new setup.
Your new server should appear in Windows' My Network Places (look for the
shortcut on your desktop, by default). Alternatively, open the Start menu and
click "Run...", then enter:
\\server
Replacing server with the name or IP
address of the machine running your Samba server. A Windows Explorer window
with the browseable shares from your server should open up. If you've made a
non-browseable share, access it using this link:
\\server\share name
Is is easy to make shared directories more accessible. In
Windows XP, right click on the share in Explorer and choose "Map Network
Drive..." You will be able to assign them a drive letter, such as Z:, so
that they may be easily found in My Computer, even after a reboot.
In my testing on Windows
XP with the security level set to
share, printers are automatically be detected
and available to use from the Windows machine. With user level security set, it
was necessary to log into the server in a Windows Explorer window before trying
to print. Your experience on other versions of Windows may vary.
Accessing SMB/CIFS shares from other Linux
machines
Samba and Windows shares can be easily accessed from the
default file managers of both Gnome and KDE. We'll begin with accessing shares
from Nautilus in Gnome. Open Nautilus and go to File -> Connect to Server.
Choose "Windows share" from the listbox and enter
the server name or IP address of your Samba server. You can also click the
"Browse Network" button and look in the "Windows Network"
directory to search for the server manually. Click "Connect" and a
Nautilus window will open with the browseable resources of your Samba server.
Accessing Samba shares
with Konqueror is just as simple. To browse for your server, enter the URL remote:/ in Konqueror. For direct
access, type the URL of the server in directly in this format:
smb://user@server/share
Note that user and share are optional criteria.
Configuring printers over Samba is similarly easy in both
these desktop environments. In Gnome, go to System -> Administration ->
Printing. In the printer configuration application, select Printer -> Add
printer. You will be prompted for your password. In the add printer wizard,
select "Network Printer" and then "Windows Printer SMB" from
the listbox. You will be prompted for a user name and password on your Samba
server. Identify your Host and Printer on the Samba server and then move on to
the next screen. Select your printer model and then click Apply.
To do the same in KDE,
open the configuration center by launching the command Normal
account," if using
kcontrol. Navigate to the Printers module and go to Add
-> Add Printer/Class... In the resulting dialog, click Next and then select
"SMB shared printer (Windows)." Click Next again and configure the
username and password of a "user level security. Click Next another time and then Scan to
browse for your Samba server.
Alternatively, enter the server details manually. On the
next screen, select your printer model from the list. Click through the next
few screens and give your networked printer a title to finish up.
Troubleshooting
If you've experienced
any problems getting any of this functionality to work, turn to the Samba troubleshooting checklist. A quick trick
borrowed from that document for testing your Samba configuration file for
obvious errors is to run the following command:
testparm smb.conf
Again, the exact path of
your smb.conf may vary by distribution.
We have only explored
basic Samba functionality here, tailored for a home network. More extreme usage
scenarios are addressed in detail in the Samba by example guide.
Introduction to the command line
People can interact with computers running Linux in two ways
-- using the graphical user interface (GUI) or the command line interface
(CLI). If you're familiar with the GUI, you may find the CLI intimidating at
first sight. Instead of pretty buttons, you get the computer equivalent of a
blank, empty sheet: the whole screen, or at least a whole window, with nothing
but the borders and the actual command line. But by learning a few
fundamentals, you can use the command line to accomplish miracles.
At the command line, you type one or more commands, all in
one line, then press the Enter key; the computer analyzes what you typed,
executes it, and (sometimes) prints the result just below your instructions.
Then you type another command, and so on. You have to know in advance which
commands exist, what they do, and how they interact with each other.
Often, a graphical interface is the best, if not the only,
way to go: the most common example is advanced photo editing. A mouse-only
approach, however, can be extremely limiting. In a graphical interface you only
find the buttons that somebody else considered necessary. Above all, you must
be there to push them, so it may be impossible to automate anything but the
simplest button sequences. If doing something requires just three mouse clicks,
doing it 100 times may require 300 mouse clicks. Doing the same thing at the
CLI, however, would be just require an action loop. This command, for example,
is all you need to find all the JPG images in the current folder and place a
thumbnail of each of them in /tmp/thumbnails/:
for picture in `find . -name
"*jpg"`; do convert -sample 80x40 $picture /tmp/thumbnails/$picture ;
done
The shell
You can get to the CLI
in two ways. The first is the standard Linux console, which you'll see if your
system isn't running X or if you switch to one of the virtual consoles while X
is running. To switch to a virtual terminal, press
Ctrl-Alt-F1. Most Linux distributions are set up to have
six virtual consoles, and you can access each by using Ctrl-Alt-F2, Ctrl-Alt-F3, and so forth.
A more convenient way, if you're using X, is to use a
terminal emulator. Linux distros come with a wide variety of terminal emulators
-- from the basic xterm that has been part of X for years, to Konsole and
Gnome-Terminal, which have additional features like tabbed windows.
No matter how you access
the command line, it always works in the same way. Everything you enter at the
command line is interpreted by the shell, which is a program that interprets and
executes commands run at the command line or read from a script. To do their
job, a shell or its user can create, read or modify variables, which are containers for storing numbers,
names, or any other data. Data and variables made only of text are also called strings.
You have the choice of
several shells on Linux, each with a slightly different specialization. Some
are optimized to reduce memory consumptions, others to perform calculations.
The default shell on most Linux distributions is the Bourne again shell, or bash.
The shell looks for
executable programs by default in any folders listed in a system-defined
variable called $PATH. You can see what folders are defined on your system by
typing the command
echo
$PATH.
You can change the value of this or any other shell variable by redefining them
in configuration files like /etc/bashrc (for all users) or $HOME/.bashrc (just
for yourself), and thus make bash work just as you like. You can also define aliases, or short strings to type in place of
commonly used but much longer instructions.
Every time you type a command, the shell does one of two
things. If the first argument -- that is, the first sequence of non-whitespace
characters -- is the name of a program, then the shell launches that program,
passing as arguments to it everything you wrote after that string.
If what you typed isn't
a program name, the shell interprets it as a command. The shell also has a
simple programming language built in, with the possibility to read or create
files and manyreserved words associated to the most common
functions and operations. For example,
cd means "change directory," pwd means "print the
name of the current working directory," and historylists the most recent commands you typed.
Combining and mixing commands
You can execute two or more unrelated instructions one after
each other by separating them with a semicolon. For instance, if you need to
create a backup archive in tar format of all the files in your mywork directory
and copy it to some remote server using an encrypted connection, use a command
like:
tar cf monthly_backup.tar work/ ; scp
monthly_backup.tar myaccount@some.remote.server:monthly_backup.tar
Normally the doesn't
allow you to enter further commands until the last one is finished and has
displayed its output on the screen. To have the CLI return to the command
prompt without waiting for the current task to finish, you have to put the
first command in the background -- that is, keep it running but without locking the terminal
window. To do this, type
Ctrl-Z and then the bg(background) command:tar cf monthly_backup.tar work/
(the prompt disappears while tar is running)
Ctrl-Z
bg
(the prompt reappears and you can type another command)
To start a program directly in background mode so that it
doesn't lock your terminal, add an ampersand to the end of the command before
pressing you press Enter:
tar cf monthly_backup.tar work &
You can also combine commands in a more powerful way. The
pipe operator (|) attaches one program to another, so that the latter
automatically receives and processes all the data created by the former. You
can, therefore, type something like:
find . -type f -exec ls -s {} \; | sort -n -r | head -3
5500 ./monthly_backup.tar
287 ./picture.jpg
150 ./diary.odt
This command lists by
size (
ls -s) all the files in the
current directory, sorts them in reverse numerical order (-n -r), and displays only the first three
elements (head -3) of the ordered list.
While every command performs one generic task, you get only one final result,
which is the only thing you were interested in: the three biggest files in the
current directory.
You don't have to sit at
the keyboard to look at the output of commands. You can use redirection to save the results to a
text file. If you add
> bigger_files.txt to the previous command: find . -type f -exec ls -s {} \; | sort -n -r | head -3 > bigger_documents.txt
the
> operator redirects the
output of the command to bigger_documents.txt.
Shells are extremely powerful also thanks to another
feature: any sequence of commands can be saved to a plain text file and
executed again, any time you wish, without retyping everything. All you have to
do is to write as the first line in that file the string:
#! /bin/bash
This tells the system
that the rest of the file should be directly interpreted by bash. You must also
make the file executable with the chmod
command:
chmod 755 my_shell_script_file
This form of programming, called scripting, may be all you
ever need to fully customize your Linux computer.
What you can do with bash: practical examples
The point of this article is not so much to teach the basics
of shell programming, but to help you understand what the command line is, how
it works, and why you should learn more about it.
The best documentation
freely available online to help you become a shell guru is probably the Advanced Bash Scripting Guide. As far as quick
and practical tips go, instead, there are plenty of them in the "CLI
Magic" series on Linux.com. Some are related to system administration,
from knowing
what is happening in your computer to automating
file searches and other operations ordiscovering
malware. Desktop-wise, is is possible to access a
Bluetooth phone or manage
your contacts.
Together with the
serious stuff, however, you can also learn how to play
music, rip and
convert songs from audio CDs, download
and play podcasts, and even upload
videos to YouTube. Finally, if you're just bored, you can play at
the command line Miller's
Quest, Nethack and other
games.
Using documentation: man and info
Many Linux commands and
programs have documentation available right at the command line. When you need
to know how some program works or what are its options, type
man or infofollowed by the program name, and most of times you'll have
the answer.
ليست هناك تعليقات:
إرسال تعليق