This commit is contained in:
gferg 2003-01-03 15:03:41 +00:00
parent bfea843c42
commit 5db9bfb6ae
44 changed files with 254410 additions and 0 deletions

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
<!ENTITY chap1 SYSTEM "chap1.xml">
<!ENTITY chap2 SYSTEM "chap2.xml">
<!ENTITY chap3 SYSTEM "chap3.xml">
<!ENTITY chap4 SYSTEM "chap4.xml">
<!ENTITY chap5 SYSTEM "chap5.xml">
<!ENTITY chap6 SYSTEM "chap6.xml">
<!ENTITY chap7 SYSTEM "chap7.xml">
<!ENTITY chap8 SYSTEM "chap8.xml">
<!ENTITY chap9 SYSTEM "chap9.xml">
<!ENTITY chap10 SYSTEM "chap10.xml">
<!ENTITY app1 SYSTEM "app1.xml">
<!ENTITY app2 SYSTEM "app2.xml">
<!ENTITY app3 SYSTEM "app3.xml">
<!ENTITY app4 SYSTEM "app4.xml">
<!ENTITY gloss SYSTEM "gloss.xml">
]>
<book>
<bookinfo>
<title>Introduction to Linux</title>
<subtitle>A Hands on Guide</subtitle>
<authorgroup>
<author>
<firstname>Machtelt</firstname>
<surname>Garrels</surname>
<affiliation>
<orgname>CoreSequence.com
</orgname>
<address>
<email>tille@coresequence.com</email>
</address>
</affiliation>
</author>
</authorgroup>
<edition>Version 3.0.1 Last updated 20021112</edition>
<keywordset>
<keyword>Linux</keyword>
<keyword>Beginners</keyword>
<keyword>linux</keyword>
<keyword>start</keyword>
<keyword>Getting started</keyword>
<keyword>guide</keyword>
<keyword>Guide</keyword>
<keyword>Exercises</keyword>
<keyword>exercises</keyword>
</keywordset>
</bookinfo>
<preface>
<title>Introduction</title>
<section id="intro_01">
<title>Why this guide?</title>
<para>Many people still believe that learning Linux is difficult, or that only experts can understand how a Linux system works. Though there is a lot of free documentation available, the documentation is widely scattered on the Web, and often confusing, since it is usually oriented toward experienced UNIX or Linux users. Today, thanks to the advancements in development, Linux has grown in popularity both at home and at work. The goal of this guide is to show people of all ages that Linux can be simple and fun, and used for all kinds of purposes.</para>
</section>
<section id="intro_02">
<title>Who should read this book?</title>
<para>
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. We hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.</para>
<para>Everybody who wants to get a CLUE, a Command Line User Experience, with Linux (and UNIX in general) will find this book useful.</para>
</section>
<section id="intro_03">
<title>New versions of this guide</title>
<para>This document is published in the Linux Documentation Project collection (<ulink url="http://www.tldp.org">http://www.tldp.org</ulink>). The most recent edition is also available at <ulink url="http://tille.soti.org/training/linux/new/">http://tille.soti.org/training/linux/new/</ulink>.</para>
</section>
<section id="intro_04">
<title>Revision History</title>
<para>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>2002-11-30</date>
<authorinitials>MG</authorinitials>
<revremark>Initial release</revremark>
</revision>
</revhistory>
</para>
</section>
<section id="intro_05">
<title>Contributions</title>
<para>
Many thanks to all the people who shared their experiences. And especially to the Belgian Linux users, among them my husband, for hearing me out every day and always being generous in their comments.</para>
<para>Also a special thought for Tabatha Persad for doing a really thorough revision.</para>
</section>
<section id="intro_06">
<title>Feedback</title>
<para>
Missing information, missing links, missing characters? Mail it to the maintainer of this document: <address><email>tille@coresequence.com</email></address>
</para>
</section>
<section id="intro_07">
<title>Copyright information</title>
<para>Copyright &copy; 2002 Machtelt Garrels.</para>
<para> Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being "New versions of this document", "Contributions", "Feedback" and "Copyright information", with no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in <xref linkend="app4" /> entitled "GNU Free Documentation License".</para>
<para>The author and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor the publisher nor any dealer or distributor will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.</para>
<para>The logos, trademarks and symbols used in this book are the properties of their respective owners.</para>
</section>
<section id="intro_08">
<title>What do you need?</title>
<para>You will require a computer and a medium containing a Linux distribution. While this book was written for RedHat Linux, most of it applies to all Linux distributions - and UNIX in general. Apart from time, there are no further specific requirements.</para>
<para>The <ulink url="http://www.tldp.org/HOWTO/Installation-HOWTO/">Installation HOWTO</ulink> contains helpful information on how to obtain Linux software and install it on your computer. Hardware requirements and coexistence with other operating systems are also discussed.</para>
</section>
</preface>
<toc></toc>
&chap1;
&chap2;
&chap3;
&chap4;
&chap5;
&chap6;
&chap7;
&chap8;
&chap9;
&chap10;
&app1;
&app2;
&app3;
&app4;
&gloss;
</book>

View File

@ -0,0 +1,126 @@
<appendix id="app1">
<title>Where to go from here?</title>
<abstract><para>This document gives an overview of useful books and sites.</para></abstract>
<sect1><title>Useful Books</title>
<sect2><title>General Linux</title>
<itemizedlist>
<listitem><para>"Linux in a Nutshell" by Ellen Siever, Jessica P. Hackman, Stephen SPainhour, Stephen Figgins, O'Reilly UK, ISBN 0596000251</para></listitem>
<listitem><para>"Running Linux" by Matt Welsh, Matthias Kalle Dalheimer, Lar Kaufman, O'Reilly UK, ISBN 156592469X</para></listitem>
<listitem><para>"Linux Unleashed" by Tim Parker, Bill Ball, David Pitts, Sams, ISBN 0672316889</para></listitem>
<listitem><para>"When You Can't Find Your System Administrator" by Linda Mui, O'Reilly UK, ISBN 1565921046</para></listitem>
<listitem><para>When you actually buy a distribution, it will contain a very decent user manual.</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Editors</title>
<itemizedlist>
<listitem><para>"Learning the Vi Editor" by Linda Lamb and Arnold Robbins, O'Reilly UK, ISBN 1565924266</para></listitem>
<listitem><para>"GNU Emacs Manual" by Richard M.Stallman, iUniverse.Com Inc., ISBN 0595100333</para></listitem>
<listitem><para>"Learning GNU Emacs" by Debra Cameron, Bill Rosenblatt and Eric Raymond, O'Reilly UK, ISBN 1565921526</para></listitem>
<listitem><para>"Perl Cookbook" by Tom Christiansen and Nathan Torkington, O'Reilly UK, ISBN 1565922433</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Shells</title>
<itemizedlist>
<listitem><para>"Unix Shell Programming" by Stephen G.Kochan and Patrick H.Wood, Sams Publishing, ISBN 067248448X</para></listitem>
<listitem><para>"Learning the Bash Shell" by Cameron Newham and Bill Rosenblatt, O'Reilly UK, ISBN 1565923472</para></listitem>
<listitem><para>"The Complete Linux Shell Programming Training Course" by Ellie Quigley and Scott Hawkins, Prentice Hall PTR, ISBN 0130406767</para></listitem>
<listitem><para>"Linux and Unix Shell Programming" by David Tansley, Addison Wesley Publishing Company, ISBN 0201674726</para></listitem>
<listitem><para>"Unix C Shell Field Guide" by Gail and Paul Anderson, Prentice Hall, ISBN 013937468X</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>X Windows</title>
<itemizedlist>
<listitem><para>"Gnome User's Guide" by the Gnome Community, iUniverse.Com Inc., ISBN 0595132251</para></listitem>
<listitem><para>"KDE Bible" by Dave Nash, Hungry Minds Inc., ISBN 0764546929</para></listitem>
<listitem><para>"The Concise Guide to XFree86 for Linux" by Aron HSiao, Que, ISBN 0789721821</para></listitem>
<listitem><para>"The New XFree86" by Bill Ball, Prima Publishing, ISBN 0761531521</para></listitem>
<listitem><para>"Beginning GTK+ and Gnome" by Peter Wright, Wrox Press, ISBN 1861003811</para></listitem>
<listitem><para>"KDE 2.0 Development" by David Sweet and Matthias Ettrich, Sams Publishing, ISBN 0672318911</para></listitem>
<listitem><para>"GTK+/Gnome Application Development" by Havoc Pennington, New Riders Publishing, ISBN 0735700788</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Networking</title>
<itemizedlist>
<listitem><para>"DNS and BIND" by Paul Albitz, Cricket Liu, Mike Loukides and Deborah Russell, O'Reilly &amp; Associates, ISBN 0596001584</para></listitem>
<listitem><para>"The Concise Guide to DNS and BIND" by Nicolai Langfeldt, Que, ISBN 0789722739</para></listitem>
<listitem><para>"Implementing LDAP" by Mark Wilcox, Wrox Press, ISBN 1861002211</para></listitem>
<listitem><para>"Understanding and deploying LDAP directory services" by Tim Howes and co., Sams, ISBN 0672323168</para></listitem>
<listitem><para>"Sendmail" by Brian Costales and Eric Allman, O'Reilly UK, ISBN 1565922220</para></listitem>
<listitem><para>"Removing the Spam : Email Processing and Filtering" by Geoff Mulligan, Addison Wesley Publishing Company, ISBN 0201379570</para></listitem>
<listitem><para>"Managing IMAP" by Dianna &amp; Kevin Mullet, O'Reilly UK, ISBN 059600012X</para></listitem>
</itemizedlist>
</sect2>
</sect1>
<sect1><title>Useful sites</title>
<sect2><title>General</title>
<itemizedlist>
<listitem><para><ulink url="http://www.tldp.org">The Linux documentation project</ulink>: all docs, manpages, HOWTOs, FAQs</para></listitem>
<listitem><para><ulink url="http://www.google.com/linux">Google for Linux</ulink>: the specialized search engine</para></listitem>
<listitem><para><ulink url="http://www.deja.com">Deja</ulink>: an archive of all newsgroup postings, including the comp.os.linux hierarchy</para></listitem>
<listitem><para><ulink url="http://slashdot.org">Slashdot</ulink>: daily news</para></listitem>
<listitem><para><ulink url="http://www.oreilly.com">http://www.oreilly.com</ulink>: books on Linux System and Network administration, Perl, Java, ...</para></listitem>
<listitem><para><ulink url="http://www.posix.com/posix.html">POSIX</ulink>: the standard</para></listitem>
<listitem><para><ulink url="http://www.linuxhq.com">Linux HQ</ulink>: Maintains a complete database of source, patches and documentation for various versions of the Linux kernel.</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Architecture Specific References</title>
<itemizedlist>
<listitem><para><ulink url="http://www.linuxppc.org">Linux PPC</ulink>: Linux on a Power PC (e.g. Apple PowerPC, PowerMac, Amiga, IBM ThinkPad/PowerSeries/RS/6000, Motorola...)</para></listitem>
<listitem><para><ulink url="http://www.alphalinux.org">AlphaLinux</ulink>: Linux on Alpha architecture (e.g. Digital Workstation)</para></listitem>
<listitem><para><ulink url="http://www.linux-mips.org">Linux-MIPS</ulink>: Linux on MIPS (e.g. SGI Indy)</para></listitem>
<listitem><para><ulink url="http://www.bibliorg/mdw/HOWTO/Laptop-HOWTO.html">Laptop HOWTO</ulink>: Specific guidelines for installing and running Linux on laptops, configuration files for various models.</para></listitem>
<listitem><para><ulink url="http://www.mklinux.org">MkLinux</ulink>: Linux on Apple</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Distributions</title>
<itemizedlist>
<listitem><para><ulink url="http://www.redhat.com">RedHat</ulink></para></listitem>
<listitem><para><ulink url="http://www.mandrake.com">Mandrake</ulink></para></listitem>
<listitem><para><ulink url="http://www.freebsd.org">FreeBSD</ulink></para></listitem>
<listitem><para><ulink url="http://www.debian.org">Debian</ulink></para></listitem>
<listitem><para><ulink url="http://www.openbsd.org">OpenBSD</ulink></para></listitem>
<listitem><para><ulink url="http://www.turbolinux.com">TurboLinux</ulink></para></listitem>
<listitem><para><ulink url="http://www.suse.de">Suse</ulink></para></listitem>
<listitem><para><ulink url="http://www.caldera.com">Caldera</ulink></para></listitem>
<listitem><para>...</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Software</title>
<itemizedlist>
<listitem><para><ulink url="http://linux.tucows.com">Tucows</ulink> (or your local mirror, e.g. linux.skynet.be): CD images, GNU packages, major distributions</para></listitem>
<listitem><para><ulink url="http://freshmeat.net">Freshmeat</ulink>: new software, software archives</para></listitem>
<listitem><para><ulink url="http://www.openssh.org">OpenSSH</ulink>: Secure SHell site</para></listitem>
<listitem><para><ulink url="http://www.openoffice.org">OpenOffice</ulink>: MS compatible Office Suite</para></listitem>
<listitem><para><ulink url="http://www.kde.org">KDE</ulink>: K Desktop site</para></listitem>
<listitem><para><ulink url="http://www.gnu.org">GNU</ulink>: GNU and GNU software</para></listitem>
<listitem><para><ulink url="http://www.gnome.org">Gnome</ulink>: The official Gnome site</para></listitem>
<listitem><para><ulink url="http://www.ximian.com">Ximian</ulink>: Ximian Gnome, Red Carpet package management system for StarOffice, Opera, CodeWeavers, Loki Demos, Evolution, system packages, ...</para></listitem>
<listitem><para><ulink url="http://www.rpmfind.net">RPM Find</ulink>: all RPM packages</para></listitem>
<listitem><para><ulink url="http://www.samba.org">Samba</ulink>: MS Windows file and print services</para></listitem>
<listitem><para><ulink url="http://www.openldap.org">Home of the OpenLDAP Project</ulink>: OpenLDAP server/clients/utilities, FAQ and other documentation.</para></listitem>
<listitem><para><ulink url="http://www.sendmail.org">Sendmail Homepage</ulink>: A thorough technical discussion of Sendmail features, includes configuration examples.</para></listitem>
<listitem><para><ulink url="http://netfilter.samba.org">Netfilter</ulink>: contains assorted information about iptables: HOWTO, FAQ, guides, ...</para></listitem>
<listitem><para><ulink url="http://www.gimp.org">Official GIMP website</ulink>: All information about the GNU Image Manipulation Program.</para></listitem>
</itemizedlist>
</sect2>
</sect1>
</appendix>

View File

@ -0,0 +1,36 @@
<appendix id="app2">
<title>DOS versus Linux commands</title>
<abstract><para>In this appendix, we matched DOS commands with their Linux equivalent.</para></abstract>
<para>As an extra means of orientation for new users with a Windows background, the table below lists MS-DOS commands with their Linux counterparts. Keep in mind that Linux commands usually have a number of options. Read the Info or man pages on the command to find out more.</para>
<table frame="all">
<title>Overview of DOS/Linux commands</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row><entry>DOS commands</entry><entry>Linux command</entry></row>
</thead>
<tbody>
<row><entry><command>&lt;command&gt; /?</command></entry><entry><command>man &lt;command&gt;</command></entry></row>
<row><entry><command>cd</command></entry><entry><command>cd</command></entry></row>
<row><entry><command>chdir</command></entry><entry><command>pwd</command></entry></row>
<row><entry><command>cls</command></entry><entry><command>clear</command></entry></row>
<row><entry><command>copy</command></entry><entry><command>cp</command></entry></row>
<row><entry><command>date</command></entry><entry><command>date</command></entry></row>
<row><entry><command>del</command></entry><entry><command>rm</command></entry></row>
<row><entry><command>dir</command></entry><entry><command>ls</command></entry></row>
<row><entry><command>echo</command></entry><entry><command>echo</command></entry></row>
<row><entry><command>edit</command></entry><entry><command>pico (or other editor)</command></entry></row>
<row><entry><command>exit</command></entry><entry><command>exit</command></entry></row>
<row><entry><command>fc</command></entry><entry><command>diff</command></entry></row>
<row><entry><command>find</command></entry><entry><command>grep</command></entry></row>
<row><entry><command>format</command></entry><entry><command>mke2fs or mformat</command></entry></row>
<row><entry><command>mem</command></entry><entry><command>free</command></entry></row>
<row><entry><command>mkdir</command></entry><entry><command>mkdir</command></entry></row>
<row><entry><command>more</command></entry><entry><command>more or even less</command></entry></row>
<row><entry><command>move</command></entry><entry><command>mv</command></entry></row>
<row><entry><command>ren</command></entry><entry><command>mv</command></entry></row>
<row><entry><command>time</command></entry><entry><command>date</command></entry></row>
</tbody>
</tgroup>
</table>
</appendix>

View File

@ -0,0 +1,446 @@
<appendix id="app3">
<title>Shell Features</title>
<abstract><para>This document gives an overview of common shell features (the same in every shell flavour) and differing shell features (shell specific features).</para></abstract>
<sect1>
<title>Common features</title>
<para>
The following features are standard in every shell. Note that the stop, suspend, jobs, bg and fg commands are only available on systems that support job control.
</para>
<table frame="all">
<title>Common Shell Features</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row>
<entry>Command</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry>&gt;</entry>
<entry>Redirect output</entry>
</row>
<row>
<entry>&gt;&gt;</entry>
<entry>Append to file</entry>
</row>
<row>
<entry>&lt;</entry>
<entry>Redirect input</entry>
</row>
<row>
<entry>&lt;&lt;</entry>
<entry>"Here" document (redirect input)</entry>
</row>
<row>
<entry>|</entry>
<entry>Pipe output</entry>
</row>
<row>
<entry>&amp;</entry>
<entry>Run process in background.</entry>
</row>
<row>
<entry>;</entry>
<entry>Separate commands on same line</entry>
</row>
<row>
<entry>*</entry>
<entry>Match any character(s) in filename</entry>
</row>
<row>
<entry>?</entry>
<entry>Match single character in filename</entry>
</row>
<row>
<entry>[ ]</entry>
<entry>Match any characters enclosed</entry>
</row>
<row>
<entry>( )</entry>
<entry>Execute in subshell</entry>
</row>
<row>
<entry>` `</entry>
<entry>Substitute output of enclosed command</entry>
</row>
<row>
<entry>" "</entry>
<entry>Partial quote (allows variable and command expansion)</entry>
</row>
<row>
<entry>' '</entry>
<entry>Full quote (no expansion)</entry>
</row>
<row>
<entry>\</entry>
<entry>Quote following character</entry>
</row>
<row>
<entry>$var</entry>
<entry>Use value for variable</entry>
</row>
<row>
<entry>$$</entry>
<entry>Process id</entry>
</row>
<row>
<entry>$0</entry>
<entry>Command name</entry>
</row>
<row>
<entry>$n</entry>
<entry>nth argument (n from 0 to 9)</entry>
</row>
<row>
<entry>$*</entry>
<entry>All arguments as a simple word</entry>
</row>
<row>
<entry><literal>#</literal></entry>
<entry>Begin comment</entry>
</row>
<row>
<entry>bg</entry>
<entry>Background execution</entry>
</row>
<row>
<entry>break</entry>
<entry>Break from loop statements</entry>
</row>
<row>
<entry>cd</entry>
<entry>Change directories</entry>
</row>
<row>
<entry>continue</entry>
<entry>Resume a program loop</entry>
</row>
<row>
<entry>echo</entry>
<entry>Display output</entry>
</row>
<row>
<entry>eval</entry>
<entry>Evaluate arguments</entry>
</row>
<row>
<entry>exec</entry>
<entry>Execute a new shell</entry>
</row>
<row>
<entry>fg</entry>
<entry>Foreground execution</entry>
</row>
<row>
<entry>jobs</entry>
<entry>Show active jobs</entry>
</row>
<row>
<entry>kill</entry>
<entry>Terminate running jobs</entry>
</row>
<row>
<entry>newgrp</entry>
<entry>Change to a new group</entry>
</row>
<row>
<entry>shift</entry>
<entry>Shift positional parameters</entry>
</row>
<row>
<entry>stop</entry>
<entry>Suspend a background job</entry>
</row>
<row>
<entry>suspend</entry>
<entry>Suspend a foreground job</entry>
</row>
<row>
<entry>time</entry>
<entry>Time a command</entry>
</row>
<row>
<entry>umask</entry>
<entry>Set or list file permissions</entry>
</row>
<row>
<entry>unset</entry>
<entry>Erase variable or function definitions</entry>
</row>
<row>
<entry>wait</entry>
<entry>Wait for a background job to finish</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1><title>Differing features</title>
<para>The table below shows major differences between the standard shell (sh), Korn shell (ksh) and the C shell (csh).</para>
<note><title>Shell compatibility</title>
<para>Since the Bourne again shell is a superset of sh, all sh commands will also work in bash. Since the Turbo C shell is a superset of csh, all csh commands will work in tcsh. For more details on these two popular shells, see man the man pages for these shells on your system.</para></note>
<table frame="all"><title>Differing Shell Features</title>
<tgroup cols="4" align="left" colsep="1" rowsep="1">
<thead>
<row>
<entry>sh</entry>
<entry>ksh</entry>
<entry>csh</entry>
<entry>Meaning/Action</entry>
</row>
</thead>
<tbody>
<row>
<entry>$</entry>
<entry>$</entry>
<entry>%</entry>
<entry>Prompt</entry>
</row>
<row>
<entry> </entry><entry> </entry><entry>&gt;!</entry><entry>Force redirection</entry>
</row>
<row>
<entry> </entry><entry> </entry><entry>&gt;&gt;!</entry><entry>Force append</entry>
</row>
<row>
<entry>&gt; file 2&gt;&amp;1</entry>
<entry>> file 2&gt;&amp;1</entry>
<entry>&gt;&amp; file</entry>
<entry>Combine stdout and stderr</entry>
</row>
<row>
<entry> </entry><entry> </entry> <entry>{ }</entry>
<entry> Expand elements in list</entry>
</row>
<row>
<entry>` `</entry>
<entry>$( )</entry>
<entry>` `</entry>
<entry>Substitute output of enclosed command</entry>
</row>
<row>
<entry>$HOME</entry>
<entry>$HOME</entry>
<entry>$home</entry>
<entry>Home directory</entry>
</row>
<row>
<entry> </entry> <entry>~</entry>
<entry>~</entry>
<entry>Home directory symbol</entry>
</row>
<row>
<entry>var=value</entry>
<entry>var=value</entry>
<entry>set var=value</entry>
<entry>Variable assignment</entry>
</row>
<row>
<entry>export var</entry>
<entry>export var=val</entry>
<entry>setenv var val</entry>
<entry>Set environment variable</entry>
</row>
<row><entry> </entry>
<entry>${nn}</entry><entry> </entry>
<entry>More than 9 args can be referenced</entry>
</row>
<row>
<entry>"$@"</entry>
<entry>"$@"</entry><entry> </entry>
<entry>All args as separate words</entry>
</row>
<row>
<entry><literal>$#</literal></entry>
<entry><literal>$#</literal></entry>
<entry><literal>$#argv</literal></entry>
<entry>Number of arguments</entry>
</row>
<row>
<entry>$?</entry>
<entry>$?</entry>
<entry>$status</entry>
<entry>Exit status</entry>
</row>
<row>
<entry>$!</entry>
<entry>$!</entry><entry> </entry>
<entry>Background exit status</entry>
</row>
<row>
<entry>$-</entry>
<entry>$-</entry><entry> </entry>
<entry>Current options</entry>
</row>
<row>
<entry>. file</entry>
<entry>. file</entry>
<entry>source file</entry>
<entry>Read commands in file</entry>
</row>
<row>
<entry> </entry>
<entry>alias x=y</entry>
<entry>alias x y</entry>
<entry>Name x stands for y</entry>
</row>
<row>
<entry>case</entry>
<entry>case</entry>
<entry>switch/case</entry>
<entry>Choose alternatives</entry>
</row>
<row><entry> </entry>
<entry>cd ~-</entry>
<entry>popd/pushd</entry>
<entry>Switch directories</entry>
</row>
<row>
<entry>done</entry>
<entry>done</entry>
<entry>end</entry>
<entry>End a loop statement</entry>
</row>
<row>
<entry>esac</entry>
<entry>esac</entry>
<entry>endsw</entry>
<entry>End case or switch</entry>
</row>
<row>
<entry>exit [n]</entry>
<entry>exit [n]</entry>
<entry>exit [(expr)]</entry>
<entry>Exit with a status</entry>
</row>
<row>
<entry>for/do</entry>
<entry>for/do</entry>
<entry>foreach</entry>
<entry>Loop through variables</entry>
</row>
<row><entry> </entry>
<entry>print -r</entry>
<entry>glob</entry>
<entry>Ignore echo escapes</entry>
</row>
<row>
<entry>hash</entry>
<entry>alias -t</entry>
<entry>hashstat</entry>
<entry>Display hashed commands (tracked aliases)</entry>
</row>
<row>
<entry>hash cmds</entry>
<entry>alias -t cmds</entry>
<entry>rehash</entry>
<entry>Remember command locations</entry>
</row>
<row>
<entry>hash -r</entry><entry> </entry>
<entry>unhash</entry>
<entry>Forget command locations</entry>
</row>
<row><entry> </entry>
<entry>history</entry>
<entry>history</entry>
<entry>List previous commands</entry>
</row>
<row><entry> </entry>
<entry>r</entry>
<entry>!!</entry>
<entry>Redo previous command</entry>
</row>
<row><entry> </entry>
<entry>r str</entry>
<entry>!str</entry>
<entry>Redo command that starts with str</entry>
</row>
<row><entry> </entry>
<entry>r x=y cmd</entry>
<entry>!cmd:s/x/y/</entry>
<entry>Edit command, then execute</entry>
</row>
<row>
<entry>if [ $i -eq 5 ]</entry>
<entry>if ((i==5))</entry>
<entry>if ($i==5)</entry>
<entry>Sample if statement</entry>
</row>
<row>
<entry>fi</entry>
<entry>fi</entry>
<entry>endif</entry>
<entry>End if statement</entry>
</row>
<row>
<entry>ulimit</entry>
<entry>ulimit</entry>
<entry>limit</entry>
<entry>Set resource limits</entry>
</row>
<row>
<entry>pwd</entry>
<entry>pwd</entry>
<entry>dirs</entry>
<entry>Print working directory</entry>
</row>
<row>
<entry>read</entry>
<entry>read</entry>
<entry>$&lt;</entry>
<entry>Read from terminal</entry>
</row>
<row>
<entry>trap 2</entry>
<entry>trap 2</entry>
<entry>onintr</entry>
<entry>Ignore interrupts</entry>
</row>
<row><entry> </entry>
<entry>unalias</entry>
<entry>unalias</entry>
<entry>Remove aliases</entry>
</row>
<row>
<entry>until</entry>
<entry>until</entry><entry> </entry>
<entry>Begin until loop</entry>
</row>
<row>
<entry>while/do</entry>
<entry>while/do</entry>
<entry>while</entry>
<entry>Begin while loop</entry>
</row>
</tbody>
</tgroup>
</table>
<para>Bash specific features:</para>
<itemizedlist>
<listitem><para>tab: file name completion</para></listitem>
<listitem><para>tab tab: choices</para></listitem>
<listitem><para>navigation through previous commands with arrow-keys (.bash_history)
</para></listitem>
</itemizedlist>
<para>More information:</para>
<para>You should at least read one manual, being the manual of your shell. Print it out and take it home, study it whenever you have 5 minutes.</para>
<itemizedlist>
<listitem><para>man sh</para></listitem>
<listitem><para>man bash</para></listitem>
<listitem><para>man csh</para></listitem>
<listitem><para>man tcsh</para></listitem>
<listitem><para>man ksh</para></listitem>
<listitem><para>See appendix 2 for a readinglist.</para></listitem>
</itemizedlist>
</sect1>
</appendix>

View File

@ -0,0 +1,444 @@
<appendix id="app4">
<title>GNU Free Documentation License</title>
<para>Version 1.1, March 2000</para>
<blockquote>
<para>Copyright (C) 2000 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.</para>
</blockquote>
<sect1 id="gfdl-0">
<title>PREAMBLE</title>
<para>The purpose of this License is to make a manual, textbook,
or other written document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or
noncommercially. Secondarily, this License preserves for the
author and publisher a way to get credit for their work, while not
being considered responsible for modifications made by
others.</para>
<para>This License is a kind of "copyleft", which means that
derivative works of the document must themselves be free in the
same sense. It complements the GNU General Public License, which
is a copyleft license designed for free software.</para>
<para>We have designed this License in order to use it for manuals
for free software, because free software needs free documentation:
a free program should come with manuals providing the same
freedoms that the software does. But this License is not limited
to software manuals; it can be used for any textual work,
regardless of subject matter or whether it is published as a
printed book. We recommend this License principally for works
whose purpose is instruction or reference.</para>
</sect1>
<sect1 id="gfdl-1">
<title>APPLICABILITY AND DEFINITIONS</title>
<para>This License applies to any manual or other work that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. The "Document",
below, refers to any such manual or work. Any member of the
public is a licensee, and is addressed as "you".</para>
<para>A "Modified Version" of the Document means any work
containing the Document or a portion of it, either copied
verbatim, or with modifications and/or translated into another
language.</para>
<para>A "Secondary Section" is a named appendix or a front-matter
section of the Document that deals exclusively with the
relationship of the publishers or authors of the Document to the
Document's overall subject (or to related matters) and contains
nothing that could fall directly within that overall subject.
(For example, if the Document is in part a textbook of
mathematics, a Secondary Section may not explain any mathematics.)
The relationship could be a matter of historical connection with
the subject or with related matters, or of legal, commercial,
philosophical, ethical or political position regarding
them.</para>
<para>The "Invariant Sections" are certain Secondary Sections
whose titles are designated, as being those of Invariant Sections,
in the notice that says that the Document is released under this
License.</para>
<para>The "Cover Texts" are certain short passages of text that
are listed, as Front-Cover Texts or Back-Cover Texts, in the
notice that says that the Document is released under this
License.</para>
<para>A "Transparent" copy of the Document means a
machine-readable copy, represented in a format whose specification
is available to the general public, whose contents can be viewed
and edited directly and straightforwardly with generic text
editors or (for images composed of pixels) generic paint programs
or (for drawings) some widely available drawing editor, and that
is suitable for input to text formatters or for automatic
translation to a variety of formats suitable for input to text
formatters. A copy made in an otherwise Transparent file format
whose markup has been designed to thwart or discourage subsequent
modification by readers is not Transparent. A copy that is not
"Transparent" is called "Opaque".</para>
<para>Examples of suitable formats for Transparent copies include
plain ASCII without markup, Texinfo input format, LaTeX input
format, SGML or XML using a publicly available DTD, and
standard-conforming simple HTML designed for human modification.
Opaque formats include PostScript, PDF, proprietary formats that
can be read and edited only by proprietary word processors, SGML
or XML for which the DTD and/or processing tools are not generally
available, and the machine-generated HTML produced by some word
processors for output purposes only.</para>
<para>The "Title Page" means, for a printed book, the title page
itself, plus such following pages as are needed to hold, legibly,
the material this License requires to appear in the title page.
For works in formats which do not have any title page as such,
"Title Page" means the text near the most prominent appearance of
the work's title, preceding the beginning of the body of the
text.</para>
</sect1>
<sect1 id="gfdl-2">
<title>VERBATIM COPYING</title>
<para>You may copy and distribute the Document in any medium,
either commercially or noncommercially, provided that this
License, the copyright notices, and the license notice saying this
License applies to the Document are reproduced in all copies, and
that you add no other conditions whatsoever to those of this
License. You may not use technical measures to obstruct or
control the reading or further copying of the copies you make or
distribute. However, you may accept compensation in exchange for
copies. If you distribute a large enough number of copies you
must also follow the conditions in section 3.</para>
<para>You may also lend copies, under the same conditions stated
above, and you may publicly display copies.</para>
</sect1>
<sect1 id="gfdl-3">
<title>COPYING IN QUANTITY</title>
<para>If you publish printed copies of the Document numbering more
than 100, and the Document's license notice requires Cover Texts,
you must enclose the copies in covers that carry, clearly and
legibly, all these Cover Texts: Front-Cover Texts on the front
cover, and Back-Cover Texts on the back cover. Both covers must
also clearly and legibly identify you as the publisher of these
copies. The front cover must present the full title with all
words of the title equally prominent and visible. You may add
other material on the covers in addition. Copying with changes
limited to the covers, as long as they preserve the title of the
Document and satisfy these conditions, can be treated as verbatim
copying in other respects.</para>
<para>If the required texts for either cover are too voluminous to
fit legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto
adjacent pages.</para>
<para>If you publish or distribute Opaque copies of the Document
numbering more than 100, you must either include a
machine-readable Transparent copy along with each Opaque copy, or
state in or with each Opaque copy a publicly-accessible
computer-network location containing a complete Transparent copy
of the Document, free of added material, which the general
network-using public has access to download anonymously at no
charge using public-standard network protocols. If you use the
latter option, you must take reasonably prudent steps, when you
begin distribution of Opaque copies in quantity, to ensure that
this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you
distribute an Opaque copy (directly or through your agents or
retailers) of that edition to the public.</para>
<para>It is requested, but not required, that you contact the
authors of the Document well before redistributing any large
number of copies, to give them a chance to provide you with an
updated version of the Document.</para>
</sect1>
<sect1 id="gfdl-4">
<title>MODIFICATIONS</title>
<para>You may copy and distribute a Modified Version of the
Document under the conditions of sections 2 and 3 above, provided
that you release the Modified Version under precisely this
License, with the Modified Version filling the role of the
Document, thus licensing distribution and modification of the
Modified Version to whoever possesses a copy of it. In addition,
you must do these things in the Modified Version:</para>
<orderedlist numeration="upperalpha">
<listitem><para>Use in the Title Page
(and on the covers, if any) a title distinct from that of the
Document, and from those of previous versions (which should, if
there were any, be listed in the History section of the
Document). You may use the same title as a previous version if
the original publisher of that version gives permission.</para>
</listitem>
<listitem><para>List on the Title Page,
as authors, one or more persons or entities responsible for
authorship of the modifications in the Modified Version,
together with at least five of the principal authors of the
Document (all of its principal authors, if it has less than
five).</para>
</listitem>
<listitem><para>State on the Title page
the name of the publisher of the Modified Version, as the
publisher.</para>
</listitem>
<listitem><para>Preserve all the
copyright notices of the Document.</para>
</listitem>
<listitem><para>Add an appropriate
copyright notice for your modifications adjacent to the other
copyright notices.</para>
</listitem>
<listitem><para>Include, immediately
after the copyright notices, a license notice giving the public
permission to use the Modified Version under the terms of this
License, in the form shown in the Addendum below.</para>
</listitem>
<listitem><para>Preserve in that license
notice the full lists of Invariant Sections and required Cover
Texts given in the Document's license notice.</para>
</listitem>
<listitem><para>Include an unaltered
copy of this License.</para>
</listitem>
<listitem><para>Preserve the section
entitled "History", and its title, and add to it an item stating
at least the title, year, new authors, and publisher of the
Modified Version as given on the Title Page. If there is no
section entitled "History" in the Document, create one stating
the title, year, authors, and publisher of the Document as given
on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.</para>
</listitem>
<listitem><para>Preserve the network
location, if any, given in the Document for public access to a
Transparent copy of the Document, and likewise the network
locations given in the Document for previous versions it was
based on. These may be placed in the "History" section. You
may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.</para>
</listitem>
<listitem><para>In any section entitled
"Acknowledgements" or "Dedications", preserve the section's
title, and preserve in the section all the substance and tone of
each of the contributor acknowledgements and/or dedications
given therein.</para>
</listitem>
<listitem><para>Preserve all the
Invariant Sections of the Document, unaltered in their text and
in their titles. Section numbers or the equivalent are not
considered part of the section titles.</para>
</listitem>
<listitem><para>Delete any section
entitled "Endorsements". Such a section may not be included in
the Modified Version.</para>
</listitem>
<listitem><para>Do not retitle any
existing section as "Endorsements" or to conflict in title with
any Invariant Section.</para>
</listitem>
</orderedlist>
<para>If the Modified Version includes new front-matter sections
or appendices that qualify as Secondary Sections and contain no
material copied from the Document, you may at your option
designate some or all of these sections as invariant. To do this,
add their titles to the list of Invariant Sections in the Modified
Version's license notice. These titles must be distinct from any
other section titles.</para>
<para>You may add a section entitled "Endorsements", provided it
contains nothing but endorsements of your Modified Version by
various parties--for example, statements of peer review or that
the text has been approved by an organization as the authoritative
definition of a standard.</para>
<para>You may add a passage of up to five words as a Front-Cover
Text, and a passage of up to 25 words as a Back-Cover Text, to the
end of the list of Cover Texts in the Modified Version. Only one
passage of Front-Cover Text and one of Back-Cover Text may be
added by (or through arrangements made by) any one entity. If the
Document already includes a cover text for the same cover,
previously added by you or by arrangement made by the same entity
you are acting on behalf of, you may not add another; but you may
replace the old one, on explicit permission from the previous
publisher that added the old one.</para>
<para>The author(s) and publisher(s) of the Document do not by
this License give permission to use their names for publicity for
or to assert or imply endorsement of any Modified Version.</para>
</sect1>
<sect1 id="gfdl-5">
<title>COMBINING DOCUMENTS</title>
<para>You may combine the Document with other documents released
under this License, under the terms defined in section 4 above for
modified versions, provided that you include in the combination
all of the Invariant Sections of all of the original documents,
unmodified, and list them all as Invariant Sections of your
combined work in its license notice.</para>
<para>The combined work need only contain one copy of this
License, and multiple identical Invariant Sections may be replaced
with a single copy. If there are multiple Invariant Sections with
the same name but different contents, make the title of each such
section unique by adding at the end of it, in parentheses, the
name of the original author or publisher of that section if known,
or else a unique number. Make the same adjustment to the section
titles in the list of Invariant Sections in the license notice of
the combined work.</para>
<para>In the combination, you must combine any sections entitled
"History" in the various original documents, forming one section
entitled "History"; likewise combine any sections entitled
"Acknowledgements", and any sections entitled "Dedications". You
must delete all sections entitled "Endorsements."</para>
</sect1>
<sect1 id="gfdl-6">
<title>COLLECTIONS OF DOCUMENTS</title>
<para>You may make a collection consisting of the Document and
other documents released under this License, and replace the
individual copies of this License in the various documents with a
single copy that is included in the collection, provided that you
follow the rules of this License for verbatim copying of each of
the documents in all other respects.</para>
<para>You may extract a single document from such a collection,
and distribute it individually under this License, provided you
insert a copy of this License into the extracted document, and
follow this License in all other respects regarding verbatim
copying of that document.</para>
</sect1>
<sect1 id="gfdl-7">
<title>AGGREGATION WITH INDEPENDENT WORKS</title>
<para>A compilation of the Document or its derivatives with other
separate and independent documents or works, in or on a volume of
a storage or distribution medium, does not as a whole count as a
Modified Version of the Document, provided no compilation
copyright is claimed for the compilation. Such a compilation is
called an "aggregate", and this License does not apply to the
other self-contained works thus compiled with the Document, on
account of their being thus compiled, if they are not themselves
derivative works of the Document.</para>
<para>If the Cover Text requirement of section 3 is applicable to
these copies of the Document, then if the Document is less than
one quarter of the entire aggregate, the Document's Cover Texts
may be placed on covers that surround only the Document within the
aggregate. Otherwise they must appear on covers around the whole
aggregate.</para>
</sect1>
<sect1 id="gfdl-8">
<title>TRANSLATION</title>
<para>Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section
4. Replacing Invariant Sections with translations requires
special permission from their copyright holders, but you may
include translations of some or all Invariant Sections in addition
to the original versions of these Invariant Sections. You may
include a translation of this License provided that you also
include the original English version of this License. In case of
a disagreement between the translation and the original English
version of this License, the original English version will
prevail.</para>
</sect1>
<sect1 id="gfdl-9">
<title>TERMINATION</title>
<para>You may not copy, modify, sublicense, or distribute the
Document except as expressly provided for under this License. Any
other attempt to copy, modify, sublicense or distribute the
Document is void, and will automatically terminate your rights
under this License. However, parties who have received copies, or
rights, from you under this License will not have their licenses
terminated so long as such parties remain in full
compliance.</para>
</sect1>
<sect1 id="gfdl-10">
<title>FUTURE REVISIONS OF THIS LICENSE</title>
<para>The Free Software Foundation may publish new, revised
versions of the GNU Free Documentation License from time to time.
Such new versions will be similar in spirit to the present
version, but may differ in detail to address new problems or
concerns. See <ulink
url="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</ulink>.</para>
<para>Each version of the License is given a distinguishing
version number. If the Document specifies that a particular
numbered version of this License "or any later version" applies to
it, you have the option of following the terms and conditions
either of that specified version or of any later version that has
been published (not as a draft) by the Free Software Foundation.
If the Document does not specify a version number of this License,
you may choose any version ever published (not as a draft) by the
Free Software Foundation.</para>
</sect1>
<sect1 id="gfdl-11">
<title>How to use this License for your documents</title>
<para>To use this License in a document you have written, include
a copy of the License in the document and put the following
copyright and license notices just after the title page:</para>
<blockquote><para>
Copyright (c) YEAR YOUR NAME.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1
or any later version published by the Free Software Foundation;
with the Invariant Sections being LIST THEIR TITLES, with the
Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
</para></blockquote>
<para>If you have no Invariant Sections, write "with no Invariant
Sections" instead of saying which ones are invariant. If you have
no Front-Cover Texts, write "no Front-Cover Texts" instead of
"Front-Cover Texts being LIST"; likewise for Back-Cover
Texts.</para>
<para>If your document contains nontrivial examples of program
code, we recommend releasing these examples in parallel under your
choice of free software license, such as the GNU General Public
License, to permit their use in free software.</para>
</sect1>
</appendix>

View File

@ -0,0 +1,261 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_01"><title>What is Linux?</title>
<abstract>
<para>We will start with an overview of how Linux became the operating system it is today. We will discuss past and future development and take a closer look at the advantages and disadvantages of this system. We will talk about distributions, about Open Source in general and try to explain a little something about GNU.</para>
<para>This chapter answers questions like:</para>
<para>
<itemizedlist>
<listitem><para>What is Linux?</para></listitem>
<listitem><para>Where and how did Linux start?</para></listitem>
<listitem><para>Isn't Linux that system where everything is done in text mode?</para></listitem>
<listitem><para>Does Linux have a future or is it just hype?</para></listitem>
<listitem><para>What are the advantages of using Linux?</para></listitem>
<listitem><para>What are the disadvantages?</para></listitem>
<listitem><para>What kinds of Linux are there and how do I choose the one that fits me?</para></listitem>
<listitem><para>What are the Open Source and GNU movements?</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1 id="sect_01_01">
<title>History</title>
<sect2 id="sect_01_01_01"><title>UNIX</title>
<para>
In order to understand the popularity of Linux, we need to travel back in time, about 30 years ago...
</para>
<para>Imagine computers as big as houses, even stadiums. While the sizes of those computers posed substantial problems, there was one thing that made this even worse: every computer had a different operating system. Software was always customized to serve a specific purpose, and software for one given system didn't run on another system. Being able to work with one system didn't automatically mean that you could work with another. It was difficult, both for the users and the system administrators.</para>
<para>Computers were extremely expensive then, and sacrifices had to be made even after the original purchase just to get the users to understand how they worked. The total cost of IT was enormous.</para>
<para>Technologically the world was not quite that advanced, so they had to live with the size for another decade. In 1969, a team of developers in the Bell Labs laboratories started working on a solution for the software problem, to address these compatibility issues. They developed a new operating system, which was</para>
<itemizedlist>
<listitem><para>simple and elegant</para></listitem>
<listitem><para>written in the C programming language instead of in assembly code</para></listitem>
<listitem><para>able to recycle code.</para></listitem>
</itemizedlist>
<para>The Bell Labs developers named their project <quote>UNIX.</quote></para>
<para>
The code recycling features were very important. Until then, all commercially available computer systems were written in a code specifically developed for one system. UNIX on the other hand needed only a small piece of that special code, which is now commonly named the kernel. This kernel is the only piece of code that needs to be adapted for every specific system and forms the base of the UNIX system. The operating system and all other functions were built around this kernel and written in a higher programming language, C. This language was especially developed for creating the UNIX system. Using this new technique, it was much easier to develop an operating system that could run on many different types of hardware.</para>
<para>The software vendors were quick to adapt, since they could sell ten times more software almost effortlessly. Weird new situations came in existence: imagine for instance computers from different vendors communicating in the same network, or users working on different systems without the need for extra education to use another computer. UNIX did a great deal to help users become compatible with different systems.</para>
<para>Throughout the next couple of decades the development of UNIX continued. More things became possible to do and more hardware and software vendors added support for UNIX to their products.</para>
<para>UNIX was initially found only in very large environments with mainframes and minicomputers (note that a PC is a <quote>micro</quote> computer). You had to work at a university, for the government or for large financial corporations in order to get your hands on a UNIX system. Smaller computers were being developed, and by the end of the 80's, many people had home computers, but UNIX was still only used by a select few.</para>
</sect2>
<sect2 id="sect_01_01_02"><title>Linus and Linux</title>
<para>
The fact that UNIX was a system for the elite started to get on the nerves of a young man studying computer science at the university of Helsinki. Linus Torvalds thought it would be a good idea to have some sort of freely available academic version of UNIX, and promptly started to code. There was already Minix, an educational tool, but it wasn't free, it was not completely like UNIX and it didn't run on this new emerging hardware platform, the PC. And all Linus had at that time was a 386 PC.
</para>
<para>He started to ask questions, looking for answers and solutions that would help him get UNIX on his PC. Below is one of his first posts in comp.os.minix, dating from 1991:</para>
<screen>
From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: Gcc-1.40 and a posix-question
Message-ID: &lt;1991Jul3.100050.9886@klaava.Helsinki.FI&gt;
Date: 3 Jul 91 10:00:50 GMT
Hello netlanders,
Due to a project I'm working on (in minix), I'm interested in the posix
standard definition. Could somebody please point me to a (preferably)
machine-readable format of the latest posix rules? Ftp-sites would be
nice.
</screen>
<para>From the start, it was Linus' goal to have a free system that was completely compliant with the original UNIX. That is why he asked for POSIX standards, POSIX still being the standard for UNIX.</para>
<para>In those days plug-and-play wasn't invented yet, but so many people were interested in having a UNIX system of their own, that this was only a small obstacle. New drivers became available for all kinds of new hardware, at a continuously rising speed. Almost as soon as a new piece of hardware became available, someone bought it and submitted it to the Linux test, as the system was gradually being called, releasing more free code for an ever wider range of hardware. These coders didn't stop at their PC's; every piece of hardware they could find was useful for Linux.</para>
<para>Back then, those people were called <quote>nerds</quote> or <quote>freaks</quote>, but it didn't matter to them, as long as the supported hardware list grew longer and longer. Thanks to these people, Linux is now not only ideal to run on new PC's, but is also the system of choice for old and exotic hardware that would be useless if Linux didn't exist.</para>
<para>Two years after Linus' post, there were 12000 Linux users. But the hobby project continued to grow, always complying to the original POSIX standards. All the features of UNIX were added over the next couple of years, resulting in the mature operating system Linux has become today. Linux is a full UNIX clone, fit for use on workstations as well as on middle-range and high-end servers. Today, all the important players on the hard- and software market each have their team of Linux developers; at your local dealer's you can even buy pre-installed Linux systems with official support.</para>
</sect2>
<sect2 id="sect_01_01_03">
<title>Current application of Linux systems</title>
<para>Today Linux has joined the desktop market. Linux developers concentrated on networking and services in the beginning, and office applications have been the last barrier to be taken down. We don't like to admit that Microsoft is ruling this market, so plenty of alternatives have been started over the last couple of years to make Linux an acceptable choice as a workstation, providing an easy user interface and MS compatible office applications like word processors, spreadsheets, presentations and the like.</para>
<para>On the server side, Linux is well-known as a stable and reliable platform, providing database and trading services for companies like Amazon, the well-known online bookshop, the US Post Offices, the German army and such. Especially Internet providers and Internet service providers have grown fond of Linux as firewall, proxy- and web server, and you will find a Linux box within reach of every UNIX system administrator who appreciates a comfortable management station.</para>
</sect2>
</sect1>
<sect1 id="sect_01_02">
<title>The user interface</title>
<sect2 id="sect_01_02_01">
<title>Is Linux difficult?</title>
<para>Whether Linux is difficult to learn depends on the person you're asking. Experienced UNIX users will say no, because Linux is an ideal operating system for power-users and programmers, because it has been and is being developed by such people.</para>
<para>Everything a good programmer can wish for is available: compilers, libraries, development and debugging tools. These packages come with every standard Linux distribution. The C-compiler is included for free, all the documentation and manuals are there, and examples are often included to help you get started in no time. It feels like UNIX and switching between UNIX and Linux is a natural thing.
</para>
<para>In the early days of Linux, being an expert was kind of required to start using the system. Those who mastered Linux felt better than the rest of the <quote>lusers</quote> who hadn't seen the light yet. It was common practice to tell a beginning user to <quote>RTFM</quote> (read the manuals). While the manuals were on every system, it was difficult to find the documentation, and even if someone did, explanations were in such technical terms that the new user became easily discouraged from learning the system.</para>
<para>The Linux-using community started to realize that if Linux was ever to be an important player on the operating system market, there had to be some serious changes in the accessibility of the system.</para>
</sect2>
<sect2 id="sect_01_02_02">
<title>Linux for non-experienced users</title>
<para>Companies such as RedHat, Suse and Mandrake have sprung up, providing packaged Linux distributions suitable for mass consumption. They integrated a great deal of graphical user interfaces (GUIs), developed by the community, in order to ease management of programs and services. As a Linux user today you have all the means of getting to know your system inside out, but it is no longer necessary to have that knowledge in order to make the system comply to your requests.</para>
<para>Nowadays you can log in graphically and start all required applications without even having to type a single character, while you still have the ability to access the core of the system if needed. Because of its structure, Linux allows a user to grow into the system: it equally fits new and experienced users. New users are not forced to do difficult things, while experienced users are not forced to work in the same way they did when they first started learning Linux.</para>
<para>While development in the service area continues, great things are being done for desktop users, generally considered as the group least likely to know how a system works. Developers of desktop applications are making incredible efforts to make the most beautiful desktops you've ever seen, or to make your Linux machine look just like your former MS Windows or MacIntosh workstation. The latest developments also include 3D acceleration support and support for USB devices, single-click updates of system and packages, and so on. Linux has these, and tries to present all available services in a logical form that ordinary people can understand.</para>
<para>The screenshot below shows how each item in the Channel list (RH 7.2, StarOffice, Opera, Ximian Gnome, Loki games and CodeWeavers) can be updated with one mouse click. Adding or removing software packages or keeping the system up to date is simple with tools like this one, called Red Carpet:</para>
<figure><title>Ximian Red Carpet: automated package management</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/redcarpet.png" format="PNG"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/redcarpet.eps" format="EPS"></imagedata>
</imageobject>
</mediaobject>
</figure>
</sect2>
</sect1>
<sect1 id="sect_01_03"><title>Does Linux have a future?</title>
<sect2 id="sect_01_03_01"><title>Open Source</title>
<para>The idea behind Open Source software is rather simple: when programmers can read, distribute and change code, the code will mature. People can adapt it, fix it, debug it, and they can do it at a speed that dwarfs the performance of software developers at conventional companies. This software will be more flexible and of a better quality than software that has been developed using the conventional channels, because more people have tested it in more different conditions than the closed software developer ever can.</para>
<para>The Open Source initiative started to make this clear to the commercial world, and very slowly, commercial vendors are starting to see the point. While lots of academics and technical people have already been convinced for 20 years now that this is the way to go, commercial vendors needed applications like the Internet to make them realize they can profit from Open Source. Now Linux has grown past the stage where it was almost exclusively an academic system, useful only to a handful of people with a technical background. Now Linux provides more than the operating system: there is an entire infrastructure supporting the chain of effort of creating an operating system, of making and testing programs for it, of bringing everything to the users, of supplying maintenance, updates and support and customizations, etcetera. Today, Linux is ready to accept the challenge of a fast-changing world.</para>
</sect2>
<sect2 id="sect_01_03_02"><title>Ten years of experience at your service</title>
<para>While Linux is probably the most well-known Open Source initiative, there is another project that contributed enormously to the popularity of the Linux operating system. This project is called SAMBA, and its achievement is the reverse engineering of the Server Message Block (SMB)/Common Internet File System (CIFS) protocol used for file- and print-serving on PC-related machines, natively supported by MS Windows NT and OS/2, and Linux. Packages are now available for almost every system and provide interconnection solutions in mixed environments using MS Windows protocols: Windows-compatible (up to and including Win2K) file- and print-servers.</para>
<para>Maybe even more successful than the SAMBA project is the Apache HTTP server project. The server runs on UNIX, Windows NT and many other operating systems. Originally known as <quote>A PAtCHy server</quote>, based on existing code and a series of <quote>patch files</quote>, the name for the matured code deserves to be connotated with the native American tribe of the Apache, well-known for their superior skills in warfare strategy and inexhaustible endurance. Apache has been shown to be substantially faster, more stable and more feature-full than many other web servers. Apache is run on sites that get millions of visitors per day, and while no official support is provided by the developers, the Apache user community provides answers to all your questions. Commercial support is now being provided by a number of third parties.</para>
<para>In the category of office applications, a choice of MS Office suite clones is available, ranging from partial to full implementations of the applications available on MS Windows workstations. These initiatives helped a great deal to make Linux acceptable for the desktop market, because the users don't need extra training to learn how to work with new systems. With the desktop comes the praise of the common users, and not only their praise, but also their specific requirements, which are growing more intricate and demanding by the day.</para>
<para>The Open Source community, consisting largely of people who have been contributing for over half a decade, assures Linux' position as an important player on the desktop market as well as in general IT application. Paid employees and volunteers alike are working diligently so that Linux can maintain a position in the market. The more users, the more questions. The Open Source community makes sure answers keep coming, and watches the quality of the answers with a suspicious eye, resulting in ever more stability and accessibility.</para>
<para>Listing all the available Linux software is beyond the scope of this guide, as there are tens of thousands of packages. Throughout this course we will present you with the most common packages, which are almost all freely available. In order to take away some of the fear of the beginning user, here's a screenshot of one of your most-wanted programs. You can see for yourself that no effort has been spared to make users who are switching from Windows feel at home:</para>
<figure><title>AbiWord Word processor taskbar</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/abiword-taskbar.png" format="PNG"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/abiword-taskbar.eps" format="EPS"></imagedata>
</imageobject>
</mediaobject>
</figure>
</sect2>
</sect1>
<sect1 id="sect_01_04"><title>Properties of Linux</title>
<sect2 id="sect_01_04_01"><title>Linux Pros:</title>
<para>A lot of the advantages of Linux are a consequence of Linux' origins, deeply rooted in UNIX, except for the first advantage, of course:</para>
<itemizedlist>
<listitem>
<para>Linux is free:</para>
<para>As in free beer, they say. If you want to spend absolutely nothing, you don't even have to pay the price of a CD. Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.</para>
<para>Most of all, Linux is free as in free speech:</para>
<para>The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image, for instance to add support for teletransportation machines or time travel and sell your new code, as long as your customers can still have a copy of that code.</para>
</listitem>
<listitem>
<para>Linux is portable to any hardware platform:</para>
<para>A vendor who wants to sell a new type of computer and who doesn't know what kind of OS his new machine will run (say the CPU in your car or washing machine), can take a Linux kernel and make it work on his hardware, because documentation related to this activity is freely available.</para>
</listitem>
<listitem>
<para>Linux was made to keep on running:</para>
<para>As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other calm moments, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable also in environments where people don't have the time or the possibility to control their systems night and day.</para>
</listitem>
<listitem>
<para>Linux is secure and versatile:</para>
<para>The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only fit for use as a fort against enemy attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security. Your development machine or control station will be as secure as your firewall.</para>
</listitem>
<listitem>
<para>Linux is scalable:</para>
<para>From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. You don't need a supercomputer anymore, because you can use Linux to do big things using the building blocks provided with the system. Iff you want to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.</para>
</listitem>
<listitem>
<para>The Linux OS and Linux applications have very short debug-times:</para>
<para>Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_01_04_02"><title>Linux Cons:</title>
<itemizedlist>
<listitem>
<para>There are far too many different distributions:</para>
<para>"Quot capites, tot rationes", as the Romans already said: the more people, the more opinions. On first sight, the amount of Linux distributions can be frightening, or ridiculous, depending on your point of view. But it also means that everyone will find what he or she needs. You don't need to be an expert to find a suitable release.</para>
<para>When asked, generally every Linux user will say that the best distribution is the specific version he is using. So which one should you choose? Don't worry too much about that: all releases contain more or less the same set of basic packages. On top of the basics, special third party software is added making, for example, TurboLinux more suitable for the small and medium enterprise, RedHat for servers and Suse for workstations. However, the differences are likely to be very superficial. The best strategy is to test a couple of distributions; unfortunately not everybody has the time for this. Luckily, there is plenty of advice on the subject of choosing your Linux. One place is <ulink url="http://www.linuxjournal.com/bg/advice/distributions.php">LinuxJournal</ulink>, which discusses hardware and support, among many other subjects. The <ulink url="http://www.tldp.org/HOWTO/Installation-HOWTO/">Installation HOWTO</ulink> also discusses choosing your distribution.</para>
</listitem>
<listitem>
<para>Linux is not user friendly and confusing for beginners:</para>
<para>
In light of its popularity, considerable effort has been made to make Linux even easier to use, especially for new users. More information is being released daily, such as this guide, to help fill the gap for documentation available to users at all levels.</para>
</listitem>
<listitem>
<para>Is an Open Source product trustworthy?</para>
<para>How can something that is free also be reliable? Linux users have the choice whether to use Linux or not, which gives them an enormous advantage compared to users of proprietary software, who don't have that kind of freedom. After long periods of testing, most Linux users come to the conclusion that Linux is not only as good, but in many cases better and faster that the traditional solutions. If Linux were not trustworthy, it would have been long gone, never knowing the popularity it has now, with millions of users. Now users can influence their systems and share their remarks with the community, so the system gets better and better every day. It is a project that is never finished, that is true, but in an ever changing environment, Linux is also a project that continues to strive for perfection.</para>
</listitem>
</itemizedlist>
</sect2>
</sect1>
<sect1 id="sect_01_05"><title>Linux Flavors</title>
<sect2 id="sect_01_05_01"><title>Linux and GNU</title>
<para>
Although there are a large number of Linux implementations, you will find a lot of similarities in the different distributions, if only because every Linux machine is a box with building blocks that you may put together following your own needs and views. Installing the system is only the beginning of a longterm relationship. Just when you think you have a nice running system, Linux will stimulate your imagination and creativeness, and the more you realize what power the system can give you, the more you will try to redefine its limits.
</para>
<para>Linux may appear different depending on the distribution, your hardware and personal taste, but the fundamentals on which all GUI and other interfaces are built, remain the same. The Linux system is based on GNU tools (Gnu's Not UNIX), which provide a set of standard ways to handle and use the system. All GNU tools are open source, so they can be installed on any system. Most distributions offer pre-compiled packages of most common tools, such as RPM packages on RedHat and apt-get packages on Debian, so you needn't be a programmer to install a package on your system.</para>
<para>A list of common GNU software:</para>
<itemizedlist>
<listitem><para>Findutils: to search and find files</para></listitem>
<listitem><para>Fontutils: to convert fonts from one format to another or make new fonts</para></listitem>
<listitem><para>The Gimp: GNU Image Manipulation Program</para></listitem>
<listitem><para>Gnome: the GNU desktop environment</para></listitem>
<listitem><para>Emacs: a very powerful editor</para></listitem>
<listitem><para>Ghostscript and Ghostview: interpreter and graphical frontend for PDF files.</para></listitem>
<listitem><para>GNU Photo: software for interaction with digital cameras</para></listitem>
<listitem><para>Octave: a program to calculate mathematical functions and images.</para></listitem>
<listitem><para>GNU SQL: relational database system</para></listitem>
<listitem><para>Radius: a remote authentication and accounting server</para></listitem>
<listitem><para>...</para></listitem>
</itemizedlist>
<para>Many commercial applications are available for Linux, and for more information about these packages we refer to their specific documentation. Throughout this guide we will only discuss freely available software, which comes (in most cases) with a GNU license.</para>
<para>To install missing or new packages, you will need some form of software management. The most common implementations, which are also available on RedHat systems, include RPM, dpkg(apt-get) and Ximian Red Carpet. Dpkg is the Debian package management system, and will work on RedHat, but RedHat is typically an RPM system (RPM also stands for RedHat Package Manager). Later on, we will see in more detail how RPM works and what special features will help you impress your friends. Ximian Red Carpet is a third party implementation of RPM with a graphical front-end. Other third party software vendors may have their own installation procedures, sometimes resembling the InstallShield and such, as known on MS Windows and other platforms.</para>
</sect2>
<sect2 id="sect_01_05_02"><title>Which distribution should I install?</title>
<para>Prior to installation, the most important factor is your hardware. Since every Linux distribution contains the basic packages and can be built to meet most any requirement (because they all use the Linux kernel), you only need to consider if the distribution will run on your hardware. LinuxPPC for example has been made to run on MacIntosh and other PowerPCs and does not run on an ordinary x86 based PC. LinuxPPC does run on the new Macs, but you can't use it for some of the older ones with ancient bus technology. Another tricky case is Sun hardware, which could be an old SPARC CPU or a newer UltraSparc, both requiring different versions of Linux.</para>
<para>Some Linux distributions are optimized for certain processors, such as Athlon CPUs, while they will at the same time run decent enough on the standard 486, 586 and 686 Intel processors. Sometimes distributions for special CPUs are not as reliable, since they are tested by fewer people.</para>
<para>Most Linux distributions offers a distribution for generic PCs with special packages containing optimized kernels for the x86 Intel based CPUs. These distributions are well-tested and maintained on a regular basis, focusing on reliant server implementation and easy installation and update procedures. It is probably the most popular Linux system and generally considered easy to handle for the beginning user, while not blocking professionals from getting the most out of their Linux machines. Linux also runs decently on laptops and middle-range servers. Drivers for new hardware are included only after extensive testing, which adds to the stability of a RedHat system.</para>
<para>While the standard RedHat desktop is Gnome, KDE is also available. Suse comes with KDE by default. Generally, both Gnome and KDE are available for all Linux distributions. The standard installation process allows to choose between a workstation, where all packages needed for everyday use and development are installed, or a server installation, where different network services can be selected. Expert users can install every combination of packages they want during the initial installation process.</para>
</sect2>
</sect1>
<sect1 id="sect_01_06"><title>Summary</title>
<para>In this chapter, we learned that:</para>
<itemizedlist>
<listitem><para>Linux is an implementation of UNIX.</para></listitem>
<listitem><para>The Linux operating system is written in the C programming language.</para></listitem>
<listitem><para>De gustibus et coloribus non disputandum est: there's a Linux for everyone.</para></listitem>
<listitem><para>Linux uses GNU tools, a set of freely available standard tools for handling the operating system.</para></listitem>
</itemizedlist>
</sect1>
<sect1 id="sect_01_07"><title>Exercises</title>
<para>
A practical exercise for starters: install Linux on your PC. Read the installation manual for your distribution and/or the Installation HOWTO and do it.</para>
<note><title>Read the docs!</title><para>
Most errors stem from not reading the information provided during the install. Reading the installation messages carefully is the first step on the road to success.</para></note>
<para>Things you must know BEFORE starting a Linux installation:</para>
<itemizedlist>
<listitem><para>Will this distribution run on my hardware?</para>
<para>Check with <ulink url="http://www.ibiblio.org/mdw/HOWTO/Hardware-HOWTO/index.html">http://www.ibiblio.org/mdw/HOWTO/Hardware-HOWTO/index.html</ulink> when in doubt about your hardware compatibility.</para>
</listitem>
<listitem><para>What kind of keyboard do I have (number of keys, layout)? What kind of mouse (serial/parallel)? How many MB of RAM?</para></listitem>
<listitem><para>Will I install a basic workstation or a server, or will I need to select specific packages myself?</para></listitem>
<listitem><para>Will I install from my hard disk, from a CD-ROM, or using the network? Should I adapt the BIOS for any of this? Does the installation method require a boot disk?</para></listitem>
<listitem><para>Will Linux be the only system on this computer, or will it be a dual boot installation? Should I make a large partition in order to install virtual systems later on, or is this a virtual installation itself?</para></listitem>
<listitem><para>Is this computer in a network? What is its hostname, IP address? Are there any gateway servers or other important networked machines my box should communicate with?</para>
<note><title>Linux expects to be networked</title>
<para>Not using the network or configuring it incorrectly may result in slow startup.</para></note>
</listitem>
<listitem><para>Is this computer a gateway/router/firewall?</para></listitem>
<listitem><para>Partitioning: let the installation program do it for you this time, we will discuss partitions in detail in <xref linkend="chap_03" />. There is system-specific documentation available if you want to know everything about it.</para></listitem>
<listitem><para>Will this machine start up in text mode or in graphical mode?</para></listitem>
<listitem><para>Think of a good password for the administrator of this machine (root). Create a non-root user account.</para></listitem>
<listitem><para>Do I need a rescue disk? (recommended)</para></listitem>
</itemizedlist>
<para>The full checklist can be found at <ulink url="http://www.ibiblio.org/mdw/HOWTO/Installation-HOWTO/index.html">http://www.ibiblio.org/mdw/HOWTO/Installation-HOWTO/index.html</ulink>.</para>
<para>In the following chapters we will find out if the installation has been successful.</para>
</sect1>
</chapter>

View File

@ -0,0 +1,766 @@
<?xml version='1.0' encoding='ISO8859-1'?>
<chapter id="chap_10"><title>Networking</title>
<abstract>
<para>When it comes to networking, Linux is your operating system of choice, not only because networking is tightly integrated with the OS itself and a wide variety of free tools and applications are available, but for the robustness under heavy loads that can only be achieved after years of debugging and testing in an Open Source project.</para>
<para>Bookshelves full of information have been written about Linux and networking, but we will try to give an overview in this chapter. After completing this, you will know about</para>
<para>
<itemizedlist>
<listitem><para>Supported networking protocols</para></listitem>
<listitem><para>File sharing and printing</para></listitem>
<listitem><para>Other common Internet/Intranet services</para></listitem>
<listitem><para>Remote execution of commands and applications</para></listitem>
<listitem><para>Basic network interconnection</para></listitem>
<listitem><para>Networking tools</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1><title>General networking</title>
<sect2><title>Networking protocols</title>
<para>Linux supports many different networking protocols. We list only the most important:</para>
<sect3><title>TCP/IP</title>
<para>The Internet was originally developed three decades ago for the United States Department of Defense (DoD), mainly for the purpose of interconnecting different-brand computers. The TCP/IP suite of protocols allowed, through its layered structure, to insulate applications from networking hardware.
</para>
<para>Although it is based on a layered model, it is focused more on delivering interconnectivity than on rigidly adhering to functional layers. This is one of the reasons why TCP/IP has become the de facto standard internetworking protocol as opposed to OSI.
</para>
<para>TCP/IP networking has been present in Linux since its beginnings. It has been implemented from scratch. It is one of the most robust, fast and reliable implementations and is one of the key factors of the success of Linux. In fact, a Linux system expects to be networked.
</para>
</sect3>
<sect3><title>TCP/IPv6</title>
<para>IPv6, sometimes also referred to as IPng (IP Next Generation) is an upgrade to the IPv4 protocol in order to address many issues. These issues include a shortage of available IP addresses, lack of mechanisms to handle time-sensitive traffic, lack of network layer security, and so forth.
</para>
<para>The larger name space is accompanied by an improved addressing scheme, which has great impact on routing performance.</para>
</sect3>
<sect3><title>PPP, SLIP, PLIP, PPPOE</title>
<para>The Linux kernel has built-in support for PPP (Point-to-Point-Protocol), SLIP (Serial Line IP) and PLIP (Parallel Line IP). PPP is the most popular way individual users access their ISP (Internet Service Provider), although (in Belgium) it is currently being replaced by PPPOE, PPP over Ethernet, the protocol used in cable modem connections.</para>
<para>RedHat provides an easy to use tool, <command>internet-druid</command>, which makes easy work of connecting analog and cable modems to the Internet.</para>
</sect3>
<sect3><title>ISDN</title>
<para>The Linux kernel has built-in ISDN capabilities. Isdn4linux controls ISDN PC cards and can emulate a modem with the Hayes command set (<quote>AT</quote> commands). The possibilities range from simply using a terminal program to full connection to the Internet.</para>
<para>The <command>internet-druid</command> tool may be used to set ISDN connections as well.</para>
</sect3>
<sect3><title>AppleTalk</title>
<para>Appletalk is the name of Apple's internetworking stack. It allows a peer-to-peer network model which provides basic functionality such as file and printer sharing. Each machine can simultaneously act as a client and a server, and the software and hardware necessary are included with every Apple computer.</para>
<para>Linux provides full Appletalk networking. Netatalk is a kernel-level implementation of the AppleTalk Protocol Suite, originally for BSD-derived systems. It includes support for routing AppleTalk, serving UNIX and AFS file systems using AppleShare and serving UNIX printers and accessing AppleTalk printers.</para>
</sect3>
<sect3><title>IPX/SPX</title>
<para>IPX/SPX (Internet Packet Exchange/Sequenced Packet Exchange) is a proprietary protocol stack developed by Novell and based on the Xerox Network Systems (XNS) protocol. IPX/SPX became prominent during the early 1980s as an integral part of Novell, Inc.'s NetWare. NetWare became the standard network operating system (NOS) of first generation LANs. Novell complemented its NOS with a business-oriented application suite and client-side connection utilities.</para>
<para>Linux has a very clean IPX/SPX implementation, allowing it to be configured as an IPX router/bridge, NCP client and/or server and Novel Print client or server. It enables PPP/IPX and IPX tunneling through IP.</para>
</sect3>
<sect3><title>SMB/NMB</title>
<para>For compatibility with MS Windows environments, the Samba suite, including support for the NMB and SMB protocols, can be installed on any UNIX-like system. The Server Message Block protocol (also called Session Message Block, NetBIOS or LanManager protocol) is used on MS Windows 3.11, NT, 95/98, 2K and XP to share disks and printers.</para>
<para>The basic functions of the Samba suite are: sharing Linux drives with Windows machines, accessing SMB shares from Linux machines, sharing Linux printers with Windows machines and sharing Windows printers with Linux machines.</para>
<para>Most Linux distributions provide a <emphasis>samba</emphasis> package, which does most of the server setup and starts up <command>smbd</command>, the Samba server, and <command>nmbd</command>, the netbios name server, at boot time by default. Example sections for use in various situations are provided.</para>
<para>More information can be found in the <filename>smb.conf</filename> man page or in the <ulink url="http://www.redhat.com/support/resources/print_file/samba.html">Samba</ulink> section of the RedHat Support Resources on Printing and File Services. The <ulink url="http://ftp.easynet.be/samba/docs/Samba-HOWTO-Collection.html">Samba Project Documentation</ulink> contains an easy to read installation and testing guide, which also explains how to configure your Samba server as a Primary Domain Controller. The <ulink url="http://www.samba.org">Samba website</ulink> contains more documentation, including a troubleshooting guide.</para>
</sect3>
<sect3><title>Miscellaneous protocols</title>
<para>Linux also has support for Amateur Radio, WAN internetworking (X25, Frame Relay, ATM), but since these protocols usually require special hardware, we won't discuss them in this document.</para>
</sect3>
</sect2>
<sect2><title>General networking tools</title>
<sect3><title>Configuration of local network interfaces</title>
<para>To obtain the graphical configuration tools for networking devices, routes, hosts and so on, refer to the distribution-specific documentation. The graphical tool RedHat 7.2 currently offers is called <command>neat</command>, which allows easy configuration of network interfaces, routes, gateways and DNS without requiring much knowledge about the actual configuration files, among others in <filename>/etc/sysconfig/network-scripts</filename>.</para>
<para>Configuration on the command line used to be done using the <command>ifconfig</command> command, but this is being deprecated and replaced with <command>ip</command>, which can handle different protocols easier and allows for flexible configuration. The most up to date documentation can be found in <filename>/usr/share/doc/iproute-&lt;version&gt;</filename>; the command has extended help features for short hints as well. Setting the IP address on a network interface, for instance, can be done like this:</para>
<screen>
[root@blob root] ip addr add 192.168.30.2 dev eth0
</screen>
<para>This edits the file <filename>/etc/sysconfig/network-scripts/ifcfg-eth0</filename>:</para>
<screen>
[root@blob root] cat ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.30.15
NETMASK=255.255.255.0
BROADCAST=192.168.30.255
NETWORK=192.168.30.0
IPV6INIT=yes
</screen>
<para>General activation of the network facilities is configured in <filename>/etc/sysconfig/network</filename>:</para>
<screen>
jenny@blob /etc/sysconfig&gt; cat network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=blob.hq.somewhere.org
GATEWAY=192.168.30.1
</screen>
<para>The <command>ip</command> command can also be used to display network information. Below are some examples, displaying IP address configuration, routes and neighbouring proxies:</para>
<screen>
benny@home benny&gt; ip addr show
1: lo: &lt;LOOPBACK,UP&gt; mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
inet6 ::1/128 scope host
2: eth0: &lt;BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc pfifo_fast qlen 100
link/ether 00:50:bf:7e:54:9a brd ff:ff:ff:ff:ff:ff
inet 192.168.42.15/24 brd 192.168.42.255 scope global eth0
inet6 fe80::250:bfff:fe7e:549a/10 scope link
benny@home benny&gt; ip route show
192.168.42.0/24 dev eth0 scope link
127.0.0.0/8 dev lo scope link
default via 192.168.42.1 dev eth0
benny@home benny&gt; ip neigh
192.168.42.1 dev eth0 lladdr 00:50:bf:7e:54:99 nud reachable
</screen>
<para>For displaying the network configuration, there's the common <command>netstat</command> command which has a lot of options and is generally useful on any UNIX system. Use the <option>-i</option> option to display information about network interfaces:</para>
<screen>
bob:~&gt;netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 58459 0 0 0 63865 0 0 0 BMRU
lo 16436 0 24060 0 0 0 24060 0 0 0 LRU
</screen>
<para>Routing information is displayed with the <option>-nr</option> option:</para>
<screen>
bob:~&gt;netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.42.0 0.0.0.0 255.255.255.0 U 40 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 40 0 0 lo
0.0.0.0 192.168.42.1 0.0.0.0 UG 40 0 0 eth0
</screen>
<para>This is a typical client machine in an IP network. It only has one network device, <emphasis>eth0</emphasis>. The <emphasis>lo</emphasis> interface is the local loop.</para>
<para>Information about name resolvers and when to contact which is stored in the <filename>/etc/nsswitch.conf</filename> file, the system databases and name service switch configuration file. It usually looks something like this:</para>
<screen>
#
# /etc/nsswitch.conf
#
passwd: files ldap
shadow: files ldap
group: files ldap
hosts: files dns
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files ldap
rpc: files
services: files ldap
netgroup: files ldap
publickey: nisplus
automount: files ldap
aliases: files
</screen>
<para>This file tells the system to resolve host names first looking in the local databases (such as <filename>/etc/hosts</filename>), and when these don't recognize the host name, to look it up using the DNS service (<emphasis>hosts</emphasis> entry).</para>
</sect3>
<sect3><title>Other hosts</title>
<para>An impressive amount of tools is focused on network management and remote administration of Linux machines. Your local Linux software mirror will offer plenty of those. It would lead us too far to discuss them in this document, so please refer to the program-specific documentation.</para>
<para>We will only discuss common UNIX/Linux text tools in this section.</para>
<para>To display information on hosts or domains, use the <command>host</command> command:</para>
<screen>
[emmy@pc10 emmy]$ host www.eunet.be
www.eunet.be. has address 193.74.208.177
[emmy@pc10 emmy]$ host -t any eunet.be
eunet.be. SOA dns.eunet.be. hostmaster.Belgium.EU.net. 2002021300 28800\
7200 604800 86400
eunet.be. mail is handled by 50 pophost.eunet.be.
eunet.be. name server ns.EU.net.
eunet.be. name server dns.eunet.be.
</screen>
<para>Similar information can be displayed using the <command>dig</command> command. To check if a host is alive, use <command>ping</command>. If your system is configured to send more than one packet, interrupt <command>ping</command> with the [CTRL]-[C] key combination:</para>
<screen>
[emmy@pc10 emmy]$ ping a.host.be
PING a.host.be (1.2.28.23) from 80.200.84.246: 56(84) bytes of data.
64 bytes from a.host.be (1.2.28.23): icmp_seq=0 ttl=244 time=99.977 msec
--- a.host.be ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/mdev = 99.977/99.977/99.977/0.000 ms
</screen>
<para>To check the route that packets follow to a network host, use the <command>traceroute</command> command:</para>
<screen>
[emmy@pc10 emmy]$ /usr/sbin/traceroute www.eunet.be
traceroute to www.eunet.be (193.74.208.177), 30 hops max, 38 byte packets
1 blob (192.168.42.1) 0.297ms 0.257ms 0.174ms
2 adsl-65.turboline.skynet.be (217.136.111.1) 12.120ms 13.058ms 13.009ms
3 194.78.255.177 (194.78.255.177) 13.845ms 14.308ms 12.756ms
4 gigabitethernet2-2.intl2.gam.brussels.skynet.be (195.238.2.226)
13.123ms 13.164ms 12.527ms
5 pecbru2.car.belbone.be (194.78.255.118) 16.336ms 13.889ms 13.028ms
6 ser-2-1-110-ias-be-vil-ar01.kpnbelgium.be (194.119.224.9)
14.602ms 15.546ms 15.959ms
7 unknown-195-207-939.eunet.be (195.207.93.49) 16.514ms 17.661ms 18.889ms
8 S0-1-0.Leuven.Belgium.EU.net (195.207.129.1) 22.714ms 19.193ms 18.432ms
9 dukat.Belgium.EU.net (193.74.208.178) 22.758ms * 25.263ms
</screen>
<para>The <command>mtr</command> program gives streaming information about reachability of remote hosts, but you need to be <emphasis>root</emphasis> to run it.</para>
<para>Specific domain name information can be queried using the <command>whois</command> command, as is explained by many <command>whois</command> servers, like the one below:</para>
<screen>
[emmy@pc10 emmy]$ whois cnn.com
[whois.crsnic.net]
Whois Server Version 1.3
$&lt;--snap server message--&gt;
Domain Name: CNN.COM
Registrar: NETWORK SOLUTIONS, INC.
Whois Server: whois.networksolutions.com
Referral URL: http://www.networksolutions.com
Name Server: TWDNS-01.NS.AOL.COM
Name Server: TWDNS-02.NS.AOL.COM
Name Server: TWDNS-03.NS.AOL.COM
Name Server: TWDNS-04.NS.AOL.COM
Updated Date: 12-mar-2002
&gt;&gt;&gt; Last update of whois database: Fri, 5 Apr 2002 05:04:55 EST &lt;&lt;&lt;
The Registry database contains ONLY .COM, .NET, .ORG, .EDU domains and
Registrars.
[whois.networksolutions.com]
$&lt;--snap server message--&gt;
Registrant:
Turner Broadcasting (CNN-DOM)
1 CNN Center
Atlanta, GA 30303
Domain Name: CNN.COM
Administrative Contact:
$&lt;--snap contactinfo--&gt;
Technical Contact:
$&lt;--snap contactinfo--&gt;
Billing Contact:
$&lt;--snap contactinfo--&gt;
Record last updated on 12-Mar-2002.
Record expires on 23-Sep-2009.
Record created on 22-Sep-1993.
Database last updated on 4-Apr-2002 20:10:00 EST.
Domain servers in listed order:
TWDNS-01.NS.AOL.COM 149.174.213.151
TWDNS-02.NS.AOL.COM 152.163.239.216
TWDNS-03.NS.AOL.COM 205.188.146.88
TWDNS-04.NS.AOL.COM 64.12.147.120
</screen>
<para>For Belgian domain names, specify the whois server:</para>
<cmdsynopsis><command>whois <option>domain.be@whois.dns.be</option></command></cmdsynopsis>
</sect3>
</sect2>
</sect1>
<sect1><title>Internet/Intranet applications</title>
<para>The Linux system is a great platform for offering networking services. In this section, we will try to give an overview of most common network servers and applications.</para>
<sect2><title>Mail</title>
<sect3><title>Servers</title>
<para><emphasis>Sendmail</emphasis> is the standard mail server program or Mail Transport Agent for UNIX platforms. It is robust, scalable, and when properly configured with appropriate hardware, handles thousands of users without blinking. More information about how to configure Sendmail is included with the sendmail and sendmail-cf packages, you may want to read the <filename>README</filename> and <filename>README.cf</filename> files in <filename>/usr/share/doc/sendmail</filename>. The <command>man sendmail</command> and <command>man aliases</command> are also useful.</para>
<para>Qmail is another mail server, gaining popularity because it claims to be more secure than Sendmail. While Sendmail is a monolithic program, Qmail consists of smaller interacting program parts that can be better secured.</para>
<para>These servers handle mailing lists, filtering, virus scanning and much more. Free and commercial scanners are available for use with Linux. Examples of mailing list software are Mailman, Listserv, Majordomo and EZmlm. See the web page of your favorite virus scanner for information on Linux client and server support.</para>
</sect3>
<sect3><title>Remote mail servers</title>
<para>The most popular protocols to access mail remotely are <emphasis>POP3</emphasis> and <emphasis>IMAP4</emphasis>. IMAP and POP both allow offline operation, remote access to new mail and they both rely on an SMTP server to send mail.</para>
<para>While POP is a simple protocol, easy to implement and supported by almost any mail client, IMAP is to be preferred because:</para>
<itemizedlist>
<listitem><para>It can manipulate persistent message status flags.</para></listitem>
<listitem><para>It can store as well as fetch mail messages.</para></listitem>
<listitem><para>It can access and manage multiple mailboxes.</para></listitem>
<listitem><para>It supports concurrent updates and shared mailboxes.</para></listitem>
<listitem><para>It is also suitable for accessing Usenet messages and other documents.</para></listitem>
<listitem><para>IMAP works both on-line and off-line.</para></listitem>
<listitem><para>it is optimized for on-line performance, especially over low-speed links.</para></listitem>
</itemizedlist>
</sect3>
<sect3><title>Mail user-agents</title>
<para>There are plenty of both text and graphical E-mail clients, we'll just name a few of the common ones. Pick your favorite.</para>
<para>The UNIX <command>mail</command> command has been around for years, even before networking existed. It is a simple interface to send messages and small files to other users, who can then save the message, redirect it, reply to it and such.</para>
<para>While it is not commonly used as a client anymore, the <command>mail</command> program is still useful, for example to mail the output of a command to somebody:</para>
<cmdsynopsis><command>cat cv.txt | mail future.employer@whereIwant2work.com</command></cmdsynopsis>
<para>The <command>elm</command> mail reader is a much needed improvement to <command>mail</command>, and so is <command>pine</command> (Pine Is Not ELM). The <command>mutt</command> mail reader is even more recent and offers features like threading.</para>
<para>For those users who prefer a graphical interface to their mail (and a tennis elbow or a mouse arm), there are hundreds of options. The most popular is probably Netscape Mail, although Mozilla Mail is a rising star. Ximian Gnome offers an MS Exchange clone, Evolution. There are also tens of webmail applications available.</para>
<para>An overview is available via the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Mail-User-HOWTO/index.html">Linux Mail User HOWTO</ulink>.</para>
<para>Most Linux distributions include <command>fetchmail</command>, a mail-retrieval and forwarding utility. It fetches mail from remote mail servers (POP, IMAP and some others) and forwards it to your local delivery system. You can then handle the retrieved mail using normal mail clients. It can be run in daemon mode to repeatedly poll one or more systems at a specified interval. Information and usage examples can be found in the Info pages; the directory <filename>/usr/share/doc/fetchmail-&lt;version&gt;</filename> contains a full list of features and a FAQ for beginners.</para>
<para>The <command>procmail</command> filter can be used for filtering incoming mail, to create mailing lists, to pre-process mail, to selectively forward mail and more. The accompanying <command>formail</command> program, among others, enables generation of auto-replies and splitting up mailboxes. Procmail has been around for years on UNIX and Linux machines and is a very robust system, designed to work even in the worst circumstances. More information may be found in the <filename>/usr/share/doc/procmail-&lt;version&gt;</filename> directory and in the man pages.</para>
</sect3>
</sect2>
<sect2><title>Web</title>
<sect3><title>The Apache Web Server</title>
<para>Apache is by far the most popular web server, used on more than half of all Internet web servers. Most Linux distributions include Apache. Apache's advantages include its modular design, SSL support, stability and speed. Given the appropriate hardware and configuration it can support the highest loads.</para>
<para>On Linux systems, the server configuration is usually done in the <filename>/etc/httpd</filename> directory. The most important configuration file is <filename>httpd.conf</filename>; it is rather self-explanatory. Should you need help, you can find it in the <command>httpd</command> man page or on the <ulink url="http://www.apache.org">Apache website</ulink>.</para>
</sect3>
<sect3><title>Web browsers</title>
<para>A number of web browsers, both free and commercial, exist for the Linux platform. Netscape Navigator has long been the only decent option, but with Mozilla a competitive alternative is available.</para>
<para>Amaya is the W3C browser. Opera is a commercial browser, compact and fast. Many desktop managers offer web browsing features in their file manager, like <command>galeon</command>or <command>nautilus</command>.</para>
<para>Among the popular text based browsers are <command>lynx</command> and <command>links</command>. You may need to define proxy servers in your shell, by setting the appropriate variables.</para>
<para>Text browsers are fast and handy when no graphical environment is available, such as when used in scripts. Below is an excerpt from a shell script that acts as a network worm probing available services:</para>
<screen>
# Is a webserver running on port 80 ? Which version ?
tcpcheck 80
if [ -z "$RESULT" ] ; then
PORTHTTP="$(lynx -dump -head http://$SERVERIP/|grep '^Server'|cut -d" " -f2-)"
else
PORTHTTP=$(echo "no")
fi
</screen>
<para>For www.eunet.be, for instance, the result of this <command>lynx</command> probe would be:</para>
<screen>
eve:~&gt;lynx -dump -head http://www.eunet.be |grep '^Server' |cut -d" " -f2
Apache/1.3.14
</screen>
</sect3>
</sect2>
<sect2><title>File Transfer Protocol</title>
<sect3><title>FTP servers</title>
<para>On a Linux system, an FTP server is typically run from <command>xinetd</command>, using the <emphasis>WU-ftpd</emphasis> server, although the FTP server may be configured as a stand-alone server on systems with heavy FTP traffic. See the exercises.</para>
<para>Other FTP servers include among others <emphasis>Ncftpd</emphasis> and <emphasis>Proftpd</emphasis>.</para>
<para>Most Linux distributions contain the <emphasis>anonftp</emphasis> package, which sets up an anonymous FTP server tree and accompanying configuration files.</para>
</sect3>
<sect3><title>FTP clients</title>
<para>Most Linux distributions include <command>ncftp</command>, an improved version of the common UNIX <command>ftp</command> command, which you may also know from the Windows command line. The <command>ncftp</command> program offers extra features such as a nicer and more comprehensible user interface, file name completion, append and resume functions, bookmarking, session management and more:</para>
<screen>
thomas:~&gt;ncftp blob
NcFTP 3.0.3 (April 15, 2001) by Mike Gleason (ncftp@ncftp.com).
Connecting to blubber...
blubber.soti.org FTP server (Version wu-2.6.1-20) ready.
Logging in...
Guest login ok, access restrictions apply.
Logged in to blubber.
ncftp / &gt; help
Commands may be abbreviated. 'help showall' shows hidden and unsupported
commands. 'help &lt;command&gt;' gives a brief description of &lt;command&gt;.
ascii cat help lpage open quote site
bgget cd jobs lpwd page rename type
bgput chmod lcd lrename pdir rhelp umask
bgstart close lchmod lrm pls rm version
binary debug lls lrmdir put rmdir
bookmark dir lmkdir ls pwd set
bookmarks get lookup mkdir quit show
ncftp / >
</screen>
<para>Use the <option>-u</option> option for non-anonymous login. Excellent help with lot of examples can be found in the man pages.</para>
<para>Again, a number of GUI applications are available.</para>
</sect3>
</sect2>
<sect2><title>News services</title>
<para>Running a Usenet server involves a lot of expertise and fine-tuning, so refer to the <ulink url="http://www.isc.org">INN homepage</ulink> for more information.</para>
<para>There are a couple of interesting newsgroups in the <emphasis>comp.*</emphasis> hierarchy, which can be accessed using a variety of text and graphical clients. A lot of mail clients support newsgroup browsing as well, check your program or see your local Open Source software mirror for text clients such as <command>tin</command>, <command>slrnn</command> and <command>mutt</command>, or download Mozilla or one of a number of other graphical clients.</para>
</sect2>
<sect2><title>The Domain Name System</title>
<para>All these applications need DNS services to match IP addresses to host names and vice versa. A DNS server does not know all the IP addresses in the world, but networks with other DNS servers which it can query to find an unknown address. Most UNIX systems can run <command>named</command>, which is part of the bind (Berkeley Internet Name Domain) package distributed by the Internet Software Consortium. It can run as a stand-alone caching <emphasis>nameserver</emphasis>, which is often done on Linux systems in order to speed up network access.</para>
<para>Your main client configuration file is <filename>/etc/resolv.conf</filename>, which determines the order in which Domain Name Servers are contacted:</para>
<screen>
search somewhere.org
nameserver 192.168.42.1
nameserver 193.74.208.137
</screen>
<para>More information can be found in the Info pages on <command>named</command>, in the <filename>/usr/share/doc/bind-&lt;version&gt;</filename> files and on the <ulink url="http://www.isc.org/products/BIND">Bind project</ulink> homepage. The <ulink url="http://www.ibiblio.org/mdw/HOWTO/DNS-HOWTO.html">DNS HOWTO</ulink> covers the use of BIND as a DNS server.</para>
</sect2>
<sect2><title>DHCP</title>
<para>DHCP is the Dynamic Host Configuration Protocol, which is gradually replacing good old <command>bootp</command> in larger environments. It is used to control vital networking parameters such as IP addresses and name servers of hosts. DHCP is backward compatible with <command>bootp</command>. For configuring the server, you will need to read the HOWTO.</para>
<para>RedHat DHCP client machines will usually be configured using the GUI, <command>redhat-config-network</command>, which will set <varname>BOOTPROTO</varname> to <emphasis>dhcp</emphasis> in <filename>/etc/sysconfig/network-scripts/ifcfg-eth0</filename>. The <command>netconfig</command> command does the same in text mode. DHCP clients need to run the DHCP client daemon, <command>dhcpcd</command> to obtain network information from a remote server.</para>
<figure><title>Network Configuration Tool</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/redhat-config-network.eps" format="EPS"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/redhat-config-network.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
</sect2>
<sect2><title>Authentication</title>
<sect3><title>PAM</title>
<para>Linux can use PAM, the Pluggable Authentication Module, a flexible method of UNIX authentication. Advantages of PAM:</para>
<itemizedlist>
<listitem><para>A common authentication scheme that can be used with a wide variety of applications.
</para></listitem>
<listitem><para>PAM can be implemented with various applications without having to recompile the applications to specifically support PAM.</para></listitem>
<listitem><para>Great flexibility and control over authentication for the administrator and application developer.
</para></listitem>
<listitem><para>Application developers do not need to develop their program to use a particular authentication scheme. Instead, they can focus purely on the details of their program.</para></listitem>
</itemizedlist>
<para>The directory <filename>/etc/pam.d</filename> contains the PAM configuration files (used to be <filename>/etc/pam.conf</filename>). Each application or service has its own file. Each line in the file has four elements:</para>
<itemizedlist>
<listitem><para><emphasis>Module</emphasis>:</para>
<itemizedlist>
<listitem><para><option>auth</option>: provides the actual authentication (perhaps asking for and checking a password) and sets credentials, such as group membership or Kerberos tickets.</para></listitem>
<listitem><para><option>account</option>: checks to make sure that access is allowed for the user (the account has not expired, the user is allowed to log in at this time of day, and so on).</para></listitem>
<listitem><para><option>password</option>: used to set passwords.</para></listitem>
<listitem><para><option>session</option>: used after a user has been authenticated. This module performs additional tasks which are needed to allow access (for example, mounting the user's home directory or making their mailbox available).</para>
</listitem>
</itemizedlist>
<para>The order in which modules are stacked, so that multiple modules can be used, is very important.</para>
</listitem>
<listitem><para><emphasis>Control Flags</emphasis>: tell PAM which actions to take upon failure or success. Values can be <option>required</option>, <option>requisite</option>, <option>sufficient</option> or <option>optional</option>.</para></listitem>
<listitem><para><emphasis>Module Path</emphasis>: path to the pluggable module to be used, usually in <filename>/lib/security</filename>.</para></listitem>
<listitem><para><emphasis>Arguments</emphasis>: information for the modules</para></listitem>
</itemizedlist>
<para>Shadow password files are automatically detected by PAM.</para>
<para>More information can be found in the <command>pam</command> man pages or at <ulink url="http://www.kernel.org/pub/linux/libs/pam">the Linux-PAM project</ulink> homepage.</para>
</sect3>
<sect3><title>LDAP</title>
<para>The Lightweight Directory Access Protocol is a client-server system for accessing global or local directory services over a network. On Linux, the OpenLDAP implementation is used. It includes <command>slapd</command>, a stand-alone server; <command>slurpd</command>, a stand-alone LDAP replication server; libraries implementing the LDAP protocol and a series of utilities, tools and sample clients.</para>
<para> The main benefit of using LDAP is the consolidation of certain types of information within your organization. For example, all of the different lists of users within your organization can be merged into one LDAP directory. This directory can be queried by any LDAP-enabled applications that need this information. It can also be accessed by users who need directory information.
</para><para>
Other LDAP or X.500 Lite benefits include its ease of implementation (compared to X.500) and its well-defined Application Programming Interface (API), which means that the number of LDAP-enabled applications and LDAP gateways should increase in the future.
</para><para>
On the negative side, if you want to use LDAP, you will need LDAP-enabled applications or the ability to use LDAP gateways. While LDAP usage should only increase, currently there are not very many LDAP-enabled applications available for Linux. Also, while LDAP does support some access control, it does not possess as many security features as X.500.
</para>
<para> Since LDAP is an open and configurable protocol, it can be used to store almost any type of information relating to a particular organizational structure. Common examples are mail address lookups, central authentication in combination with PAM, telephone directories and machine configuration databases.</para>
<para>RedHat comes with a slightly improved OpenLDAP version. See the system specific information and the man pages for related commands such as <command>ldapmodify</command> and <command>ldapsearch</command> for details. More information can be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/LDAP-HOWTO.html">LDAP Linux HOWTO</ulink>, which discusses installation, configuration, running and maintenance of an LDAP server on Linux. The <ulink url="http://www.ibiblio.org/mdw/HOWTO/LDAP-Implementation-HOWTO/index.html">LDAP Implementation HOWTO</ulink> describes the technical aspects of storing application data in an LDAP server.</para>
</sect3>
</sect2>
</sect1>
<sect1><title>Remote execution of applications</title>
<sect2><title>Introduction</title>
<para>There are a couple of different ways to execute commands or run programs on a remote machine and have the output, be it text or graphics, sent to your workstation. The connections can be secure or insecure. While it is of course advised to use secure connections instead of transporting your password over the network unencrypted, we will discuss some practical applications of the older (unsafe) mechanisms, as they are still useful in a modern networked environment, such as for troubleshooting or running exotic programs.</para>
</sect2>
<sect2><title>Rsh, rlogin and telnet</title>
<para>The <command>rlogin</command> and <command>rsh</command> commands for remote login and remote execution of commands are a heritance from UNIX. While seldom used because they are blatantly insecure, they still come with almost every Linux distribution for backward compatibility with UNIX programs.</para>
<para>Telnet, on the other hand, is still commonly used, often by system and network administrators. Telnet is one of the most powerful tools for remote access to files and remote administration, allowing connections from anywhere on the Internet. Combined with an X server, remote graphical applications can be displayed locally. There is no difference between working on the local machine and using the remote machine.</para>
<para>Because the entire connection is unencrypted, allowing <command>telnet</command> connections involves taking high security risks. For normal remote execution of programs, Secure SHell or <command>ssh</command> is advised. We will discuss the secure method later in this section.</para>
<para>However, <command>telnet</command> is still used in many cases. Below are some examples in which a mail server and a web server are tested for replies:</para>
<screen>
[jimmy@blob ~] telnet mailserver 25
Trying 192.168.42.1...
Connected to mailserver.
Escape character is '^]'.
220 m1.some.net ESMTP Sendmail 8.11.6/8.11.6; Fri, 22 Mar 2002 10:55:11 +0100
ehlo some.net
250-m1.some.net Hello blob.some.net [192.168.42.15], pleased to meet you
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE
250-DSN
250-ONEX
250-ETRN
250-XUSR
250 HELP
mail from: jimmy@some.net
250 2.1.0 jimmy@some.net... Sender ok
rcpt to: davy@some.net
250 2.1.5 davy@some.net... Recipient ok
data
354 Enter mail, end with "." on a line by itself
test
.
250 2.0.0 g2MA1R619237 Message accepted for delivery
quit
221 2.0.0 m1.some.net closing connection
Connection closed by foreign host.
[jimmy@blob ~] telnet www.some.net 80
Trying 64.39.151.23...
Connected to www.some.net.
Escape character is '^]'.
HEAD / ;HTTP/1.0
HTTP/1.1 200 OK
Date: Fri, 22 Mar 2002 10:05:14 GMT
Server: Apache/1.3.22 (UNIX) (Red-Hat/Linux) mod_ssl/2.8.5 OpenSSL/0.9.6
DAV/1.0.2 PHP/4.0.6 mod_perl/1.24_01
Last-Modified: Fri, 04 Jan 2002 08:21:00 GMT
ETag: "70061-68-3c3565ec"
Accept-Ranges: bytes
Content-Length: 104
Connection: close
Content-Type: text/html
Connection closed by foreign host.
[jimmy@blob ~]
</screen>
</sect2>
<sect2><title>The X Window System</title>
<sect3><title>X features</title>
<para>Developed at MIT in the late 1980s, the X Window System rapidly became the industry standard windowing system for UNIX graphical workstations (see configuring your graphical environment). It is important to realize the distinction between the X server and the X client application(s). The server controls the display directly and is responsible for all input and output via keyboard, mouse and display. The client, on the other hand, does not access the input and output devices directly. It communicates with the server which handles input and output. It is the client which does the real work, like computing values, running applications and so forth. The server only opens windows to handle input and output for the specified client.</para>
<para>This nature of the X system makes it an ideal environment for remote execution of applications and programs. Because the process is actually being executed on the remote machine, very little CPU power is needed on the local host. Such machines, purely acting as servers for X, are called X terminals and were once very popular. More information may be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/mini/Remote-X-Apps.html">Remote X applications mini-HOWTO</ulink>.</para>
</sect3>
<sect3><title>Telnet and X</title>
<para>If you would want to use <command>telnet</command> to display graphical applications running on a remote machine, you first need to give the remote machine access to your display using the <command>xhost</command> command, by typing a command similar to the one below in a terminal window on your local machine:</para>
<screen>
davy:~&gt;xhost +remote.machine.com
</screen>
<para>After that, connect to the remote host and tell it to display graphics on the local machine by setting the environment variable <varname>DISPLAY</varname>:</para>
<screen>
[davy@remote ~] export DISPLAY="local.host.com:0.0"
</screen>
<para>After completing this step, any application started in this terminal window will be displayed on your local desktop.</para>
</sect3>
</sect2>
<sect2><title>The SSH suite</title>
<sect3><title>Introduction</title>
<para>Most UNIX and Linux systems now run Secure SHell in order to leave out the security risks that came with <command>telnet</command>. Most Linux systems will run a version of OpenSSH, an Open Source implementation of the SSH protocol, providing secure encrypted communications between untrusted hosts over an untrusted network. In the standard setup X connections are automatically forwarded, but arbitrary TCP/IP ports may also be forwarded using a secure channel.</para>
<para>The <command>ssh</command> client connects and logs into the specified host name. The user must provide his identity to the remote machine as specified in the <filename>sshd_config</filename> file, which can usually be found in <filename>/etc/ssh</filename>. The configuration file is rather self-explanatory and by defaults enables most common features. Should you need help, you can find it in the <command>sshd</command> man pages.</para>
<para>When the user's identity has been accepted by the server, the server either executes the given command, or logs into the machine and gives the user a normal shell on the remote machine. All communication with the remote command or shell will be automatically encrypted.</para>
<para>The session terminates when the command or shell on the remote machine exits and all X11 and TCP/IP connections have been closed.</para>
</sect3>
<sect3><title>X11 and TCP forwarding</title>
<para>If the <varname>X11Forwarding</varname> entry is set to <emphasis>yes</emphasis> and the user is using X applications, the <varname>DISPLAY</varname> environment variable is set, the connection to the X11 display is automatically forwarded to the remote side in such a way that any X11 programs started from the shell will go through the encrypted channel, and the connection to the real X server will be made from the local machine. The user should not manually set <varname>DISPLAY</varname>. Forwarding of X11 connections can be configured on the command line or in the <command>sshd</command> configuration file.</para>
<para>The value for <varname>DISPLAY</varname> set by <command>ssh</command> will point to the server machine, but with a display number greater than zero. This is normal, and happens because <command>ssh</command> creates a <emphasis>proxy</emphasis> X server on the server machine for forwarding the connections over the encrypted channel:</para>
<figure><title>SSH X11 forwarding</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/ssh_X11.eps" format="EPS"></imagedata></imageobject>
<imageobject>
<imagedata fileref="images/ssh_X11.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>SSH will also automatically set up Xauthority data on the server machine. For this purpose, it will generate a random authorization cookie, store it in <filename>Xauthority</filename> on the server, and verify that any forwarded connections carry this cookie and replace it by the real cookie when the connection is opened. The real authentication cookie is never sent to the server machine (and no cookies are sent in the plain).</para>
<para>Forwarding of arbitrary TCP/IP connections over the secure channel can be specified either on the command line or in a configuration file.</para>
</sect3>
<sect3><title>Server authentication</title>
<para>The <command>ssh</command> client/server system automatically maintains and checks a database containing identifications for all hosts it has ever been used with. Host keys are stored in <filename>$HOME/.ssh/known_hosts</filename> in the user's home directory. Additionally, the file <filename>/etc/ssh/ssh_known_hosts</filename> is automatically checked for known hosts. Any new hosts are automatically added to the user's file. If a host's identification ever changes, <command>ssh</command> warns about this and disables password authentication to prevent a Trojan horse from getting the user's password. Another purpose of this mechanism is to prevent man-in-the-middle attacks which could otherwise be used to circumvent the encryption. In environments where high security is needed, <command>sshd</command> can even be configured to prevent logins to machines whose host keys have changed or are unknown.</para>
</sect3>
<sect3><title>Secure remote copying</title>
<para>The SSH suite provides <command>scp</command> as a secure alternative to the <command>rcp</command> command that used to be popular when only <command>rsh</command> existed. <command>scp</command> uses <command>ssh</command> for data transfer, uses the same authentication and provides the same security as <command>ssh</command>. Unlike <command>rcp</command>, <command>scp</command> will ask for passwords or passphrases if they are needed for authentication.</para>
<para>Any file name may contain a host and user specification to indicate that the file is to be copied to/from that host. Copies between two remote hosts are permitted. See the Info pages for more information.</para>
</sect3>
<sect3><title>Authentication keys</title>
<para>The <command>ssh-keygen</command> command generates, manages and converts authentication keys for <command>ssh</command>. It can create RSA keys for use by SSH protocol version 1 and RSA or DSA keys for use by SSH protocol version 2.</para>
<para>Normally each user wishing to use SSH with RSA or DSA authentication runs this once to create the authentication key in <filename>$HOME/.ssh/identity</filename>, <filename>id_dsa</filename> or <filename>id_rsa</filename>. Additionally, the system administrator may use this to generate host keys for the system.</para>
<para>Normally this program generates the key and asks for a file in which to store the private key. The public key is stored in a file with the same name but <emphasis>.pub</emphasis> appended. The program also asks for a passphrase. The passphrase may be empty to indicate no passphrase (host keys must have an empty passphrase), or it may be a string of arbitrary length.</para>
<para>There is no way to recover a lost passphrase. If the passphrase is lost or forgotten, a new key must be generated and copied to the corresponding public keys.</para>
<para>We will study SSH keys in the exercises. All information can be found in the man or Info pages.</para>
</sect3>
</sect2>
<sect2><title>VNC</title>
<para>VNC or Virtual Network Computing is in fact a remote display system which allows viewing a desktop environment not only on the local machine on which it is running, but from anywhere on the Internet and from a wide variety of machines and architectures, including MS Windows and several UNIX distributions. You could, for example, run MS Word on a Windows NT machine and display the output on your Linux desktop. VNC provides servers as well as clients, so the opposite also works and it may thus be used to display Linux programs on Windows clients. VNC is probably the easiest way to have X connections on a PC. The following features make VNC different from a normal X server or commercial implementations:</para>
<itemizedlist>
<listitem><para>No state is stored at the viewer side: you can leave your desk and resume from another machine, continuing where you left. When you are running a PC X server, and the PC crashes or is restarted, all remote applications that you were running will die. With VNC, they keep on running.</para></listitem>
<listitem><para>It is small and simple, no installation needed, can be run from a floppy if needed.</para></listitem>
<listitem><para>Platform independent with the Java client, runs on virtually everything that supports X.</para></listitem>
<listitem><para>Sharable: one desktop may be displayed on multiple viewers.</para></listitem>
<listitem><para>Free (GNU Public License).</para></listitem>
</itemizedlist>
<para>More information can be found in the VNC client man pages (<command>man vncviewer</command>) or on the <ulink url="http://www.uk.research.att.com/vnc/">VNC website</ulink>.</para>
</sect2>
</sect1>
<sect1><title>Linux as a network appliance</title>
<sect2><title>Router</title>
<para>IP Routing is the process by which a host with multiple network connections decides where to deliver the IP datagrams that it has received.</para>
<para>While this is a fairly simple sentence, routing is a topic on which large volumes of text have been written. Most people have fairly simple routing requirements, but get mixed up easily enough. Detailed information can be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Net-HOWTO/index.html">Linux Networking HOWTO.</ulink> For now, remember that you need at least two network interfaces for building a router. While it is a sensible thing to install a firewall on every machine, hosts with only one network interface should never be configured as a router.</para>
<para>The Linux kernel has built-in support for routing functions. A Linux box can act either as an IP or IPX router for a fraction of the cost of a commercial router. Recent kernels include special options for machines acting primarily as routers, such as multi-casting and IP policy routing.</para>
<para>As with some other special functions, there is a project for running a Linux router off a floppy disk. More information may be found at the <ulink url="http://www.linuxrouter.org">Linux router project homepage</ulink>.</para>
</sect2>
<sect2><title>Bridge</title>
<para>An Ethernet bridge is a device that controls data packets within a subnet in an attempt to cut down the amount of traffic. A bridge is usually placed between two separate groups of computers that talk within themselves, but not so much with the computers in the other group. A good example of this is to consider a cluster of MacIntoshes and a cluster of UNIX machines. Both of these groups of machines tend to be quite chatty among themselves, and the traffic they produce on the network causes collisions for the other machines who are trying to speak to one another. A bridge would be placed between these groups of computers. The job of the bridge is then to examine the destination of the data packets one at a time and decide whether or not to pass the packets to the other side of the Ethernet segment. The result is a faster, quieter network with less collisions.</para>
<para>The Linux kernel has built-in support for acting as an Ethernet bridge, which means that the different Ethernet segments it is connected to will appear as one Ethernet to the participants. Several bridges can work together to create even larger networks. Linux bridges will inter-operate properly with other third party bridge products. Additional packages allow filtering based on IP, IPX or MAC addresses.</para>
<para>Additional information can be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/mini/Bridge+Firewall.html">Linux Bridge+Firewall Mini-HOWTO</ulink> or in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/mini/Bridge.html">Bridging mini-HOWTO</ulink>.</para>
</sect2>
<sect2><title>IP Masquerading and IP aliasing</title>
<para>With the appropriate modules loaded, the Linux kernel will act as the official connection point for hosts without an officially assigned IP address connecting to that machine, as with a workstation with the unresolvable IP address of 10.0.0.10. This means cost reductions, since a lot of hosts may be connected to the Internet using a single connection. Since the masquerading machine will not accept direct connections for the machines with the unresolvable addresses, it also contributes to increase security.</para>
<para>Extended information can be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/IP-Masquerade-HOWTO/">IP Masquerade HOWTO</ulink>.</para>
<para>The IP aliasing feature of the Linux kernel provides the possibility of setting up multiple network addresses on the same network interface. This is typically used for services that behave differently based on the address they listen on (for example, virtual domains).</para>
</sect2>
<sect2><title>Firewall and IP accounting</title>
<para>A firewall is a device that protects a private network from the public part (the Internet as a whole). It is designed to control the flow of packets based on the source, destination, port and packet type information contained in each packet. In combination with the IP accounting features, the Linux kernel can perform packet logging. A series of rules may be defined to have the firewall take actions upon a pattern match, such as increasing a counter or accepting or rejecting the packet.</para>
<para>Different firewall toolkits exist for Linux as well as built-in support in the kernel. More information can be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Firewall-HOWTO.html">Firewall and Proxy Server HOWTO</ulink>.</para>
</sect2>
<sect2><title>Port forwarding</title>
<para>An increasing number of web sites are becoming interactive by having cgi-bins or Java applets that access some database or other service. Since this access may pose a security problem, the machine containing the database should not be directly connected to the Internet.</para>
<para>Port forwarding can provide an almost ideal solution to this access problem. On the firewall, IP packets that come in to a specific port number can be rewritten and forwarded to the internal server providing the actual service. The reply packets from the internal server are rewritten to make it appear that they came from the firewall.</para>
</sect2>
<sect2><title>Load balancing</title>
<para>Load balancing is achieved using the Network Address Translation features provided in the Linux kernel. Network administrators can replace a single server that provides things like Web services with a logical pool of servers sharing a common IP address. Incoming connections are directed to a particular server using one load-balancing algorithm. The virtual server rewrites incoming and outgoing packets to give clients the appearance that only one server exists.</para>
<para>The Apache webserver itself comes with several modules that allow distribution of requests among servers, for redundancy, increased availability and so on. One technique is the reverse proxy, which consists of having an Apache front-end server acting as a proxy for the back-end servers. Another method allows seamless redirection of HTTP requests from one server to another. This redirection can be used to target machines with under-utilized resources, thus providing fine-tuned, per-request balancing. Detailed documentation is on the <ulink url="http://apache.org">Apache Web site</ulink>.</para>
</sect2>
<sect2><title>Proxy</title>
<para>The term proxy means <quote>to do something on behalf of someone else.</quote> In networking terms, a proxy server computer can act on the behalf of several clients. An HTTP proxy is a machine that receives requests for web pages from another machine (Machine A). The proxy gets the page requested and returns the result to Machine A. The proxy may have a cache containing the last <emphasis>n</emphasis> megabytes of requested pages, so if Machine B asks for the same page as Machine A, the copy in the cache will be returned instead. This allows efficient use of bandwidth resources and reduces response time. As a side effect, as client machines are not directly connected to the outside world this is a way of securing the internal network. A well-configured proxy can be as effective as a good firewall.</para>
<para>The two best known proxy server solutions for Linux are Squid and the Apache proxy module. More information is located at the <ulink url="http://www.squid-cache.org">Squid</ulink> and <ulink url="http://www.apache.org">Apache</ulink> web sites.</para>
</sect2>
<sect2><title>Dial on demand</title>
<para>The purpose of dial on demand is to make it transparently appear that the users have a permanent connection to a remote site. Usually, there is a daemon who monitors the traffic of packets and where an interesting packet (interesting is defined usually by a set of rules/priorities/permissions) arrives it establishes a connection with the remote end. When the channel is idle for a certain period of time, it drops the connection.</para>
<para>Full information is in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Diald-HOWTO.html">Diald HOWTO</ulink>.</para>
</sect2>
<sect2><title>Tunneling, mobile IP and VPN's</title>
<para>The Linux kernel allows the tunneling (encapsulation) of protocols. It can do IPX tunneling through IP, allowing the connection of two IPX networks through an IP-only link. It can also do IP-IP tunneling, which it is essential for mobile IP support, multi-cast support and amateur radio.</para>
<para>Mobile IP specifies enhancements that allow transparent routing of IP datagrams to mobile nodes in the Internet. Each mobile node is always identified by its home address, regardless of its current point of attachment to the Internet. While situated away from its home, a mobile node is also associated with a care-of address, which provides information about its current point of attachment to the Internet. The protocol provides for registering the care-of address with a home agent. The home agent sends datagrams destined for the mobile node through a tunnel to the care-of address. After arriving at the end of the tunnel, each datagram is then delivered to the mobile node.</para>
<para>Point-to-Point Tunneling Protocol (PPTP) is a networking technology that allows the use of the Internet as a secure virtual private network (VPN). PPTP is integrated with the Remote Access Services (RAS) server which is built into Windows NT Server. With PPTP, users can dial into a local ISP or connect directly to the Internet, and access their network as if they were at their desks. PPTP is a closed protocol and its security has recently been compromised. It is highly recommended that you use other Linux based alternatives, since they rely on open standards which have been carefully examined and tested.</para>
<para>Detailed information can be found at the <ulink url="http://pptpclient.sourceforge.net/">PPTP Client Project homepage</ulink>, in the <ulink url="http://www.radio.org/linux/">Linux HAM HOWTO</ulink> and in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/mini/VPN.html">VPN HOWTO</ulink>.</para>
</sect2>
<sect2><title>Network management station</title>
<para>There is a huge amount of tools available for network management, remote administration, monitoring, traffic analysis, security, backup and so forth. An archive of the most important tools is kept at <ulink url="http://www.ibiblio.org/pub/Linux/system/network/">Metalab</ulink>. Your local provider probably also has a mirror of one of the many sites providing Free/Open Source software.</para>
<para>Most Linux distributions support SNMP, the Simple Network Management Protocol. Here, too, a lot of applications are available. More information can be found on the <ulink url="http://linas.org/linux/NMS.html">Linux SNMP Network Management Tools site</ulink>.</para>
</sect2>
</sect1>
<sect1><title>Security</title>
<sect2><title>Introduction</title>
<para>As soon as a computer is connected to the network, all kinds of abuse becomes possible, be it UNIX-based or any other system. Admittedly, mountains of papers have been spilled on this subject and it would lead us too far to discuss the subject of security in detail, but there are a couple of fairly logical things even a novice user can do to obtain a very secure system, because most break-ins are the result of ignorant or careless users.</para>
<para>Maybe you are asking yourself if this all applies to you, using your computer at home or working at your office on a desktop in a fairly protected environment. The questions you should be asking yourself, however, are more on the lines of:</para>
<itemizedlist>
<listitem><para>Do you want to be in control of your own system?</para></listitem>
<listitem><para>Do you want to (unwittingly) participate in criminal activities?</para></listitem>
<listitem><para>Do you want your equipment to be used by someone else?</para></listitem>
<listitem><para>Do you want to take risks on losing your Internet connection?</para></listitem>
<listitem><para>Do you want to rebuild your system every time it has been hacked?</para></listitem>
<listitem><para>Do you want to risk personal or other data loss?</para></listitem>
</itemizedlist>
<para>Presuming you don't, we will quickly list the steps you can take to secure your machine. Extended information can be found in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Security-HOWTO.html">Linux Security HOWTO</ulink>.</para>
</sect2>
<sect2><title>Services</title>
<para>The goal is to run as few services as possible. If the number of ports that are open for the outside world are kept to a minimum, this is all the better to keep an overview. If services can't be turned off for the local network, try to at least disable them for outside connections.</para>
<para>A rule of thumb is that if you don't recognize a particular service, you probably won't need it anyway. Also keep in mind that some services are not really meant to be used over the Internet. Don't rely on what <emphasis>should</emphasis> be running, check which services are listening on what TCP ports using the <command>netstat</command> command:</para>
<screen>
[elly@mars ~] netstat -l | grep tcp
tcp 0 0 *:32769 *:* LISTEN
tcp 0 0 *:32771 *:* LISTEN
tcp 0 0 *:printer *:* LISTEN
tcp 0 0 *:kerberos_master *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:6001 *:* LISTEN
tcp 0 0 *:785 *:* LISTEN
tcp 0 0 localhost.localdom:smtp *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 ::1:x11-ssh-offset *:* LISTEN
</screen>
<para>Things to avoid:</para>
<itemizedlist>
<listitem><para><command>exec</command>, <command>rlogin</command> and <command>rsh</command>, and <command>telnet</command> just to be on the safe side.</para></listitem>
<listitem><para>X11 on server machines.</para></listitem>
<listitem><para>No lp if no printer is physically attached.</para></listitem>
<listitem><para>No MS Windows hosts in the network, no Samba required.</para></listitem>
<listitem><para>Don't allow FTP unless an FTP server is required.</para></listitem>
<listitem><para>Don't allow NFS and NIS over the Internet, disable all related services on a stand-alone installation.</para></listitem>
<listitem><para>Don't run an MTA if you're not actually on a mail server.</para></listitem>
<listitem><para>...</para></listitem>
</itemizedlist>
<para>Stop running services using the <command>chkconfig</command> command, the initscripts or by editing the <command>(x)inetd</command> configuration files.
</para>
</sect2>
<sect2><title>Update regularly</title>
<para>Its ability to adapt quickly in an ever changing environment is what makes Linux thrive. But it also creates a possibility that security updates have been released even while you are installing a brand new version, so the first thing you should do (and this goes for about any OS you can think of) after installing is getting the updates as soon as possible. After that, update <emphasis>all</emphasis> the packages you use regularly.</para>
<para>RedHat provides the <command>up2date</command> utility to automatically keep all packages current with the release. See <xref linkend="chap_07" /> for more on installing packages.</para>
<para>Some updates may require new configuration files, and old files may be replaced. Check the documentation, and ensure that everything runs normal after updating.</para>
<para>Most Linux distributions provide mailing list services for security update announcements. General Linux only security issues are reported among others at <ulink url="http://linuxsecurity.com">Linuxsecurity.com</ulink>.</para>
<para>Updating is an ongoing process, so it should be an almost daily habit.</para>
</sect2>
<sect2><title>Firewalls and access policies</title>
<sect3><title>What is a firewall?</title>
<para>In the previous section we already mentioned firewall capabilities in Linux. While firewall administration is one of the tasks of your network admin, you should know a couple of things about firewalls.</para>
<para><emphasis>Firewall</emphasis> is a vague term that can mean anything that acts as a protective barrier between us and the outside world, generally the Internet. A firewall can be a dedicated system or a specific application that provides this functionality. Or it can be a combination of components, including various combinations of hardware and software. Firewalls are built from <quote>rules</quote> that are used to define what is allowed to enter and/or exit a given system or network.</para>
<para>After disabling unnecessary services, we now want to restrict accepted services as to allow only the minimum required connections. A fine example is working from home: only the specific connection between your office and your home should be allowed, connections from other machines on the Internet should be blocked.</para>
</sect3>
<sect3><title>Packet filters</title>
<para>The first line of defense is a <emphasis>packet filter</emphasis>, which can look inside IP packages and make decisions based on the content. RedHat provides the <command>firewall-config</command> tool as a front-end for systems running the <command>ipchains</command> (2.2 kernel). Newer systems (2.4 kernel) use <command>iptables</command>, a next generation packet filter for Linux, and the Gnome Lokkit tool. This tool was only created to provide an easy interface for normal users. It sets up a basic firewall configuration for a desktop, a dial-up or cable modem connection, and that's about it. It should not be used in larger environments.</para>
<para>One of the most noteworthy enhancements in the newer kernels is the <emphasis>stateful inspection</emphasis> feature, which not only tells what is inside a packet, but also detects if a packet belongs or is related to a new or existing connection.</para>
<para>Development is ongoing, so it is best to check with each new version of a distribution which system is being used.</para>
</sect3>
<sect3><title>TCP wrappers</title>
<para>TCP wrapping provides much the same results as the packet filters, but works differently. The wrapper actually accepts the connection attempt, then examines configuration files and decides whether to accept or reject the connection request. It controls connections at the application level rather than at the network level.</para>
<para>TCP wrappers are typically used with <command>xinetd</command> to provide host name and IP-address-based access control. In addition, these tools include logging and utilization management capabilities that are easy to configure.</para>
<para>The advantages of TCP wrappers are that the connecting client is unaware that wrappers are used, and that they operate separately from the applications they protect.</para>
<para>The host based access is controlled in the <filename>hosts.allow</filename> and <filename>hosts.deny</filename> files. More information can be found in the TCP wrapper documentation files and in the man pages for these files, which contain examples.</para>
</sect3>
<sect3><title>Proxies</title>
<para>Proxies can perform various duties, not all of which have much to do with security. But the fact that they are an intermediary make proxies a good place to enforce access control policies, limit direct connections through a firewall, and control how the network behind the proxy looks to the Internet.</para>
<para>Usually in combination with a packet filter, but sometimes all by themselves, proxies provide an extra level of control. More information can be found in the <ulink url="http://www.tldp.org/HOWTO/Firewall-HOWTO.html">Firewall HOWTO</ulink> or on the Squid website.</para>
</sect3>
<sect3><title>Access to individual applications</title>
<para>Some servers may have their own access control features. Common examples include Samba, X11, Bind, Apache and CUPS. For every service you want to offer check which configuration files apply.</para>
</sect3>
<sect3><title>Log files</title>
<para>If anything, the UNIX way of logging all kinds of activities into all kinds of files confirms that <quote>it is doing something.</quote> Of course, log files should be checked regularly, manually or automatically. Firewalls and other means of access control tend to create huge amounts of log files, so the trick is to try and only log abnormal activities.</para></sect3>
</sect2>
<sect2><title>Intrusion detection</title>
<para> Intrusion Detection Systems are designed to catch what might have gotten past the firewall. They can either be designed to catch an active break-in attempt in progress, or to detect a successful break-in after the fact. In the latter case, it is too late to prevent any damage, but at least we have early awareness of a problem. There are two basic types of IDS: those protecting networks, and those protecting individual hosts.</para>
<para> For host based IDS, this is done with utilities that monitor the file system for changes. System files that have changed in some way, but should not change, are a dead give-away that something is amiss. Anyone who gets in and gets root access will presumably make changes to the system somewhere. This is usually the very first thing done, either so he can get back in through a backdoor, or to launch an attack against someone else, in which case, he has to change or add files to the system. RedHat comes with the <command>tripwire</command> monitoring system, which is documented at the <ulink url="http://www.tripwire.org">Tripwire Open Source Project</ulink> website.</para>
<para>Network intrusion detection is handled by a system that sees all the traffic that passes the firewall (not by portscanners, which advertise usable ports). <ulink url="http://www.snort.org">Snort</ulink> is an Open Source example of such a program. Whitehats.com features an open Intrusion detection database, <ulink url="http://www.whitehats.com">arachNIDS</ulink>. </para>
</sect2>
<sect2><title>More tips</title>
<para>Some general things you should keep in mind:</para>
<itemizedlist>
<listitem><para>Do not allow root logins. UNIX developers came up with the <command>su</command> over two decades ago for extra security.</para></listitem>
<listitem><para>Take passwords seriously. Use shadow passwords. Change your passwords regularly.</para></listitem>
<listitem><para>Try to always use SSH. Avoid <command>telnet</command>, FTP clients, and other client programs, such as a POP3 mail client, which send unencrypted passwords over the network.</para></listitem>
<listitem><para>Limit resources using <command>quota</command> and/or <command>ulimit</command>.</para></listitem>
<listitem><para>The mail for root should be delivered to an actual person.</para></listitem>
<listitem>
<para>The <ulink url="http://www.sans.org">SANS institute</ulink> has more tips and tricks, sorted per distribution, with mailing list service. They advertise the use of the <ulink url="http://www.bastille-linux.org">Bastille hardening system</ulink> for RedHat users.</para></listitem>
<listitem><para>Check the origin of new software, get it from a trusted place/site. Verify new packages before installing.</para></listitem>
<listitem><para>When using a non-permanent Internet connection, shut it down as soon as you don't need it anymore.</para></listitem>
<listitem><para>Run private services on odd ports instead of the ones expected by possible hackers.</para></listitem>
<listitem><para>Know your system. After a while, you can almost feel when something is happening.</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Have I been hacked?</title>
<para>How can you tell? This is a checklist of suspicious events:</para>
<itemizedlist>
<listitem><para>Mysterious open ports, strange processes.</para></listitem>
<listitem><para>System utilities (common commands) behaving strange.</para></listitem>
<listitem><para>Login problems.</para></listitem>
<listitem><para>Unexplained bandwidth usage.</para></listitem>
<listitem><para>Damaged or missing log files, syslog daemon behaving strange.</para></listitem>
<listitem><para>Interfaces in unusual modes.</para></listitem>
<listitem><para>Unexpectedly modified configuration files.</para></listitem>
<listitem><para>Strange entries in shell history files.</para></listitem>
<listitem><para>Unidentified temporary files.</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Recovering from intrusion</title>
<para>In short, stay calm. Then take the following actions in this order:</para>
<itemizedlist>
<listitem><para>Disconnect the machine from the network.</para></listitem>
<listitem><para>Try to find out as much as you can about how your security was breached.</para></listitem>
<listitem><para>Backup important non-system data.</para></listitem>
<listitem><para>Re-install the system.</para></listitem>
<listitem><para>Use new passwords.</para></listitem>
<listitem><para>Restore from system and data backups.</para></listitem>
<listitem><para>Apply all available updates.</para></listitem>
<listitem><para>Re-examine the system: block off unnecessary services, check firewall rules and other access policies.</para></listitem>
<listitem><para>Reconnect.</para></listitem>
</itemizedlist>
</sect2>
</sect1>
<sect1><title>Summary</title>
<para>Linux and networking go hand in hand. The Linux kernel has support for all common and most uncommon network protocols. The standard UNIX networking tools are provided in each distribution. Next to those, most distributions offer tools for easy network installation and management.</para>
<para>Linux is well know as a stable platform for running various Internet services, the amount of Internet software is endless. Like UNIX, Linux can be just as well used and administered from a remote location, using one of several solutions for remote execution of programs.</para>
<para>We briefly touched the subject of security. Linux is an ideal firewall system, light and cheap, but can be used in several other network functions such as routers and proxy servers.</para>
<para>Increasing network security is mainly done by applying frequent updates and common sense.</para>
</sect1>
<sect1><title>Exercises</title>
<sect2><title>General networking</title>
<itemizedlist>
<listitem><para>Display network information for your workstation: IP address, routes, name servers.</para></listitem>
<listitem><para>Suppose no DNS is available. What would you do to reach your neighbour's machine without typing the IP address all the time?</para></listitem>
<listitem><para>How would you permanently store proxy information for a text mode browser such as <command>links</command>?</para></listitem>
<listitem><para>Which name servers handle the redhat.com domain?</para></listitem>
<listitem><para>Send an E-mail to your local account. Try two different ways to send and read it. How can you check that it really arrived?</para></listitem>
<listitem><para>Does your machine accept anonymous FTP connections? How do you use the <command>ncftp</command> program to authenticate with your user name and password?</para></listitem>
<listitem><para>Does your machine run a web server? If not, make it do so. Check the log files!</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Remote connections</title>
<itemizedlist>
<listitem><para>From your local workstation, display a graphical application, such as <command>xclock</command> on your neighbour's screen. The necessary accounts will have to be set up. Use a secure connection!</para></listitem>
<listitem><para>Set up SSH keys so you can connect to your neighbour's machine without having to enter a password.</para></listitem>
<listitem><para>Make a backup copy of your home directory in <filename>/var/tmp</filename> on your neighbour's <quote>backup server,</quote> using <command>scp</command>.</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Security</title>
<itemizedlist>
<listitem><para>Make a list of open (listening) ports on your machine.</para></listitem>
<listitem><para>Supposing you want to run a webserver. Which services would you deactivate? How would you do that?</para></listitem>
<listitem><para>Install available updates.</para></listitem>
<listitem><para>How can you see who connected to your system?</para></listitem>
<listitem><para>Make a repetitive job that reminds you each month to change the root password.</para></listitem>
</itemizedlist>
</sect2>
</sect1>
</chapter>

View File

@ -0,0 +1,264 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_02"><title>Quickstart</title>
<abstract>
<para>In order to get the most out of this guide, we will immediately start with a practical chapter on connecting to the Linux system and doing some basic things.</para>
<para>We will discuss:</para>
<para>
<itemizedlist>
<listitem><para>Connecting to the system</para></listitem>
<listitem><para>Disconnecting from the system</para></listitem>
<listitem><para>Text and graphic mode</para></listitem>
<listitem><para>Changing your password</para></listitem>
<listitem><para>Navigating through the file system</para></listitem>
<listitem><para>Determining file type</para></listitem>
<listitem><para>Looking at text files</para></listitem>
<listitem><para>Moving and deleting files</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1 id="sect_02_01"><title>Logging in, activating the user interface and logging out</title>
<sect2 id="sect_02_01_01"><title>Introduction</title>
<para>In order to work on a Linux system directly, you will need to provide a user name and password. You always need to authenticate to the system. As we already mentioned in the exercise from <xref linkend="chap_01" />, most PC-based Linux systems have two basic modes for a system to run in: either quick and sober in text console mode, which looks like DOS with mouse, multitasking and multi-user features, or in graphical console mode, which looks better but eats more system resources.</para>
</sect2>
<sect2 id="sect_02_01_02"><title>Graphical mode</title>
<para>When you see something in a window, you're in graphical mode.</para>
<para>To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click OK or press [ENTER].</para>
<note><title>Careful with that root account!</title>
<para>It is generally considered a bad idea to connect (graphically) using the <emphasis>root</emphasis> user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account.</para></note>
<para>After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer and the software used.</para>
<para>To continue, you will need to open a <emphasis>terminal window</emphasis> or <emphasis>xterm</emphasis> for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the Utilities or Internet menu, depending on what window manager you are using. There might be icons that you can use as a shortcut to get an xterm window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.</para>
<para>While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old point-'n'-click method of dealing with the computer will do. But this guide is for future network and system administrators, who will need to meddle with the heart of the system. They need a stronger tool than a mouse to handle all the tasks they will face. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.</para>
<para>The terminal window is your control panel for the system. Almost everything that follows is done using this simple but powerful text tool. A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, the name of the machine which this terminal commands, and the current working directory:</para>
<figure><title>Terminal window</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/xterm.eps" format="EPS"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/xterm.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>Later we will discuss prompts and their behavior in detail.</para>
<para>To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the logout icon or find <emphasis>Log Out</emphasis> in the menu. Closing everything is not really necessary, and the system can do this for you, but session management will put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect.</para>
<para>When you see the login screen again, asking to enter user name and password, logout was successful.</para>
</sect2>
<sect2 id="sect_02_01_03"><title>Text mode</title>
<para>You know you're in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in:</para>
<screen>
RedHat Linux Release 7.2 (Enigma)
blast login: _
</screen>
<para>The login is different from a graphical login, in that you have to hit the [ENTER] key after providing your user name. Then you should enter your password, followed by another [ENTER]. You won't see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security reasons.</para>
<para>When the system has accepted you as a valid user, you may get some more information, called the <emphasis>message of the day</emphasis>, which can be anything and is not displayed when opening a graphical terminal. But after that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.</para>
<para>Logging out is done by entering the <command>logout</command> command, followed by [ENTER]. You are successfully disconnected from the system when you see the login screen again.</para>
<note><title>Don't hit the power button!</title>
<para>Don't power-off the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!</para></note>
<para>Now that we know how to connect to and disconnect from the system, we're ready for our first commands.</para>
</sect2>
</sect1>
<sect1 id="sect_02_02"><title>Absolute basics</title>
<sect2 id="sect_02_02_01"><title>The commands</title>
<para>These are the quickies, which we need to get started, and we will discuss them later in more detail:</para>
<table frame="all">
<title>Quickstart commands</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row>
<entry>Command</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry><command>ls</command></entry>
<entry><para>Displays a list of files in the current working directory, like the <command>dir</command> command in DOS</para></entry>
</row>
<row>
<entry><command>cd <filename>directory</filename></command></entry>
<entry><para>change directories</para></entry>
</row>
<row>
<entry><command>passwd</command></entry>
<entry>change the password for the current user</entry>
</row>
<row>
<entry><command>file <filename>filename</filename></command></entry>
<entry>display file type of file with name <filename>filename</filename></entry>
</row>
<row>
<entry><command>cat <filename>textfile</filename></command></entry>
<entry>throws content of <filename>textfile</filename> on the screen</entry>
</row>
<row><entry><command>pwd</command></entry>
<entry>display present working directory</entry>
</row>
<row>
<entry><command>exit</command> or <command>logout</command></entry>
<entry>leave this session</entry>
</row>
<row>
<entry><command>man <option>command</option></command></entry>
<entry>read man pages on <command>command</command></entry>
</row>
<row>
<entry><command>info <option>command</option></command></entry>
<entry>read Info pages on <command>command</command></entry>
</row>
<row>
<entry><command>apropos <option>string</option></command></entry>
<entry>search the <emphasis>whatis</emphasis> database for strings</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="sect_02_02_02"><title>General remarks</title>
<para>In Linux, like in UNIX, directories are separated using forward slashes, like the ones used in web addresses (URLs). We will discuss directory structure indepth later.</para>
<para>The symbols . and .. have special meaning when directories are concerned. We will try to find out about those during the exercises, and more in the next chapter.</para>
<para>Try to avoid logging in with or using the system administrator's account, <emphasis>root</emphasis>. Besides doing your normal work, most tasks, including checking the system, collecting information etc., can be executed using a normal user account with no special permissions at all. If needed, the preferred way of obtaining root access is by switching user IDs. Almost all commands in this book can be executed without system administrator priviledges. In most cases, when issuing a command as a user, the system will warn you or prompt you for the root password when root access is required.</para>
<para>Reading documentation should become your second nature. Especially in the beginning, it is important to read system documentation, manuals for basic commands, HOWTOs and so on. Since the amount of documentation is so enormous, it is impossible to include all related documentation. This book will try to guide you to the most appropriate documentation on every subject discussed, in order to stimulate the habit of reading the man pages.</para>
</sect2>
<sect2 id="sect_02_02_03"><title>The man pages</title>
<para>A lot of beginning users fear the man (manual) pages, because they are an overwhelming source of documentation. They are, however, very structured, as you will see from the example below on: <command>man <option>man</option></command>.</para>
<para>Reading man pages is usually done in a terminal window when in graphical mode, or just in text mode if you prefer it. Type the command like this at the prompt, followed by enter:</para>
<screen>
yourname@yourcomp ~&gt; man man
</screen>
<para>The documentation for <command>man</command> will be displayed on your screen. Browse to the next page using the space bar. You can go back to the previous page using the b-key. When you reach the end, <command>man</command> will quit and you get the prompt back, or type q if you want to leave the man page before reaching the end.</para>
<para>Each man page usually contains a couple of standard sections, as we can see from the <command>man <option>man</option></command> example:</para>
<itemizedlist>
<listitem><para>The first line contains the name of the command you are reading about, and the id of the section in which this man page is located. The man pages are ordered in chapters. Commands are likely to have multiple man pages, for example the man page from the user section, the man page from the system admin section, and the man page from the programmer section.</para></listitem>
<listitem><para>The name of the command and a short description are given, which is used for building an index of the man pages. You can look for any given search string in this index using the <command>apropos</command> command.</para></listitem>
<listitem><para>The synopsis of the command provides a technical notation of all the options and/or arguments this command can take. You can think of an option as a way of executing the command. The argument is what you execute it on. Some commands have no options or no arguments.</para></listitem>
<listitem><para>A longer description of the command is given.</para></listitem>
<listitem><para>Options with their descriptions are listed. Options can usually be combined. If not so, this section will tell you about it.</para></listitem>
<listitem><para>Environment describes the shell variables that influence the behavior of this command (not all commands have this).</para></listitem>
<listitem><para>Sometimes sections specific to this command are provided, such as the CAT PAGES section in the example.</para></listitem>
<listitem><para>A reference to other man pages is given in the SEE ALSO section. In between parentheses is the number of the man page section in which to find this command. Experienced users often switch to the SEE ALSO part using the <command>/</command> command followed by the search string SEE and [ENTER].</para></listitem>
<listitem><para>Usually there is also information about known bugs (anomalies) and where to report new bugs you may find.</para></listitem>
<listitem><para>There might also be author and copyright information.</para></listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_02_02_04"><title>More info</title>
<para>In addition to the man pages, you can read the info pages about a command, using the <command>info</command> command. These usually contain more recent information and are somewhat easier to use. The man pages for some commands refer to the info pages.</para>
<para>Get started with <command>info <option>info</option></command>. Use the arrow keys to browse trough the text and move the cursor on a line starting with an asterisk, containing the keyword about which you want info. Use the p- and n-keys to go to the previous or next subject. The space bar will move you one page further, no matter whether this starts a new subject or an info page for another command. The <command>info</command> program has more information.</para>
</sect2>
</sect1>
<sect1 id="sect_02_03"><title>Exercises</title>
<para>Most of what we learn is by making mistakes and by seeing how things can go wrong. These exercises are made to get you to read some error messages. The order in which you do these exercises, is important.</para>
<sect2 id="sect_02_03_01"><title>Connecting and disconnecting</title>
<para>
<itemizedlist>
<listitem><para>Determine whether you are working in text or in graphical mode.</para>
<para>I am working in text/graphical mode. (cross out what's not applicable)</para>
</listitem>
<listitem><para>Log in with the user name and password you made for yourself during the installation.</para>
</listitem>
<listitem><para>Log out.</para></listitem>
<listitem><para>Log in again, using a non-existent user name</para>
<para>-&gt; What happens?</para>
</listitem>
</itemizedlist>
</para>
</sect2>
<sect2 id="sect_02_03_02"><title>Passwords</title>
<para>Log in again with your user name and password.</para>
<itemizedlist>
<listitem><para>Change your password into <emphasis>P6p3.aa!</emphasis> and hit the [ENTER] key.</para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>Try again, this time enter a password that is ridiculously easy, like <emphasis>123</emphasis> or <emphasis>aaa</emphasis>.</para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>Try again, this time don't enter a password but just hit the [ENTER] key.</para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>Try the command <command>psswd</command> instead of <command>passwd</command></para>
<para>-&gt; What happens?</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_02_03_03"><title>Directories</title>
<para>These are some exercises to help you get the feel.</para>
<itemizedlist>
<listitem><para>Enter the command <command>cd <filename>blah</filename></command></para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>Enter the command <command>cd <filename>..</filename></command></para>
<para>Mind the space between "cd" and ".."! Use the <command>pwd</command> command.</para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>List the directory contents with the <command>ls</command> command.</para>
<para>-&gt; What do you see?</para>
<para>-&gt; What do you think these are?</para>
<para>-&gt; Check using the <command>pwd</command> command.</para>
</listitem>
<listitem><para>Enter the <command>cd</command> command.</para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>Repeat step 2 two times.</para>
<para>-&gt; What happens?</para>
</listitem>
<listitem><para>Display the content of this directory.</para></listitem>
<listitem><para>Try the command <command>cd <filename>root</filename></command></para>
<para>-&gt; What happens?</para>
<para>-&gt; To which directories do you have access?</para>
</listitem>
<listitem><para>Repeat step 4.</para>
<para>Do you know another possibility to get where you are now?</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_02_03_04"><title>Files</title>
<itemizedlist>
<listitem><para>Change directory to <filename>/</filename> and then to <filename>etc</filename>. Type <command>ls</command>; if the output is longer than your screen, make the window longer, or try [SHIFT]+[Page Up] and [SHIFT]+[Page Down].</para>
<para>The file <filename>inittab</filename> contains the answer to the first question in this list. Try the <command>file</command> command on it.</para>
<para>-&gt; The file type of my <filename>inittab</filename> is .....</para>
</listitem>
<listitem><para>Use the command <command>cat <filename>inittab</filename></command> and read the file.</para>
<para>-&gt; What is the default mode of your computer?</para>
</listitem>
<listitem><para>Return to your home directory using the <command>cd</command> command.</para></listitem>
<listitem><para>Enter the command <command>file .</command></para>
<para>-&gt; Does this help to find the meaning of "."? </para>
</listitem>
<listitem><para>Can you look at "." using the <command>cat</command> command?</para>
<para></para>
</listitem>
<listitem><para>Display help for the <command>cat</command> program, using the <option>--help</option> option. Use the option for numbering of output lines to count how many users are listed in the file <filename>/etc/passwd</filename>.</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_02_03_05"><title>Getting help</title>
<itemizedlist>
<listitem><para>Read <command>man <option>intro</option></command></para></listitem>
<listitem><para>Read <command>man <option>ls</option></command></para></listitem>
<listitem><para>Read <command>info <option>passwd</option></command></para></listitem>
<listitem><para>Read <command>apropos <option>pwd</option></command></para></listitem>
<listitem><para>Try <command>man</command> or <command>info</command> on <command>cd</command>.</para>
<para>-&gt; How would you find out more about <command>cd</command>? </para>
</listitem>
</itemizedlist>
</sect2>
</sect1>
</chapter>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,754 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_04">
<title>Processes</title>
<abstract>
<para>Next to files, processes are the most important things on a UNIX/Linux system. In this chapter, we will take a closer look at those processes. We will learn more about:</para>
<para>
<itemizedlist>
<listitem><para>Multi-user processing and multi-tasking</para></listitem>
<listitem><para>Process types</para></listitem>
<listitem><para>Controlling processes</para></listitem>
<listitem><para>Process attributes</para></listitem>
<listitem><para>The life cycle of a process</para></listitem>
<listitem><para>System startup and shutdown</para></listitem>
<listitem><para>SUID and GUID</para></listitem>
<listitem><para>Managing processes</para></listitem>
<listitem><para>System speed and response</para></listitem>
<listitem><para>Scheduling processes</para></listitem>
<listitem><para>The Vixie cron system</para></listitem>
<listitem><para>How to get the most out of your system</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1 id="sect_04_01"><title>Processes inside out</title>
<sect2 id="sect_04_01_01"><title>Multi-user and multi-tasking</title>
<para>Now that we are more used to our environment and we are able to communicate a little bit with our system, it is time to study the processes we can start in more detail. Not every command starts a single process. Some commands initiate a series of processes, such as <command>mozilla</command>; others, like <command>ls</command>, are executed as a single command.</para>
<para>Furthermore, Linux is based on UNIX, where it has been common policy to have multiple users running multiple commands, at the same time and on the same system. It is obvious that measures have to be taken to have the CPU manage all these processes, and that functionality has to be provided so users can switch between processes. In some cases, processes will have to continue to run even when the user who started them logs out. And users need a means to reactivate interrupted processes.</para>
<para>We will explain the structure of Linux processes in the next sections.</para>
</sect2>
<sect2 id="sect_04_01_02"><title>Process types</title>
<sect3 id="sect_04_01_02_01"><title>Interactive processes</title>
<para>Interactive processes are initialized and controlled through a terminal session. In other words, there has to be someone connected to the system to start these processes; they are not started automatically as part of the system functions. These processes can run in the foreground, occupying the terminal that started the program, and you can't start other applications as long as this process is running in the foreground. Alternatively, they can run in the background, so that the terminal in which you started the program can accept new commands while the program is running. Until now, we only used programs running in the foreground - the length of time taken to run them was too short to notice - but viewing a file with the <command>less</command> command is a good example of a command occupying the terminal session. In this case, the activated program is waiting for you to do something. The program is still connected to the terminal from where it was started, and the terminal is only useful for entering commands this program can understand. Other commands will just result in errors or unresponsiveness of the system.</para>
<para>While a process runs in the background, however, the user is not prevented from doing other things in the terminal in which he started the program, while it is running.</para>
<para>The shell offers a feature called <emphasis>job control</emphasis> which allows easy handling of multiple processes. This mechanism switches processes between the foreground and the background. Using this system, programs can also be started in the background immediately.</para>
<para>Running a process in the background is only useful for programs that don't need user input (via the shell). Putting a job in the background is typically done when execution of a job is expected to take a long time. In order to free the issuing terminal after entering the command, a trailing ampersand is added. In the example, using graphical mode, we open an extra terminal window from the existing one:</para>
<screen>
billy:~&gt; xterm &amp;
[1] 26558
billy:~&gt; jobs
[1]+ Running xterm &amp;
</screen>
<para>The full job control features are explained in detail in the <command>bash</command> Info pages, so only the frequently used job control applications are listed here:</para>
<table frame="all">
<title>Controlling processes</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row>
<entry>(part of) command</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row><entry><command>regular_command</command></entry><entry>Runs this command in the foreground.</entry></row>
<row><entry><command>command &amp;</command></entry><entry>Run this command in the background (release the terminal)</entry></row>
<row><entry><command>jobs</command></entry><entry>Show commands running in the background.</entry></row>
<row><entry><command>[CTRL] + [Z]</command></entry><entry>Interrupt a process running in the foreground (suspend).</entry></row>
<row><entry><command>[CTRL] + [C]</command></entry><entry>Stop a process running in the foreground.</entry></row>
<row><entry><command>%n</command></entry><entry>Every process running in the background, gets a number assigned to it. By using the % expression a job can be referred to using its number (e.g. <command>fg %2</command>.</entry></row>
<row><entry><command>bg</command></entry><entry>Reactivate a suspended program in the background.</entry></row>
<row><entry><command>fg</command></entry><entry>Puts the job back in the foreground.</entry></row>
<row><entry><command>kill</command></entry><entry>End a process (also see Shell Builtin Commands in the Info pages of <command>bash</command>)</entry></row><row><entry><command></command></entry><entry></entry></row>
</tbody>
</tgroup>
</table>
<para>More practical examples can be found in the exercises.</para>
<para>Most UNIX systems are likely to be able to run <command>screen</command>, which is useful when you actually want another shell to execute commands. Upon calling <command>screen</command>, a new session is created with an accompanying shell and/or commands as specified, which you can then put out of the way. In this new session you may do whatever it is you want to do. All programs and operations will run independent of the issuing shell. You can then detach this session, while the programs you started in it continue to run, even when you log out of the originating shell, and pick your <emphasis>screen</emphasis> up again any time you like.</para>
<para>This program originates from a time when virtual consoles were not invented yet, and everything needed to be done using one text terminal. To addicts, it still has meaning in Linux, even though we've had virtual consoles for almost ten years.</para>
</sect3>
<sect3 id="sect_04_01_02_02"><title>Automatic processes</title>
<para>Automatic or batch processes are not connected to a terminal. Rather, these are tasks that can be queued into a spooler area, where they wait to be executed on a FIFO bases. Such tasks can be executed using one of two criteria:</para>
<itemizedlist>
<listitem><para>At a certain date and time: done using the <command>at</command> command, which we will discuss in the second part of this chapter.</para></listitem>
<listitem><para>At times when the total system load is low enough to accept extra jobs: done using the <command>batch</command> command. By default, tasks are put in a queue where they wait to be executed until the system load is lower than 0.8. In large environments, the system administrator may prefer batch processing when large amounts of data have to be processed or when tasks demanding a lot of system resources have to be executed on an already loaded system. Batch processing is also used for optimizing system performance.</para></listitem>
</itemizedlist>
</sect3>
<sect3 id="sect_04_01_02_03"><title>Daemons</title>
<para>Daemons are server processes that run continuously. Most of the time, they are initialized at system startup and then wait in the background until their service is required. A typical example is the networking daemon, <emphasis>xinetd</emphasis>, which is started in almost every boot procedure. After the system is booted, the network daemon just sits and waits until a client program, such as an FTP client, needs to connect.</para>
</sect3>
</sect2>
<sect2 id="sect_04_01_03"><title>Process attributes</title>
<para>A process has a series of characteristics:</para>
<itemizedlist>
<listitem><para>The process ID or PID: a unique identification number used to refer to the process.</para></listitem>
<listitem><para>The parent process ID or PPID: the number of the process that started this process.</para></listitem>
<listitem><para>Nice number: the degree of friendliness of this process toward other processes (not to be confused with process priority, which is calculated based on this nice number and recent CPU usage of the process).</para></listitem>
<listitem><para>Terminal or TTY: terminal to which the process is connected.</para></listitem>
<listitem><para>User name of the real and effective user (RUID and EUID): the owner of the process. The real owner is the user issuing the command, the effective user is the one determining access to system resources. RUID and EUID are usually the same, and the process has the same access rights the issuing user would have. An example to clarify this: the browser <command>mozilla</command> in <filename>/usr/bin</filename> is owned by user <emphasis>root</emphasis>:</para>
<screen>
theo:~&gt;ls -l /usr/bin/mozilla
-rwxr-xr-x 1 root root 4996 Nov 20 18:28 /usr/bin/mozilla*
theo:~&gt;mozilla &amp;
[1] 26595
theo:~&gt;ps -af
UID PID PPID C STIME TTY TIME CMD
theo 26601 26599 0 15:04 pts/5 00:00:00 /usr/lib/mozilla/mozilla-bin
theo 26613 26569 0 15:04 pts/5 00:00:00 ps -af
</screen>
<para>When user <emphasis>theo</emphasis> starts this program, the process itself and all processes started by the initial process, will be owned by user <emphasis>theo</emphasis> and not by the system administrator. When <command>mozilla</command> needs access to certain files, that access will be determined by <emphasis>theo</emphasis>'s permissions and not by <emphasis>root</emphasis>'s.</para>
</listitem>
<listitem><para>Real and effective group owner (RGID and EGID): The real group owner of a process is the primary group of the user who started the process. The effective group owner is usually the same, except when SGID access mode has been applied to a file.</para></listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_04_01_04"><title>Displaying process information</title>
<para>The <command>ps</command> command is one of the tools for visualizing processes. This command has several options which can be combined to display different process attributes. More info can be found the usual way: <command>ps <option>--help</option></command> or <command>man ps</command>.</para>
<para>Note that <command>ps</command> only gives a momentary state of the active processes, it is a one-time recording. The <command>top</command> program displays a more precise view by updating the results given by <command>ps</command> (with a bunch of options) once every five seconds, generating a new list of the processes causing the heaviest load periodically, meanwhile integrating more information about the swap space in use and the state of the CPU, from the <filename>proc</filename> file system:</para>
<screen>
12:40pm up 9 days, 6:00, 4 users, load average: 0.21, 0.11, 0.03
89 processes: 86 sleeping, 3 running, 0 zombie, 0 stopped
CPU states: 2.5% user, 1.7% system, 0.0% nice, 95.6% idle
Mem: 255120K av, 239412K used, 15708K free, 756K shrd, 22620K buff
Swap: 1050176K av, 76428K used, 973748K free 82756K cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
5005 root 14 0 91572 15M 11580 R 1.9 6.0 7:53 X
19599 jeff 14 0 1024 1024 796 R 1.1 0.4 0:01 top
19100 jeff 9 0 5288 4948 3888 R 0.5 1.9 0:24 gnome-terminal
19328 jeff 9 0 37884 36M 14724 S 0.5 14.8 1:30 mozilla-bin
1 root 8 0 516 472 464 S 0.0 0.1 0:06 init
2 root 9 0 0 0 0 SW 0.0 0.0 0:02 keventd
3 root 9 0 0 0 0 SW 0.0 0.0 0:00 kapm-idled
4 root 19 19 0 0 0 SWN 0.0 0.0 0:00 ksoftirqd_CPU0
5 root 9 0 0 0 0 SW 0.0 0.0 0:33 kswapd
6 root 9 0 0 0 0 SW 0.0 0.0 0:00 kreclaimd
7 root 9 0 0 0 0 SW 0.0 0.0 0:00 bdflush
8 root 9 0 0 0 0 SW 0.0 0.0 0:05 kupdated
9 root -1 -20 0 0 0 SW&lt; 0.0 0.0 0:00 mdrecoveryd
13 root 9 0 0 0 0 SW 0.0 0.0 0:01 kjournald
89 root 9 0 0 0 0 SW 0.0 0.0 0:00 khubd
219 root 9 0 0 0 0 SW 0.0 0.0 0:00 kjournald
220 root 9 0 0 0 0 SW 0.0 0.0 0:00 kjournald
</screen>
<para>The first line of <command>top</command> contains the same information displayed by the <command>uptime</command> command:</para>
<screen>
jeff:~&gt;uptime
3:30pm up 12 days, 23:29, 6 users, load average: 0.01, 0.02, 0.00
</screen>
<para>The data for these programs is stored among others in <filename>/var/run/utmp</filename> (information about currently connected users) and in the virtual file system <filename>/proc</filename>, for example <filename>/proc/loadavg</filename> (average load information). There are all sorts of graphical applications to view this data, such as the <emphasis>Gnome System Monitor</emphasis> and <emphasis>lavaps</emphasis>. Open Source initiatives like Big Brother centralize this information along with other server data and logs from multiple servers on one web server, allowing monitoring of the entire IT infrastructure from one workstation.</para>
<para>The relations between processes can be visualized using the <command>pstree</command> command:</para>
<screen>
sophie:~&gt;pstree
init-+-amd
|-apmd
|-2*[artsd]
|-atd
|-crond
|-deskguide_apple
|-eth0
|-gdm---gdm-+-X
| `-gnome-session-+-Gnome
| |-ssh-agent
| `-true
|-geyes_applet
|-gkb_applet
|-gnome-name-serv
|-gnome-smproxy
|-gnome-terminal-+-bash---vim
| |-bash
| |-bash---pstree
| |-bash---ssh
| |-bash---mozilla-bin---mozilla-bin---3*[mozilla-bin]
| `-gnome-pty-helpe
|-gpm
|-gweather
|-kapm-idled
|-3*[kdeinit]
|-keventd
|-khubd
|-5*[kjournald]
|-klogd
|-lockd---rpciod
|-lpd
|-mdrecoveryd
|-6*[mingetty]
|-8*[nfsd]
|-nscd---nscd---5*[nscd]
|-ntpd
|-3*[oafd]
|-panel
|-portmap
|-rhnsd
|-rpc.mountd
|-rpc.rquotad
|-rpc.statd
|-sawfish
|-screenshooter_a
|-sendmail
|-sshd---sshd---bash---su---bash
|-syslogd
|-tasklist_applet
|-vmnet-bridge
|-xfs
`-xinetd-ipv6
</screen>
<para>The <option>-u</option> and <option>-a</option> options give additional information, and for more, refer to the Info pages.</para>
<para>In the next section, we will see how one process can create another.</para>
</sect2>
<sect2 id="sect_04_01_05"><title>Life and death of a process</title>
<sect3 id="sect_04_01_05_01"><title>Process creation</title>
<para>A new process is created because an existing process makes an exact copy of itself. This child process has the same environment as its parent, only the process ID number is different. This procedure is called <emphasis>forking</emphasis>.</para>
<para>After the forking process, the address space of the child process is overwritten with the new process data. This is done through an <emphasis>exec</emphasis> call to the system.</para>
<para>The <emphasis>fork-and-exec</emphasis> mechanism thus switches an old command with a new, while the environment in which the new program is executed remains the same, including configuration of input and output devices, environment variables and priority. This mechanism is used to create all UNIX processes, so it also applies to the Linux operating system. Even the first process, <command>init</command>, with process ID 1, is forked during the boot procedure in the so-called <emphasis>bootstrapping</emphasis> procedure.</para>
<para>This scheme illustrates the fork-and-exec mechanism. The process ID changes after the fork procedure:</para>
<figure><title>Fork-en-exec mechanism</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/fork-and-exec.eps" format="EPS"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/fork-and-exec.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>There are a couple of cases in which <command>init</command> becomes the parent of a process, while the process was not started by <command>init</command>, as we already saw in the <command>pstree</command> example. Many programs, for instance, <emphasis>daemonize</emphasis> their child processes, so they can keep on running when the parent stops or is being stopped. A window manager is a typical example; it starts an <command>xterm</command> process that generates a shell that accepts commands. The window manager then denies any further responsibility and passes the child process to <command>init</command>. Using this mechanism, it is possible to change window managers without interrupting running applications.</para>
<para>Every now and then things go wrong, even in good families. In an exceptional case, a process might lose its parent for one reason or another. Such an abandoned process is called a <emphasis>zombie</emphasis> process. Zombies get <command>init</command> as a substitute parent.</para>
</sect3>
<sect3 id="sect_04_01_05_02"><title>Ending processes</title>
<para>When a process ends, by using any quit functions (menus, the [CTRL]+[C] key combination or the <command>kill</command>command) to stop a running program, the program returns its <emphasis>exit status</emphasis> to the parent. This exit status is a number returned by the program providing the results of the program's execution. The system of returning information upon executing a job has its origin in the C programming language in which UNIX has been written.</para>
<para>The return codes can then be interpreted by the parent, or in scripts. The values of the return codes are program-specific. This information can usually be found in the man pages of the specified program, for example the <command>grep</command> command returns <computeroutput>-1</computeroutput> if no matches are found, upon which a message on the lines of "No files found" can be printed. Another example is the Bash Builtin command <command>true</command>, which does nothing except return an exit status of 0, meaning success.</para>
</sect3>
</sect2>
<sect2 id="sect_04_01_06"><title>SUID and GUID</title>
<para>As promised in the previous chapter, we will now discuss the special modes SUID and GUID in more detail. These modes exist to provide normal users the ability to execute tasks they would normally not be able to do because of the tight file permission scheme used on UNIX based systems. In the ideal situation special modes are used as sparsely as possible, since they include security risks. Linux developers have generally tried to avoid them as much as possible. The Linux <command>ps</command> version, for example, uses the information stored in the <filename>/proc</filename> file system, which is accessible to everyone, thus avoiding exposition of sensitive system data and resources to the general public. Before that, and still on older UNIX systems, the <command>ps</command> program needed access to files such as <filename>/dev/mem</filename> and <filename>/dev/kmem</filename>, which had disadvantages because of the permissions and ownerships on these files:</para>
<screen>
rita:~&gt;ls -l /dev/*mem
crw-r----- 1 root kmem 1, 2 Aug 30 22:30 /dev/kmem
crw-r----- 1 root kmem 1, 1 Aug 30 22:30 /dev/mem
</screen>
<para>With older versions of <command>ps</command>, it was not possible to start the program as a common user, unless special modes were applied to it.</para>
<para>While we generally try to avoid applying any special modes, it is sometimes necessary to use an SUID. An example is the mechanism for changing passwords. Of course users will want to do this themselves instead of having their password set by the system administrator. As we know, user names and passwords are listed in the <filename>/etc/passwd</filename> file, which has these access permissions and owners:</para>
<screen>
bea:~&gt;ls -l /etc/passwd
-rw-r--r-- 1 root root 1267 Jan 16 14:43 /etc/passwd
</screen>
<para>Still, users need to be able to change their own information in this file. This is achieved by giving the <command>passwd</command> program special permissions:</para>
<screen>
mia:~&gt;which passwd
passwd is /usr/bin/passwd
mia:~&gt;ls -l /usr/bin/passwd
-r-s--x--x 1 root root 13476 Aug 7 06:03 /usr/bin/passwd*
</screen>
<para>When called, the <command>passwd</command> command will run using the access permissions of <emphasis>root</emphasis>, thus enabling a common user to edit the password file which is owned by the system admin.</para>
<para>SGID modes on a file don't occur nearly as frequently as SUID, because SGID often involves the creation of extra groups. In some cases, however, we have to go through this trouble in order to build an elegant solution (don't worry about this too much - the necessary groups are usually created upon installation). This is the case for the <command>write</command> and <command>wall</command> programs, which are used to send messages to other users' terminals (ttys). The <command>write</command> command writes a message to a single user, while <command>wall</command> writes to all connected users.</para>
<para>Sending text to another user's terminal or graphical display is normally not allowed. In order to bypass this problem, a group has been created, which owns all terminal devices. When the <command>write</command> and <command>wall</command> commands are granted SGID permissions, the commands will run using the access rights as applicable to this group, <emphasis>tty</emphasis> in the example. Since this group has write access to the destination terminal, also a user having no permissions to use that terminal in any way can send messages to it.</para>
<para>In the example below, user <emphasis>joe</emphasis> first finds out on which terminal his correspondent is connected, using the <command>who</command> command. Then he sends her a message using the <command>write</command> command. Also illustrated are the access rights on the <command>write</command> program and on the terminals occupied by the receiving user: it is clear that others than the user owner have no permissions on the device, exept for the group owner, which can write to it.</para>
<screen>
joe:~&gt;which write
write is /usr/bin/write
joe:~&gt;ls -l /usr/bin/write
-rwxr-sr-x 1 root tty 8744 Dec 5 00:55 /usr/bin/write*
joe:~&gt;who
jenny tty1 Jan 23 11:41
jenny pts/1 Jan 23 12:21 (:0)
jenny pts/2 Jan 23 12:22 (:0)
jenny pts/3 Jan 23 12:22 (:0)
joe pts/0 Jan 20 10:13 (lo.callhost.org)
joe:~&gt;ls -l /dev/tty1
crw--w---- 1 jenny tty 4, 1 Jan 23 11:41 /dev/tty1
joe:~&gt;write jenny tty1
hey Jenny, shall we have lunch together?
^C
</screen>
<para>User <emphasis>jenny</emphasis> gets this on her screen:</para>
<screen>
Message from joe@lo.callhost.org on ptys/1 at 12:36 ...
hey Jenny, shall we have lunch together?
EOF
</screen>
<para>After receiving a message, the terminal can be cleared using the [CTRL]-[L] key combination. In order to receive no messages at all (except from the system administrator), use the <command>mesg</command> command. To see which connected users accept messages from others use <command>who <option>-w</option></command>. All features are fully explained in the Info pages of each command.</para>
<note><title>Group names may vary</title>
<para>The group scheme is specific to the distribution. Other distributions may use other names or other solutions.</para></note>
</sect2>
</sect1>
<sect1 id="sect_04_02"><title>Boot process, Init and shutdown</title>
<sect2 id="sect_04_02_01"><title>Introduction</title>
<para> One of the most powerful aspects of Linux concerns its open method of starting and stopping the operating system, where it loads specified programs using their particular configurations, permits you to change those configurations to control the boot process, and shuts down in a graceful and organized way.</para>
<para> Beyond the question of controlling the boot or shutdown process, the open nature of Linux makes it much easier to determine the exact source of most problems associated with starting up or shutting down your system. A basic understanding of this process is quite beneficial to everybody who uses a Linux system.</para>
<para>A lot of Linux systems use <command>lilo</command>, the LInux LOader for booting operating systems. We will only discuss GRUB, however, which is easier to use and more flexible. Should you need information about <command>lilo</command>, refer to the man pages and HOWTOs. Both systems support dual boot installations, we refer to the HOWTOs on this subject for practical examples and background information.</para>
</sect2>
<sect2 id="sect_04_02_02"><title>The boot process</title>
<para>When an x86 computer is booted, the processor looks at the end of the system memory for the BIOS (Basic Input/Output System) and runs it. The BIOS program is written into permanent read-only memory and is always available for use. The BIOS provides the lowest level interface to peripheral devices and controls the first step of the boot process.</para>
<para> The BIOS tests the system, looks for and checks peripherals, and then looks for a drive to use to boot the system. Usually it checks the floppy drive (or CD-ROM drive on many newer systems) for bootable media, if present, and then it looks to the hard drive. The order of the drives used for booting is usually controlled by a particular BIOS setting on the system. Once Linux is installed on the hard drive of a system, the BIOS looks for a Master Boot Record (MBR) starting at the first sector on the first hard drive, loads its contents into memory, then passes control to it.</para>
<para> This MBR contains instructions on how to load the GRUB (or LILO) boot-loader, using a pre-selected operating system. The MBR then loads the boot-loader, which takes over the process (if the boot-loader is installed in the MBR). In the default Red Hat Linux configuration, GRUB uses the settings in the MBR to display boot options in a menu. Once GRUB has received the correct instructions for the operating system to start, either from its command line or configuration file, it finds the necessary boot file and hands off control of the machine to that operating system.</para>
</sect2>
<sect2 id="sect_04_02_03"><title>GRUB features</title>
<para>This boot method is called <emphasis>direct loading</emphasis> because instructions are used to directly load the operating system, with no intermediary code between the boot-loaders and the operating system's main files (such as the kernel). The boot process used by other operating systems may differ slightly from the above, however. For example, Microsoft's DOS and Windows operating systems completely overwrite anything on the MBR when they are installed without incorporating any of the current MBR's configuration. This destroys any other information stored in the MBR by other operating systems, such as Linux. The Microsoft operating systems, as well as various other proprietary operating systems, are loaded using a chain loading boot method. With this method, the MBR points to the first sector of the partition holding the operating system, where it finds the special files necessary to actually boot that operating system.</para>
<para>
GRUB supports both boot methods, allowing you to use it with almost any operating system, most popular file systems, and almost any hard disk your BIOS can recognize.</para>
<para>GRUB contains a number of other features; the most important include:</para>
<itemizedlist>
<listitem><para>GRUB provides a true command-based, pre-OS environment on x86 machines to allow maximum flexibility in loading operating systems with certain options or gathering information about the system.</para></listitem>
<listitem><para>GRUB supports Logical Block Addressing (LBA) mode, needed to access many IDE and all SCSI hard disks. Before LBA, hard drives could encounter a 1024-cylinder limit, where the BIOS could not find a file after that point.</para></listitem>
<listitem><para>GRUB's configuration file is read from the disk every time the system boots, preventing you from having to write over the MBR every time you change the boot options.</para></listitem>
</itemizedlist>
<para>A full description of GRUB may be found by issuing the <command>info grub</command> command or at <ulink url="http://www.gnu.org/software/grub/">the GRUB site</ulink>. The Linux Documentation Project has a <ulink url="http://www.tldp.org/HOWTO/mini/Multiboot-with-GRUB.html">Multiboot with GRUB Mini-HOWTO</ulink>.</para>
</sect2>
<sect2 id="sect_04_02_04"><title>Init</title>
<para>The kernel, once it is loaded, finds <command>init</command> in <filename>sbin</filename> and executes it.</para>
<para>When <command>init</command> starts, it becomes the parent or grandparent of all of the processes that start up automatically on your Linux system. First, it runs the <filename>/etc/rc.d/rc.sysinit</filename> script, which sets your path, starts swapping, checks the file systems, and so on. Basically, <filename>rc.sysinit</filename> takes care of everything that your system needs to have done at system initialization: setting the clock, initializing serial ports and so forth.</para>
<para> Then <command>init</command> runs the <filename>/etc/inittab</filename> script, which describes how the system should be set up in each run level and sets the default run level. This file states, among other things, that <command>/sbin/update</command> should be run whenever a run level starts. The <command>update</command> program is used to flush dirty buffers back to disk.</para>
<para> Whenever the run level changes, <command>init</command> uses the scripts in <filename>/etc/rc.d/init.d</filename> to start and stop various services, such as your web server, DNS server, and so on. First, <command>init</command> sets the source function library for the system (commonly <filename>/etc/rc.d/init.d/functions</filename>), which spells out how to start or kill a program and how to find out the PID of a program. Then <command>init</command> determines the current and the previous run level.</para>
<para>Next, <command>init</command> starts all of the background processes necessary for the system to run by looking in the appropriate <filename>rc</filename> directory for that run level. <command>init</command> runs each of the kill scripts (their file names start with a K) with a stop parameter. It then runs all of the start scripts (their file names start with an S) in the appropriate run level directory so that all services and applications are started correctly. In fact, you can execute these same scripts manually after the system is finished booting with a command like <command>/etc/rc.d/init.d/httpd stop</command> or <command>service httpd stop</command> logged in as <emphasis>root</emphasis>, in this case stopping the web server.</para>
<para> None of the scripts that actually start and stop the services are located in <filename>/etc/rc.d/rc&lt;x&gt;.d</filename>. Rather, all of the files in <filename>/etc/rc.d/rc&lt;x&gt;.d</filename> are symbolic links that point to the actual scripts located in <filename>/etc/rc.d/init.d</filename>. A symbolic link is nothing more than a file that points to another file, and is used in this case because it can be created and deleted without affecting the actual scripts that kill or start the services. The symbolic links to the various scripts are numbered in a particular order so that they start in that order. You can change the order in which the services start up or are killed by changing the name of the symbolic link that refers to the script that actually controls the service. You can use the same number multiple times if you want a particular service started or stopped right before or after another service.</para>
<para>Below a sample of <filename>/etc/rc5.d</filename> content:</para>
<screen>
[jean@blub /etc/rc5.d] ls
K15httpd@ K45named@ S08ipchains@ S25netfs@ S85gpm@
K16rarpd@ K46radvd@ S08iptables@ S26apmd@ S90crond@
K20nfs@ K61ldap@ S09isdn@ S28autofs@ S90xfs@
K20rstatd@ K65identd@ S10network@ S30nscd@ S95anacron@
K20rusersd@ K74ntpd@ S12syslog@ S55sshd@ S95atd@
K20rwalld@ K74ypserv@ S13portmap@ S56rawdevices@ S97rhnsd@
K20rwhod@ K74ypxfrd@ S14nfslock@ S56xinetd@ S99local@
K25squid@ K89bcm5820@ S17keytable@ S60lpd@
K34yppasswdd@ S05kudzu@ S20random@ S80sendmail@
</screen>
<para>After <command>init</command> has progressed through the run levels to get to the default run level, the <filename>/etc/inittab</filename> script forks a <command>getty</command> process for each virtual console (login prompt) for each run level (run levels 2-5 get all six consoles; run level 1, which is single user mode, only gets one console; run levels 0 and 6 get no virtual consoles). <command>getty</command> opens tty lines, sets their modes, prints the login prompt, gets the user's name, and then initiates a login process for that user. This allows users to authenticate themselves to the system and use it.</para>
<para>
<filename>/etc/inittab</filename> also tells <command>init</command> how it should handle a user pressing [CTRL]-[ALT]-[DEL] at the console. As the system should be properly shut down and restarted rather than immediately power-cycled, <command>init</command> is told to execute the command <command>/sbin/shutdown <option>-t3 -r now</option></command> when a user hits those keys. In addition, <filename>/etc/inittab</filename> states what <command>init</command> should do in case of power failures, if your system has a UPS unit attached to it.</para>
<para>
In run level 5, <filename>/etc/inittab</filename> runs a script called <filename>/etc/X11/prefdm</filename>. The <filename>prefdm</filename> script runs the preferred X display manager (<command>gdm</command> if you run GNOME or <command>kdm</command> if you run KDE) based on the contents of the <filename>/etc/sysconfig/desktop</filename> directory. The <filename>/etc/sysconfig</filename> directory contains entries for a range of functions and services, these are all read at boot time. This last part, however, might be somewhat different depending on your Linux distribution.</para>
<para>Besides the graphical user environment, a lot of other services may be started as well. But if all goes well, you should be looking at a login prompt or login screen when the boot process has finished.</para>
<note><title>Other procedures</title>
<para>We explained how SysV <command>init</command> works on x86 based machines. Startup procedures may vary on other architectures. Other UNIX systems may use BSD <command>init</command>.</para></note>
</sect2>
<sect2 id="sect_04_02_05"><title>Init run levels</title>
<para> The idea behind operating different services at different run levels essentially revolves around the fact that different systems can be used in different ways. Some services cannot be used until the system is in a particular state, or <emphasis>mode</emphasis>, such as being ready for more than one user or having networking available.</para>
<para>
There are times in which you may want to operate the system in a lower mode. Examples are fixing disk corruption problems in run level 1 so no other users can possibly be on the system, or leaving a server in run level 3 without an X session running. In these cases, running services that depend upon a higher system mode to function does not make sense because they will not work correctly anyway. By already having each service assigned to start when its particular run level is reached, you ensure an orderly start up process, and you can quickly change the mode of the machine without worrying about which services to manually start or stop.</para>
<para>Available run levels are generally described in <filename>/etc/inittab</filename>, which is partially shown below:</para>
<screen>
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, &lt;miquels@drinkel.nl.mugnet.org&gt;
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
</screen>
<para> Feel free to configure runlevels 2 and 4 as you see fit. Many users configure those runlevels in a way that makes the most sense for them while leaving the standard runlevels 3 and 5 alone. This allows them to quickly move in and out of their custom configuration without disturbing the normal set of features at the standard runlevels.</para>
<para> If your machine gets into a state where it will not boot due to a bad <filename>/etc/inittab</filename> or will not let you log in because you have a corrupted <filename>/etc/passwd</filename> file (or if you have simply forgotten your password), boot into single-user mode.</para>
<sect3 id="sect_04_02_05_01"><title>Tools</title>
<para>The <command>chkconfig</command> utility in <filename>/sbin</filename> provides a simple command-line tool for maintaining the <filename>/etc/rc.d/init.d</filename> directory hierarchy. It relieves system administrators from having to directly manipulate the numerous symbolic links in the directories under <filename>/etc/rc.d</filename>.</para>
<para>
In addition, there is <command>ntsysv</command>, which provides a text-based interface; you may find this easier to use than <command>chkconfig</command>'s command-line interface.</para>
<para>
If you prefer a graphical interface, use the <command>serviceconf</command> program.</para>
<para>
All of these utilities must be run as root.</para>
</sect3>
</sect2>
<sect2 id="sect_04_02_06"><title>Shutdown</title>
<para>UNIX was not made to be shut down, but if you really must, use the <command>shutdown</command> command. After completing the shutdown procedure, the <option>-h</option> option will halt the system, while <option>-r</option> will reboot it.</para>
<para>The <command>reboot</command> and <command>halt</command> commands are now able to invoke <command>shutdown</command> if run when the system is in runlevels 1-5, and thus ensure proper shutdown of the system,but it is a bad habit to get into, as not all UNIX/Linux versions have this feature.</para>
<para>If your computer does not power itself down, you should not turn off the computer until you see a message indicating that the system is halted or finished shutting down, in order to give the system the time to unmount all partitions. Being impatient may cause data loss.</para>
</sect2>
</sect1>
<sect1 id="sect_04_03"><title>Managing processes</title>
<sect2 id="sect_04_03_01"><title>Work for the system admin</title>
<para>While managing system resources, including processes, is a task for the local system administrator, it doesn't hurt a common user to know something about it, especially where his or her own processes and their optimal execution are concerned.</para>
<para>We will explain a little bit on a theoretical level about system performance, though not as far as hardware optimization and such. Instead, we will study the daily problems a common user is confronted with, and actions such a user can take to optimally use the resources available. As we learn in the next section, this is mainly a matter of thinking before acting.</para>
<figure><title>Can't you go faster?</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/trappen.eps" format="EPS"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/trappen.gif" format="GIF"></imagedata>
</imageobject>
</mediaobject>
</figure>
</sect2>
<sect2 id="sect_04_03_02"><title>How long does it take?</title>
<para>Bash offers a built-in <command>time</command> command that displays how long a command takes to execute. The timing is highly accurate and can be used on any command. In the example below, it takes about a minute and a half to make this book:</para>
<screen>
tille:~/xml/src&gt;time make
Output written on abook.pdf (222 pages, 1619861 bytes).
Transcript written on abook.log.
real 1m41.056s
user 1m31.190s
sys 0m1.880s
</screen>
<para>The GNU <command>time</command> command in <filename>/usr/bin</filename> (as opposed to the shell built-in version) displays more information that can be formatted in different ways. It also shows the exit status of the command, and the total elapsed time. The same command as the above using the independent <command>time</command> gives this output:</para>
<screen>
tille:~/xml/src&gt;/usr/bin/time make
Output written on abook.pdf (222 pages, 1595027 bytes).
Transcript written on abook.log.
Command exited with non-zero status 2
88.87user 1.74system 1:36.21elapsed 94%CPU
(0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (2192major+30002minor)pagefaults 0swaps
</screen>
<para>Refer again to the Info pages for all the information.</para>
</sect2>
<sect2 id="sect_04_03_03"><title>Performance</title>
<para>To a user, performance means quick execution of commands. To a system manager, on the other hand, it means much more: the system admin has to optimize system performance for the whole system, including users, all programs and daemons. System performance can depend on a thousand tiny things which are not accounted for with the <command>time</command> command:</para>
<itemizedlist>
<listitem><para>the program executing is badly written or doesn't use the computer appropriately</para></listitem>
<listitem><para>access to disks, controllers, display, all kinds of interfaces, etc.</para></listitem>
<listitem><para>reachability of remote systems (network performance)</para></listitem>
<listitem><para>amount of users on the system, amount of users actually working simultaneously</para></listitem>
<listitem><para>time of day</para></listitem>
<listitem><para>...</para></listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_04_03_04"><title>Load</title>
<para>In short: the load depends on what is normal for your system. My old P133 running a firewall, SSH server, file server, a route daemon, a sendmail server, a proxy server and some other services doesn't complain with 7 users connected; the load is still 0 on average. Some (multi-CPU) systems I've seen were quite happy with a load of 67. There is only one way to find out - check the load regularly if you want to know what's normal. If you don't, you will only be able to measure system load from the response time of the command line, which is a very rough measurement since this speed is influenced by a hundred other factors.</para>
<para>Keep in mind that different systems will behave different with the same load average. For example, a system with a graphics card supporting hardware acceleration will have no problem rendering 3D images, while the same system with a cheap VGA card will slow down tremendously while rendering. My old P133 will become quite uncomfortable when I start the X server, but on a modern system you hardly notice the difference in the system load.</para>
</sect2>
<sect2 id="sect_04_03_05"><title>Can I do anything as a user?</title>
<para>A big environment can slow you down. If you have lots of environment variables set (instead of shell variables), long search paths that are not optimized (errors in setting the path environment variable) and such, the system will need more time to search and read data.</para>
<para>In X, window managers and desktop environments can be real CPU-eaters. A really fancy desktop comes with a price, even when you can download it for free, since most desktops provide add-ons ad infinitum. Modesty is a virtue if you don't buy a new computer every year.</para>
<sect3 id="sect_04_03_05_01"><title>Priority</title>
<para>The priority or importance of a job is defined by it's <emphasis>nice</emphasis> number. A program with a high nice number is friendly to other programs, other users and the system; it is not an important job. The lower the nice number, the more important a job is and the more resources it will take without sharing them.</para>
<para>Making a job nicer by increasing its nice number is only useful for processes that use a lot of CPU time (compilers, math applications and such). Processes that always use a lot of I/O time are automatically rewarded by the system and given a higher priority (a lower nice number), for example keyboard input always gets highest priority on a system.</para>
<para>Defining the priority of a program is done with the <command>nice</command> command.</para>
<para>Most systems also provide the BSD <command>renice</command> command, which allows you to change the <emphasis>niceness</emphasis> of a running command. Again, read the man page for your system-specific information.</para>
<note><title>Interactive programs</title>
<para>It is NOT a good idea to <command>nice</command> or <command>renice</command> an interactive program or a job running in the foreground.</para></note>
<para>Use of these commands is usually a task for the system administrator.</para>
</sect3>
<sect3 id="sect_04_03_05_02"><title>CPU resources</title>
<para>On every Linux system, many programs want to use the CPU(s) at the same time, even if you are the only user on the system. Every program needs a certain amount of cycles on the CPU to run. There may be times when there are not enough cycles because the CPU is too busy. The <command>uptime</command> command is wildly inaccurate (it only displays averages, you have to know what is normal), but far from being useless. There are some actions you can undertake if you think your CPU is to blame for the unresponsiveness of your system:</para>
<itemizedlist>
<listitem><para>Run heavy programs when the load is low. This may be the case on your system during the night. See next section for scheduling.</para></listitem>
<listitem><para>Prevent the system from doing unnecessary work: stop daemons and programs that you don't use, use <command>locate</command> instead of a heavy <command>find</command>, ...</para></listitem>
<listitem><para>Run big jobs with a low priority</para></listitem>
</itemizedlist>
<para>If none of these solutions are an option in your particular situation, you may want to upgrade your CPU. On a UNIX machine this is a job for the system admin.</para>
</sect3>
<sect3 id="sect_04_03_05_03"><title>Memory resources</title>
<para>When the currently running processes expect more memory than the system has physically available, a Linux system will not crash; it will start paging, or <emphasis>swapping</emphasis>, meaning the process uses the memory on disk or in swap space, moving contents of the physical memory (pieces of running programs or entire programs in the case of swapping) to disk, thus reclaiming the physical memory to handle more processes. This slows the system down enormously since access to disk is much slower than access to memory. The <command>top</command> command can be used to display memory and swap use. Systems using glibc, such as RedHat, offer the <command>memusage</command> and <command>memusagestat</command> commands to visualize memory usage.</para>
<para>If you find that a lot of memory and swap space are being used, you can try:</para>
<itemizedlist>
<listitem><para>Killing, stopping or renicing those programs that use a big chunk of memory</para></listitem>
<listitem><para>Adding more memory (and in some cases more swap space) to the system.</para></listitem>
<listitem><para>Tuning system performance, which is beyond the scope of this document. See the <xref linkend="app1" />reading list in Appendix 1 for more.</para></listitem>
</itemizedlist>
</sect3>
<sect3 id="sect_04_03_05_04"><title>I/O resources</title>
<para>While I/O limitations are a major cause of stress for system admins, the Linux system offers rather poor utilities to measure I/O performance. The <command>ps</command>, <command>vmstat</command> and <command>top</command> tools give some indication about how many programs are waiting for I/O; <command>netstat</command> displays network interface statistics, but there are virtually no tools available to measure the I/O response to system load, and the <command>iostat</command> command gives a brief overview of general I/O usage. Various graphical front-ends exist to put the output of these commands in a humanly understandable form.</para>
<para>Each device has its own problems, but the bandwidth available to network interfaces and the bandwidth available to disks are the two primary causes of bottlenecks in I/O performance.</para>
<para>Network I/O problems:</para>
<itemizedlist>
<listitem><para>Network overload:</para>
<para>The amount of data transported over the network is larger than the network's capacity, resulting in slow execution of every network related task for all users. They can be solved by cleaning up the network (which mainly involves disabling protocols and services that you don't need) or by reconfiguring the network (e.g. use of subnets, replacing hubs with switches, upgrading interfaces and equipment).</para>
</listitem>
<listitem><para>Network integrity problems:</para>
<para>Occurs when data is transferred incorrectly. Solving this kind of problem can only be done by isolating the faulty element and replacing it.</para>
</listitem>
</itemizedlist>
<para>Disk I/O problems:</para>
<itemizedlist>
<listitem><para>per-process transfer rate:</para>
<para>Read or write speed for a single process.</para></listitem>
<listitem><para>aggregate transfer rate:</para>
<para>Maximum total bandwidth that the system can provide to all programs that run.</para></listitem>
</itemizedlist>
<para>This kind of problem is more difficult to detect, and usually takes extra hardware in order to re-devide data streams over buses, controlers and disks, if overloaded hardware is cause of the problem. One solution to solve this is a RAID array configuration optimized for input and output actions. This way, you get to keep the same hardware. An upgrade to faster buses, controlers and disks is usually the other option.</para>
<para>If overload is not the cause, maybe your hardware is gradually failing, or not well connected to the system. Check contacts, connectors and plugs to start with.</para>
</sect3>
<sect3 id="sect_04_03_05_05"><title>Users</title>
<para>Users can be divided in several classes, depending on their behavior with resource usage:</para>
<itemizedlist>
<listitem><para>Users who run a (large) number of small jobs: you, the beginning Linux user, for instance.</para></listitem>
<listitem><para>Users who run relatively few but large jobs: users running simulations, calculations, emulators or other programs that eat a lot of memory, and usually these users have accompanying large data files.</para></listitem>
<listitem><para>Users who run few jobs but use a lot of CPU time (e.g. developers).</para></listitem>
</itemizedlist>
<para>You can see that system requirements may vary for each class of users, and that it can be hard to satisfy everyone. If you are on a multi-user system, it is useful (and fun) to find out habits of other users and the system, in order to get the most out of it for your specific purposes.</para>
</sect3>
<sect3 id="sect_04_03_05_06"><title>Graphical tools</title>
<para>For the graphical environment, there are a whole bunch of monitoring tools available. Below is a screen shot of the GTop System Monitor, which has features for displaying <command>ps</command> and <command>df</command> in an elegant way, next to the process size display:</para>
<figure><title>GTop System Monitor</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/system-monitor.eps" format="EPS"></imagedata></imageobject>
<imageobject>
<imagedata fileref="images/system-monitor.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>There are also a couple of handy icons you can install in the task bar, such as a disk, memory and load monitor. <command>xload</command> is another small X application for monitoring system load. Find your favorite!</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_04_04"><title>Scheduling processes</title>
<sect2 id="sect_04_04_01"><title>Use that idle time!</title>
<para>A Linux system can have a lot to suffer from, but it usually suffers only during office hours. Whether in an office environment, a server room or at home, most Linux systems are just idling away during the morning, the evening, the nights and weekends. Using this idle time can be a lot cheaper than buying those machines you'd absolutely need if you want everything done at the same time.</para>
<para>There are three types of delayed execution:</para>
<itemizedlist>
<listitem><para>Waiting a little while and then resuming job execution, using the <command>sleep</command> command. Execution time depends on the system time at the moment of submission.</para></listitem>
<listitem><para>Running a command at a specified time, using the <command>at</command> command. Execution of the job(s) depends on system time, not the time of submission.</para></listitem>
<listitem><para>Regularly running a command on a monthly, weekly, daily or hourly basis, using the <command>cron</command> facilities.</para></listitem>
</itemizedlist>
<para>The following sections discuss each possibility.</para>
</sect2>
<sect2 id="sect_04_04_02"><title>The sleep command</title>
<para>The Info page on sleep is probably one of the shortest there is. All sleep does is wait. By default the time to wait is expressed in seconds.</para>
<para>So why does it exist? Some practical examples:</para>
<para>Somebody calls you on the phone, you say "Yes I'll be with you in half an hour" but you're about drowned in work as it is and bound to forget your lunch:</para>
<cmdsynopsis><command>(sleep 1800; echo "Lunch time..") &amp;</command></cmdsynopsis>
<para>When you can't use the <command>at</command> command for some reason, it's five o'clock, you want to go home but there's still work to do and right now somebody is eating system resources:</para>
<cmdsynopsis><command>(sleep 10000; myprogram) &amp;</command></cmdsynopsis>
<para>Make sure there's an auto-logout on your system, and that you log out or lock your desktop/office when submitting this kind of job, or run it in a <command>screen</command> session.</para>
<para>When you run a series of printouts of large files, but you want other users to be able to print in between:</para>
<cmdsynopsis><command>lp lotoftext; sleep 900; lp hugefile; sleep 900; lp anotherlargefile</command></cmdsynopsis>
<para>Programmers often use the sleep command to halt script or program execution for a certain time.</para>
</sect2>
<sect2 id="sect_04_04_03"><title>The at command</title>
<para>The <command>at</command> command executes commands at a given time, using your default shell unless you tell the command otherwise (see the man page).</para>
<para>The options to <command>at</command> are rather user-friendly, which is demonstrated in the examples below:</para>
<screen>
steven@home:~&gt;at tomorrow + 2 days
warning: commands will be executed using (in order) a) $SHELL
b) login shell c) /bin/sh
at> cat reports | mail myboss@mycompany
at> &lt;EOT&gt;
job 1 at 2001-06-16 12:36
</screen>
<para>User <emphasis>steven</emphasis> does a strange thing here combining two commands; we will study this sort of practice in <xref linkend="chap_05" />, Redirecting Input and Output.</para>
<screen>
steven@home:~&gt;at 0237
warning: commands will be executed using (in order) a) $SHELL
b) login shell c) /bin/sh
at> cd new-programs
at> ./configure; make
at> &lt;EOT&gt;
job 2 at 2001-06-14 02:00
</screen>
<para>The <command>-m</command> option sends mail to the user when the job is done, or explains when a job can't be done. The command <command>atq</command> lists jobs; perform this command before submitting jobs in order prevent them from starting at the same time as others. With the <command>atrm</command> command you can remove scheduled jobs if you change your mind.</para>
<para>It is a good idea to pick strange execution times, because system jobs are often run at <quote>round</quote> hours, as you can see in <xref linkend="sect_04_04_04" /> the next section. For example, jobs are often run at exactly 1 o'clock in the morning (e.g. system indexing to update a standard locate database), so entering a time of 0100 may easily slow your system down rather than fire it up. To prevent jobs from running all at the same time, you may also use the <command>batch</command> command, which queues processes and feeds the work in the queue to the system in an evenly balanced way, preventing excessive bursts of system resource usage. See the Info pages for more information.</para>
</sect2>
<sect2 id="sect_04_04_04"><title>Cron and crontab</title>
<para>The cron system is managed by the cron daemon. It gets information about which programs and when they should run from the system's and users' crontab entries. Only the root user has access to the system crontabs, while each user should only have access to his own crontabs. On some systems (some) users may not have access to the cron facility.</para>
<para>At system startup the daemon searches <filename>/var/spool/cron/</filename> for crontab entries which are named after accounts in <filename>/etc/passwd</filename>, it searches <filename>/etc/cron.d/</filename> and it searches <filename>/etc/crontab</filename>, then uses this information every minute to check if there is something to be done. It executes commands as the user who owns the crontab file and mails any output of commands to the owner.</para>
<para>On systems using Vixie cron, jobs that occur hourly, daily, weekly and monthly are kept in separate directories in <filename>/etc</filename> to keep an overview, as opposed to the standard UNIX cron function, where all tasks are entered into one big file.</para>
<para>Example of a crontab file:</para>
<screen>
[root@blob /etc]# more crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
# commands to execute every hour
01 * * * * root run-parts /etc/cron.hourly
# commands to execute every day
02 4 * * * root run-parts /etc/cron.daily
# commands to execute every week
22 4 * * 0 root run-parts /etc/cron.weekly
commands to execute every month
42 4 1 * * root run-parts /etc/cron.monthly
</screen>
<para>Some variables are set, and after that there's the actual scheduling, one line per job, starting with 5 time and date fields. The first field contains the minutes (from 0 to 59), the second defines the hour of execution (0-23), the third is day of the month (1-31), then the day of the month (1-12), the last is day of the week (0-7, both 0 and 7 are Sunday). An asterisk in these fields represents the total acceptable range for the field. Lists are allowed; to execute a job from Monday to Friday enter 1-5 in the last field, to execute a job on Monday, Wednesday and Friday enter 1,3,5.</para>
<para>Then comes the user who should run the processes which are listed in the last column. The example above is from a Vixie cron configuration where root runs the program <command>runparts</command> on regular intervals, with the appropriate directories as options. In these directories, the actual jobs to be executed at the scheduled time are stored as shell scripts, like this little script that is run daily to update the database used by the <command>locate</command> command:</para>
<screen>
billy@ahost cron.daily]$ cat slocate.cron
#!/bin/sh
renice +19 -p $$ &gt;/dev/null 2>&amp;1
/usr/bin/updatedb -f "nfs,smbfs,ncpfs,proc,devpts" -e "/tmp,/var/tmp,\
/usr/tmp,/afs,/net"
</screen>
<para>Users are supposed to edit their crontabs in a safe way using the <command>crontab -e</command> command. This will prevent a user from accidentally opening more than one copy of his/her crontabfile. The default editor is <command>vi</command> (see <xref linkend="chap_06" />. When you quit, the system will tell you that a new crontab is installed.</para>
<para>This crontab entry reminds <emphasis>billy</emphasis> to go to his sports club every Thursday night:</para>
<screen>
billy:~>crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.18185 installed on Wed Sep 19 16:37:08 2001)
# (Cron version -- $Id$)
38 16 * * 3 mail -s "sports evening" billy
</screen>
<para>Cron will also report about the executed tasks via E-mail. Note that normal users don't have to specify the user who should run the commands. They are executed with the user's own permissions by default.</para>
</sect2>
</sect1>
<sect1 id="sect_04_05"><title>Summary</title>
<para>Linux is a multi-user, multi-tasking operating system that has a UNIX-like way of handling processes. Execution speed of commands can depend on a thousand tiny things. Among others, we learned a lot of new commands to visualize and handle processes. Here's a list:</para>
<table frame="all"><title>Process handling commands</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row>
<entry>Command</entry><entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry><command>at</command></entry><entry>Queue jobs for later execution</entry>
</row>
<row>
<entry><command>atq</command></entry><entry>Lists the user's pending jobs</entry>
</row>
<row>
<entry><command>atrm</command></entry><entry>Deletes jobs, determined by their job number.</entry>
</row>
<row>
<entry><command>batch</command></entry><entry>Executes commands when system load level permits.</entry>
</row>
<row>
<entry><command>crontab</command></entry><entry>Maintain crontab files for individual users.</entry>
</row>
<row>
<entry><command>halt</command></entry><entry>Stop the system</entry>
</row>
<row>
<entry><command>init</command></entry><entry>Process control initialization</entry>
</row>
<row>
<entry><command>jobs</command></entry><entry>Lists currently executing jobs.</entry>
</row>
<row>
<entry><command>kill</command></entry><entry>Terminate a process.</entry>
</row>
<row>
<entry><command>mesg</command></entry><entry>Control write access to your terminal.</entry>
</row>
<row>
<entry><command>netstat</command></entry><entry>Display network connections, routing tables, interface statistics, masquerade connections and multicast memberships.</entry>
</row>
<row>
<entry><command>nice</command></entry><entry>Run a program with modified scheduling priority.</entry>
</row>
<row>
<entry><command>ps</command></entry><entry>Report process status</entry>
</row>
<row>
<entry><command>pstree</command></entry><entry>Display a tree of processes.</entry>
</row>
<row>
<entry><command>reboot</command></entry><entry>Stop the system.</entry>
</row>
<row>
<entry><command>renice</command></entry><entry>Alter priority of running processes.</entry>
</row>
<row>
<entry><command>shutdown</command></entry><entry>Bring the system down.</entry>
</row>
<row>
<entry><command>sleep</command></entry><entry>Delay for a specified time.</entry>
</row>
<row>
<entry><command>time</command></entry><entry>Time a command or report resource usage.</entry>
</row>
<row>
<entry><command>top</command></entry><entry>Display top CPU processes.</entry>
</row>
<row>
<entry><command>uptime</command></entry><entry>Show how long the system has been running.</entry>
</row>
<row>
<entry><command>vmstat</command></entry><entry>Report virtual memory statistics.</entry>
</row>
<row>
<entry><command>w</command></entry><entry>Show who is logged on and what they are doing.</entry>
</row>
<row>
<entry><command>wall</command></entry><entry>Send a message to everybody's terminals.</entry>
</row>
<row>
<entry><command>who</command></entry><entry>Show who is logged on.</entry>
</row>
<row>
<entry><command>write</command></entry><entry>Send a message to another user.</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1 id="sect_04_06"><title>Exercises</title>
<para>These are some exercises that will help you get the feel for processes running on your system.</para>
<sect2><title>General</title>
<itemizedlist>
<listitem><para>Run <command>top</command> in one terminal while you do the exercises in another.</para></listitem>
<listitem><para>Run the <command>ps</command> command.</para></listitem>
<listitem><para>Read the man pages to find out how to display all your processes.</para></listitem>
<listitem><para>Run the command <command>find /</command>. What effect does it have on system load? Stop this command.</para></listitem>
<listitem><para>In graphical mode, start the <command>xclock</command> program in the foreground. Then let it run in the background. Stop the program using the <command>kill</command> command.</para></listitem>
<listitem><para>What does <command>kill -9 -1</command> do?</para></listitem>
<listitem><para>Open two terminals or terminal windows again and use <command>write</command> to send a message from one to the other.</para></listitem>
<listitem><para>Issue the <command>dmesg</command> command. What does it tell?</para></listitem>
<listitem><para>How long does it take to execute <command>ls</command> in the current directory?</para></listitem>
<listitem><para>Based on process entries in <filename>/proc</filename>, owned by your UID, how would you work to find out which processes these actually represent?</para></listitem>
<listitem><para>How long has your system been running?</para></listitem>
<listitem><para>Which is your current TTY?</para></listitem>
<listitem><para>Name 3 processes that couldn't have had <command>init</command> as an initial parent.</para></listitem>
<listitem><para>Name 3 commands which use SUID mode. Explain why this is so.</para></listitem>
<listitem><para>Name the commands that are generally causing the highest load on your system.</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Booting, init etc.</title>
<itemizedlist>
<listitem><para>Can you reboot the system as a normal user? Why is that?</para></listitem>
<listitem><para>According to your current runlevel, name the steps that are taken during shutdown.</para></listitem>
<listitem><para>How do you change the system runlevel? Switch from 3 to 5 and vice versa.</para></listitem>
<listitem><para>Which kernel does GRUB currently load at startup?</para></listitem>
<listitem><para>Suppose you have to start some exotic server at boot time. Up until now, you logged in after booting the system and started this server manually using a script named <filename>deliver_pizza</filename> in your home directory. What do you have to do in order to have the service start up automatically in run level 4, which you defined for this purpose only?</para></listitem>
</itemizedlist>
</sect2>
<sect2><title>Scheduling</title>
<itemizedlist>
<listitem><para>Use <command>sleep</command> to create a reminder that your pasta is ready in ten minutes.</para></listitem>
<listitem><para>Create an <command>at</command> job that copies all files in your home directory to <filename>/var/tmp</filename> within half an hour. You may want to create a sub-directory in <filename>/var/tmp</filename>.</para></listitem>
<listitem><para>Make a cronjob that does this task every Monday to Friday during lunch.</para></listitem>
<listitem><para>Check that it works.</para></listitem>
<listitem><para>Make a mistake in the crontab entry, like issuing the unexisting command <command>coppy</command> instead of <command>cp</command>. What happens upon execution of the task?</para></listitem>
</itemizedlist>
</sect2>
</sect1>
</chapter>

View File

@ -0,0 +1,193 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_05">
<title>Input and output redirection</title>
<abstract>
<para>This chapter describes more about the powerful UNIX mechanism of redirecting input and output. Topics include:</para>
<para>
<itemizedlist>
<listitem><para>Standard input, output and errors</para></listitem>
<listitem><para>Redirection operators</para></listitem>
<listitem><para>How to use output of one command as input for another</para></listitem>
<listitem><para>Input redirection</para></listitem>
<listitem><para>Handling standard error messages</para></listitem>
<listitem><para>Combining redirection of input, output and error streams</para></listitem>
<listitem><para>Output filters</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1 id="sect_05_01"><title>What are standard input and standard output?</title>
<para>
Most Linux commands read input, such as a file or another attribute for the command, and write output. By default, input is being given with the keyboard, and output is displayed on your screen. Your keyboard is your <quote>standard input</quote> (stdin) device, and the screen is the <quote>standard output</quote> (stdout) device.
</para>
<para>However, since Linux is a flexible system, these default settings don't necessarily have to be applied. The standard output, for example, on a heavily monitored server in a large environment may be a printer.</para>
<sect2 id="sect_05_01_01"><title>The redirection operators</title>
<sect3 id="sect_05_01_01_01"><title>Output redirection with &gt; and |</title>
<para>Sometimes you will want to put output of a command in a file, or you may want to issue another command on the output of one command. This is known as redirecting output. Redirection is done using either the <quote>&gt;</quote> (greater-than symbol), or using the <quote>|</quote> (pipe) operator which sends the standard output of one command to another command as standard input.</para>
<para>As we saw before, the <command>cat</command> command concatenates files and puts them all together to the standard output. By redirecting this output to a file, this file name will be created - or overwritten if it already exists, so take care.</para>
<screen>
nancy:~&gt;cat test1
some words
nancy:~&gt;cat test2
some other words
nancy:~&gt;cat test1 test2 &gt; test3
nancy:~&gt;cat test3
some words
some other words
</screen>
<para>Redirecting <quote>nothing</quote> to an existing file is equal to emptying the file:</para>
<screen>
[jean@saturnus ~/Documents] ls -l list
-rw-rw-r-- 1 jean jean 117 Apr 2 18:09 list
[jean@saturnus ~/Documents] &gt; list
[jean@saturnus ~/Documents] ls -l list
-rw-rw-r-- 1 jean jean 0 Apr 4 12:01 list
</screen>
<para>This process is called <emphasis>truncating</emphasis>. The same redirection to an unexisting file will create a new empty file with the given name:</para>
<screen>
[jean@saturnus ~] ls -l newlist
ls: newlist: No such file or directory
[jean@saturnus ~] &gt; newlist
[jean@saturnus ~] ls -l newlist
-rw-rw-r-- 1 jean jean 0 Apr 4 12:05 newlist
</screen>
<para><xref linkend="chap_07" /> gives some more examples on the use of this sort of redirection.</para>
<para>Some examples using piping of commands:</para>
<itemizedlist>
<listitem><para>To mail a text file to somebody:</para>
<para><command>cat <filename>file</filename> | mail somebody@somewhere.com</command></para>
</listitem>
<listitem><para>To find a word within some text, display all lines matching pattern1, or exclude lines also matching pattern2 from being displayed:</para>
<para><command>grep pattern1 <filename>file</filename> | grep -v pattern2</command></para>
</listitem>
<listitem><para>To display output of a directory listing one page at a time:</para>
<para><command>ls -la | less</command></para>
</listitem>
<listitem><para>To find an entry in a directory:</para>
<para><command>ls -l | grep <filename>entry</filename></command></para></listitem>
</itemizedlist>
<para>In another case, you may want a file to be the input for a command that normally wouldn't accept a file as an option. This redirecting of input is done using the <quote>&lt;</quote> (less-than symbol) operator.</para>
<para>Below is an example of sending a file to somebody, using input redirection.</para>
<screen>
andy:~&gt;mail mike@somewhere.org &lt; to_do
</screen>
<para>If the user <emphasis>mike</emphasis> exists on the system, you don't need to type the full address. If you want to reach somebody on the Internet, enter the fully qualified address as an argument to <command>mail</command>.</para>
<para>The following example combines input and output redirection. The file <filename>text.txt</filename> is first checked for spelling mistakes, and the output is redirected to an error log file:</para>
<para><command>aspell &lt; <filename>text.txt</filename> &gt; error.log</command></para>
<note><title>Don't overwrite!</title>
<para>Be careful not to overwrite existing (important) files when redirecting output. Many shells, including Bash, have a built-in feature to protect you from that risk: <command>noclobber</command>. See the Info pages for more information. In Bash, you would want to add the <command>set -o noclobber</command> command to your <filename>.bashrc</filename> configuration file in order to prevent accidental overwriting of files.</para></note>
<para>The pipe command (<command>|</command>) will feed output of one program as input to another. This is a way of sending mail using redirection of output instead of redirection of input:</para>
<screen>
andy:~&gt;cat to_do | mail mike
</screen>
<para>The output of the piped command can then be piped into another command, just as long as these commands would normally read input from the standard input and put output to the standard output.</para>
</sect3>
<sect3 id="sect_05_01_01_02"><title>The &gt; &gt; operator</title>
<para>Instead of overwriting file data, you can also append text to an existing file.</para>
<para>Example:</para>
<screen>
mike:~&gt;date &gt; &gt; today's_wishlist
mike:~&gt;cat today's_wishlist
more money
less work
Thu Feb 28 20:23:07 CET 2002
</screen>
<para>The <command>date</command> command would normally put the last line on the screen; now it is appended to the file <filename>test3</filename>.
</para>
</sect3>
</sect2>
<sect2 id="sect_05_01_02"><title>Advanced redirection features</title>
<para>There are three types of output, which each have their own identifier, called a file descriptor:</para>
<itemizedlist>
<listitem><para>standard input: 0</para></listitem>
<listitem><para>standard output: 1</para></listitem>
<listitem><para>standard error: 2</para></listitem>
</itemizedlist>
<para>In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is &lt;, the redirection refers to the standard input (file descriptor 0). If the first character of the redirection operator is &gt;, the redirection refers to the standard output (file descriptor 1).</para>
<para>Some practical examples will make this more clear:</para>
<cmdsynopsis><command>ls &gt; <filename>dirlist</filename> 2&gt;&amp;1</command></cmdsynopsis>
<para>will direct both standard output and standard error to the file <filename>dirlist</filename>, while the command</para>
<cmdsynopsis><command>ls 2&gt;&amp;1 &gt; <filename>dirlist</filename></command></cmdsynopsis>
<para>will only direct standard output to <filename>dirlist</filename>. This can be a useful option for programmers.</para>
<para>All this is explained in detail in the Bash Info pages.</para>
</sect2>
<sect2 id="sect_05_01_03">
<title>Filters</title>
<para>When a program performs operations on input and writes the result to the standard output, it is called a filter. One of the most common uses of filters is to restructure output. We'll discuss a couple of the most important filters below.</para>
<sect3 id="sect_05_01_03_01"><title><command>grep</command></title>
<para><command>grep</command> scans the output line per line, searching for matching patterns. All lines containing the pattern will be printed to standard output. This behavior can be reversed using the <command>-v</command> option.
</para>
<para>Some examples: suppose we want to know which files in a certain directory have been modified in February:</para>
<screen>
jenny:~&gt;ls -la | grep Feb
</screen>
<para>The <command>grep</command> command, like most commands, is case sensitive. Use the <option>-i</option> option to make no difference between upper and lower case. Again, all the information is contained in the Info pages.</para>
</sect3>
<sect3 id="sect_05_01_03_02"><title>Filtering output</title>
<para>The command <command>sort</command> arranges lines in alphabetical order by default:</para>
<screen>
thomas:~&gt;cat people-I-like | sort
Auntie Emmy
Boyfriend
Dad
Grandma
Mum
My boss
</screen>
<para>But there are many more things <command>sort</command> can do. Looking at the file size, for instance. With this command, directory content is sorted smallest files first, biggest files last:</para>
<cmdsynopsis><command>ls <option>-la</option> | sort <option>-nk 5</option></command></cmdsynopsis>
<note><title>Old sort syntax</title>
<para>You might obtain the same result with <command>ls <option>-la</option> | sort <option>+4n</option></command>, but this is an old form which does not comply with the current standards.</para></note>
<para>The <command>sort</command> command is also used in combination with the <command>uniq</command> program (or <command>sort <option>-u</option></command>) to sort output and filter out double entries.</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_05_02"><title>Summary</title>
<para>In this chapter we learned how commands can be linked to each other, and how input from one command can be used as output for another command.</para>
<para>Input/output redirection is a common task on UNIX and Linux machines. This powerful mechanism allows flexible use of the building blocks UNIX is made of.</para>
</sect1>
<sect1 id="sect_05_03"><title>Exercises</title>
<para>These exercises give more examples on how to combine commands. The main goal is to try and use the [ENTER]-key as little as possible.</para>
<para>All exercises are done using a normal user ID, so as to generate some errors. While you're at it, don't forget to read those man pages!</para>
<itemizedlist>
<listitem><para>Use the <command>cut</command> command on the output of a long directory listing in order to display only the file permissions. Then pipe this output to <command>sort</command> and <command>uniq</command> to filter out any double lines. Then use the <command>wc</command> to count the different permission types in this directory.</para></listitem>
<listitem><para>Put the output of <command>date</command> in a file. Append the output of <command>ls</command> to this file. Send this file to your local mailbox. When using Bash, you will see a new mail notice upon success.</para></listitem>
<listitem><para>List the devices which are currently used by your UID. Pipe through <command>less</command> to view them properly.</para></listitem>
<listitem><para>Use the command <command>bash -x</command> to start up the HTTP daemon with the script in <filename>/etc/rc.d/init.d</filename>. Send standard error to a file. Do the same but now send standard output to the file. Note the difference.</para></listitem>
<listitem><para>How many processes are you currently running?</para></listitem>
<listitem><para>How many invisible files are in your home directory?</para></listitem>
<listitem><para>Use <command>rpm</command> to check which version of the GCC package is installed on your system (use <command>rpm <option>--help</option></command> for an overview of options).</para></listitem>
<listitem><para>Use <command>locate</command> to find documentation about the kernel.</para></listitem>
<listitem><para>Find out which file contains the following entry:</para>
<screen>
root:x:0:0:root:/root:/bin/bash
</screen>
<para>And this one:</para>
<screen>
system: root
</screen></listitem>
<listitem><para>See what happens upon issuing this command:</para>
<screen>&gt; time; date &gt;&gt; time; cat &lt; time</screen>
</listitem>
</itemizedlist>
</sect1>
</chapter>

View File

@ -0,0 +1,115 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_06">
<title>Text editors</title>
<abstract>
<para>In this chapter, we will discuss the importance of mastering an editor. We will focus mainly on the Improved <command>vi</command> editor.</para>
<para>After finishing this chapter, you will be able to:</para>
<para>
<itemizedlist>
<listitem><para>Open and close files in text mode</para></listitem>
<listitem><para>Edit files</para></listitem>
<listitem><para>Search text</para></listitem>
<listitem><para>Undo errors</para></listitem>
<listitem><para>Merge files</para></listitem>
<listitem><para>Recover lost files</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1 id="sect_06_01"><title>Text editors</title>
<sect2 id="sect_06_01_01"><title>Why should I use an editor?</title>
<para>It is very important to be able to use at least one text mode editor. Knowing how to use an editor on your system is the first step to independence.</para>
<para>We will need to master an editor by the next chapter as we need it to edit files that influence our environment. As an advanced user, you may want to start writing scripts, or books, develop websites or new programs. Mastering an editor will immensely improve your productivity as well as your capabilities.</para>
</sect2>
<sect2 id="sect_06_01_02"><title>Which editor should I use?</title>
<para>Since graphical editors, running in an X session, such as Office suites and the like, have very similar interfaces to the ones used on Windows or MacIntosh machines, we won't discuss them here. Please refer to the help function these commands usually include, or to the user manuals.</para>
<para>Instead, our focus is on text editors, which can also be used on systems without a graphical environment. The additional advantage of mastering a text editor is in using it on remote machines. Since you don't need to transfer the entire graphical environment over the network, working with text editors tremendously improves network speed.</para>
<para>There are, as usual, multiple ways to handle the problem. Let's see what editors are commonly available:</para>
<sect3 id="sect_06_01_02_01"><title>Pico</title>
<para>Pico is a simple display-oriented text editor in the style of the Pine Composer (Pine Is Not Elm, see <xref linkend="chap_10" /> on mail clients). As with Pine, commands are displayed at the bottom of the screen, and context-sensitive help is provided. As characters are typed they are immediately inserted into the text.</para>
<para>Editing commands are entered using Control-key combinations. As a work-around for communications programs that swallow certain control characters, you can emulate a control key by pressing [ESCAPE] twice, followed by the desired control character. The editor has five basic features: paragraph justification, searching, block cut/paste, a spell-checker, and a file browser. See the Info pages for more details.</para>
<para>While <command>pico</command> is a fine editor for beginners, it has two main disadvantages: it is not completely Open Source software, and advanced users want more out of an editor.</para>
</sect3>
<sect3 id="sect_06_01_02_02"><title>GNU Emacs</title>
<para>Emacs is the extensible, customizable, self-documenting, real-time display editor, known on many UNIX and other systems. The text being edited is visible on the screen and is updated automatically as you type your commands. It is a real-time editor because the display is updated very frequently, usually after each character or pair of characters you type. This minimizes the amount of information you must keep in your head as you edit. Emacs is called advanced because it provides facilities that go beyond simple insertion and deletion: controlling subprocesses; automatic indentation of programs; viewing two or more files at once; editing formatted text; and dealing in terms of characters, words, lines, sentences, paragraphs, and pages, as well as expressions and comments in several different programming languages.</para>
<para><emphasis>Self-documenting</emphasis> means that at any time you can type a special character, [CTRL]-[H], to find out what your options are. You can also use it to find out what any command does, or to find all the commands that pertain to a topic. <emphasis>Customizable</emphasis> means that you can change the definitions of Emacs commands in little ways. For example, if you use a programming language in which comments start with `&lt;**' and end with `**&gt;', you can tell the Emacs comment manipulation commands to use those strings. Another sort of customization is rearrangement of the command set. For example, if you prefer the four basic cursor motion commands (up, down, left and right) on keys in a diamond pattern on the keyboard, you can rebind the keys that way.</para>
<para><emphasis>Extensible</emphasis> means that you can go beyond simple customization and write entirely new commands, programs in the Lisp language that are run by Emacs's own Lisp interpreter. Emacs is an <emphasis>online</emphasis> extensible system, which means that it is divided into many functions that call each other, any of which can be redefined in the middle of an editing session. Almost any part of Emacs can be replaced without making a separate copy of all of Emacs. Most of the editing commands of Emacs are written in Lisp already; the few exceptions could have been written in Lisp but are written in C for efficiency. Although only a programmer can write an extension, anybody can use it afterward.</para>
<para>When run under the X Window System, Emacs provides its own menus and convenient bindings to mouse buttons. But Emacs can provide many of the benefits of a window system on a text-only terminal. For instance, you can look at or edit several files at once, move text between files, and edit files while running shell commands.</para>
</sect3>
<sect3 id="sect_06_01_02_03"><title>Vi(m)</title>
<para>Vim stands for Vi IMproved. It used to be Vi IMitation, but there are so many improvements that a name change was appropriate. Vim is a text editor which includes almost all the commands from the UNIX program <command>vi</command> and a lot of new ones.</para>
<para>Commands in the <command>vi</command> editor are entered using only the keyboard, which has the advantage that you can keep your fingers on the keyboard and your eyes on the screen, rather than moving your arm repeatedly to the mouse. For those who want it, mouse support and a GUI version with scrollbars and menus can be activated.</para>
<para>We will refer to <command>vi</command> or <command>vim</command> throughout this book for editing files, while you are of course free to use the editor of your choice. We chose this <command>vi</command> because it is the standard text editor on almost all UNIX systems, while <command>emacs</command> can be an optional package. There may be small differences between different computers and terminals, but the main point is that if you can work with <command>vi</command>, you can survive on any UNIX system.</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_06_02"><title>Using the Vim editor</title>
<sect2 id="sect_06_02_01"><title>Two modes</title>
<para>The <command>vi</command> editor is a very powerful tool and has a very extensive built-in manual, which you can activate using the <command>:help</command> command when the program is started (instead of using <command>man</command> or <command>info</command>, which don't contain nearly as much information). We will only discuss the very basics here to get you started.</para>
<para>What makes <command>vi</command> confusing to the beginner is that it can operate in two modes: command mode and insert mode. The editor always starts in command mode. Commands move you through the text, search, replace, mark blocks and perform other editing tasks, and some of them switch the editor to insert mode.</para>
<para>This means that each key has not one, but likely two meanings: it can either represent a command for the editor when in command mode, or a character that you want in a text when in insert mode.</para>
<note><title>Pronunciation</title>
<para>It's pronounced <quote>vee-eye</quote>.</para></note>
</sect2>
<sect2 id="sect_06_02_02"><title>Basic commands</title>
<sect3 id="sect_06_02_02_01"><title>Moving through the text</title>
<para>Moving through the text is usually possible with the arrow keys. If not, try:</para>
<itemizedlist>
<listitem><para><command>h</command> to move the cursor to the left</para></listitem>
<listitem><para><command>l</command> to move it to the right</para></listitem>
<listitem><para><command>k</command> to move up</para></listitem>
<listitem><para><command>j</command> to move down</para></listitem>
</itemizedlist>
<para>SHIFT-G will put the prompt at the end of the document.</para>
</sect3>
<sect3 id="sect_06_02_02_02"><title>Basic operations</title>
<itemizedlist>
<listitem><para><command>n dd</command> will delete n lines starting from the current cursor position.</para></listitem>
<listitem><para><command>n dw</command> will delete n words at the right side of the cursor.</para></listitem>
<listitem><para><command>x</command> will delete the character on which the cursor is positioned</para></listitem>
<listitem><para><command>:n</command> moves to line n of the file.</para></listitem>
<listitem><para><command>:w</command> will save (write) the file</para></listitem>
<listitem><para><command>:q</command> will exit the editor.</para></listitem>
<listitem><para><command>:q!</command> forces the exit when you want to quit a file containing unsaved changes.</para></listitem>
<listitem><para><command>:wq</command> will save and exit</para></listitem>
<listitem><para><command>:w newfile</command> will save the text to <filename>newfile</filename>.</para></listitem>
<listitem><para><command>:wq!</command> overrides read-only permission (if you have the permission to override permissions, for instance when you are using the <emphasis>root</emphasis> account.</para></listitem>
<listitem><para><command>/astring</command> will search the string in the file and position the cursor on the first match below its position.</para></listitem>
<listitem><para><command>/</command> will perform the same search again, moving the cursor to the next match.</para></listitem>
<listitem><para><command>:1, $s/word/anotherword/g</command> will replace <filename>word</filename> with <filename>anotherword</filename> throughout the file.</para></listitem>
<listitem><para><command>yy</command> will copy a block of text.</para></listitem>
<listitem><para><command>n p</command> will paste it n times.</para></listitem>
<listitem><para><command>:recover</command> will recover a file after an unexpected interruption.</para></listitem>
</itemizedlist>
</sect3>
<sect3 id="sect_06_02_02_03"><title>
Commands that switch the editor to insert mode</title>
<itemizedlist>
<listitem><para><command>a</command> will append: it moves the cursor one position to the right before switching to insert mode</para></listitem>
<listitem><para><command>i</command> will insert</para></listitem>
<listitem><para><command>o</command> will insert a blank line under the current cursor position and move the cursor to that line.</para></listitem>
</itemizedlist>
<para>Pressing the ESC key switches back to command mode. If you're not sure what mode you're in because you use a really old version of <command>vi</command> that doesn't display an <quote>INSERT</quote> message, type ESC and you'll be sure to return to command mode. It is possible that the system gives a little alert when you are already in command mode when hitting ESC, by beeping or giving a visual bell (a flash on the screen). This is normal behavior.</para>
</sect3>
</sect2>
<sect2 id="sect_06_02_03"><title>The easy way</title>
<para>Instead of reading the text, which is quite boring, you can use the vimtutor to learn you first Vim commands. This is a thirty minute tutorial that teaches the most basic Vim functionality hands-on. While you can't learn everything about <command>vim</command> in just half an hour, the tutor is designed to describe enough of the commands that you will be able to easily use Vim as an all-purpose editor.</para>
<para>In UNIX and MS Windows, if Vim has been properly installed, you can start it from the shell or command line using the <command>vimtutor</command> command. This will make a copy of the tutor file, so that you can edit it without the risk of damaging the original. There are a few translated versions of the tutor. To find out if yours is available, use the two-letter language code. For French this would be <command>vimtutor fr</command> (if installed on the system).</para>
</sect2>
</sect1>
<sect1 id="sect_06_03"><title>Summary</title>
<para>In this chapter we learned to use an editor. While it depends on your own individual preference which one you use, it is necessary to at least know how to use one editor.</para>
<para>The <command>vi</command> editor is available on every UNIX system.</para>
</sect1>
<sect1 id="sect_06_04"><title>Exercises</title>
<para>This chapter has only one exercise: start the Vim tutor and use it.</para>
<para>You may alternatively start <command>emacs</command> and type [CTRL]-[H] [T] to invoke the self-paced Emacs tutorial.</para>
<para>Practice is the only way!</para>
</sect1>
</chapter>

View File

@ -0,0 +1,685 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_07"><title>Home sweet /home</title>
<abstract>
<para>This chapter is about configuring your environment. Now that we now how to use an editor, we can change all kinds of files to make ourselves feel better at home. After completing this chapter, you will know more about:</para>
<para>
<itemizedlist>
<listitem><para>Organizing your environment</para></listitem>
<listitem><para>Common shell setup files</para></listitem>
<listitem><para>Shell configuration</para></listitem>
<listitem><para>Configuring the prompt</para></listitem>
<listitem><para>Configuring the graphical environment</para></listitem>
<listitem><para>Display and window managers</para></listitem>
<listitem><para>How the X client-server system works</para></listitem>
<listitem><para>Language settings</para></listitem>
<listitem><para>Installing new software</para></listitem>
<listitem><para>Updating existing packages</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1 id="sect_07_01"><title>General good housekeeping</title>
<sect2 id="sect_07_01_01"><title>Introduction</title>
<para>As we mentioned before, it is easy enough to make a mess of the system. We can't put enough stress on the importance of keeping the place tidy. When you learn this from the start, it will become a good habit that will save you time when programming on a Linux or UNIX system or when confronted with system management tasks. Here are some ways of making life easier on yourself:</para>
<itemizedlist>
<listitem><para>Make a <filename>bin</filename> directory for your program files and scripts.</para></listitem>
<listitem><para>Organize non-executable files in appropriate directories, and make as many directories as you like. Examples include separate directories for images, documents, projects, downloaded files, spreadsheets, personal files, and so on.</para></listitem>
<listitem><para>Make directories private with the <command>chmod 700 dirname</command> command.</para></listitem>
<listitem><para>Give your files sensible names, such as <filename>Complaint to the prime minister 050302</filename> rather than <filename>letter1</filename>.</para></listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_07_01_02"><title>Make space</title>
<para>On some systems, the <command>quota</command> system may force you to clean up from time to time, or the physical limits of your hard disk may force you to make more space without running any monitoring programs. This section discusses a number of ways, besides using the <command>rm</command> command, to reclaim disk space.</para>
<para>Run the <command>quota -v</command> command to see how much space is left.</para>
<sect3 id="sect_07_01_02_01"><title>Emptying files</title>
<para>Sometimes the content of a file doesn't interest you, but you need the file name as a marker (for instance, you just need the timestamp of a file, a reminder that the file was there or should be there some time in the future). Redirecting the output of a null command is how this is done in the Bourne and Bash shells:</para>
<screen>
andy:~&gt;cat wishlist &gt; placeholder
andy:~&gt;ls -la placeholder
-rw-rw-r-- 1 andy andy 200 Jun 12 13:34 placeholder
andy:~&gt; &gt; placeholder
andy:~&gt;ls -la placeholder
-rw-rw-r-- 1 andy andy 0 Jun 12 13:35 placeholder
</screen>
<para>The process of reducing an existing file to a file with the same name that is 0 bytes large is called <quote>truncating.</quote></para>
<para>For creating a new empty file, the same effect is obtained with the <command>touch</command> command. On an existing file, <command>touch</command> will only update the timestamp. See the Info pages on <command>touch</command> for more details.</para>
<para>To <quote>almost</quote> empty a file, use the <command>tail</command> command. Suppose user <emphasis>andy</emphasis>'s wishlist becomes rather long because he always adds stuff at the end but never deletes the things he actually gets. Now he only wants to keep the last five items:</para>
<screen>
andy:~&gt;tail -5 wishlist &gt; newlist
andy:~&gt;cat newlist &gt; wishlist
andy:~&gt;rm newlist
</screen>
</sect3>
<sect3 id="sect_07_01_02_02"><title>More about log files</title>
<para>Some Linux programs insist on writing all sorts of output in a log file. Usually there are options to only log errors, or to log a minimal amount of information, for example setting the debugging level of the program. But even then, you might not care about the log file. Here are some ways to get rid of them or at least set some limits to their size:</para>
<itemizedlist>
<listitem><para>Try removing the log file when the program is not running, if you are sure that you won't need it again. Some programs may even see, when restarted, that there is no log file and will therefore not log.</para></listitem>
<listitem><para>If you remove the log file and the program recreates it, read the documentation for this particular program in search for command options that avoid making logfiles.</para></listitem>
<listitem><para>Try making smaller logfiles by logging only the information that is relevant to you, or by logging only significant information.</para></listitem>
<listitem><para>Try replacing the log file with a symbolic link to <filename>/dev/null</filename>; if you're lucky the program won't complain. Don't do this with the log files of programs that run at system boot or programs that run from cron (see <xref linkend="chap_04" />). These programs might replace the symbolic link with a small file that starts growing again.</para></listitem>
</itemizedlist>
</sect3>
<sect3 id="sect_07_01_02_03"><title>Mail</title>
<para>Regularly clean out your mailbox, make sub-folders and automatic redirects using <command>procmail</command> (see the Info pages) or the filters of your favorite mail reading application. If you have a trash folder, clean it out on a regular basis.</para>
<para>To redirect mail, use the <filename>.forward</filename> file in your home directory. The Linux mail service looks for this file whenever it has to deliver local mail. The content of the file defines what the mail system should do with your mail. It can contain a single line holding a fully qualified E-mail address. In that case the system will send all your mail to this address. For instance, when renting space for a website, you might want to forward the mail destined for the webmaster to your own account in order not to waste disk space. The webmaster's <filename>.forward</filename> may look like this:</para>
<screen>
webmaster@www ~/>cat .forward
mike@pandora.be
</screen>
<para>Using mail forwarding is also useful to prevent yourself from having to check several different mailboxes. You can make every address point to a central and easily accessible account.</para>
<para>You can ask your system administrator to define a forward for you in the local mail aliases file, like when an account is being closed but E-mail remains active for a while.</para>
</sect3>
<sect3 id="sect_07_01_02_04"><title>Save space with a link</title>
<para>When several users need access to the same file or program, when the original file name is too long or too difficult to remember, use a symbolic link instead of a separate copy for each user or purpose.</para>
<para>Multiple symbolic links may have different names, e.g. a link may be called <filename>monficher</filename> in one user's directory, and <filename>mylink</filename> in another's. Multiple links (different names) to the same file may also occur in the same directory. This is often done in the <filename>/lib</filename> directory, e.g. these references to the shared PAM (pluggable authentication modules) libraries:</para>
<screen>
adam@eve /lib&gt; ls -l libpam.so *
lrwxrwxrwx 1 root root 14 Nov 15 08:05 libpam.so -&gt; libpam.so.0.75*
lrwxrwxrwx 1 root root 14 Oct 28 14:20 libpam.so.0 -&gt; libpam.so.0.75*
-rwxr-xr-x 1 root root 35424 Nov 9 17:30 libpam.so.0.75*
</screen>
</sect3>
<sect3 id="sect_07_01_02_05"><title>Limit file sizes</title>
<para>The shell contains a built-in command to limit file sizes, <command>ulimit</command>, which can also be used to display limitations on system resources:</para>
<screen>
cindy:~&gt;ulimit -a
core file size (blocks) 0
data seg size (kbytes) unlimited
file size (blocks) unlimited
max locked memory (kbytes) unlimited
max memory size (kbytes) unlimited
open files 1024
pipe size (512 bytes) 8
stack size (kbytes) 8192
cpu time (seconds) unlimited
max user processes 512
virtual memory (kbytes) unlimited
</screen>
<para>Cindy is not a developer and doesn't care about core dumps, which contain debugging information on a program. If you do want core dumps, you can set their size using the <command>ulimit</command> command. Read the Info pages on <command>bash</command> for a detailed explanation.</para>
</sect3>
<sect3 id="sect_07_01_02_06"><title>Compressed files</title>
<para>Compressed files are useful, but unpacking them all the time just to get a little bit of information out of them and then having to compress them again is very boring.</para>
<para>Most systems support <command>egrep</command>, <command>zgrep</command>, <command>zcat</command>, <command>zmore</command> and such to prevent unnecessary decompressing/compressing actions. See you system's binary directory and the Info pages.</para>
<para>See Chapter 9 on Backups for more on the actual compressing of files and examples on making archives.</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_07_02"><title>Your text environment</title>
<sect2 id="sect_07_02_1"><title>Environment variables</title>
<para>We already mentioned a couple of environment variables, such as <varname>PATH</varname> and <varname>HOME</varname>. Until now, we only saw examples in which they serve a certain purpose to the shell. But there are many other Linux utilities that need information about you in order to do a good job.</para>
<para>What other information do programs need apart from paths and home directories?</para>
<para>A lot of programs want to know about the kind of terminal you are using; this information is stored in the <varname>TERM</varname> variable. In text mode, this will be the <emphasis>linux</emphasis> terminal emulation, in graphical mode you are likely to use <emphasis>xterm</emphasis>. Lots of programs want to know what your favorite editor is, in case they have to start an editor in a subprocess. The shell you are using is stored in the <varname>SHELL</varname> variable, the operating system type in <varname>OS</varname> and so on. A list of all variables currently defined for your session can be viewed entering the <command>printenv</command> command.</para>
<para>The environment variables are managed by the shell. As opposed to regular shell variables, environment variables are inherited by any program you start, including another shell. New processes are assigned a copy of these variables, which they can read, modify and pass on in turn to their own child processes.</para>
<para>There is nothing special about variable names, except that the common ones are in upper case characters by convention. You may come up with any name you want, although there are standard variables that are important enough to be the same on every Linux system, such as <varname>PATH</varname> and <varname>HOME</varname>.</para>
<para>The following table gives an overview of the most common predefined variables:</para>
<table frame="all">
<title>Common environment variables</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row><entry>Variable name</entry><entry>Stored information</entry></row>
</thead>
<tbody>
<row><entry><varname>DISPLAY</varname></entry><entry>used by the X Window system to identify the display server</entry></row>
<row><entry><varname>DOMAIN</varname></entry><entry>domain name</entry></row>
<row><entry><varname>EDITOR</varname></entry><entry>stores your favorite line editor</entry></row>
<row><entry><varname>HISTSIZE</varname></entry><entry>size of the shell history file in number of lines</entry></row>
<row><entry><varname>HOME</varname></entry><entry>path to your home directory</entry></row>
<row><entry><varname>HOSTNAME</varname></entry><entry>local host name</entry></row>
<row><entry><varname>INPUTRC</varname></entry><entry>location of definition file for input devices such as keyboard</entry></row>
<row><entry><varname>LANG</varname></entry><entry>preferred language</entry></row>
<row><entry><varname>LD_LIBRARY_PATH</varname></entry><entry>paths to search for libraries</entry></row>
<row><entry><varname>LOGNAME</varname></entry><entry>login name</entry></row>
<row><entry><varname>MAIL</varname></entry><entry>location of your incoming mail folder</entry></row>
<row><entry><varname>MANPATH</varname></entry><entry>paths to search for man pages</entry></row>
<row><entry><varname>OS</varname></entry><entry>string describing the operating system</entry></row>
<row><entry><varname>OSTYPE</varname></entry><entry>more information about version etc.</entry></row>
<row><entry><varname>PAGER</varname></entry><entry>used by programs like <command>man</command> which need to know what to do in case output is more than one terminal window.</entry></row>
<row><entry><varname>PATH</varname></entry><entry>serach paths for commands</entry></row>
<row><entry><varname>PS1</varname></entry><entry>primary prompt</entry></row>
<row><entry><varname>PS2</varname></entry><entry>secundary prompt</entry></row>
<row><entry><varname>PWD</varname></entry><entry>present working directory</entry></row>
<row><entry><varname>SHELL</varname></entry><entry>current shell</entry></row>
<row><entry><varname>TERM</varname></entry><entry>terminal type</entry></row>
<row><entry><varname>UID</varname></entry><entry>user ID</entry></row>
<row><entry><varname>USER(NAME)</varname></entry><entry>user name</entry></row>
<row><entry><varname>VISUAL</varname></entry><entry>your favorite full-screen editor</entry></row>
<row><entry><varname>XENVIRONMENT</varname></entry><entry>location of your personal settings for X behavior</entry></row>
<row><entry><varname>XFILESEARCHPATH</varname></entry><entry>paths to search for graphical libraries</entry></row>
</tbody>
</tgroup>
</table>
<para>A lot of variables are not only predefined but also preset, using configuration files. We discuss these in the next section.</para>
</sect2>
<sect2 id="sect_07_02_02"><title>Shell setup files</title>
<para>When entering the <command>ls -al</command> command to get a long listing of all files, including the ones starting with a dot, in your home directory, you will see one or more files starting with a . and ending in <emphasis>rc</emphasis>. For the case of <command>bash</command>, this is <filename>.bashrc</filename>. This is the counterpart of the system-wide configuration file <filename>/etc/bashrc</filename>.</para>
<para>When logging into an interactive login shell, <command>login</command> will do the authentication, set the environment and start your shell. In the case of <command>bash</command>, the next step is reading the general <filename>profile</filename> from <filename>/etc</filename>, if that file exists. <command>bash</command> then looks for <filename>~/.bash_profile</filename>, <filename>~/.bash_login</filename> and <filename>~/.profile</filename>, in that order, and reads and executes commands from the first one that exists and is readable. If none exists, <filename>/etc/bashrc</filename> is applied.</para>
<para>When a login shell exits, <command>bash</command> reads and executes commands from the file <filename>~/.bash_logout</filename>, if it exists.
</para>
<para>This procedure is explained in detail in the <command>login</command> and <command>bash</command> man pages.</para>
</sect2>
<sect2 id="sect_07_02_03"><title>A typical set of setup files</title>
<para>Let's look at some of these config files. First <filename>/etc/profile</filename> is read, in which important variables such as <varname>PATH</varname>, <varname>USER</varname> and <varname>HOSTNAME</varname> are set:</para>
<screen>
debby:~&gt;cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# Path manipulation
if [ `id -u` = 0 ] &amp;&amp; ! echo $PATH | /bin/grep -q "/sbin" ; then
PATH=/sbin:$PATH
fi
if [ `id -u` = 0 ] &amp;&amp; ! echo $PATH | /bin/grep -q "/usr/sbin" ; then
PATH=/usr/sbin:$PATH
fi
if [ `id -u` = 0 ] &amp;&amp; ! echo $PATH | /bin/grep -q "/usr/local/sbin" ; then
PATH=/usr/local/sbin:$PATH
fi
if ! echo $PATH | /bin/grep -q "/usr/X11R6/bin" ; then
PATH="$PATH:/usr/X11R6/bin"
fi
</screen>
<para>These lines check the path to set: if <emphasis>root</emphasis> opens a shell (user ID 0), it is checked that <filename>/sbin</filename>, <filename>/usr/sbin</filename> and <filename>/usr/local/sbin</filename> are in the path. If not, they are added. It is checked for everyone that <filename>/usr/X11R6/bin</filename> is in the path.</para>
<screen>
# No core files by default
ulimit -S -c 0 &gt; /dev/null 2&gt;&amp;1
</screen>
<para>All trash goes to <filename>/dev/null</filename> if the user doesn't change this setting.</para>
<screen>
USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
</screen>
<para>Here general variables are assigned their proper values.</para>
<screen>
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
</screen>
<para>If the variable <varname>INPUTRC</varname> is not set, and there is no <filename>.inputrc</filename> in the user's home directory, then the default input control file is loaded.</para>
<screen>
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
</screen>
<para>All variables are exported together.</para>
<screen>
for i in /etc/profile.d/*.sh ; do
if [ -r $i ]; then
. $i
fi
done
unset i
</screen>
<para>All readable shell scripts from the <filename>/etc/profile.d</filename> directory are read and executed. These do things like enabling <emphasis>color-ls</emphasis>, aliasing <command>vi</command> to <command>vim</command>, setting locales etc. The temporary variable <varname>i</varname> is unset to prevent it from disturbing shell behavior lateron.</para>
<para>Then <command>bash</command> looks for a <filename>.bash_profile</filename> in the user's home directory:</para>
<screen>
debby:~&gt;cat .bash_profile
#################################################################
# #
# .bash_profile file #
# #
# Executed from the bash shell when you log in. #
# #
#################################################################
DO_FORTUNE=1
source ~/.bashrc
source ~/.bash_login
case "$OS" in
IRIX)
stty sane dec
stty erase
;;
# SunOS)
# stty erase
# ;;
*)
stty sane
;;
esac
if test "$DO_FORTUNE" -a ! -f "$HOME/.hushlogin"; then
"$DO_FORTUNE"
fi
</screen>
<para>First, a variable is set that is used in the end to determine whether or not to display a fortune cookie. If the user has a <filename>~/.hushlogin</filename> file, which silences the login process (see <command>man login</command>), nothing is done. Then (this is a general config file for use on multiple architectures) terminal line settings are defined for operating systems that might make a fuss about them.</para>
<para>The <filename>~/.bash_login</filename> file defines default file protection by setting the <command>umask</command> value. The <filename>~/.bashrc</filename> is used to define a bunch of user-specific aliases and functions and personal environment variables. It first reads <filename>/etc/bashrc</filename>, which describes the default prompt (<varname>PS1</varname>) and the default umask value. After that, you can add your own settings. If no <filename>~/.bashrc</filename> exists, <filename>/etc/bashrc</filename> is read by default:</para>
<screen>
debby:~&gt;cat /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ `id -gn` = `id -un` -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -x /usr/bin/tput ]; then
if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal
stty erase `tput kbs`
elif [ -x /usr/bin/wc ]; then
if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb"\
terminal
stty erase `tput kbs`
fi
fi
fi
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] &amp;&amp; PROMPT_COMMAND=/etc/sysconfig/\
bash-prompt-default
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] &amp;&amp; PS1="[\u@\h \W]\\$ "
if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -x $i ]; then
. $i
fi
done
fi
fi
</screen>
<para>Upon logout, the commands in <filename>~/.bash_logout</filename> are executed, which can e.g. clear the terminal.</para>
<para>Let's take a closer look at how these scripts work in the next section. Keep <command>man bash</command> close at hand.</para>
</sect2>
<sect2 id="sect_07_02_04"><title>The Bash prompt</title>
<sect3 id="sect_07_02_04_01"><title>Introduction</title>
<para>
The Bash prompt can do much more than displaying such simple information as your user name, the name of your machine and some indication about the present working directory. We can add other information such as the current date and time, number of connected users etc.</para>
<para>Before we begin, however, we will save our current prompt in another environment variable:
</para>
<screen>
[jerry@nowhere jerry]$ MYPROMPT=$PS1
[jerry@nowhere jerry]$ echo $MYPROMPT
[\u@\h \W]\$
[jerry@nowhere jerry]$
</screen>
<para>When we change the prompt now, e.g. issuing the command <command>PS1="-&gt;"</command>, we can always get our original prompt back with the command <command>PS1=$MYPROMPT</command>. You will, of course, also get it back when you reconnect, as long as you just fiddle with the prompt on the command line and avoid putting it in a shell configuration file.</para>
</sect3>
<sect3 id="sect_07_02_04_02"><title>Some examples</title>
<para>In order to understand these prompts and the escape sequences used, we refer to the Bash Info or man pages.</para>
<itemizedlist>
<listitem><para><command>export PS1="[\t \j] "</command></para><para>Displays time of day and number of running jobs</para>
</listitem>
<listitem><para><command>export PS1="[\d][\u@\h \w] : "</command></para><para>Displays date, user name, host name and current working directory. Note that \W displays only base names of the present working directory.</para></listitem>
<listitem><para><command>export PS1="{\!} "</command></para><para>Displays history number for each command.</para></listitem>
<listitem><para><command>export PS1="\[\033[1;35m\]\u@\h\[\033[0m\] "</command></para><para>Displays user@host in pink.</para></listitem>
<listitem><para><command>export PS1="\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] "</command></para><para>Sets the user name in pink and the present working directory in blue.</para></listitem>
<listitem><para><command>export PS1="\[\033[1;44m\]$USER is in \w\[\033[0m\] "</command></para></listitem>
<listitem><para><command>export PS1=...</command></para></listitem>
</itemizedlist>
<para>Variables are exported so the subsequently executed commands will also know about the environment. The prompt configuration line that you want is best put in your shell configuration file, <filename>~/.bashrc</filename>.</para>
<para>If you want, prompts can execute shell scripts and behave different under different conditions. You can even have the prompt play a tune every time you issue a command, although this way it gets boring pretty soon. More information can be found in the <ulink url="http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/">Bash-Prompt HOWTO</ulink>.</para>
</sect3>
</sect2>
<sect2 id="sect_07_02_05"><title>Shell scripts</title>
<para>A shell script is, as we saw in the shell configuration examples, a text file containing shell commands. When such a file is used as the first non-option argument when invoking Bash, and neither the `-c' nor `-s' option is supplied, Bash reads and executes commands from the file, then exits. This mode of operation creates a non-interactive shell. When Bash runs a shell script, it sets the special parameter `0' to the name of the file, rather than the name of the shell, and the positional parameters are set to the remaining arguments, if any are given. If no additional arguments are supplied, the positional parameters are unset.</para>
<para>A shell script may be made executable by using the <command>chmod</command> command to turn on the execute bit. When Bash finds such a file while searching the <varname>PATH</varname> for a command, it spawns a sub-shell to execute it. In other words, executing</para>
<cmdsynopsis><command>filename <option>ARGUMENTS</option></command></cmdsynopsis>
<para>is equivalent to executing</para>
<cmdsynopsis><command>bash file_name <option>ARGUMENTS</option></command></cmdsynopsis>
<para>if `filename' is an executable shell script. This sub-shell reinitializes itself, so that the effect is as if a new shell had been invoked to interpret the script, with the exception that the locations of commands remembered by the parent (see <command>hash</command> in the Info pages) are retained by the child.</para>
<para>Most versions of UNIX make this a part of the operating system's command execution mechanism. If the first line of a script begins with the two characters `#!', the remainder of the line specifies an interpreter for the program. Thus, you can specify <command>bash</command>, <command>awk</command>, <command>perl</command> or some other interpreter or shell and write the rest of the script file in that language.</para>
<para>The arguments to the interpreter consist of a single optional argument following the interpreter name on the first line of the script file, followed by the name of the script file, followed by the rest of the arguments. Bash will perform this action on operating systems that do not handle it themselves.</para>
<para>Bash scripts often begin with `#! /bin/bash' (assuming that Bash has been installed in `/bin'), since this ensures that Bash will be used to interpret the script, even if it is executed under another shell.</para>
<sect3 id="sect_07_02_05_01"><title>Some simple examples</title>
<para>A very simple script consisting of only one command, that says hello to the user executing it:</para>
<screen>
#!/bin/bash
echo "Hello $USER"
</screen>
<para>The script actually consists of only one command, <command>echo</command>, which uses the <emphasis>value of</emphasis> ($) the <varname>USER</varname> environment variable to print a string customized to the user issuing the command.</para>
<para>Another on-liner, used for displaying connected users:</para>
<screen>
#!/bin/bash
who | cut -d " " -f 1 | sort -u
</screen>
<para>Here is a script consisting of some more lines, that I use to convert wav-files to mp3-format using the <command>lame</command> command. The script first makes a list of all wav-files in the current directory and puts it in the variable <varname>LIST</varname>. Then it sets the new name for each file, and converts the file format. After that, it cleans up the wav-files which are replaced by their mp3 counterparts:</para>
<screen>
tille:~>cat /usr/local/bin/wav2mp3
#!/bin/bash
# convert *.wav into *.mp3
LIST=$(ls *.wav)
for i in $LIST; do
ORIG=$i
DEST=$(ls $i | cut -d "." -f 1).mp3
lame -h $ORIG $DEST
echo "done converting $i, removing.."
rm $i
done
</screen>
<para>The <command>cut</command> command is used in this example to separate the actual file name from the file name suffix. Just entering a line like <command>mv *.wav *.mp3</command> won't work. An <command>echo</command> command was added in order to display some activity. <command>echo</command>'s are generally useful when a script won't work: insert one after each doubted step and you will find the error in no time.</para>
<para>The <filename>/etc/rc.d/init.d</filename> directory contains loads of examples. Let's look at this script that controls the RedHat Interchange server (E-commerce server), which uses somewhat more advanced techniques:</para>
<screen>
#!/bin/sh
#
# Run control script for Interchange
# http://interchange.redhat.com/
#
# chkconfig: 345 96 4
# description: Interchange is a database access and HTML templating system focused on ecommerce
# processname: interchange
# pidfile: /var/run/interchange/interchange.pid
# config: /etc/interchange.cfg
# config: /var/lib/interchange/*/catalog.cfg
# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
start)
echo -n "Starting Interchange: "
daemon interchange -q
echo
touch /var/lock/subsys/interchange
;;
stop)
echo -n "Shutting down Interchange: "
killproc interchange
echo
rm -f /var/lock/subsys/interchange
rm -f /var/run/interchange/interchange.pid
;;
status)
status interchange
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
</screen>
<para>First, with the <command>.</command> command a set of functions, used by almost all shell scripts in <filename>/etc/rc.d/init.d</filename>, is loaded. Then a <command>case</command> command is issued, which defines 4 different ways the script can execute. An example might be <command>interchange start</command>. The decision of which case to apply is made by reading the (first) argument to the script, with the expression <emphasis>$1</emphasis>.</para>
<para>When no compliant input is given, the default case, *, is applied, upon which the script gives an error message. The <command>case</command> list is ended with the <command>esac</command> statement. In the <emphasis>start</emphasis> case the server program is started as a daemon, and a PID and lock are assigned. In the <emphasis>stop</emphasis> case, the server is traced down and stopped, the lock and the PID are removed, etc. Each case is defined in the <filename>functions</filename> file. Options, such as the <option>daemon</option> option, and functions like <option>killproc</option>, are also defined in this file.</para>
<para>Upon success, the script returns an exit code of zero to its parent.</para>
<para>
This script is a fine example of using functions, which make the script easier to read and the work done faster. Note that they use <command>sh</command> instead of <command>bash</command>, to make them useful on a wider range of systems.</para>
<para>The <command>bash</command> man pages contain more information about combining commands, for- and while-loops and regular expressions, as well as examples.</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_7_03"><title>The graphical environment</title>
<sect2 id="sect_7_03_01"><title>Introduction</title>
<para>The average user may not care too much about his login settings, but Linux offers a wide variety of flashing window managers for use under X, the graphical environment. The use and configuration of window managers is straightforward and may even resemble the standard MS Windows, MacIntosh or UNIX CDE environment, although many Linux users prefer flashier desktops using Sawfish, KDE, Gnome or other window managers. We won't discuss the user specific configuration here. Just experiment and read the documentation using the built-in Help functions these managers provide and you will get along fine.</para>
<para>We will, however, take a closer look at the underlying system.</para>
</sect2>
<sect2 id="sect_07_03_02"><title>The X Window System</title>
<para>The X Window System is a network-transparent window system which runs on a wide range of computing and graphics machines. X Window System servers run on computers with bitmap displays. The server distributes user input to and accepts output requests from several client programs through a variety of different interprocess communication channels. Although the most common case is for the client programs to be running on the same machine as the server, clients can be run transparently from other machines (including machines with different architectures and operating systems) as well. We will learn how to do this in <xref linkend="chap_10" /> on networking and remote applications.</para>
<para>X supports overlapping hierarchical sub-windows and text and graphics operations, on both monochrome and color displays. The number of programs that use X is quite large. Some of the programs provided in the core X Consortium distribution include:</para>
<itemizedlist>
<listitem><para><command>xterm</command>: a terminal emulator</para></listitem>
<listitem><para><command>twm</command>: a minimalistic window manager</para></listitem>
<listitem><para><command>xdm</command>: a display manager</para></listitem>
<listitem><para><command>xconsole</command>: a console redirect program</para></listitem>
<listitem><para><command>bitmap</command>: a bitmap editor</para></listitem>
<listitem><para><command>xauth</command>, <command>xhost</command> and <command>iceauth</command>: access control programs</para></listitem>
<listitem><para><command>xset</command>, <command>xmodmap</command> and many others: user preference setting programs</para></listitem>
<listitem><para><command>xclock</command>: a clock</para></listitem>
<listitem><para><command>xlsfonts</command> and others: a font displayer, utilities for listing information about fonts, windows and displays</para></listitem>
<listitem><para><command>xfs</command>: a font server</para></listitem>
<listitem><para>...</para></listitem>
</itemizedlist>
<para>We refer again to the man pages of these commands for detailed information. More explanations on available functions can be found in the <emphasis>Xlib - C language X Interface</emphasis> manual that comes with your X distribution, the <emphasis>X Window System Protocol</emphasis> specification, and the various manuals and documentation of X toolkits. The <filename>/usr/share/doc</filename> directory contains references to these documents and many others.</para>
<para>Many other utilities, window managers, games, toolkits and gadgets are included as user-contributed software in the X Consortium distribution, or are available using anonymous FTP on the Internet. Good places to start are <ulink url="http://www.x.org">http://www.x.org</ulink> and <ulink url="http://www.xfree.org">http://www.xfree.org</ulink>.</para>
<sect3 id="sect_07_03_02_01"><title>Display names</title>
<para>From the user's perspective, every X server has a <emphasis>display name</emphasis> in the form of:</para>
<cmdsynopsis><command>hostname:displaynumber.screennumber</command></cmdsynopsis>
<para>This information is used by the application to determine how it should connect to the server and which screen it should use by default (on displays with multiple monitors):</para>
<itemizedlist>
<listitem><para><emphasis>hostname</emphasis>: The host name specifies the name of the machine to which the display is physically connected. If the host name is not given, the most efficient way of communicating to a server on the same machine will be used.</para></listitem>
<listitem><para><emphasis>displaynumber</emphasis>: The phrase <quote>display</quote> is usually used to refer to a collection of monitors that share a common key board and pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one display. Larger, multi-user systems, however, frequently have several displays so that more than one person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a <emphasis>display number</emphasis> (beginning at 0) when the X server for that display is started. The display number must always be given in a display name.</para></listitem>
<listitem><para><emphasis>screen number</emphasis>: Some displays share a single keyboard and pointer among two or more monitors. Since each monitor has its own set of windows, each screen is assigned a <emphasis>screen number</emphasis> (beginning at 0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.</para></listitem>
</itemizedlist>
<para>On POSIX systems, the default display name is stored in your <varname>DISPLAY</varname> environment variable. This variable is set automatically by the <command>xterm</command> terminal emulator. However, when you log into another machine on a network, you will need to set <varname>DISPLAY</varname> by hand to point to your display.</para>
<para>More information can be found in the X man pages.</para>
</sect3>
<sect3 id="sect_07_03_02_02"><title>Window managers</title>
<para>The layout of windows on the screen is controlled by special programs called <emphasis>window managers</emphasis>. Although many window managers will honor geometry specifications as given, others may choose to ignore them (requiring the user to explicitly draw the window's region on the screen with the pointer, for example).</para>
<para>Since window managers are regular (albeit complex) client programs, a variety of different user interfaces can be built. The X Consortium distribution comes with a window manager named <command>twm</command>, but most users prefer something more fancy when system resources permit.</para>
</sect3>
</sect2>
<sect2 id="sect_07_03_03"><title>X server configuration</title>
<para>The X distribution that comes with Linux, <emphasis>XFree86</emphasis>, uses the configuration file <filename>XF86Config</filename> for its initial setup. This file configures your video card and is searched for in a number of locations, although it is usually in <filename>/etc/X11</filename>. This file is composed of a number of sections which may be present in any order:</para>
<itemizedlist>
<listitem><para><emphasis>Files</emphasis>: File pathnames</para></listitem>
<listitem><para><emphasis>ServerFlags</emphasis>: Server options</para></listitem>
<listitem><para><emphasis>Module</emphasis>: Dynamic module loading</para></listitem>
<listitem><para><emphasis>InputDevice</emphasis>: Input device description</para></listitem>
<listitem><para><emphasis>Device</emphasis>: Graphics device description</para></listitem>
<listitem><para><emphasis>VideoAdapter</emphasis>: Video adapter description</para></listitem>
<listitem><para><emphasis>Monitor</emphasis>: Monitor description</para></listitem>
<listitem><para><emphasis>Modes</emphasis>: Video modes (modlines) description</para></listitem>
<listitem><para><emphasis>Screen</emphasis>: Screen configuration</para></listitem>
<listitem><para><emphasis>ServerLayout</emphasis>: Overall layout</para></listitem>
<listitem><para><emphasis>DRI</emphasis>: DRI-specific configuration (3D settings)</para></listitem>
<listitem><para><emphasis>Vendor</emphasis>: Vendor-specific configuration</para></listitem>
</itemizedlist>
<para>A full description can be found in the Info or man pages about <filename>XF86Config</filename>. As a user, you needn't worry too much about what is in this file, since everything is normally determined at the time the system is installed.</para>
<para>Should you need to change graphical server settings, however, you can run the <command>Xconfigurator</command> manually as <emphasis>root</emphasis>. <command>Xconfigurator</command> sets up the necessary configuration files and file links to use XFree86 on a RedHat system. See the man page for more information; your distribution might have its own tool. Since misconfiguration may result in unreadable garbage in graphical mode, you may want to make a backup copy of the <filename>XF86Config</filename> file before attempting to change it, just to be on the safe side.</para>
</sect2>
</sect1>
<sect1 id="sect_07_04"><title>Sound card configuration</title>
<sect2 id="sect_07_04_01"><title>When all works fine</title>
<para>Most Linux distributions provide tools that probe your system for sound cards. Most currently available plug-and-play sound cards should be recognized automatically. If you can hear the samples, just click <guibutton>OK</guibutton> and everything will be set up for you.</para>
<para>If your card is not detected automatically, you may be presented with a list of sound cards and/or of sound card properties from which to choose. After that, you will have to provide the correct I/O port, IRQ and DMA settings. Information about these settings can be found in your sound card documentation. If you are on a dual boot system with MS Windows, this information can be found in the Windows Control Panel.</para>
</sect2>
<sect2 id="sect_07_04_02"><title>If automatic sound card detection does not work</title>
<para>
If your soundcard is not supported, you will need to apply other techniques. These are described in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Sound-HOWTO/index.html">Linux Sound HOWTO</ulink>.</para>
</sect2>
<sect2 id="sect_07_04_03"><title>Sound-playing</title>
<para>General sound playing is discussed in the <ulink url="http://www.ibiblio.org/mdw/HOWTO/Sound-Playing-HOWTO.html">Sound-Playing HOWTO</ulink>. Since most of this is handled automatically on an up-to-date Linux system, providing all kinds of media players, mixers and sequencers, we won't discuss sound any further here.</para>
<note><title>You and the others</title>
<para>Regardless of how you chose to listen to music or other sounds, remember that there may be other people who may not be interested in hearing you or your computer. Try to be courteous, especially in office environments.</para>
</note>
</sect2>
</sect1>
<sect1 id="sect_07_05"><title>Region specific settings</title>
<sect2 id="sect_07_05_01"><title>System configuration</title>
<sect3 id="sect_07_05_01_01"><title>Keyboard setup</title>
<para>Setting the keyboard layout is done using the <command>loadkeys</command> command for text consoles. You may then run <command>Xconfigurator</command> or edit the <emphasis>Keyboard</emphasis> section in <filename>XF86Config</filename> manually to configure the layout for graphical mode. The Gnome Keyboard Applet enables real-time switching between layouts.</para>
</sect3>
<sect3 id="sect_07_05_01_02"><title>Fonts</title>
<para>Use the <command>setfont</command> tool to load fonts in text mode. RedHat comes with a standard <filename>inputrc</filename> file which enables combining of characters, such as é (meta characters). The system admin should then add the line</para>
<screen>
export INPUTRC="/etc/inputrc"
</screen>
<para>to the <filename>/etc/bashrc</filename> file. The environment variables <varname>LC_CTYPE</varname>, <varname>SYSFONT</varname> and <varname>SYSTERM</varname> need to be set to appropriate values.</para>
<para>To ensure the use of the right font for the Euro symbol, set <varname>SYSFONT</varname> to <emphasis>lat0-16.psf</emphasis>.</para>
</sect3>
<sect3 id="sect_07_05_01_03"><title>Time zone</title>
<para>RedHat provides the <command>timeconfig</command> tool to configure system time parameters. Information about the system clock is set in <filename>/etc/sysconfig/clock</filename>, time zone data in <filename>/etc/localtime</filename>.</para>
<para>Setting time information is usually done at installation time. After that, it can be kept up to date using an NTP (Network Time Protocol) client. Most Linux systems support <command>ntpd</command> by default. See the documentation that comes with the package.</para>
</sect3>
<sect3 id="sect_07_05_01_04"><title>Language</title>
<para>If you'd rather get your messages from the system in Dutch or French, you may want to set the <varname>LANG</varname> and <varname>LANGUAGE</varname> environment variables, thus enabling locale support for the desired language.</para>
</sect3>
<sect3 id="sect_07_05_01_05"><title>Specific information for Belgium</title>
<para>The <ulink url="http://www.ibiblio.org/mdw/HOWTO/Belgian-HOWTO/index.html">Belgian HOWTO</ulink> gives more detailed information on configuring your machine for Flanders, la Wallonie and the Oostkantons, on how to get on the Internet in Belgium and contains a list of Belgian providers of Linux related commercial and free services.</para>
<para>The <ulink url="http://www.ibiblio.org/mdw/HOWTO/Francophones-HOWTO.html">Francophones HOWTO</ulink> discusses the available support for the French language indepth.</para>
</sect3>
<sect3 id="sect_07_05_01_06"><title>Other countries</title>
<para>The <ulink url="http://www.tldp.org/HOWTO/HOWTO-INDEX/howtos.html">list of HOWTOs</ulink> contains references to Belarusian, Chinese, Esperanto, Finnish, Hebrew, Hellenic, Latvian, Polish, Portugese, Serbian, Slovak, Slovenian, Spanish, Thai and Turkish localization instructions.</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_07_06"><title>Installing new software</title>
<sect2 id="sect_07_06_01"><title>General</title>
<para>Most people are surprised to see that they have a running, usable computer after installing Linux; most distributions contain ample support for video and network cards, monitors and other external devices, so there is usually no need to install extra drivers. Also common tools such as office suites, web browsers, E-mail clients and such are included in the main distributions. Even so, an initial installation might not meet your requirements.</para>
<para>If you just can't find what you need, maybe it is not installed on your system. It may also be that you have the required software, but it does not do what it is supposed to do. Remember that Linux moves fast, and software improves on a daily basis. Don't waste your time troubleshooting problems that might already be resolved.</para>
<para>You can update your system or add packages to it at any time you want. Most software comes in packages. Extra software may be found on your installation CDs or on the Internet. The website of your Linux distribution is a good place to start looking for additional software and containes instructions about how to install it on your type of Linux, see <xref linkend="app1" />. Always read the documentation that comes with new software, and any installation guidelines the package might contain. All software comes with a <filename>README</filename> file, which you are very strongly advised to read.</para>
</sect2>
<sect2 id="sect_07_06_02"><title>Package formats</title>
<sect3 id="sect_07_06_02_01"><title>RPM packages</title>
<para>RPM, the RedHat Package Manager, is a powerful package manager that you can use to install, update and remove packages. It allows you to search for packages and keeps track of the files that come with each package. A system is built in so that you can verify the authenticity of packages downloaded from the Internet. Advanced users can build their own packages with RPM.</para>
<para>An RPM package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package. Packages come in two varieties: binary packages, used to encapsulate software to be installed, and source packages, containing the source code and recipe necessary to produce binary packages.</para>
<para>Many other distributions support RPM packages, among the popular ones Mandrake and SuSE Linux. Apart from the advice for your distribution, you will want to read <command>man rpm</command>.</para>
<para>Most packages are simply installed with the upgrade option, whether the package is already installed or not. The RPM package contains a complete version of the program, which overwrites existing versions or installs as a new package.</para>
<para>New kernel packages, however, are installed with the install option which does not overwrite existing version(s) of the package, least to be able to boot your system with the old kernel if the new one does not work.</para>
<para>The <ulink url="http://www.ibiblio.org/mdw/HOWTO/RPM-HOWTO/index.html">RPM HOWTO</ulink> contains further references.</para>
</sect3>
<sect3 id="sect_07_06_02_02"><title>DEB packages</title>
<para>This package format is the default on Debian GNU/Linux, where <command>dselect</command> is the standard tool for managing the packages. It is used to select packages that you want to install or upgrade, but it will also run during the installation of a Debian system and help you to define the access method to use, to list available packages and to configure packages.</para>
<para>The <ulink url="http://debian.org">Debian web site</ulink> contains all information you need, including a <emphasis>dselect Documentation for Beginners</emphasis>.</para>
</sect3>
<sect3 id="sect_07_06_02_03"><title>Source packages</title>
<para>The largest part of Linux programs is Free/Open Source, so source packages are available for these programs. Source files are needed for compiling your own program version. Sources are provided when you install development packages or can be downloaded from the particular web site for a program, in the raw (<filename>program-version.tar.gz</filename> or similar) or packaged in an RPM or Debian package.</para>
<para>Specific requirements, dependencies and installation instructions are provided in the <filename>README</filename> file. You will probably need a C compiler, <command>gcc</command>. This GNU C compiler is included in most Linux systems and is ported to many other platforms.</para>
</sect3>
</sect2>
<sect2 id="sect_07_06_03"><title>Automating package management and updates</title>
<sect3 id="sect_07_06_03_01"><title>General remarks</title>
<para>The first thing you do after installing a new system is applying updates;
this applies to all operating systems and Linux is not different.</para>
<para>The updates for most Linux systems can usually be found on a nearby site mirroring your distribution. Lists of sites offering this service can be found at your distribution's web site, see <xref linkend="app1" />.</para>
<para>Updates should be applied regularly, daily if possible - but every couple of weeks would be a reasonable start. You really should try to have the most recent versions of all packages, since Linux changes constantly. As we said before, new features, improvements and bug fixes are supplied at a steady rhythm, and sometimes important security problems are addressed. All this not because Linux is a sloppy system, but rather because the Linux user is not easily satisfied. We want our software to be the best, but getting there and staying there demands some flexibility.</para>
<para>The good news is that most Linux distributions provide tools so that you don't have to upgrade tens of packages daily by hand. The following sections give an overview of <quote>package manager managers.</quote> There is much more to this subject, even regular updates of source packages is manageable automatically; we only list the most commonly known systems. Always refer to the documentation for your specific distribution for advised procedures.</para>
</sect3>
<sect3 id="sect_07_06_03_02"><title>APT</title>
<para>The Advanced Package Tool is a management system for software packages. The command line tool for handling packages is <command>apt-get</command>, which comes with an excellent man page describing how to install and update packages and how to upgrade singular packages or your entire distribution. APT has its roots in the Debian GNU/Linux distribution, where it is the default manager for the Debian packages. APT has been ported to work with RPM packages as well. The main advantage of APT is that it is free and flexible to use. It will allow you to set up systems similar to the distribution specific (and in some cases commercial) ones listed in the next sections.</para>
<para>More information can be found in the <ulink url="http://www.debian.org/doc/user-manuals#apt-howto">APT HOWTO</ulink>.</para>
</sect3>
<sect3 id="sect_07_06_03_03"><title>Systems supporting RPM packages</title>
<para>RedHat Linux has the <command>up2date</command>, the Update Agent, which provides a complete system for updating the RPM packages on a RedHat Linux system. Both command line and graphical interfaces are supported. Use for one machine is free, but for updating multiple systems you need to subscribe to RedHat Network web interface and pay a fee per host.</para>
<para>On SuSE Linux, everything is done with <emphasis>YaST</emphasis>, Yet another Setup Tool, which supports a wide variety of system administration tasks, among which updating RPM packages. Starting from SuSE Linux 7.1 you can also upgrade using a web interface and <emphasis>YOU</emphasis>, Yast Online Update.</para>
<para>Mandrake Linux provides so-called URPMI tools, a set of wrapper programs that make installing new software easier for the user. These tools combine with RPMDrake and MandrakeUpdate to provide everything needed for smooth install and uninstall of software packages. MandrakeOnline offers an extended range of services and can automatically notify administrators when updates are available for your particular Mandrake system. Also the KDE and Gnome desktop suites have their own (graphical) versions of package managers, such as <emphasis>gnorpm</emphasis> and <emphasis>KPackage</emphasis>.</para>
</sect3>
<sect3 id="sect_07_06_03_04"><title>Systems supporting DEB packages</title>
<para><ulink url="http://www.ximian.com">Ximian</ulink>, a Linux desktop software vendor, has developed RedCarpet, a graphical tool that you can use to subscribe to different upgrade <quote>channels</quote>. Different channels are available for upgrading a series of Linux distributions and versions, and for upgrading individual Ximian products, such as the Ximian desktop, the E-mail client Evolution, the upgrade tool itself and much more.</para>
<para>Ximian currently supports RedHat, Debian, Mandrake, Solaris, Suse and YellowDog systems.</para>
</sect3>
</sect2>
<sect2 id="sect_07_06_04"><title>Upgrading your kernel</title>
<para>Most Linux installations are fine if you periodically upgrade your distribution. The upgrade procedure will install a new kernel when needed and make all necessary changes to your system. You should only compile or install a new kernel manually if you need kernel features that are not supported by the default kernel included in your Linux distribution.</para>
<para>Whether compiling your own optimized kernel or using a pre-compiled kernel package, install it in co-existence with the old kernel until you are sure that everything works according to plan.</para>
<para>Then create a dual boot system that will allow you to choose which kernel to boot by updating your boot loader configuration file <filename>grub.conf</filename>. This is a simple example:</para>
<screen>
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hde8
# initrd /initrd-version.img
#boot=/dev/hde
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux new (2.4.9-31)
root (hd0,0)
kernel /vmlinuz-2.4.9-31 ro root=/dev/hde8
initrd /initrd-2.4.9-31.img
title old-kernel
root (hd0,0)
kernel /vmlinuz-2.4.9-21 ro root=/dev/hde8
initrd /initrd-2.4.9-21.img
</screen>
<para>After the new kernel has proven to work, you may remove the lines for the old one from the GRUB config file, although it is best to wait a couple of days just to be sure.</para>
</sect2>
<sect2 id="sect_07_06_05"><title>Installing extra packages from the installation CDs</title>
<para>This is basically done in the same way as installing packages manually, except that you have to append the file system of the CD to your machine's file system to make it accessible. On most systems, this will be done automatically upon insertion of a CD in the drive. If not, issue the <command>mount</command> command in a terminal window. Depending on your actual system configuration, a line similar to this one will usually do the trick:</para>
<para><cmdsynopsis><command>mount <filename>/dev/cdrom /mnt/cdrom</filename></command></cmdsynopsis></para>
<para>You may even try to right click on the CD icon on your desktop to mount the CD if your file manager doesn't do it for you. You can check whether it worked issuing the <command>mount</command> command with no arguments:</para>
<screen>
[david@jupiter ~] mount | grep cdrom
/dev/cdrom on /mnt/cdrom type iso9660 (ro,nosuid,nodev)
</screen>
<para>After that, you can change to a subdirectory of <filename>/mnt/cdrom</filename> or your mount directory and install the required packages. Note that in order to detach the CD-ROM file system from your own file system, it should be unused. Stop using the data on the CD and leave the <filename>/mnt/cdrom</filename> directory. After that, you can unmount the CD, either using the graphical interface or issuing a command like <command>eject <option>cdrom</option></command> or <command>umount <filename>/mnt/cdrom</filename></command>.</para>
<para>After mounting the CD, you can change directories, usually to <filename>/mnt/cdrom</filename>, where you can access the content of the CD-ROM. Use <command>rpm</command> just like described in the above section to install additional packages.</para>
</sect2>
</sect1>
<sect1 id="sect_07_07"><title>Summary</title>
<para>When everything has its place, that means already half the work is done.</para>
<para>While keeping order is important, it is equally important to feel at home in your environment, whether text or graphical. The text environment is controlled through the shell setup files. The graphical environment is primarily dependent on the X server configuration, on which a number of other applications are built, such as window and desktop managers and graphical applications, each with their own config files. You should read the system and program specific documentation to find out about how to configure them.</para>
<para>Regional settings such as keyboard setup, installing appropriate fonts and language support are best done at installation time.</para>
<para>Software is managed either automatically or manually using the RPM system.</para>
</sect1>
<sect1 id="sect_07_08"><title>Exercises</title>
<sect2 id="sect_07_08_01"><title>Shell environment</title>
<itemizedlist>
<listitem><para>Print out your environment settings. Which variable may be used to store the CPU type of your machine?</para></listitem>
<listitem><para>Make a script that can say something on the lines of <quote>hello, world.</quote> Give it appropriate permissions so it can be run. Test your script.</para></listitem>
<listitem><para>Create a directory in your home directory and move the script to the new directory. Permanently add this new directory to your search path. Test that the script can be executed without giving a path to its actual location.</para></listitem>
<listitem><para>Create a personalized prompt.</para></listitem>
<listitem><para>Display limits on resource usage. Can you change them?</para></listitem>
<listitem><para>Try to read compressed man pages without decompressing them first.</para></listitem>
<listitem><para>Make an alias <command>lll</command> which actually executes <command>ls -la</command>.</para></listitem>
<listitem><para>Why does the command <command>tail testfile &gt; testfile</command> not work?</para></listitem>
<listitem><para>Find out how to use the shell as a calculator.</para></listitem>
<listitem><para>Write a script that will move all files in a directory to <filename>filename.old</filename>.</para></listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_07_08_02"><title>Graphical environment</title>
<itemizedlist>
<listitem><para>Try all the mouse buttons in different regions (terminal, background, task bar).</para></listitem>
<listitem><para>Explore the menus.</para></listitem>
<listitem><para>Customize your terminal window.</para></listitem>
<listitem><para>Use the mouse buttons to copy and paste text from one terminal to another.</para></listitem>
<listitem><para>Find out how to configure your window manager; try different workspaces (virtual screens).</para></listitem>
<listitem><para>Add an applet, such as a load monitor, to the task bar.</para></listitem>
<listitem><para>Apply a different theme.</para></listitem>
<listitem><para>Enable the so-called <emphasis>sloppy</emphasis> focus.</para></listitem>
<listitem><para>Switch to a different window manager.</para></listitem>
<listitem><para>Log out and select a different session type, like KDE if you were using Gnome before. Repeat the previous steps.</para></listitem>
</itemizedlist>
</sect2>
</sect1>
</chapter>

View File

@ -0,0 +1,235 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_08">
<title>Printers and printing</title>
<abstract>
<para>In this chapter we will learn more about printers and printing files. After reading this part, you will be able to:</para>
<para>
<itemizedlist>
<listitem><para>Format documents</para></listitem>
<listitem><para>Print files and check on printer status</para></listitem>
<listitem><para>Troubleshoot printing</para></listitem>
<listitem><para>Install a printer</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1><title>Printing files</title>
<sect2><title>General</title>
<para>RedHat ships with LPRng, an improved version of the well-known UNIX print system. If the printer has been set up, all you need to do is learn how to use <command>lpr</command> to send files to the printer, which basically comes down to</para>
<cmdsynopsis><command>lpr <filename>file(s)</filename></command></cmdsynopsis>
<para><command>Lpr</command> uses a spooling daemon, <command>lpd</command> to print the named files when facilities become available. If no names appear, standard input is assumed (such as when the output of a command is piped into <command>lpr</command>). The <command>lpr</command> command has a lot of options, which can be displayed using the <option>--help</option> option. Full information is in the Info pages. You will also find the <command>lp</command> command on your Linux system, for compatibility reasons with other (UNIX) programs. You will find that <command>lp</command> is in fact a symbolic link to <command>lpr</command>:</para>
<screen>
davy:~&gt;ls -l /usr/bin/lp*
lrwxrwxrwx 1 root root 3 Oct 28 14:21 /usr/bin/lp -> lpr
-rwxr-xr-x 1 lp lp 395192 Aug 11 2001 /usr/bin/lpq
-rwxr-xr-x 1 lp lp 408536 Aug 11 2001 /usr/bin/lpr
-rwxr-xr-x 1 lp lp 392984 Aug 11 2001 /usr/bin/lprm
-rwxr-xr-x 1 root root 4651 Oct 19 22:17 /usr/bin/lprsetup.sh
-rwxr-xr-x 1 lp lp 398488 Aug 11 2001 /usr/bin/lpstat
davy:~&gt;ps -ef | grep lpd
lp 1003 1 0 Feb22 ? 00:00:00 lpd Waiting
</screen>
<para>Once the file is accepted in the print queue, an identification number for the print job is assigned:</para>
<screen>
davy:~&gt;lp /etc/profile
request id is davy@blob+253
</screen>
<para>To view (query) the print queue, use the <command>lpq</command> command. When entered without arguments, it displays the contents of the default print queue.</para>
<screen>
davy:~&gt;lpq
Printer: lp@blob
Queue: no printable jobs in queue
Status: job 'cfA284blob.somewhere.org' removed at 11:02:47.098
</screen>
<para>If you don't like what you see, use <command>lprm</command> to delete jobs. Use <command>lprm -</command> to delete all jobs which you submitted. If you only want to cancel one job, use the number of that job as an argument to <command>lprm</command>.</para>
<para>In larger environments, <command>lpc</command> may be used to control multiple printers. See the Info on each command.</para>
<para>There are many GUI print tools used as a front-end to <command>lpr</command>, and most graphical applications have a print function that uses <command>lpr</command>. See the built-in Help functions and program specific documentation for more.</para>
</sect2>
<sect2><title>Formatting</title>
<sect3><title>Tools</title>
<para>If we want to get something sensible out of the printer, files should be formatted first. Apart from an abundance of formatting software, Linux comes with the basic UNIX formatting tools and languages.</para>
<para>Most markup languages are more suitable for large or repetitive jobs, where the computer controls the layout of the text, like when executing scripts.</para>
<itemizedlist>
<listitem><para><command>groff</command>: GNU version of the UNIX <command>roff</command> command. It is a front-end to the groff document formatting system. Normally it runs the <command>troff</command> command and a post-processor appropriate for the selected device. It allows generation of PostScript files.</para></listitem>
<listitem><para><emphasis>TeX</emphasis> and the macro package <emphasis>LaTeX</emphasis>: one of the most widely used markup languages on UNIX systems. Usually invoked as <command>tex</command>, it formats files and outputs a corresponding device-independent representation of the typeset document.</para>
<para>Technical works are <emphasis>still</emphasis> frequently written in LaTeX because of its support for mathematic formulas, although efforts are being made at <ulink url="http://www.w3.org">W3C</ulink> (the World Wide Web Consortium) to include this feature in other applications.</para></listitem>
<listitem><para>SGML and XML: Free parsers are available for UNIX and Linux. XML is the next generation SGML, it forms the basis for DocBook XML, a document system (this book is written in XML, for instance).</para></listitem>
</itemizedlist>
<para>Linux comes with a lot of formatting tools, such as <command>pdf2ps</command>, <command>fax2ps</command> and <command>a2ps</command>.</para>
<para>Apart from these command line tools there are a lot of graphical word processing programs. Several complete office suites are available, many are free. These do the formatting automatically upon submission of a print job. Just to name a few: AbiWord, KWord, StarOffice, OpenOffice, Applix, WordPerfect, etc.</para>
<note><title>Printing documentation</title>
<para>The man pages contain pre-formatted <command>troff</command> data, they have to be formatted as well. Printing is done using the <option>-t</option> option:</para>
<cmdsynopsis><command>man <option>-t</option> command &gt; man-command.ps</command></cmdsynopsis>
<para>Then print the PostScript file. For printing Info pages, refer to the Info pages on <command>info</command> (you will need the source code of the command).</para></note>
</sect3>
<sect3><title>Previewing formatted files</title>
<para>Anything you can send to the printer, can normally be sent to the screen as well. Depending on the file format, you can use one of these commands:</para>
<itemizedlist>
<listitem><para>PostScript files: with the <command>gv</command> (GhostView) command.</para></listitem>
<listitem><para>TeX dvi files: with <command>xdvi</command>.</para></listitem>
<listitem><para>PDF files: <command>xpdf</command> or Adobe's viewer, <command>acroread</command>, which is also available for free.</para></listitem>
</itemizedlist>
</sect3>
</sect2>
</sect1>
<sect1><title>The server side</title>
<sect2><title>General</title>
<para>Until a couple of years ago, the choice for Linux users was simple: everyone ran the same old LPD, lifted mostly verbatim out of BSD's Net-2 code.</para>
<para>Today there are a number of systems to chose from. RedHat comes with LPRng, the original BSD UNIX Line Printer Daemon (LPD) revisited. LPD is also the name given to the network printing protocol. This network protocol is spoken not only by the LPD daemon itself, but by essentially every networked print-server, networked printer, and every other print spooler out there; LPD is the least common denominator of standards-based network printing.
</para>
<para> LPRng is a far better implementation of the basic LPD design than the regular one; if you must use LPD, consider using LPRng instead. There is far less voodoo involved in making it do what you want, and what voodoo there is is well documented.</para>
<para>LPRng is far easier to administer for large installations (read: more than one printer, any serial printers, or any peculiar non-lpd network printers) and has a less haphazard code base than does stock lpd. It can even honestly claim to be secure - there are no SUID binaries, and it supports authentication via PGP or Kerberos.
</para>
</sect2>
<sect2><title>The RedHat printtool</title>
<para>RedHat has a GUI printer administration tool called <command>printtool</command>, which can add remote printers and printers on local devices. It lets you choose a ghostscript-supported printer type and UNIX device file to print to, then installs a print queue in <filename>/etc/printcap</filename>. This file is best not edited by hand:</para>
<screen>
# DO NOT EDIT! MANUAL CHANGES WILL BE LOST!
# This file is autogenerated by printconf-backend during lpd init.
#
# Hand edited changes can be put in /etc/printcap.local, and will be included.
lp:\
:ml=0:\
:mx=0:\
:sd=/var/spool/lpd/lp:\
:af=/var/spool/lpd/lp/lp.acct:\
:sh:\
:lp=|/usr/share/printconf/util/jetdirectprint:\
:lpd_bounce=true:\
:if=/usr/share/printconf/util/mf_wrapper:
</screen>
<para>
The <command>printtool</command> doesn't require you to learn LPD commands. Newer installations no longer include <command>printtool</command> but use <command>printconf</command> instead, which has both a text and a graphical user interface. Both interfaces look the same, the differences have mainly to do with how information is stored. More information, including adding printers for MS Windows clients, can be found in <filename>/usr/share/doc/printconf-&lt;version&gt;/</filename>.</para>
<figure><title>RedHat printconf-gui</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/printconf.eps" format="EPS"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/printconf.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>Most Linux distributions have their own version of a graphical print tool.</para>
</sect2>
<sect2><title>CUPS</title>
<para>An interesting new project is the Common UNIX Print System, an implementation of the Internet Printing Protocol (IPP), an HTTP-like RFC standard replacement protocol for the venerable (and clunky) LPD protocol. CUPS is distributed under the GNU Public License.</para>
<para>
More information can be found at <ulink url="http://www.cups.org">the CUPS homepage</ulink>.</para>
</sect2>
<sect2><title>Buying a printer for Linux</title>
<para> The Linux kernel will let you speak with any printer that you can plug into a serial, parallel, or USB port, plus any printer on the network, but this alone is insufficient; you must also be able to generate data that the printer will understand.</para>
<para>Linux supports almost any HP- and/or IBM-compatible printer. Generally, all printers that can be used on Windows NT or UNIX are fit for Linux as well.</para>
<para>Printers that only come with a Win9x driver could be problematic if they have no other support. Check with the hardware compatibility HOWTO when in doubt.</para>
<para>Your best choice would be a printer with native PostScript support in the firmware, since nearly all UNIX or Linux software producing printable output, produces it in PostScript, the publishing industry's printer control language of choice. PostScript printers are usually a bit more expensive, but it is a device-independent, open programming language.</para>
</sect2>
</sect1>
<sect1><title>Print problems</title>
<para>In this section, we will discuss what you can do as a user when something goes wrong. We won't discuss any problems that have to do with the daemon-part of the printing service, as that is a task for system administrators.</para>
<sect2><title>Wrong file</title>
<para>If you print the wrong file, the job may be canceled using the command <command>lprm jobID</command>, where jobID is in the form <emphasis>printername-printjobnumber</emphasis> (get it from information displayed by <command>lpq</command>). This will work when other jobs are waiting to be printed in this printer's queue. However, you have to be really quick if you are the only one using this printer, since jobs are usually spooled and send to the printer in only seconds. Once they arrive on the printer, it is too late to remove jobs using Linux tools.</para>
</sect2>
<sect2>
<title>My print hasn't come out</title>
<para>Use the <command>lpq</command> command and see if you can spot your job:</para>
<screen>
elly:~&gt;lpq
Printer: lp@blob
Queue: 2 printable jobs
Server: pid 29998 active
Unspooler: pid 29999 active
Status: waiting for subserver to exit at 09:43:20.699
Rank Owner/ID Class Job Files Size Time
1 elly@blob+997 A 997 (STDIN) 129 09:42:54
2 elly@blob+22 A 22 /etc/profile 917 09:43:20
</screen>
<para>Lots of printers have web interfaces these days, which can display status information by typing the printer's IP address in your web browser:</para>
<figure><title>Printer Status through web interface</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/brother-webinterface.eps" format="EPS"></imagedata>
</imageobject>
<imageobject>
<imagedata fileref="images/brother-webinterface.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>If your job ID is not there and not on the printer, contact your system administrator. If your job ID is listed in the output, check that the printer is currently printing. If so, just wait, your job will get done in due time.</para>
<para>If the printer is not printing, check that it has paper, check the physical connections to both electricity and data network. If that's okay, the printer may need restarting. Ask your system admin for advice.</para>
<para>In the case of a network printer, try printing from another host. If the printer is reachable from your own host (see <xref linkend="chap_10" /> for the <command>ping</command> utility), you may try to put the formatted file on it, like <filename>file.ps</filename> in case of a PostScript printer, using an FTP client. If that works, your print system is misconfigured. If it doesn't work, maybe the printer doesn't understand the format you are feeding it.</para>
<para>The <ulink url="http://www.linuxprinting.org">GNU/Linux Printing site</ulink> contains more tips and tricks.</para>
</sect2>
</sect1>
<sect1><title>Summary</title>
<para>The Linux print service comes with a set of printing tools based on the standard UNIX LPD tools. Below is a list of print-related commands.</para>
<table frame="all"><title>Printing related commands</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row>
<entry>Command</entry><entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry><command>lpr</command></entry><entry>Print file</entry>
</row>
<row>
<entry><command>lpq</command></entry><entry>Query print queue</entry>
</row>
<row>
<entry><command>lprm</command></entry><entry>Remove print job</entry>
</row>
<row>
<entry><command>acroread</command></entry><entry>PDF viewer</entry>
</row>
<row>
<entry><command>groff</command></entry><entry>Formatting tool</entry>
</row>
<row>
<entry><command>gv</command></entry><entry>PostScript viewer</entry>
</row>
<row>
<entry><command>printconf</command></entry><entry>Configure printers</entry>
</row>
<row>
<entry><command>xdvi</command></entry><entry>DVI viewer</entry>
</row>
<row>
<entry><command>xpdf</command></entry><entry>PDF viewer</entry>
</row>
<row>
<entry><command>*2ps</command></entry><entry>Convert file to PostScript</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1><title>Exercises</title>
<para>Configuring and testing printers involves being in the possession of one, and having access to the <emphasis>root</emphasis> account. If so, you may try:</para>
<itemizedlist>
<listitem><para>Installing the printer using <command>printconf-gui</command>.</para></listitem>
<listitem><para>Printing a test page using the GUI.</para></listitem>
<listitem><para>Printing a test page using the <command>lp</command> command.</para></listitem>
<listitem><para>Print from within an application, for example Mozilla.</para></listitem>
<listitem><para>Disconnect the printer from the network or the local machine/print-server. What happens when you try to print something?</para></listitem>
</itemizedlist>
<para>The following exercises can be done without printer or root access.</para>
<itemizedlist>
<listitem><para>Try to make PostScript files from different source files, (e.g. HTML, PDF, man pages). Test the results with the <command>gv</command> viewer.</para></listitem>
<listitem><para>Check that the print daemon is running.</para></listitem>
<listitem><para>Print the files anyway. What happens?</para></listitem>
<listitem><para>Make a PostScript file using Mozilla. Test it with <command>gv</command>.</para></listitem>
<listitem><para>Convert it to PDF format. Test with <command>xpdf</command>.</para></listitem>
<listitem><para>How would you go about printing a GIF file from the command line?</para></listitem>
</itemizedlist>
</sect1>
</chapter>

View File

@ -0,0 +1,265 @@
<?xml version ='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_09">
<title>Fundamental Backup Techniques</title>
<abstract><para>Accidents will happen sooner or later. In this chapter, we'll discuss how to get data to a safe place using other hosts, floppy disks, CD-ROMs and tapes. We will also discuss the most popular compressing and archiving commands.</para>
<para>Upon completion of this chapter, you will know how to:</para>
<para>
<itemizedlist>
<listitem><para>Make, query and unpack file archives</para></listitem>
<listitem><para>Handle floppy disks and make a boot disk for your system</para></listitem>
<listitem><para>Write CD-ROMs</para></listitem>
<listitem><para>Find documentation to use other backup devices</para></listitem>
</itemizedlist>
</para>
</abstract>
<sect1><title>Introduction</title>
<para>Although Linux is one of the safest operating systems in existence, and even if it is designed to keep on going, data can get lost. Data loss is most often the consequence of user errors, but occasionally a system fault, such as a power failure, is the cause, so it's always a good idea to keep an extra copy of sensitive and/or important data.</para>
<sect2><title>Preparing your data</title>
<sect3><title>Compressing with <command>tar</command></title>
<para>In some cases, you will want to compress your data so that they don't take up more space than usual. In Linux, this is commonly done with the <command>tar</command> command. <command>tar</command> was originally designed to archive tapes, but it can also make a <emphasis>tarball</emphasis>, a file containing other compressed files.</para>
<para><command>tar</command> has many options, the most important ones cited below:</para>
<itemizedlist>
<listitem><para>v: verbose</para></listitem>
<listitem><para>t: test, shows content of a tarball</para></listitem>
<listitem><para>x: extract archive</para></listitem>
<listitem><para>c: create archive</para></listitem>
<listitem><para>-f <filename>archivedevice</filename>: use <filename>archivedevice</filename> as source/destination for the tarball, the device defaults to the first tape device (usually <filename>/dev/st0</filename> or something similar)</para></listitem>
</itemizedlist>
<para>Refer to the <command>tar</command> man page for more information.</para>
<note><title>Use GNU tar for compatibility</title>
<para>The archives made with a proprietary <command>tar</command> version on one system, may be incompatible with <command>tar</command> on another proprietary system. This may cause much headaches, such as if the archive needs to be recovered on a system that doesn't exist anymore. Use the GNU <command>tar</command> version on all systems to prevent your system admin from bursting into tears. Linux always uses GNU tar. When working on other UNIX machines, enter <command>tar --help</command> to find out which version you are using. Contact your system admin if you don't see the word GNU somewhere.</para></note>
<para>In the example below, an archive is created and unpacked.</para>
<screen>
gaby:~&gt;ls images/
me+tux.jpg nimf.jpg
gaby:~&gt;tar cvf images-in-a-dir.tar images/
images/
images/nimf.jpg
images/me+tux.jpg
gaby:~&gt;cd images
gaby:~/images&gt;tar cvf images-without-a-dir.tar *.jpg
me+tux.jpg
nimf.jpg
gaby:~/images&gt;cd
gaby:~&gt;ls */*.tar
images/images-without-a-dir.tar
gaby:~&gt;ls *.tar
images-in-a-dir.tar
gaby:~&gt;tar xvf images-in-a-dir.tar
images/
images/nimf.jpg
images/me+tux.jpg
gaby:~&gt;tar tvf images/images-without-dir.tar
-rw-r--r-- gaby/gaby 42888 1999-06-30 20:52:25 me+tux.jpg
-rw-r--r-- gaby/gaby 7578 2000-01-26 12:58:46 nimf.jpg
gaby:~&gt;tar xvf images/images-without-a-dir.tar
me+tux.jpg
nimf.jpg
gaby:~&gt;ls *.jpg
me+tux.jpg nimf.jpg
</screen>
<para>This example also illustrates the difference between a tarred directory and a bunch of tarred files. It is advisable to only compress directories, so files don't get spread all over when unpacking the tarball (which may be on another system, where you may not know which files where already there and which are the ones from the archive).</para>
<para>When a tape drive is connected to your machine and configured by your system administrator, the file names ending in <filename>.tar</filename> are replaced with the tape device name, for example:</para>
<para><command>tar cvf <filename>/dev/tape</filename> mail/</command></para>
<para>The directory <filename>mail</filename> and all the files it contains are compressed into a file that is written on the tape immediately. A content listing is displayed because we used the verbose option.</para>
</sect3>
<sect3><title>Compressing with <command>gzip</command> or <command>bzip2</command></title>
<para>
Data, including tarballs, can be compressed using zip tools. The <command>gzip</command> command will add the suffix .gz to the file name and remove the original file.
</para>
<screen>
jimmy:~&gt;ls -la | grep tar
-rw-rw-r-- 1 jimmy jimmy 61440 Jun 6 14:08 images-without-dir.tar
jimmy:~&gt;gzip images-without-dir.tar
jimmy:~&gt;ls -la images-without-dir.tar.gz
-rw-rw-r-- 1 jimmy jimmy 50562 Jun 6 14:08 images-without-dir.tar.gz
</screen>
<para>Uncompress gzipped files with the <command>-d</command> option.</para>
<para><command>bzip</command> works in a similar way, but uses an improved compression algorithm, thus creating smaller files.</para>
<para>Linux software packages are often distributed in a gzipped tarball. The sensible thing to do after unpacking that kind of archives is find the <filename>README</filename> and read it. It will generally contain guidelines to installing the package.</para>
<para>The GNU <command>tar</command> command is aware of gzipped files. Use the command</para>
<para><cmdsynopsis><command>tar zxvf <filename>file.tar.gz</filename></command></cmdsynopsis></para>
<para>for unzipping and untarring <filename>.tar.gz</filename> or <filename>.tgz</filename> files.</para>
</sect3>
<sect3><title>Transporting your data</title>
<para>Saving copies of your data on another host is an accurate way of making backups. See <xref linkend="chap_10" />, Communications, for more information.</para>
</sect3>
</sect2>
</sect1>
<sect1>
<title>Moving your data to a backup device</title>
<sect2><title>Making a copy on a floppy disk</title>
<sect3><title>Formatting the floppy</title>
<para>On most Linux systems, users have access to the floppy disk device. The name of the device may vary depending on the size and number of floppy drives, contact your system admin if you are unsure. On sensibly administered systems, there will likely be a link <filename>/dev/floppy</filename> pointing to the right device, probably <filename>/dev/fd0</filename> (the auto-detecting floppy device) or <filename>/dev/fd0H1440</filename> (set for 1,44MB floppies).</para>
<para>
<command>fdformat</command> is the low-level floppy disk formatting tool. It has the device name of the floppy disk as an option. <command>fdformat</command> will display an error when the floppy is read-protected.
</para>
<screen>
emma:~&gt;fdformat /dev/fd0H1440
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done
Verifying ... done
emma:~&gt;
</screen>
<para>The <command>mformat</command> command (from the mtools package) is used to create DOS-compatible floppies which can then be accessed using the <command>mcopy</command>, <command>mdir</command> and other m-commands.</para>
<para>Graphical tools are also available.</para>
<figure><title>Floppy formatter</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/formatfloppy.eps" format="EPS"></imagedata></imageobject><imageobject>
<imagedata fileref="images/formatfloppy.jpg" format="JPG"></imagedata>
</imageobject>
</mediaobject>
</figure>
<para>After the floppy is formatted, it can be mounted into the file system and accessed as a normal, be it small, directory, usually via the <filename>/mnt/floppy</filename> entry.</para>
<para>Almost every Linux distribution provides the <command>mkbootdisk</command> utility, which makes a floppy from which the current system can boot.</para>
</sect3>
<sect3><title>Using the <command>dd</command> command to dump data</title>
<para>The <command>dd</command> command can be used to put data on a disk, or get it off again, depending on the given input and output devices. An example:</para>
<screen>
gaby:~&gt;dd if=images-without-dir.tar.gz of=/dev/fd0H1440
98+1 records in
98+1 records out
gaby~&gt;dd if=/dev/fd0H1440 of=/tmp/images.tar.gz
2880+0 records in
2880+0 records out
gaby:~&gt;ls /tmp/images*
/tmp/images.tar.gz
</screen>
<para>Note that the dumping is done on an unmounted device. Floppies created using this method will not be mountable in the file system, but it is of course the way to go for creating boot or rescue disks. For more information on the possibilities of <command>dd</command>, read the man pages.</para>
<note><title>Dumping disks</title>
<para>The <command>dd</command> command can also be used to make a raw dump of an entire hard disk.</para></note>
</sect3>
</sect2>
<sect2><title>Making a copy with a CD-writer</title>
<para>On some systems users are allowed to use the CD-writer device. Your data will need to be formatted first. Use the <command>mkisofs</command> command to do this in the directory containing the files you want to backup. Check with <command>df</command> that enough disk space is available, because a new file about the same size as the entire current directory will be created:</para>
<screen>
[rose@blob recordables] df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/hde5 19G 15G 3.2G 82% /home
[rose@blob recordables] du -h -s .
325M .
[rose@blob recordables] mkisofs -J -r -o cd.iso .
&lt;--snap--&gt;
making a lot of conversions
&lt;--/snap--&gt;
98.95% done, estimate finish Fri Apr 5 13:54:25 2002
Total translation table size: 0
Total rockridge attributes bytes: 35971
Total directory bytes: 94208
Path table size(bytes): 452
Max brk space used 37e84
166768 extents written (325 Mb)
</screen>
<para>The <option>-J</option> and <option>-r</option> options are used to make the CD-ROM mountable on different systems, see the man pages for more. After that, the CD can be created using the <command>cdrecord</command> tool with appropriate options:</para>
<screen>
[rose@blob recordables] cdrecord -dev 0,0,0 -speed=8 cd.iso
Cdrecord 1.10 (i686-pc-linux-gnu) (C) 1995-2001 Joerg Schilling
scsidev: '0,0,0'
scsibus: 0 target: 0 lun: 0
Linux sg driver version: 3.1.20
Using libscg version 'schily-0.5'
Device type : Removable CD-ROM
Version : 0
Response Format: 1
Vendor_info : 'HP '
Identifikation : 'CD-Writer+ 8100 '
Revision : '1.0g'
Device seems to be: Generic mmc CD-RW.
Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
Driver flags : SWABAUDIO
Starting to write CD/DVD at speed 4 in write mode for single session.
Last chance to quit, starting real write in 0 seconds. Operation starts.
</screen>
<para>Depending on your CD-writer, you now have the time to smoke a cigarette and/or get a cup of coffee. Upon finishing the job, you will get a confirmation message:</para>
<screen>
Track 01: Total bytes read/written: 341540864/341540864 (166768 sectors).
</screen>
<para>There are some graphical tools available to make it easier on you. One of the popular ones is <command>xcdroast</command>, which is freely available. Both the KDE and Gnome desktop managers have facilities to make your own CDs.</para>
<figure><title>Xcdroast</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/xcdroast.eps" format="EPS"></imagedata></imageobject>
<imageobject>
<imagedata fileref="images/xcdroast.png" format="PNG"></imagedata>
</imageobject>
</mediaobject>
</figure>
</sect2>
<sect2><title>Backups on/from jazz drives, USB devices and such</title>
<para>These devices are usually mounted into the file system. After the mount procedure, they are accessed as normal directories, so you can use the standard commands for manipulating files.</para>
<para>In the example below, images are copied from a USB camera to the hard disk:</para>
<screen>
robin:~&gt;mount /mnt/camera
robin:~&gt;mount | grep camera
/dev/sda1 on /mnt/camera type vfat (rw,nosuid,nodev)
robin:~&gt;cp -R /mnt/camera/* images/
robin:~&gt;umount /mnt/camera
</screen>
<para>Likewise, a jazz drive may be mounted on <filename>/mnt/jazz</filename>.</para>
<para>Appropriate lines should be added in <filename>/etc/modules.conf</filename> and <filename>/etc/fstab</filename> to make this work. Refer to specific hardware HOWTOs for more information.</para>
</sect2>
<sect2><title>Backing up data using a tape device</title>
<para>This is done using <command>tar</command> (see above). The <command>mt</command> tool is used for controlling the magnetic tape device, like <filename>/dev/st0</filename>. Entire books have been written about tape backup, therefore, refer to our reading-list in <xref linkend="app2" /> for more information. Keep in mind that databases might need other backup procedures because of their architecture.</para>
<para>The appropriate backup commands are usually put in one of the <emphasis>cron</emphasis> directories in order to have them executed on a regular basis. In larger environments, the freely available <ulink url="http://www.amanda.org">Amanda</ulink> backup suite or a commercial solution may be implemented to back up multiple machines. Working with tapes, however, is a system administration task beyond the scope of this document.</para>
</sect2>
</sect1>
<sect1><title>Summary</title>
<para>Here's a list of the commands involving file backup:</para>
<table frame="all"><title>Backup commands</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
<thead>
<row><entry>Command</entry><entry>Meaning</entry></row>
</thead>
<tbody>
<row><entry><command>bzip2</command></entry><entry>A block-sorting file compressor.</entry></row>
<row><entry><command>cdrecord</command></entry><entry>Record audio or data Compact Disks from a master.</entry></row>
<row><entry><command>dd</command></entry><entry>Convert and copy a file</entry></row>
<row><entry><command>fdformat</command></entry><entry>Low-level formats a floppy disk.</entry></row>
<row><entry><command>gzip</command></entry><entry>Compress or expand files.</entry></row>
<row><entry><command>mcopy</command></entry><entry>Copy MSDOS files to/from UNIX.</entry></row>
<row><entry><command>mdir</command></entry><entry>Display an MSDOS directory.</entry></row>
<row><entry><command>mformat</command></entry><entry>Add an MSDOS file system to a low-level formatted floppy disk.</entry></row>
<row><entry><command>mkbootdisk</command></entry><entry>Creates a stand-alone boot floppy for the running system.</entry></row>
<row><entry><command>mount</command></entry><entry>Mount a file system (integrate it with the current file system by connecting it to a mount point).</entry></row>
<row><entry><command>tar</command></entry><entry>Tape archiving utility, also used for making archives on disk instead of on tape.</entry></row>
<row><entry><command>umount</command></entry><entry>Unmount file systems.</entry></row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1><title>Exercises</title>
<itemizedlist>
<listitem><para>Make a backup copy of your home directory in <filename>/var/tmp</filename> using the <command>tar</command> command. Then further compress the file using <command>gzip</command> or <command>bzip2</command>. Make it a clean tarred file, one that doesn't make a mess when unpacking.</para></listitem>
<listitem><para>Format a floppy and put some files from your home directory on it. Switch floppies with another trainee and recover his/her floppy in your home directory.</para></listitem>
<listitem><para>DOS format the floppy. Use the <emphasis>mtools</emphasis> to put and delete files on it.</para></listitem>
<listitem><para>What happens to an unformatted floppy when you want to mount it into the file system?</para></listitem>
</itemizedlist>
</sect1>
</chapter>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB