old-www/LDP/intro-linux/html/intro-linux.html

41131 lines
800 KiB
HTML
Raw Permalink Blame History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Introduction to Linux</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><META
NAME="KEYWORD"
CONTENT="Linux"><META
NAME="KEYWORD"
CONTENT="Beginners"><META
NAME="KEYWORD"
CONTENT="linux"><META
NAME="KEYWORD"
CONTENT="start"><META
NAME="KEYWORD"
CONTENT="Getting started"><META
NAME="KEYWORD"
CONTENT="guide"><META
NAME="KEYWORD"
CONTENT="Guide"><META
NAME="KEYWORD"
CONTENT="Exercises"><META
NAME="KEYWORD"
CONTENT="exercises"></HEAD
><BODY
CLASS="book"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="BOOK"
><A
NAME="AEN1"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
><A
NAME="AEN2"
></A
>Introduction to Linux</H1
><H2
CLASS="subtitle"
>A Hands on Guide</H2
><H3
CLASS="author"
><A
NAME="AEN6"
></A
>Machtelt Garrels</H3
><DIV
CLASS="affiliation"
><SPAN
CLASS="orgname"
>Garrels.be<BR></SPAN
><DIV
CLASS="address"
><P
CLASS="address"
><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<TT
CLASS="email"
>&#60;<A
HREF="mailto:tille wants no spam _at_ garrels dot be"
>tille wants no spam _at_ garrels dot be</A
>&#62;</TT
><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</P
></DIV
></DIV
><P
CLASS="edition"
>1.27&nbsp;Edition </P
><P
CLASS="copyright"
>Copyright &copy; 2002, 2003, 2004, 2005, 2006, 2007, 2008 Machtelt Garrels</P
><P
CLASS="pubdate"
>20080606<BR></P
><HR></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="#AEN35"
>Introduction</A
></DT
><DD
><DL
><DT
>1. <A
HREF="#intro_01"
>Why this guide?</A
></DT
><DT
>2. <A
HREF="#intro_02"
>Who should read this book?</A
></DT
><DT
>3. <A
HREF="#intro_03"
>New versions and availability</A
></DT
><DT
>4. <A
HREF="#intro_04"
>Revision History</A
></DT
><DT
>5. <A
HREF="#intro_05"
>Contributions</A
></DT
><DT
>6. <A
HREF="#intro_06"
>Feedback</A
></DT
><DT
>7. <A
HREF="#intro_07"
>Copyright information</A
></DT
><DT
>8. <A
HREF="#intro_08"
>What do you need?</A
></DT
><DT
>9. <A
HREF="#intro_09"
>Conventions used in this document</A
></DT
><DT
>10. <A
HREF="#intro_10"
>Organization of this document</A
></DT
></DL
></DD
><DT
>1. <A
HREF="#chap_01"
>What is Linux?</A
></DT
><DD
><DL
><DT
>1.1. <A
HREF="#sect_01_01"
>History</A
></DT
><DT
>1.2. <A
HREF="#sect_01_02"
>The user interface</A
></DT
><DT
>1.3. <A
HREF="#sect_01_03"
>Does Linux have a future?</A
></DT
><DT
>1.4. <A
HREF="#sect_01_04"
>Properties of Linux</A
></DT
><DT
>1.5. <A
HREF="#sect_01_05"
>Linux Flavors</A
></DT
><DT
>1.6. <A
HREF="#sect_01_06"
>Summary</A
></DT
><DT
>1.7. <A
HREF="#sect_01_07"
>Exercises</A
></DT
></DL
></DD
><DT
>2. <A
HREF="#chap_02"
>Quickstart</A
></DT
><DD
><DL
><DT
>2.1. <A
HREF="#sect_02_01"
>Logging in, activating the user interface and
logging out</A
></DT
><DT
>2.2. <A
HREF="#sect_02_02"
>Absolute basics</A
></DT
><DT
>2.3. <A
HREF="#sect_02_03"
>Getting help</A
></DT
><DT
>2.4. <A
HREF="#sect_02_04"
>Summary</A
></DT
><DT
>2.5. <A
HREF="#sect_02_05"
>Exercises</A
></DT
></DL
></DD
><DT
>3. <A
HREF="#chap_03"
>About files and the file system</A
></DT
><DD
><DL
><DT
>3.1. <A
HREF="#sect_03_01"
>General overview of the Linux file system</A
></DT
><DT
>3.2. <A
HREF="#sect_03_02"
>Orientation in the file system</A
></DT
><DT
>3.3. <A
HREF="#sect_03_03"
>Manipulating files</A
></DT
><DT
>3.4. <A
HREF="#sect_03_04"
>File security</A
></DT
><DT
>3.5. <A
HREF="#sect_03_05"
>Summary</A
></DT
><DT
>3.6. <A
HREF="#sect_03_06"
>Exercises</A
></DT
></DL
></DD
><DT
>4. <A
HREF="#chap_04"
>Processes</A
></DT
><DD
><DL
><DT
>4.1. <A
HREF="#sect_04_01"
>Processes inside out</A
></DT
><DT
>4.2. <A
HREF="#sect_04_02"
>Boot process, Init and shutdown</A
></DT
><DT
>4.3. <A
HREF="#sect_04_03"
>Managing processes</A
></DT
><DT
>4.4. <A
HREF="#sect_04_04"
>Scheduling processes</A
></DT
><DT
>4.5. <A
HREF="#sect_04_05"
>Summary</A
></DT
><DT
>4.6. <A
HREF="#sect_04_06"
>Exercises</A
></DT
></DL
></DD
><DT
>5. <A
HREF="#chap_05"
>I/O redirection</A
></DT
><DD
><DL
><DT
>5.1. <A
HREF="#sect_05_01"
>Simple redirections</A
></DT
><DT
>5.2. <A
HREF="#sect_05_02"
>Advanced redirection features</A
></DT
><DT
>5.3. <A
HREF="#sect_05_03"
>Filters</A
></DT
><DT
>5.4. <A
HREF="#sect_05_04"
>Summary</A
></DT
><DT
>5.5. <A
HREF="#sect_05_05"
>Exercises</A
></DT
></DL
></DD
><DT
>6. <A
HREF="#chap_06"
>Text editors</A
></DT
><DD
><DL
><DT
>6.1. <A
HREF="#sect_06_01"
>Text editors</A
></DT
><DT
>6.2. <A
HREF="#sect_06_02"
>Using the Vim editor</A
></DT
><DT
>6.3. <A
HREF="#sect_06_03"
>Linux in the office</A
></DT
><DT
>6.4. <A
HREF="#sect_06_04"
>Summary</A
></DT
><DT
>6.5. <A
HREF="#sect_06_05"
>Exercises</A
></DT
></DL
></DD
><DT
>7. <A
HREF="#chap_07"
>Home sweet /home</A
></DT
><DD
><DL
><DT
>7.1. <A
HREF="#sect_07_01"
>General good housekeeping</A
></DT
><DT
>7.2. <A
HREF="#sect_07_02"
>Your text environment</A
></DT
><DT
>7.3. <A
HREF="#sect_07_03"
>The graphical environment</A
></DT
><DT
>7.4. <A
HREF="#sect_07_05"
>Region specific settings</A
></DT
><DT
>7.5. <A
HREF="#sect_07_06"
>Installing new software</A
></DT
><DT
>7.6. <A
HREF="#sect_07_07"
>Summary</A
></DT
><DT
>7.7. <A
HREF="#sect_07_08"
>Exercises</A
></DT
></DL
></DD
><DT
>8. <A
HREF="#chap_08"
>Printers and printing</A
></DT
><DD
><DL
><DT
>8.1. <A
HREF="#sect_08_01"
>Printing files</A
></DT
><DT
>8.2. <A
HREF="#sect_08_02"
>The server side</A
></DT
><DT
>8.3. <A
HREF="#sect_08_03"
>Print problems</A
></DT
><DT
>8.4. <A
HREF="#sect_08_05"
>Summary</A
></DT
><DT
>8.5. <A
HREF="#sect_08_06"
>Exercises</A
></DT
></DL
></DD
><DT
>9. <A
HREF="#chap_09"
>Fundamental Backup Techniques</A
></DT
><DD
><DL
><DT
>9.1. <A
HREF="#sect_09_01"
>Introduction</A
></DT
><DT
>9.2. <A
HREF="#sect_09_02"
>Moving your data to a backup device</A
></DT
><DT
>9.3. <A
HREF="#sect_09_03"
>Using rsync</A
></DT
><DT
>9.4. <A
HREF="#sect_09_04"
>Encryption</A
></DT
><DT
>9.5. <A
HREF="#sect_09_05"
>Summary</A
></DT
><DT
>9.6. <A
HREF="#sect_09_06"
>Exercises</A
></DT
></DL
></DD
><DT
>10. <A
HREF="#chap_10"
>Networking</A
></DT
><DD
><DL
><DT
>10.1. <A
HREF="#sect_10_01"
>Networking Overview</A
></DT
><DT
>10.2. <A
HREF="#sect_10_02"
>Network configuration and information</A
></DT
><DT
>10.3. <A
HREF="#sect_10_04"
>Internet/Intranet applications</A
></DT
><DT
>10.4. <A
HREF="#sect_10_05"
>Remote execution of applications</A
></DT
><DT
>10.5. <A
HREF="#sect_10_06"
>Security</A
></DT
><DT
>10.6. <A
HREF="#sect_10_08"
>Summary</A
></DT
><DT
>10.7. <A
HREF="#sect_10_09"
>Exercises</A
></DT
></DL
></DD
><DT
>11. <A
HREF="#chap_11"
>Sound and Video</A
></DT
><DD
><DL
><DT
>11.1. <A
HREF="#sect_11_01"
>Audio Basics</A
></DT
><DT
>11.2. <A
HREF="#sect_11_02"
>Sound and video playing</A
></DT
><DT
>11.3. <A
HREF="#sect_11_02_04"
>Video playing, streams and television watching</A
></DT
><DT
>11.4. <A
HREF="#sect_11_02_05"
>Internet Telephony</A
></DT
><DT
>11.5. <A
HREF="#sect_11_03"
>Summary</A
></DT
><DT
>11.6. <A
HREF="#sect_11_04"
>Exercises</A
></DT
></DL
></DD
><DT
>A. <A
HREF="#app1"
>Where to go from here?</A
></DT
><DD
><DL
><DT
>A.1. <A
HREF="#AEN11802"
>Useful Books</A
></DT
><DT
>A.2. <A
HREF="#AEN11877"
>Useful sites</A
></DT
></DL
></DD
><DT
>B. <A
HREF="#app2"
>DOS versus Linux commands</A
></DT
><DT
>C. <A
HREF="#app3"
>Shell Features</A
></DT
><DD
><DL
><DT
>C.1. <A
HREF="#AEN12120"
>Common features</A
></DT
><DT
>C.2. <A
HREF="#AEN12249"
>Differing features</A
></DT
></DL
></DD
><DT
><A
HREF="#glossary"
>Glossary</A
></DT
><DT
><A
HREF="#AEN14033"
>Index</A
></DT
></DL
></DIV
><DIV
CLASS="LOT"
><DL
CLASS="LOT"
><DT
><B
>List of Tables</B
></DT
><DT
>1. <A
HREF="#conventions"
>Typographic and usage conventions</A
></DT
><DT
>2-1. <A
HREF="#tab_02_01"
>Quickstart commands</A
></DT
><DT
>2-2. <A
HREF="#tab_02_02"
>Key combinations in Bash</A
></DT
><DT
>2-3. <A
HREF="#AEN1438"
>New commands in chapter 2: Basics</A
></DT
><DT
>3-1. <A
HREF="#AEN1749"
>File types in a long list</A
></DT
><DT
>3-2. <A
HREF="#AEN2004"
>Subdirectories of the root directory</A
></DT
><DT
>3-3. <A
HREF="#AEN2485"
>Most common configuration files</A
></DT
><DT
>3-4. <A
HREF="#AEN2726"
>Common devices</A
></DT
><DT
>3-5. <A
HREF="#AEN3003"
>Color-ls default color scheme</A
></DT
><DT
>3-6. <A
HREF="#AEN3039"
>Default suffix scheme for ls</A
></DT
><DT
>3-7. <A
HREF="#AEN3805"
>Access mode codes</A
></DT
><DT
>3-8. <A
HREF="#AEN3825"
>User group codes</A
></DT
><DT
>3-9. <A
HREF="#AEN3908"
>File protection with chmod</A
></DT
><DT
>3-10. <A
HREF="#AEN4247"
>New commands in chapter 3: Files and the file system</A
></DT
><DT
>3-11. <A
HREF="#AEN4445"
>File permissions</A
></DT
><DT
>4-1. <A
HREF="#AEN4685"
>Controlling processes</A
></DT
><DT
>4-2. <A
HREF="#AEN5016"
>Common signals</A
></DT
><DT
>4-3. <A
HREF="#AEN5938"
>New commands in chapter 4: Processes</A
></DT
><DT
>5-1. <A
HREF="#AEN6552"
>New commands in chapter 5: I/O redirection</A
></DT
><DT
>7-1. <A
HREF="#AEN7272"
>Common environment variables</A
></DT
><DT
>7-2. <A
HREF="#AEN8431"
>New commands in chapter 7: Making yourself at home</A
></DT
><DT
>8-1. <A
HREF="#AEN8887"
>New commands in chapter 8: Printing</A
></DT
><DT
>9-1. <A
HREF="#AEN9615"
>New commands in chapter 9: Backup</A
></DT
><DT
>10-1. <A
HREF="#layered_model"
>The simplified OSI Model</A
></DT
><DT
>10-2. <A
HREF="#AEN11263"
>New commands in chapter 10: Networking</A
></DT
><DT
>11-1. <A
HREF="#AEN11708"
>New commands in chapter 11: Audio</A
></DT
><DT
>B-1. <A
HREF="#AEN12006"
>Overview of DOS/Linux commands</A
></DT
><DT
>C-1. <A
HREF="#AEN12123"
>Common Shell Features</A
></DT
><DT
>C-2. <A
HREF="#AEN12267"
>Differing Shell Features</A
></DT
></DL
></DIV
><DIV
CLASS="LOT"
><DL
CLASS="LOT"
><DT
><B
>List of Figures</B
></DT
><DT
>1. <A
HREF="#AEN59"
>Introduction to Linux front cover</A
></DT
><DT
>1-1. <A
HREF="#AEN479"
>OpenOffice MS-compatible Spreadsheet</A
></DT
><DT
>2-1. <A
HREF="#AEN819"
>Terminal window</A
></DT
><DT
>2-2. <A
HREF="#AEN1381"
>Konqueror as help browser</A
></DT
><DT
>3-1. <A
HREF="#AEN1977"
>Linux file system layout</A
></DT
><DT
>3-2. <A
HREF="#AEN3699"
>Hard and soft link mechanism</A
></DT
><DT
>4-1. <A
HREF="#AEN4957"
>Fork-and-exec mechanism</A
></DT
><DT
>4-2. <A
HREF="#AEN5442"
>Can't you go faster?</A
></DT
><DT
>4-3. <A
HREF="#AEN5639"
>Gnome System Monitor</A
></DT
><DT
>8-1. <A
HREF="#AEN8864"
>Printer Status through web interface</A
></DT
><DT
>9-1. <A
HREF="#AEN9268"
>Floppy formatter</A
></DT
><DT
>10-1. <A
HREF="#AEN10332"
>Evolution mail and news reader</A
></DT
><DT
>10-2. <A
HREF="#AEN10492"
>X-Chat</A
></DT
><DT
>10-3. <A
HREF="#AEN10847"
>SSH X11 forwarding</A
></DT
><DT
>11-1. <A
HREF="#AEN11486"
>XMMS mp3 player</A
></DT
></DL
></DIV
><DIV
CLASS="preface"
><HR><H1
><A
NAME="AEN35"
></A
>Introduction</H1
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="intro_01"
></A
>1. Why this guide?</H1
><P
>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.</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_02"
></A
>2. Who should read this book?</H1
><P
> 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.</P
><P
>Everybody who wants to get a <SPAN
CLASS="QUOTE"
>"CLUE"</SPAN
>, a Command Line User Experience,
with Linux (and UNIX in general) will find this book useful.</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_03"
></A
>3. New versions and availability</H1
><P
>This document is published in the Guides section of the Linux Documentation
Project collection at <A
HREF="http://www.tldp.org/guides.html"
TARGET="_top"
>http://www.tldp.org/guides.html</A
>; you can also
download PDF and PostScript formatted versions here.</P
><P
>The most recent edition is available at<A
HREF="http://tille.garrels.be/training/tldp/"
TARGET="_top"
> http://tille.garrels.be/training/tldp/</A
>.</P
><P
>The second edition of this guide is available in print from <A
HREF="http://fultus.com/"
TARGET="_top"
>Fultus.com Books</A
> as paperback Print On Demand (POD) book. Fultus <A
HREF="http://store.fultus.com/product_info.php?products_id=140"
TARGET="_top"
>distributes this document</A
> through Ingram and Baker &#38; Taylor to many bookstores, including <A
HREF="http://www.amazon.com/exec/obidos/ASIN/1596821124"
TARGET="_top"
>Amazon.com</A
>, <A
HREF="http://www.amazon.co.uk/exec/obidos/ASIN/1596821124"
TARGET="_top"
>Amazon.co.uk</A
>, <A
HREF="http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ISBN=1596821124"
TARGET="_top"
>BarnesAndNoble.com</A
> and <A
HREF="http://froogle.google.com/froogle?q=1596821124"
TARGET="_top"
>Google's Froogle</A
> global shopping portal and <A
HREF="http://books.google.com/books?isbn=1596821124"
TARGET="_top"
>Google Book Search</A
>.</P
><DIV
CLASS="figure"
><A
NAME="AEN59"
></A
><P
><B
>Figure 1. Introduction to Linux front cover</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/itl.jpg"></P
></DIV
></DIV
><P
>The guide has been <A
HREF="http://www.geocities.com/linuxparichay/"
TARGET="_top"
>translated into Hindi</A
> by:</P
><P
></P
><UL
><LI
><P
>Alok Kumar</P
></LI
><LI
><P
>Dhananjay Sharma</P
></LI
><LI
><P
>Kapil</P
></LI
><LI
><P
>Puneet Goel</P
></LI
><LI
><P
>Ravikant Yuyutsu</P
></LI
></UL
><P
>Andrea Montagner <A
HREF="http://www.codex.altervista.org/introlinux.html"
TARGET="_top"
>translated the guide into Italian</A
>.</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_04"
></A
>4. Revision History</H1
><P
>&#13; <DIV
CLASS="revhistory"
><TABLE
WIDTH="100%"
BORDER="0"
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
COLSPAN="3"
><B
>Revision History</B
></TH
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.27</TD
><TD
ALIGN="LEFT"
>20080606</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>updates.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.26</TD
><TD
ALIGN="LEFT"
>20070919</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Comments from readers, license.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.25</TD
><TD
ALIGN="LEFT"
>20070511</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Comments from readers, minor updates, E-mail etiquette, updated info about availability (thanks Oleg).</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.24</TD
><TD
ALIGN="LEFT"
>2006-11-01</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>added index terms, prepared for second printed edition, added gpg and proxy info.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.23</TD
><TD
ALIGN="LEFT"
>2006-07-25</TD
><TD
ALIGN="LEFT"
>Revised by: MG and FK</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Updates and corrections, removed app5 again, adapted license to enable inclusion in Debian docs.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.22</TD
><TD
ALIGN="LEFT"
>2006-04-06</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>chap8 revised completely, chap10: clarified examples, added ifconfig and cygwin info, revised network apps.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.21</TD
><TD
ALIGN="LEFT"
>2006-03-14</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Added exercises in chap11, corrected newline errors, command overview completed for chapter 9, minor corrections in chap10.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.20</TD
><TD
ALIGN="LEFT"
>2006-01-06</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Split chap7: audio stuff is now in separate chapter, chap11.xml. Small revisions, updates for commands like aptitude, more on USB storage, Internet telephony, corrections from readers.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1.13</TD
><TD
ALIGN="LEFT"
>2004-04-27</TD
><TD
ALIGN="LEFT"
>Revised by: MG</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Last read-through before sending everything to Fultus for printout. Added Fultus referrence in New Versions section, updated Conventions and Organization sections. Minor changes in chapters 4, 5, 6 and 8, added rdesktop info in chapter 10, updated glossary, replaced references to fileutils with coreutils, thankyou to Hindi translators.</TD
></TR
></TABLE
></DIV
>
</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_05"
></A
>5. Contributions</H1
><P
> Many thanks to all the people who shared their experiences. And especially to the
Belgian Linux users for hearing me out every day and always
being generous in their comments.</P
><P
>Also a special thought for Tabatha Marshall for doing a really thorough revision,
spell check and styling, and to Eugene Crosser for spotting the errors that we two
overlooked.</P
><P
>And thanks to all the readers who notified me about missing topics and who helped
to pick out the last errors, unclear definitions and typos by going through the
trouble of mailing me all their remarks. These are also the people who help me keep
this guide up to date, like Filipus Klutiero who did a complete review in 2005 and 2006 and helps me getting the guide into the Debian docs collection, and Alexey Eremenko who sent me the foundation for chapter 11.</P
><P
>In 2006, Suresh Rajashekara created a Debian package of this documentation.</P
><P
>Finally, a big thank you for the volunteers who are currently translating this
document in French, Swedish, German, Farsi, Hindi and more. It is a big work that should
not be underestimated; I admire your courage.</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_06"
></A
>6. Feedback</H1
><P
> Missing information, missing links, missing characters? Mail it to the maintainer
of this document: <P
CLASS="address"
><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<TT
CLASS="email"
>&#60;<A
HREF="mailto:tille wants no spam _at_ garrels dot be"
>tille wants no spam _at_ garrels dot be</A
>&#62;</TT
><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</P
>
</P
><P
>Don't forget to check with the <A
HREF="http://tille.garrels.be/training/tldp/"
TARGET="_top"
>latest version</A
> first!</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_07"
></A
>7. Copyright information</H1
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;* Copyright (c) 2002-2007, Machtelt Garrels
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the author, Machtelt Garrels, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The logos, trademarks and symbols used in this book are the properties of their
respective owners.</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_08"
></A
>8. What do you need?</H1
><P
>You will require a computer and a medium containing a Linux distribution. Most of
this guide applies to all Linux distributions - and UNIX in general. Apart from
time, there are no further specific requirements.</P
><P
>The <A
HREF="http://www.tldp.org/HOWTO/Installation-HOWTO/"
TARGET="_top"
> Installation
HOWTO</A
> 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.</P
><P
>CD images can be downloaded from <A
HREF="http://www.linux-iso.com/"
TARGET="_top"
>&#13; linux-iso.com</A
> and many other locations, see <A
HREF="#app1"
>Appendix A</A
>.</P
><P
>An interesting alternative for those who don't dare to take the step of an actual
Linux installation on their machine are the Linux distributions that you can run
from a CD, such as the <A
HREF="http://www.knoppix.com/"
TARGET="_top"
> Knoppix</A
> distribution.</P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_09"
></A
>9. Conventions used in this document</H1
><P
>The following typographic and usage conventions occur in this text:</P
><DIV
CLASS="table"
><A
NAME="conventions"
></A
><P
><B
>Table 1. Typographic and usage conventions</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Text type</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <SPAN
CLASS="QUOTE"
>"Quoted text"</SPAN
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Quotes from people, quoted computer output.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>terminal view</PRE
></FONT
></TD
></TR
></TABLE
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Literal computer input and output captured from the terminal,
usually rendered with a light grey background.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>command</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name of a command that can be entered on the command line.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>VARIABLE</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name of a variable or pointer to content of a variable, as in <TT
CLASS="varname"
>$VARNAME</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="option"
>option</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Option to a command, as in <SPAN
CLASS="QUOTE"
>"the <TT
CLASS="option"
>-a</TT
> option
to the <B
CLASS="command"
>ls</B
> command"</SPAN
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="parameter"
><I
>argument</I
></TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Argument to a command, as in <SPAN
CLASS="QUOTE"
>"read <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>ls</I
></TT
>
</B
>
"</SPAN
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="prompt"
>prompt</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; User prompt, usually followed by a command that you type in a terminal window, like in <TT
CLASS="prompt"
>hilda@home&#62;</TT
> <B
CLASS="command"
>ls <TT
CLASS="option"
>-l</TT
></B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <P
><B
CLASS="command"
>command <TT
CLASS="option"
>options</TT
>
<TT
CLASS="parameter"
><I
>arguments</I
></TT
>
</B
> </P
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command synopsis or general usage, on a separated line.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>filename</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name of a file or directory, for example <SPAN
CLASS="QUOTE"
>"Change to
the <TT
CLASS="filename"
>/usr/bin</TT
> directory."</SPAN
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="keycap"
>Key</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Keys to hit on the keyboard, such as <SPAN
CLASS="QUOTE"
>"type
<B
CLASS="keycap"
>Q</B
> to quit"</SPAN
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <SPAN
CLASS="guibutton"
>Button</SPAN
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Graphical button to click, like the <SPAN
CLASS="guibutton"
>OK</SPAN
> button.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <SPAN
CLASS="guimenu"
>Menu</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>Choice</SPAN
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Choice to select from a graphical menu, for instance: <SPAN
CLASS="QUOTE"
>"Select<SPAN
CLASS="guimenu"
>Help</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>About Mozilla</SPAN
> in your browser."</SPAN
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <EM
>Terminology</EM
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Important term or concept: <SPAN
CLASS="QUOTE"
>"The Linux
<EM
>kernel</EM
> is the heart of the system."</SPAN
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>\</PRE
></FONT
></TD
></TR
></TABLE
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>The backslash in a terminal view or command synopsis indicates an
unfinished line. In other words, if you see a long command that is
cut into multiple lines, \ means <SPAN
CLASS="QUOTE"
>"Don't press
<B
CLASS="keycap"
>Enter</B
> yet!"</SPAN
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>See <A
HREF="#chap_01"
>Chapter 1</A
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>link to related subject within this guide.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <A
HREF="http://tille.garrels.be"
TARGET="_top"
>The author</A
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Clickable link to an external web resource.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>The following images are used:</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>This is a note</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>It contains additional information or remarks.</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="caution"
><P
></P
><TABLE
CLASS="caution"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>This is a caution</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>It means be careful.</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>This is a warning</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Be <EM
>very</EM
> careful.</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>This is a tip</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Tips and tricks.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="intro_10"
></A
>10. Organization of this document</H1
><P
>This guide is part of the Linux Documentation Project and aims to be the foundation for all other materials that you can get from
the Project. As such, it provides you with the fundamental
knowledge needed by anyone who wants to start working with a Linux system, while at
the same time it tries to consciously avoid re-inventing the hot water. Thus, you
can expect this book to be incomplete and full of links to sources of additional
information on your system, on the Internet and in your system documentation.</P
><P
>The first chapter is an introduction to the subject on Linux; the next two discuss
absolute basic commands. Chapters 4 and 5 discuss some more advanced but still basic
topics. Chapter 6 is needed for continuing with the rest, since it discusses editing
files, an ability you need to pass from Linux newbie to Linux user. The following
chapters discuss somewhat more advanced topics that you will have to deal with in
everyday Linux use.</P
><P
>All chapters come with exercises that will test your preparedness for the next chapter.</P
><P
></P
><UL
><LI
><P
>&#13; <A
HREF="#chap_01"
>Chapter 1</A
>: What is Linux, how did it come into existence, advantages and disadvantages, what does the future hold for Linux,
who should use it, installing your computer.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_02"
>Chapter 2</A
>: Getting started, connecting to the system, basic
commands, where to find help.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_03"
>Chapter 3</A
>: The filesystem, important files and directories,
managing files and directories, protecting your data.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_04"
>Chapter 4</A
>: Understanding and managing processes, boot and
shutdown procedures, postponing tasks, repetitive tasks.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_05"
>Chapter 5</A
>: What are standard input, output and error and how
are these features used from the command line.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_06"
>Chapter 6</A
>: Why you should learn to work with an editor,
discussion of the most common editors.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_07"
>Chapter 7</A
>: Configuring your graphical, text and audio
environment, settings for the non-native English speaking Linux user, tips
for adding extra software.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_08"
>Chapter 8</A
>: Converting files to a printable format, getting
them out of the printer, hints for solving print problems.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_09"
>Chapter 9</A
>: Preparing data to be backed up, discussion of
various tools, remote backup.</P
></LI
><LI
><P
>&#13; <A
HREF="#chap_10"
>Chapter 10</A
>: Overview of Linux networking tools and user
applications, with a short discussion of the underlying service daemon
programs and secure networking.</P
></LI
><LI
><P
><A
HREF="#chap_11"
>Chapter 11</A
>: Sound and video, including Voice over IP and sound recording is discussed in this chapter.</P
></LI
><LI
><P
>&#13; <A
HREF="#app1"
>Appendix A</A
>: Which books to read and sites to visit when you have
finished reading this one.</P
></LI
><LI
><P
>&#13; <A
HREF="#app2"
>Appendix B</A
>: A comparison.</P
></LI
><LI
><P
>&#13; <A
HREF="#app3"
>Appendix C</A
>: If you ever get stuck, these tables might be an
outcome. Also a good argument when your boss insists that YOU should use HIS
favorite shell.</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_01"
></A
>Chapter 1. What is Linux?</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN328"
></A
><P
></P
><P
>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.</P
><P
>This chapter answers questions like:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>What is Linux?
</P
></LI
><LI
><P
>Where and how did Linux start?
</P
></LI
><LI
><P
>Isn't Linux that system where everything is done in text mode?
</P
></LI
><LI
><P
>Does Linux have a future or is it just hype?
</P
></LI
><LI
><P
>What are the advantages of using Linux?
</P
></LI
><LI
><P
>What are the disadvantages?
</P
></LI
><LI
><P
>What kinds of Linux are there and how do I choose the one that
fits me?
</P
></LI
><LI
><P
>What are the Open Source and GNU movements?
</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_01"
></A
>1.1. History</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_01_01_01"
></A
>1.1.1. UNIX</H2
><P
>&#13;In order to understand the popularity of Linux, we need to travel back in time,
about 30 years ago...
</P
><P
>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.
</P
><P
>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 per unit of computing power was enormous.
</P
><P
>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
</P
><P
></P
><OL
TYPE="1"
><LI
><P
>Simple and elegant.
</P
></LI
><LI
><P
>Written in the C programming language instead of in assembly
code.
</P
></LI
><LI
><P
>Able to recycle code.
</P
></LI
></OL
><P
>The Bell Labs developers named their project <SPAN
CLASS="QUOTE"
>"UNIX."</SPAN
></P
><P
>&#13;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.
</P
><P
>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.
</P
><P
>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.
</P
><P
>UNIX was initially found only in very large environments with mainframes
and minicomputers (note that a PC is a <SPAN
CLASS="QUOTE"
>"micro"</SPAN
> 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.
</P
><P
>But smaller computers were being developed, and by the end of the 80's,
many people had home computers. By that time, there were several versions of
UNIX available for the PC architecture, but none of them were truly free and more important: they were all terribly slow, so most people ran MS DOS or Windows 3.1 on their home PCs.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_01_02"
></A
>1.1.2. Linus and Linux</H2
><P
>By the beginning of the 90s home PCs were finally powerful enough to run a full blown UNIX. Linus Torvalds, a young man studying computer science at the university of
Helsinki, thought it would be a good idea to have some sort of freely available
academic version of UNIX, and promptly started to code.
</P
><P
>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:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: Gcc-1.40 and a posix-question
Message-ID: &#60;1991Jul3.100050.9886@klaava.Helsinki.FI&#62;
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.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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.
</P
><P
>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.</P
><P
>Back then, those people were called <SPAN
CLASS="QUOTE"
>"nerds"</SPAN
> or
<SPAN
CLASS="QUOTE"
>"freaks"</SPAN
>, 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.
</P
><P
>Two years after Linus' post, there were 12000 Linux users. The project,
popular with hobbyists, grew steadily, all the while staying within the bounds
of the POSIX standard. 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, a lot of 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 - eventhough there is still a lot of hard- and software that is not supported, too.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_01_03"
></A
>1.1.3. Current application of Linux systems</H2
><P
>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.
</P
><P
>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, US Post Office, the German army and many others.
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. Clusters of Linux machines are used in the creation of
movies such as <SPAN
CLASS="QUOTE"
>"Titanic"</SPAN
>, <SPAN
CLASS="QUOTE"
>"Shrek"</SPAN
> and others. In
post offices, they are the nerve centers that route mail and in large search
engine, clusters are used to perform internet searches.These are only a few of
the thousands of heavy-duty jobs that Linux is performing day-to-day across the
world.
</P
><P
>It is also worth to note that modern Linux not only runs on workstations,
mid- and high-end servers, but also on <SPAN
CLASS="QUOTE"
>"gadgets"</SPAN
> like PDA's,
mobiles, a shipload of embedded applications and even on experimental
wristwatches. This makes Linux the only operating system in the world covering
such a wide range of hardware.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_02"
></A
>1.2. The user interface</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_01_02_01"
></A
>1.2.1. Is Linux difficult?</H2
><P
>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.
</P
><P
>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 - as opposed to many UNIX distributions demanding licensing fees for this tool. 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.
</P
><P
>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
<SPAN
CLASS="QUOTE"
>"lusers"</SPAN
> who hadn't seen the light yet. It was common practice to
tell a beginning user to <SPAN
CLASS="QUOTE"
>"RTFM"</SPAN
> (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.
</P
><P
>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.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_02_02"
></A
>1.2.2. Linux for non-experienced users</H2
><P
>Companies such as RedHat, SuSE and Mandriva 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.
</P
><P
>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.
</P
><P
>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 an Apple 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. Below is a short list containing some great
examples; these sites have a lot of screenshots that will give you a glimpse of
what Linux on the desktop can be like:
</P
><P
></P
><UL
><LI
><P
><A
HREF="http://www.gnome.org"
TARGET="_top"
>http://www.gnome.org</A
>
</P
></LI
><LI
><P
><A
HREF="http://kde.org/screenshots/"
TARGET="_top"
>http://kde.org/screenshots/</A
>
</P
></LI
><LI
><P
><A
HREF="http://www.openoffice.org"
TARGET="_top"
>http://www.openoffice.org</A
>
</P
></LI
><LI
><P
><A
HREF="http://www.mozilla.org"
TARGET="_top"
>http://www.mozilla.org</A
></P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_03"
></A
>1.3. Does Linux have a future?</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_01_03_01"
></A
>1.3.1. Open Source</H2
><P
>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.
</P
><P
>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.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_03_02"
></A
>1.3.2. Ten years of experience at your service</H2
><P
>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 includingWinXP) file- and print-servers.
</P
><P
>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 <SPAN
CLASS="QUOTE"
>"A PAtCHy server"</SPAN
>, based on existing
code and a series of <SPAN
CLASS="QUOTE"
>"patch files"</SPAN
>, the name for the matured code
deserves to be connoted 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.
</P
><P
>In the category of office applications, a choice of <SPAN
CLASS="application"
>MS Office</SPAN
> 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.
</P
><P
>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.
</P
><P
>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:
</P
><DIV
CLASS="figure"
><A
NAME="AEN479"
></A
><P
><B
>Figure 1-1. OpenOffice MS-compatible Spreadsheet</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/openoffice.png"></P
></DIV
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_04"
></A
>1.4. Properties of Linux</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_01_04_01"
></A
>1.4.1. Linux Pros</H2
><P
>A lot of the advantages of Linux are a consequence of Linux' origins,
deeply rooted in UNIX, except for the first advantage, of course:
</P
><P
></P
><UL
><LI
><P
>Linux is free:</P
><P
>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.
</P
><P
>Most of all, Linux is free as in free speech:</P
><P
>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.
</P
></LI
><LI
><P
>Linux is portable to any hardware platform:</P
><P
>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.
</P
></LI
><LI
><P
>Linux was made to keep on running:</P
><P
>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.
</P
></LI
><LI
><P
>Linux is secure and versatile:</P
><P
>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.
</P
></LI
><LI
><P
>Linux is scalable:</P
><P
>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. If 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.
</P
></LI
><LI
><P
>The Linux OS and most Linux applications have very short debug-times:
</P
><P
>Because Linux has been developed and tested by thousands of people, both
errors and people to fix them are usually found rather quickly. It sometimes happens that
there are only a couple of hours between discovery and fixing of a bug.
</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_04_02"
></A
>1.4.2. Linux Cons</H2
><P
></P
><UL
><LI
><P
>There are far too many different distributions:</P
><P
><SPAN
CLASS="QUOTE"
>"Quot capites, tot rationes"</SPAN
>, as the Romans already said: the more
people, the more opinions. At first glance, 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.
</P
><P
>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.
A quick search on <A
HREF="http://www.google.com/linux"
TARGET="_top"
>Google</A
>, using the keywords <SPAN
CLASS="QUOTE"
>"choosing your distribution"</SPAN
> brings up tens of
links to good advise.
The <A
HREF="http://www.tldp.org/HOWTO/Installation-HOWTO/"
TARGET="_top"
>&#13;Installation HOWTO</A
> also discusses choosing your distribution.
</P
></LI
><LI
><P
>Linux is not very user friendly and confusing for beginners:
</P
><P
>&#13;It must be said that Linux, at least the core system, is less userfriendly to use than MS Windows and certainly more difficult than MacOS, but...
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.
</P
></LI
><LI
><P
>Is an Open Source product trustworthy?</P
><P
>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.
</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_05"
></A
>1.5. Linux Flavors</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_01_05_01"
></A
>1.5.1. Linux and GNU</H2
><P
>&#13;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.
</P
><P
>Linux may appear different depending on the distribution, your hardware
and personal taste, but the fundamentals on which all graphical 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 Debian packages (also called deb or dpkg) on Debian, so you needn't be a programmer
to install a package on your system. However, if you are and like doing things
yourself, you will enjoy Linux all the better, since most distributions come
with a complete set of development tools, allowing installation of new software
purely from source code. This setup also allows you to install software even if
it does not exist in a pre-packaged form suitable for your system.
</P
><P
>A list of common GNU software:</P
><P
></P
><UL
><LI
><P
><SPAN
CLASS="application"
>Bash</SPAN
>: The GNU shell
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>GCC</SPAN
>: The GNU C Compiler
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>GDB</SPAN
>: The GNU Debugger
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Coreutils</SPAN
>: a set of basic UNIX-style utilities, such as <B
CLASS="command"
>ls</B
>, <B
CLASS="command"
>cat</B
> and <B
CLASS="command"
>chmod</B
></P
></LI
><LI
><P
><SPAN
CLASS="application"
>Findutils</SPAN
>: to search and find files
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Fontutils</SPAN
>: to convert fonts from one format to another or make
new fonts
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>The Gimp</SPAN
>: GNU Image Manipulation Program
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Gnome</SPAN
>: the GNU desktop environment
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Emacs</SPAN
>: a very powerful editor
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Ghostscript</SPAN
> and <SPAN
CLASS="application"
>Ghostview</SPAN
>: interpreter and graphical frontend
for PostScript files.
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>GNU Photo</SPAN
>: software for interaction with digital cameras
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Octave</SPAN
>: a programming language, primarily intended to perform numerical computations and image processing.
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>GNU SQL</SPAN
>: relational database system
</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Radius</SPAN
>: a remote authentication and accounting server
</P
></LI
><LI
><P
>...
</P
></LI
></UL
><P
>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.
</P
><P
>To install missing or new packages, you will need some form of software
management. The most common implementations include RPM and dpkg. RPM is the RedHat Package Manager, which is used on a variety of Linux
systems, eventhough the name does not suggest this. Dpkg is the Debian package
management system, which uses an interface called <B
CLASS="command"
>apt-get</B
>,
that can manage RPM packages as well. <SPAN
CLASS="application"
>Novell Ximian Red Carpet</SPAN
> 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. As you
advance into Linux, you will likely get in touch with one or more of these
programs.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_05_02"
></A
>1.5.2. GNU/Linux</H2
><P
>The Linux kernel (the <EM
>bones</EM
> of your system, see
<A
HREF="#sect_03_02_03_01"
>Section 3.2.3.1</A
>) is not part of the GNU project but uses the
same license as GNU software. A great majority of utilities and development
tools (the <EM
>meat</EM
> of your system), which are not
Linux-specific, are taken from the GNU project. Because any usable system must
contain both the kernel and at least a minimal set of utilities, some people
argue that such a system should be called a <EM
>GNU/Linux</EM
>
system.
</P
><P
>In order to obtain the highest possible degree of independence between
distributions, this is the sort of Linux that we will discuss throughout this
course. If we are not talking about a GNU/Linux system, the specific
distribution, version or program name will be mentioned.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_01_05_03"
></A
>1.5.3. Which distribution should I install?</H2
><P
>Prior to installation, the most important factor is your hardware. Since
every Linux distribution contains the basic packages and can be built to meet
almost 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 Apple 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.</P
><P
>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.
</P
><P
>Most Linux distributions offer a set of programs 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.
Examples are Debian, Ubuntu, Fedora, SuSE and Mandriva, which are by far the most popular Linux
systems 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 system.</P
><P
>While the standard desktop might be <SPAN
CLASS="application"
>Gnome</SPAN
> on one system, another might
offer <SPAN
CLASS="application"
>KDE</SPAN
> by default. Generally, both <SPAN
CLASS="application"
>Gnome</SPAN
> and <SPAN
CLASS="application"
>KDE</SPAN
> are available for all major Linux distributions. Other window and desktop managers are available for more advanced users.</P
><P
>The standard installation process allows users to choose between different basic
setups, such as 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.
</P
><P
>The goal of this guide is to apply to all Linux distributions. For your
own convenience, however, it is strongly advised that beginners stick to a
mainstream distribution, supporting all common hardware and applications by
default. The following are very good choices for novices:
</P
><P
></P
><UL
><LI
><P
><A
HREF="http://fedora.redhat.com"
TARGET="_top"
>Fedora Core</A
>
</P
></LI
><LI
><P
><A
HREF="http://www.debian.org"
TARGET="_top"
>Debian</A
>
</P
></LI
><LI
><P
><A
HREF="http://www.suse.de"
TARGET="_top"
>SuSE Linux</A
>
</P
></LI
><LI
><P
><A
HREF="http://www.mandrake.com"
TARGET="_top"
>Mandriva (former MandrakeSoft)</A
>
</P
></LI
><LI
><P
><A
HREF="http://www.knoppix.com"
TARGET="_top"
>Knoppix</A
>: an
operating system that runs from your CD-ROM, you don't need to install anything.
</P
></LI
></UL
><P
>Downloadable ISO-images can be obtained from <A
HREF="http://www.linuxiso.org"
TARGET="_top"
>LinuxISO.org</A
>. The main distributions can be purchased in any decent computer shop.
</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_06"
></A
>1.6. Summary</H1
><P
>In this chapter, we learned that:</P
><P
></P
><UL
><LI
><P
>Linux is an implementation of UNIX.
</P
></LI
><LI
><P
>The Linux operating system is written in the C programming
language.
</P
></LI
><LI
><P
><SPAN
CLASS="QUOTE"
>"De gustibus et coloribus non disputandum est"</SPAN
>: there's a Linux
for everyone.
</P
></LI
><LI
><P
>Linux uses GNU tools, a set of freely available standard tools
for handling the operating system.
</P
></LI
></UL
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_01_07"
></A
>1.7. Exercises</H1
><P
>&#13;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.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Read the docs!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13;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.
</P
></TD
></TR
></TABLE
></DIV
><P
>Things you must know BEFORE starting a Linux installation:
</P
><P
></P
><UL
><LI
><P
>Will this distribution run on my hardware?</P
><P
>Check with
<A
HREF="http://www.tldp.org/HOWTO/Hardware-HOWTO/index.html"
TARGET="_top"
>&#13;http://www.tldp.org/HOWTO/Hardware-HOWTO/index.html</A
> when in doubt
about compatibility of your hardware.
</P
></LI
><LI
><P
>What kind of keyboard do I have (number of keys, layout)? What
kind of mouse (serial/parallel, number of buttons)? How many MB of RAM?
</P
></LI
><LI
><P
>Will I install a basic workstation or a server, or will I need
to select specific packages myself?
</P
></LI
><LI
><P
>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?
</P
></LI
><LI
><P
>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?
</P
></LI
><LI
><P
>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?
</P
><DIV
CLASS="caution"
><P
></P
><TABLE
CLASS="caution"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Linux expects to be networked</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Not using the network or configuring it incorrectly may result in slow
startup.
</P
></TD
></TR
></TABLE
></DIV
></LI
><LI
><P
>Is this computer a gateway/router/firewall? (If you have to
think about this question, it probably isn't.)
</P
></LI
><LI
><P
>Partitioning: let the installation program do it for you this
time, we will discuss partitions in detail in <A
HREF="#chap_03"
>Chapter 3</A
>. There
is system-specific documentation available if you want to know everything about
it. If your Linux distribution does not offer default partitioning, that probably means it is not suited for beginners.
</P
></LI
><LI
><P
>Will this machine start up in text mode or in graphical mode?
</P
></LI
><LI
><P
>Think of a good password for the administrator of this machine
(root). Create a non-root user account (non-privileged access to the system).
</P
></LI
><LI
><P
>Do I need a rescue disk? (recommended)
</P
></LI
><LI
><P
>Which languages do I want?
</P
></LI
></UL
><P
>The full checklist can be found at
<A
HREF="http://www.tldp.org/HOWTO/Installation-HOWTO/index.html"
TARGET="_top"
>&#13;http://www.tldp.org/HOWTO/Installation-HOWTO/index.html</A
>.
</P
><P
>In the following chapters we will find out if the installation has been
successful.
</P
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_02"
></A
>Chapter 2. Quickstart</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN749"
></A
><P
></P
><P
>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.
</P
><P
>We will discuss:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Connecting to the system
</P
></LI
><LI
><P
>Disconnecting from the system
</P
></LI
><LI
><P
>Text and graphic mode
</P
></LI
><LI
><P
>Changing your password
</P
></LI
><LI
><P
>Navigating through the file system
</P
></LI
><LI
><P
>Determining file type
</P
></LI
><LI
><P
>Looking at text files
</P
></LI
><LI
><P
>Finding help
</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_02_01"
></A
>2.1. Logging in, activating the user interface and
logging out</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_02_01_01"
></A
>2.1.1. Introduction</H2
><P
>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 <A
HREF="#chap_01"
>Chapter 1</A
>, 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 <SPAN
CLASS="application"
>DOS</SPAN
> with mouse, multitasking and
multi-user features, or in graphical mode, which looks better but eats
more system resources.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_01_02"
></A
>2.1.2. Graphical mode</H2
><P
>This is the default nowadays on most desktop computers. You know you will connect to the system using graphical mode when you are first asked for your user name, and then, in a new window, to type your password.</P
><P
>To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click <SPAN
CLASS="guibutton"
>OK</SPAN
> or press <B
CLASS="keycap"
>Enter</B
>.</P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Careful with that root account!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>It is generally considered a bad idea to connect (graphically) using the <EM
>root</EM
> 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 to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.</P
></TD
></TR
></TABLE
></DIV
><P
>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, on the software you use and on your personal settings.</P
><P
>To continue, you will need to open a <EM
>terminal window</EM
> or <EM
>xterm</EM
> for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the <SPAN
CLASS="guimenu"
>Applications</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>Utilities</SPAN
>, <SPAN
CLASS="guimenuitem"
>System Tools</SPAN
> or <SPAN
CLASS="guimenuitem"
>Internet</SPAN
> 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.</P
><P
>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.</P
><P
>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, and the current working directory, represented by the twiddle (<TT
CLASS="filename"
>~</TT
>):</P
><DIV
CLASS="figure"
><A
NAME="AEN819"
></A
><P
><B
>Figure 2-1. Terminal window</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/xterm.png"></P
></DIV
></DIV
><P
>Another common form for a prompt is this one:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[user@host dir]</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In the above example, <EM
>user</EM
> will be your login name, <EM
>hosts</EM
> the name of the machine you are working on, and <EM
>dir</EM
> an indication of your current location in the file system.</P
><P
>Later we will discuss prompts and their behavior in detail. For now, it suffices to know that prompts can display all kinds of information, but that they are not part of the commands you are giving to your system.</P
><P
>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 <SPAN
CLASS="guimenuitem"
>Log Out</SPAN
> in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.</P
><P
>When you see the login screen again, asking to enter user name and password, logout was successful.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Gnome or KDE?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>We mentioned both the <SPAN
CLASS="application"
>Gnome</SPAN
> and <SPAN
CLASS="application"
>KDE</SPAN
> desktops already a couple of times. These are the two most popular ways of managing your desktop, although there are many, many others. Whatever desktop you chose to work with is fine - as long as you know how to open a terminal window. However, we will continue to refer to both <SPAN
CLASS="application"
>Gnome</SPAN
> and <SPAN
CLASS="application"
>KDE</SPAN
> for the most popular ways of achieving certain tasks.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_01_03"
></A
>2.1.3. Text mode</H2
><P
>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:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
RedHat Linux Release 8.0 (Psyche)
blast login: _
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The login is different from a graphical login, in that you have to hit the <B
CLASS="keycap"
>Enter</B
> key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another <B
CLASS="keycap"
>Enter</B
>. 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.</P
><P
>When the system has accepted you as a valid user, you may get some more information, called the <EM
>message of the day</EM
>, which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.</P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Don't log in as root</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a non-privileged user. Alternatively, some systems, like Ubuntu, force you to use <B
CLASS="command"
>sudo</B
>, so that you do not need direct access to the administrative account.</P
></TD
></TR
></TABLE
></DIV
><P
>Logging out is done by entering the <B
CLASS="command"
>logout</B
> command, followed by <B
CLASS="keycap"
>Enter</B
>. You are successfully disconnected from the system when you see the login screen again.</P
><DIV
CLASS="caution"
><P
></P
><TABLE
CLASS="caution"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>The power button</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>While Linux was not meant to be shut off without application of the proper procedures for halting the system, hitting the power button is equivalent to starting those procedures <EM
>on newer systems</EM
>. However, powering off an old system without going through the halting process might cause severe damage! If you want to be sure, always use the <SPAN
CLASS="guimenu"
>Shut down</SPAN
> option when you log out from the graphical interface, or, when on the login screen (where you have to give your user name and password) look around for a shutdown button.</P
></TD
></TR
></TABLE
></DIV
><P
>Now that we know how to connect to and disconnect from the system, we're ready for our first commands.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_02_02"
></A
>2.2. Absolute basics</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_02_02_01"
></A
>2.2.1. The commands</H2
><P
>These are the quickies, which we need to get started; we will discuss them later in more detail.</P
><DIV
CLASS="table"
><A
NAME="tab_02_01"
></A
><P
><B
>Table 2-1. Quickstart commands</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ls</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><P
>Displays a list of files in the current working directory, like the <B
CLASS="command"
>dir</B
> command in DOS</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cd <TT
CLASS="filename"
>directory</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><P
>change directories</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>passwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>change the password for the current user</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>file <TT
CLASS="filename"
>filename</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>display file type of file with name <TT
CLASS="filename"
>filename</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cat <TT
CLASS="filename"
>textfile</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>throws content of <TT
CLASS="filename"
>textfile</TT
> on the screen</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>pwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>display present working directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>exit</B
> or <B
CLASS="command"
>logout</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>leave this session</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>read man pages on <B
CLASS="command"
>command</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>read Info pages on <B
CLASS="command"
>command</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>apropos <TT
CLASS="parameter"
><I
>string</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>search the <EM
>whatis</EM
> database for strings</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_02_02"
></A
>2.2.2. General remarks</H2
><P
>You type these commands after the prompt, in a terminal window in graphical mode or in text mode, followed by <B
CLASS="keycap"
>Enter</B
>.</P
><P
>Commands can be issued by themselves, such as <B
CLASS="command"
>ls</B
>. A command behaves different when you specify an <EM
>option</EM
>, usually preceded with a dash (-), as in <B
CLASS="command"
>ls -a</B
>. The same option character may have a different meaning for another command. GNU programs take long options, preceded by two dashes (--), like <B
CLASS="command"
>ls --all</B
>. Some commands have no options.</P
><P
>The argument(s) to a command are specifications for the object(s) on which you want the command to take effect. An example is <B
CLASS="command"
>ls <TT
CLASS="parameter"
><I
>/etc</I
></TT
></B
>, where the directory <TT
CLASS="filename"
>/etc</TT
> is the argument to the <B
CLASS="command"
>ls</B
> command. This indicates that you want to see the content of that directory, instead of the default, which would be the content of the current directory, obtained by just typing <B
CLASS="command"
>ls</B
> followed by <B
CLASS="keycap"
>Enter</B
>. Some commands require arguments, sometimes arguments are optional.</P
><P
>You can find out whether a command takes options and arguments, and which ones are valid, by checking the online help for that command, see <A
HREF="#sect_02_03"
>Section 2.3</A
>.</P
><P
>In Linux, like in UNIX, directories are separated using forward slashes, like the ones used in web addresses (URLs). We will discuss directory structure in-depth later.</P
><P
>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.</P
><P
>Try to avoid logging in with or using the system administrator's account, <EM
>root</EM
>. 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, for instance when creating a new user or installing new software, the preferred way of obtaining root access is by switching user IDs, see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
> for an example.</P
><P
>Almost all commands in this book can be executed without system administrator privileges. In most cases, when issuing a command or starting a program as a non-privileged user, the system will warn you or prompt you for the root password when root access is required. Once you're done, leave the application or session that gives you root privileges immediately.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_02_03"
></A
>2.2.3. Using Bash features</H2
><P
>Several special key combinations allow you to do things easier and faster with the GNU shell, <SPAN
CLASS="application"
>Bash</SPAN
>, which is the default on almost any Linux system, see <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
>. Below is a list of the most commonly used features; you are strongly suggested to make a habit out of using them, so as to get the most out of your Linux experience from the very beginning.</P
><DIV
CLASS="table"
><A
NAME="tab_02_02"
></A
><P
><B
>Table 2-2. Key combinations in Bash</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Key or key combination</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Function</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>A</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Move cursor to the beginning of the command line.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>C</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>End a running program and return the prompt, see <A
HREF="#chap_04"
>Chapter 4</A
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>D</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Log out of the current shell session, equal to typing <B
CLASS="command"
>exit</B
> or <B
CLASS="command"
>logout</B
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>E</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Move cursor to the end of the command line.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>H</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Generate backspace character.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>L</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Clear this terminal.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>R</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Search command history, see <A
HREF="#sect_03_03_03_04"
>Section 3.3.3.4</A
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>Z</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Suspend a program, see <A
HREF="#chap_04"
>Chapter 4</A
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>ArrowLeft</B
> and <B
CLASS="keycap"
>ArrowRight</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Move the cursor one place to the left or right on the command line, so that you can insert characters at other places than just at the beginning and the end.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>ArrowUp</B
> and <B
CLASS="keycap"
>ArrowDown</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Browse history. Go to the line that you want to repeat, edit details if necessary, and press <B
CLASS="keycap"
>Enter</B
> to save time.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Shift</B
>+<B
CLASS="keycap"
>PageUp</B
> and <B
CLASS="keycap"
>Shift</B
>+<B
CLASS="keycap"
>PageDown</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Browse terminal buffer (to see text that has "scrolled off" the screen).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Tab</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command or filename completion; when multiple choices are possible, the system will either signal with an audio or visual bell, or, if too many choices are possible, ask you if you want to see them all.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Tab</B
> <B
CLASS="keycap"
>Tab</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Shows file or command completion possibilities.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>The last two items in the above table may need some extra explanations. For instance, if you want to change into the directory <TT
CLASS="filename"
>directory_with_a_very_long_name</TT
>, you are not going to type that very long name, no. You just type on the command line <B
CLASS="command"
>cd dir</B
>, then you press <B
CLASS="keycap"
>Tab</B
> and the shell completes the name for you, if no other files are starting with the same three characters. Of course, if there are no other items starting with <SPAN
CLASS="QUOTE"
>"d"</SPAN
>, then you might just as wel type <B
CLASS="command"
>cd d</B
> and then <B
CLASS="keycap"
>Tab</B
>. If more than one file starts with the same characters, the shell will signal this to you, upon which you can hit <B
CLASS="keycap"
>Tab</B
> twice with short interval, and the shell presents the choices you have:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>your_prompt&#62;</TT
> <B
CLASS="command"
>cd st</B
>
starthere stuff stuffit
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In the above example, if you type <SPAN
CLASS="QUOTE"
>"a"</SPAN
> after the first two characters and hit <B
CLASS="keycap"
>Tab</B
> again, no other possibilities are left, and the shell completes the directory name, without you having to type the string <SPAN
CLASS="QUOTE"
>"rthere"</SPAN
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>your_prompt&#62;</TT
> <B
CLASS="command"
>cd starthere</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Of course, you'll still have to hit <B
CLASS="keycap"
>Enter</B
> to accept this choice.</P
><P
>In the same example, if you type <SPAN
CLASS="QUOTE"
>"u"</SPAN
>, and then hit <B
CLASS="keycap"
>Tab</B
>, the shell will add the <SPAN
CLASS="QUOTE"
>"ff"</SPAN
> for you, but then it protests again, because multiple choices are possible. If you type <B
CLASS="keycap"
>Tab</B
> <B
CLASS="keycap"
>Tab</B
> again, you'll see the choices; if you type one or more characters that make the choice unambiguous to the system, and <B
CLASS="keycap"
>Tab</B
> again, or <B
CLASS="keycap"
>Enter</B
> when you've reach the end of the file name that you want to choose, the shell completes the file name and changes you into that directory - if indeed it is a directory name.</P
><P
>This works for all file names that are arguments to commands.</P
><P
>The same goes for command name completion. Typing <B
CLASS="command"
>ls</B
> and then hitting the <B
CLASS="keycap"
>Tab</B
> key twice, lists all the commands in your <TT
CLASS="varname"
>PATH</TT
> (see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
>) that start with these two characters:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>your_prompt&#62;</TT
> <B
CLASS="command"
>ls</B
>
ls lsdev lspci lsraid lsw
lsattr lsmod lspgpot lss16toppm
lsb_release lsof lspnp lsusb
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_02_03"
></A
>2.3. Getting help</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_02_03_01"
></A
>2.3.1. Be warned</H2
><P
>GNU/Linux is all about becoming more self-reliant. And as usual with this system, there are several ways to achieve the goal. A common way of getting help is finding someone who knows, and however patient and peace-loving the Linux-using community will be, almost everybody will expect you to have tried one or more of the methods in this section before asking them, and the ways in which this viewpoint is expressed may be rather harsh if you prove not to have followed this basic rule.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_03_02"
></A
>2.3.2. The man pages</H2
><P
>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: <B
CLASS="command"
>man <TT
CLASS="option"
>man</TT
></B
>.</P
><P
>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 <B
CLASS="keycap"
>Enter</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>yourname@yourcomp ~&#62;</TT
> <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>man</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The documentation for <B
CLASS="command"
>man</B
> will be displayed on your screen after you press <B
CLASS="keycap"
>Enter</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;man(1) man(1)
NAME
man - format and display the on-line manual pages
manpath - determine user's search path for man pages
SYNOPSIS
man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file]
[-M pathlist] [-P pager] [-S section_list] [section] name ...
DESCRIPTION
man formats and displays the on-line manual pages. If you specify
section, man only looks in that section of the manual.
name is normally the name of the manual page, which is typically the
name of a command, function, or file. However, if name contains a
slash (/) then man interprets it as a file specification, so that you
can do man ./foo.5 or even man /cd/foo/bar.1.gz.
See below for a description of where man looks for the manual
page files.
OPTIONS
-C config_file
lines 1-27
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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, <B
CLASS="command"
>man</B
> will usually quit and you get the prompt back. Type <B
CLASS="keycap"
>q</B
> if you want to leave the man page before reaching the end, or if the viewer does not quit automatically at the end of the page.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Pagers</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The available key combinations for manipulating the man pages depend on the <EM
>pager</EM
> used in your distribution. Most distributions use <B
CLASS="command"
>less</B
> to view the man pages and to scroll around. See <A
HREF="#sect_03_03_04_02"
>Section 3.3.4.2</A
> for more info on pagers.</P
></TD
></TR
></TABLE
></DIV
><P
>Each man page usually contains a couple of standard sections, as we can see from the <B
CLASS="command"
>man <TT
CLASS="option"
>man</TT
></B
> example:</P
><P
></P
><UL
><LI
><P
>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.</P
></LI
><LI
><P
>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 <B
CLASS="command"
>apropos</B
> command.</P
></LI
><LI
><P
>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. Optional options and arguments are put in between <SPAN
CLASS="QUOTE"
>"["</SPAN
> and <SPAN
CLASS="QUOTE"
>"]"</SPAN
> to indicate that they can be left out.</P
></LI
><LI
><P
>A longer description of the command is given.</P
></LI
><LI
><P
>Options with their descriptions are listed. Options can usually be combined. If not so, this section will tell you about it.</P
></LI
><LI
><P
>Environment describes the shell variables that influence the behavior of this command (not all commands have this).</P
></LI
><LI
><P
>Sometimes sections specific to this command are provided.</P
></LI
><LI
><P
>A reference to other man pages is given in the <SPAN
CLASS="QUOTE"
>"SEE ALSO"</SPAN
> section. In between parentheses is the number of the man page section in which to find this command. Experienced users often switch to the <SPAN
CLASS="QUOTE"
>"SEE ALSO"</SPAN
> part using the <B
CLASS="command"
>/</B
> command followed by the search string <TT
CLASS="literal"
>SEE</TT
> and press <B
CLASS="keycap"
>Enter</B
>.</P
></LI
><LI
><P
>Usually there is also information about known bugs (anomalies) and where to report new bugs you may find.</P
></LI
><LI
><P
>There might also be author and copyright information.</P
></LI
></UL
><P
>Some commands have multiple man pages. For instance, the <B
CLASS="command"
>passwd</B
> command has a man page in section 1 and another in section 5. By default, the man page with the lowest number is shown. If you want to see another section than the default, specify it after the <B
CLASS="command"
>man</B
> command:</P
><P
><B
CLASS="command"
>man <TT
CLASS="option"
>5</TT
> <TT
CLASS="parameter"
><I
>passwd</I
></TT
></B
> </P
><P
>If you want to see all man pages about a command, one after the other, use the <TT
CLASS="option"
>-a</TT
> to man:</P
><P
><B
CLASS="command"
>man <TT
CLASS="option"
>-a</TT
> <TT
CLASS="parameter"
><I
>passwd</I
></TT
></B
> </P
><P
>This way, when you reach the end of the first man page and press <B
CLASS="keycap"
>SPACE</B
> again, the man page from the next section will be displayed.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_03_03"
></A
>2.3.3. More info</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_02_03_03_01"
></A
>2.3.3.1. The Info pages</H3
><P
>In addition to the man pages, you can read the Info pages about a command, using the <B
CLASS="command"
>info</B
> command. These usually contain more recent information and are somewhat easier to use. The man pages for some commands refer to the Info pages.</P
><P
>Get started by typing <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>info</I
></TT
></B
> in a terminal window:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;File: info.info, Node: Top, Next: Getting Started, Up: (dir)
Info: An Introduction
*********************
Info is a program, which you are using now, for reading
documentation of computer programs. The GNU Project distributes most
of its on-line manuals in the Info format, so you need a program called
"Info reader" to read the manuals. One of such programs you are using
now.
If you are new to Info and want to learn how to use it, type the
command `h' now. It brings you to a programmed instruction sequence.
To learn advanced Info commands, type `n' twice. This brings you to
`Info for Experts', skipping over the `Getting Started' chapter.
* Menu:
* Getting Started:: Getting started using an Info reader.
* Advanced Info:: Advanced commands within Info.
* Creating an Info File:: How to make your own Info file.
--zz-Info: (info.info.gz)Top, 24 lines --Top-------------------------------
Welcome to Info version 4.2. Type C-h for help, m for menu item.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Use the arrow keys to browse through the text and move the cursor on a line starting with an asterisk, containing the keyword about which you want info, then hit <B
CLASS="keycap"
>Enter</B
>. Use the <B
CLASS="keycap"
>P</B
> and <B
CLASS="keycap"
>N</B
> 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. Use <B
CLASS="keycap"
>Q</B
> to quit. The <B
CLASS="command"
>info</B
> program has more information.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_02_03_03_02"
></A
>2.3.3.2. The whatis and apropos commands</H3
><P
>A short index of explanations for commands is available using the <B
CLASS="command"
>whatis</B
> command, like in the examples below:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[your_prompt]</TT
> <B
CLASS="command"
>whatis ls</B
>
ls (1) - list directory contents
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.</P
><P
>If you don't know where to get started and which man page to read, <B
CLASS="command"
>apropos</B
> gives more information. Say that you don't know how to start a browser, then you could enter the following command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>another prompt&#62;</TT
> <B
CLASS="command"
>apropos browser</B
>
Galeon [galeon](1) - gecko-based GNOME web browser
lynx (1) - a general purpose distributed information browser
for the World Wide Web
ncftp (1) - Browser program for the File Transfer Protocol
opera (1) - a graphical web browser
pilot (1) - simple file system browser in the style of the
Pine Composer
pinfo (1) - curses based lynx-style info browser
pinfo [pman] (1) - curses based lynx-style info browser
viewres (1x) - graphical class browser for Xt
</PRE
></FONT
></TD
></TR
></TABLE
><P
>After pressing <B
CLASS="keycap"
>Enter</B
> you will see that a lot of browser related stuff is on your machine: not only web browsers, but also file and FTP browsers, and browsers for documentation. If you have development packages installed, you may also have the accompanying man pages dealing with writing programs having to do with browsers. Generally, a command with a man page in section one, so one marked with <SPAN
CLASS="QUOTE"
>"(1)"</SPAN
>, is suitable for trying out as a user. The user who issued the above <B
CLASS="command"
>apropos</B
> might consequently try to start the commands <B
CLASS="command"
>galeon</B
>, <B
CLASS="command"
>lynx</B
> or <B
CLASS="command"
>opera</B
>, since these clearly have to do with browsing the world wide web.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_02_03_03_03"
></A
>2.3.3.3. The --help option</H3
><P
>Most GNU commands support the <TT
CLASS="option"
>--help</TT
>, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the <B
CLASS="command"
>cat</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>userprompt@host:</TT
> <B
CLASS="command"
>cat --help</B
>
Usage: cat [OPTION] [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonblank output lines
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank never more than one single blank line
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation,
except for LFD and TAB
--help display this help and exit
--version output version information and exit
With no FILE, or when FILE is -, read standard input.
Report bugs to &#60;bug-textutils@gnu.org&#62;.
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_02_03_04"
></A
>2.3.3.4. Graphical help</H3
><P
>Don't despair if you prefer a graphical user interface. <SPAN
CLASS="application"
>Konqueror</SPAN
>, the default <SPAN
CLASS="application"
>KDE</SPAN
> file manager, provides painless and colourful access to the man and <SPAN
CLASS="application"
>Info</SPAN
> pages. You may want to try <SPAN
CLASS="QUOTE"
>"info:info"</SPAN
> in the <EM
>Location</EM
> address bar, and you will get a browsable Info page about the <B
CLASS="command"
>info</B
> command. Similarly, <SPAN
CLASS="QUOTE"
>"man:ls"</SPAN
> will present you with the man page for the <B
CLASS="command"
>ls</B
> command. You even get command name completion: you will see the man pages for all the commands starting with <SPAN
CLASS="QUOTE"
>"ls"</SPAN
> in a scroll-down menu. Entering <SPAN
CLASS="QUOTE"
>"info:/dir"</SPAN
> in the address location toolbar displays all the Info pages, arranged in utility categories. Excellent <SPAN
CLASS="guimenu"
>Help</SPAN
> content, including the Konqueror Handbook. Start up from the menu or by typing the command <B
CLASS="command"
>konqueror</B
> in a terminal window, followed by <B
CLASS="keycap"
>Enter</B
>; see the screenshot below.</P
><DIV
CLASS="figure"
><A
NAME="AEN1381"
></A
><P
><B
>Figure 2-2. Konqueror as help browser</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/konqueror.png"></P
></DIV
></DIV
><P
>The <SPAN
CLASS="application"
>Gnome Help Browser</SPAN
> is very user friendly as well. You can start it selecting <SPAN
CLASS="guimenu"
>Applications</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>Help</SPAN
> from the <SPAN
CLASS="application"
>Gnome</SPAN
> menu, by clicking the lifeguard icon on your desktop or by entering the command <B
CLASS="command"
>gnome-help</B
> in a terminal window. The system documentation and man pages are easily browsable with a plain interface.</P
><P
>The <B
CLASS="command"
>nautilus</B
> file manager provides a searchable index of the man and <SPAN
CLASS="application"
>Info</SPAN
> pages, they are easily browsable and interlinked. <SPAN
CLASS="application"
>Nautilus</SPAN
> is started from the command line, or clicking your home directory icon, or from the <SPAN
CLASS="application"
>Gnome</SPAN
> menu.</P
><P
>The big advantage of GUIs for system documentation is that all information is completely interlinked, so you can click through in the <SPAN
CLASS="QUOTE"
>"SEE ALSO"</SPAN
> sections and wherever links to other man pages appear, and thus browse and acquire knowledge without interruption for hours at the time.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_02_03_05"
></A
>2.3.3.5. Exceptions</H3
><P
>Some commands don't have separate documentation, because they are part of another command. <B
CLASS="command"
>cd</B
>, <B
CLASS="command"
>exit</B
>, <B
CLASS="command"
>logout</B
> and <B
CLASS="command"
>pwd</B
> are such exceptions. They are part of your shell program and are called <EM
>shell built-in</EM
> commands. For information about these, refer to the man or info page of your shell. Most beginning Linux users have a Bash shell. See <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
> for more about shells.</P
><P
>If you have been changing your original system configuration, it might also be possible that man pages are still there, but not visible because your shell environment has changed. In that case, you will need to check the <TT
CLASS="varname"
>MANPATH</TT
> variable. How to do this is explained in <A
HREF="#sect_07_02_02"
>Section 7.2.1.2</A
>.</P
><P
>Some programs or packages only have a set of instructions or references in the directory <TT
CLASS="filename"
>/usr/share/doc</TT
>. See <A
HREF="#sect_03_03_04"
>Section 3.3.4</A
> to display.</P
><P
>In the worst case, you may have removed the documentation from your system by accident (hopefully by accident, because it is a very bad idea to do this on purpose). In that case, first try to make sure that there is really nothing appropriate left using a search tool, read on in <A
HREF="#sect_03_03_03"
>Section 3.3.3</A
>. If so, you may have to re-install the package that contains the command to which the documentation applied, see <A
HREF="#sect_07_06"
>Section 7.5</A
>.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_02_04"
></A
>2.4. Summary</H1
><P
>Linux traditionally operates in text mode or in graphical mode. Since CPU power and RAM are not the cost anymore these days, every Linux user can afford to work in graphical mode and will usually do so. This does not mean that you don't have to know about text mode: we will work in the text environment throughout this course, using a terminal window.</P
><P
>Linux encourages its users to acquire knowledge and to become independent. Inevitably, you will have to read a lot of documentation to achieve that goal; that is why, as you will notice, we refer to extra documentation for almost every command, tool and problem listed in this book. The more docs you read, the easier it will become and the faster you will leaf through manuals. Make reading documentation a habit as soon as possible. When you don't know the answer to a problem, refering to the documentation should become a second nature.</P
><P
>We already learned some commands:</P
><DIV
CLASS="table"
><A
NAME="AEN1438"
></A
><P
><B
>Table 2-3. New commands in chapter 2: Basics</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>apropos</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Search information about a command or subject.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show content of one or more files.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change into another directory.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>exit</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Leave a shell session.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>file</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Get information about the content of a file.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>info</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Read <SPAN
CLASS="application"
>Info</SPAN
> pages about a command.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>logout</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Leave a shell session.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ls</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>List directory content.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>man</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Read manual pages of a command.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>passwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change your password.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>pwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display the current working directory.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_02_05"
></A
>2.5. Exercises</H1
><P
>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.</P
><P
>Don't forget to use the Bash features on the command line: try to do the exercises typing as few characters as possible!</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_05_01"
></A
>2.5.1. Connecting and disconnecting</H2
><P
>&#13;<P
></P
><UL
><LI
><P
>Determine whether you are working in text or in graphical mode.</P
><P
>I am working in text/graphical mode. (cross out what's not applicable)</P
></LI
><LI
><P
>Log in with the user name and password you made for yourself during the installation.</P
></LI
><LI
><P
>Log out.</P
></LI
><LI
><P
>Log in again, using a non-existent user name</P
><P
>-&#62; What happens?</P
></LI
></UL
>
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_05_02"
></A
>2.5.2. Passwords</H2
><P
>Log in again with your user name and password.</P
><P
></P
><UL
><LI
><P
>Change your password into <EM
>P6p3.aa!</EM
> and hit the <B
CLASS="keycap"
>Enter</B
> key.</P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>Try again, this time enter a password that is ridiculously easy, like <EM
>123</EM
> or <EM
>aaa</EM
>.</P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>Try again, this time don't enter a password but just hit the <B
CLASS="keycap"
>Enter</B
> key.</P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>Try the command <B
CLASS="command"
>psswd</B
> instead of <B
CLASS="command"
>passwd</B
></P
><P
>-&#62; What happens?</P
></LI
></UL
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>New password</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Unless you change your password back again to what it was before this exercise, it will be <SPAN
CLASS="QUOTE"
>"P6p3.aa!"</SPAN
>. Change your password after this exercise!</P
><P
>Note that some systems might not allow to recycle passwords, i.e. restore the original one within a certain amount of time or a certain amount of password changes, or both.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_05_03"
></A
>2.5.3. Directories</H2
><P
>These are some exercises to help you get the feel.</P
><P
></P
><UL
><LI
><P
>Enter the command <B
CLASS="command"
>cd <TT
CLASS="filename"
>blah</TT
></B
></P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>Enter the command <B
CLASS="command"
>cd <TT
CLASS="filename"
>..</TT
></B
></P
><P
>Mind the space between "cd" and ".."! Use the <B
CLASS="command"
>pwd</B
> command.</P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>List the directory contents with the <B
CLASS="command"
>ls</B
> command.</P
><P
>-&#62; What do you see?</P
><P
>-&#62; What do you think these are?</P
><P
>-&#62; Check using the <B
CLASS="command"
>pwd</B
> command.</P
></LI
><LI
><P
>Enter the <B
CLASS="command"
>cd</B
> command.</P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>Repeat step 2 two times.</P
><P
>-&#62; What happens?</P
></LI
><LI
><P
>Display the content of this directory.</P
></LI
><LI
><P
>Try the command <B
CLASS="command"
>cd <TT
CLASS="filename"
>root</TT
></B
></P
><P
>-&#62; What happens?</P
><P
>-&#62; To which directories do you have access?</P
></LI
><LI
><P
>Repeat step 4.</P
><P
>Do you know another possibility to get where you are now?</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_05_04"
></A
>2.5.4. Files</H2
><P
></P
><UL
><LI
><P
>Change directory to <TT
CLASS="filename"
>/</TT
> and then to <TT
CLASS="filename"
>etc</TT
>. Type <B
CLASS="command"
>ls</B
>; if the output is longer than your screen, make the window longer, or try <B
CLASS="keycap"
>Shift</B
>+<B
CLASS="keycap"
>PageUp</B
> and <B
CLASS="keycap"
>Shift</B
>+<B
CLASS="keycap"
>PageDown</B
>.</P
><P
>The file <TT
CLASS="filename"
>inittab</TT
> contains the answer to the first question in this list. Try the <B
CLASS="command"
>file</B
> command on it.</P
><P
>-&#62; The file type of my <TT
CLASS="filename"
>inittab</TT
> is .....</P
></LI
><LI
><P
>Use the command <B
CLASS="command"
>cat <TT
CLASS="filename"
>inittab</TT
></B
> and read the file.</P
><P
>-&#62; What is the default mode of your computer?</P
></LI
><LI
><P
>Return to your home directory using the <B
CLASS="command"
>cd</B
> command.</P
></LI
><LI
><P
>Enter the command <B
CLASS="command"
>file <TT
CLASS="filename"
>.</TT
></B
></P
><P
>-&#62; Does this help to find the meaning of <SPAN
CLASS="QUOTE"
>"."</SPAN
>? </P
></LI
><LI
><P
>Can you look at "." using the <B
CLASS="command"
>cat</B
> command?</P
><P
></P
></LI
><LI
><P
>Display help for the <B
CLASS="command"
>cat</B
> program, using the <TT
CLASS="option"
>--help</TT
> option. Use the option for numbering of output lines to count how many users are listed in the file <TT
CLASS="filename"
>/etc/passwd</TT
>.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_02_05_05"
></A
>2.5.5. Getting help</H2
><P
></P
><UL
><LI
><P
>Read <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>intro</I
></TT
></B
></P
></LI
><LI
><P
>Read <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>ls</I
></TT
></B
></P
></LI
><LI
><P
>Read <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>passwd</I
></TT
></B
></P
></LI
><LI
><P
>Enter the <B
CLASS="command"
>apropos <TT
CLASS="option"
>pwd</TT
></B
> command.</P
></LI
><LI
><P
>Try <B
CLASS="command"
>man</B
> or <B
CLASS="command"
>info</B
> on <B
CLASS="command"
>cd</B
>.</P
><P
>-&#62; How would you find out more about <B
CLASS="command"
>cd</B
>? </P
></LI
><LI
><P
>Read <B
CLASS="command"
>ls <TT
CLASS="option"
>--help</TT
></B
> and try it out.</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_03"
></A
>Chapter 3. About files and the file system</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN1650"
></A
><P
></P
><P
>After the initial exploration in <A
HREF="#chap_02"
>Chapter 2</A
>, we are ready to discuss the files and directories on a Linux system in more detail. Many users have difficulties with Linux because they lack an overview of what kind of data is kept in which locations. We will try to shine some light on the organization of files in the file system.
</P
><P
>We will also list the most important files and directories and use different methods of viewing the content of those files, and learn how files and directories can be created, moved and deleted.</P
><P
>After completion of the exercises in this chapter, you will be able to:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Describe the layout of a Linux file system</P
></LI
><LI
><P
>Display and set paths</P
></LI
><LI
><P
>Describe the most important files, including kernel and shell</P
></LI
><LI
><P
>Find lost and hidden files</P
></LI
><LI
><P
>Create, move and delete files and directories</P
></LI
><LI
><P
>Display contents of files</P
></LI
><LI
><P
>Understand and use different link types</P
></LI
><LI
><P
>Find out about file properties and change file permissions</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_03_01"
></A
>3.1. General overview of the Linux file system</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_03_01_01"
></A
>3.1.1. Files</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_01_01_01"
></A
>3.1.1.1. General</H3
><P
>A simple description of the UNIX system, also applicable to Linux, is this:</P
><P
><SPAN
CLASS="QUOTE"
>"On a UNIX system, everything is a file; if something is not a file, it is a process."</SPAN
></P
><P
>This statement is true because there are special files that are more than just files (named pipes and sockets, for instance), but to keep things simple, saying that everything is a file is an acceptable generalization. A Linux system, just like UNIX, makes no difference between a file and a directory, since a directory is just a file containing names of other files. Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.</P
><P
>In order to manage all those files in an orderly fashion, man likes to think of them in an ordered tree-like structure on the hard disk, as we know from <SPAN
CLASS="application"
>MS-DOS</SPAN
> (Disk Operating System) for instance. The large branches contain more branches, and the branches at the end contain the tree's leaves or normal files. For now we will use this image of the tree, but we will find out later why this is not a fully accurate image.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_01_01_02"
></A
>3.1.1.2. Sorts of files</H3
><P
>Most files are just files, called <EM
>regular</EM
> files; they contain normal data, for example text files, executable files or programs, input for or output from a program and so on.</P
><P
>While it is reasonably safe to suppose that everything you encounter on a Linux system is a file, there are some exceptions.</P
><P
></P
><UL
><LI
><P
><EM
>Directories</EM
>: files that are lists of other files.</P
></LI
><LI
><P
><EM
>Special files</EM
>: the mechanism used for input and output. Most special files are in <TT
CLASS="filename"
>/dev</TT
>, we will discuss them later.</P
></LI
><LI
><P
><EM
>Links</EM
>: a system to make a file or directory visible in multiple parts of the system's file tree. We will talk about links in detail.</P
></LI
><LI
><P
><EM
>(Domain) sockets</EM
>: a special file type, similar to TCP/IP sockets, providing inter-process networking protected by the file system's access control.</P
></LI
><LI
><P
><EM
>Named pipes</EM
>: act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics.</P
></LI
></UL
><P
>The <TT
CLASS="option"
>-l</TT
> option to <B
CLASS="command"
>ls</B
> displays the file type, using the first character of each input line:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jaime:~/Documents&#62;</TT
> <B
CLASS="command"
>ls -l</B
>
total 80
-rw-rw-r-- 1 jaime jaime 31744 Feb 21 17:56 intro Linux.doc
-rw-rw-r-- 1 jaime jaime 41472 Feb 21 17:56 Linux.doc
drwxrwxr-x 2 jaime jaime 4096 Feb 25 11:50 course
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This table gives an overview of the characters determining the file type:</P
><DIV
CLASS="table"
><A
NAME="AEN1749"
></A
><P
><B
>Table 3-1. File types in a long list</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Symbol</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>-</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Regular file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>d</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>l</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Link</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>c</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Special file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>s</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Socket</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>p</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Named pipe</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>b</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Block device</TD
></TR
></TBODY
></TABLE
></DIV
><P
>In order not to always have to perform a long listing for seeing the file type, a lot of systems by default don't issue just <B
CLASS="command"
>ls</B
>, but <B
CLASS="command"
>ls <TT
CLASS="option"
>-F</TT
></B
>, which suffixes file names with one of the characters <SPAN
CLASS="QUOTE"
>"/=*|@"</SPAN
> to indicate the file type. To make it extra easy on the beginning user, both the <TT
CLASS="option"
>-F</TT
> and <TT
CLASS="option"
>--color</TT
> options are usually combined, see <A
HREF="#sect_03_03_01_01"
>Section 3.3.1.1</A
>. We will use <B
CLASS="command"
>ls <TT
CLASS="option"
>-F</TT
></B
> throughout this document for better readability.</P
><P
>As a user, you only need to deal directly with plain files, executable files, directories and links. The special file types are there for making your system do what you demand from it and are dealt with by system administrators and programmers.</P
><P
>&#13;Now, before we look at the important files and directories, we need to know more about partitions.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_01_02"
></A
>3.1.2. About partitioning</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_01_02_01"
></A
>3.1.2.1. Why partition?</H3
><P
>Most people have a vague knowledge of what partitions are, since every operating system has the ability to create or remove them. It may seem strange that Linux uses more than one partition on the same disk, even when using the standard installation procedure, so some explanation is called for.</P
><P
>One of the goals of having different partitions is to achieve higher data security in case of disaster. By dividing the hard disk in partitions, data can be grouped and separated. When an accident occurs, only the data in the partition that got the hit will be damaged, while the data on the other partitions will most likely survive. </P
><P
>This principle dates from the days when Linux didn't have journaled file systems and power failures might have lead to disaster. The use of partitions remains for security and robustness reasons, so a breach on one part of the system doesn't automatically mean that the whole computer is in danger. This is currently the most important reason for partitioning. A simple example: a user creates a script, a program or a web application that starts filling up the disk. If the disk contains only one big partition, the entire system will stop functioning if the disk is full. If the user stores the data on a separate partition, then only that (data) partition will be affected, while the system partitions and possible other data partitions keep functioning.</P
><P
>Mind that having a journaled file system only provides data security in case of power failure and sudden disconnection of storage devices. This does not protect your data against bad blocks and logical errors in the file system. In those cases, you should use a RAID (Redundant Array of Inexpensive Disks) solution.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_01_02_02"
></A
>3.1.2.2. Partition layout and types</H3
><P
>There are two kinds of major partitions on a Linux system:</P
><P
></P
><UL
><LI
><P
><EM
>data partition</EM
>: normal Linux system data, including the <EM
>root partition</EM
> containing all the data to start up and run the system; and </P
></LI
><LI
><P
><EM
>swap partition</EM
>: expansion of the computer's physical memory, extra memory on hard disk.</P
></LI
></UL
><P
>Most systems contain a root partition, one or more data partitions and one or more swap partitions. Systems in mixed environments may contain partitions for other system data, such as a partition with a FAT or VFAT file system for MS Windows data.</P
><P
>Most Linux systems use <B
CLASS="command"
>fdisk</B
> at installation time to set the partition type. As you may have noticed during the exercise from Chapter 1, this usually happens automatically. On some occasions, however, you may not be so lucky. In such cases, you will need to select the partition type manually and even manually do the actual partitioning. The standard Linux partitions have number 82 for swap and 83 for data, which can be journaled (ext3) or normal (ext2, on older systems). The <B
CLASS="command"
>fdisk</B
> utility has built-in help, should you forget these values.</P
><P
>Apart from these two, Linux supports a variety of other file system types, such as the relatively new Reiser file system, JFS, NFS, FATxx and many other file systems natively available on other (proprietary) operating systems.</P
><P
>The standard root partition (indicated with a single forward slash, <EM
>/</EM
>) is about 100-500 MB, and contains the system configuration files, most basic commands and server programs, system libraries, some temporary space and the home directory of the administrative user. A standard installation requires about 250 MB for the root partition.</P
><P
>Swap space (indicated with <EM
>swap</EM
>) is only accessible for the system itself, and is hidden from view during normal operation. Swap is the system that ensures, like on normal UNIX systems, that you can keep on working, whatever happens. On Linux, you will virtually never see irritating messages like <EM
>Out of memory, please close some applications first and try again</EM
>, because of this extra memory. The swap or virtual memory procedure has long been adopted by operating systems outside the UNIX world by now.</P
><P
>Using memory on a hard disk is naturally slower than using the real memory chips of a computer, but having this little extra is a great comfort. We will learn more about swap when we discuss processes in <A
HREF="#chap_04"
>Chapter 4</A
>.</P
><P
>Linux generally counts on having twice the amount of physical memory in the form of swap space on the hard disk. When installing a system, you have to know how you are going to do this. An example on a system with 512 MB of RAM:</P
><P
></P
><UL
><LI
><P
>1st possibility: one swap partition of 1 GB</P
></LI
><LI
><P
>2nd possibility: two swap partitions of 512 MB</P
></LI
><LI
><P
>3rd possibility: with two hard disks: 1 partition of 512 MB on each disk.</P
></LI
></UL
><P
>The last option will give the best results when a lot of I/O is to be expected.</P
><P
>Read the software documentation for specific guidelines. Some applications, such as databases, might require more swap space. Others, such as some handheld systems, might not have any swap at all by lack of a hard disk. Swap space may also depend on your kernel version.</P
><P
>The kernel is on a separate partition as well in many distributions, because it is the most important file of your system. If this is the case, you will find that you also have a <EM
>/boot</EM
> partition, holding your kernel(s) and accompanying data files.</P
><P
>The rest of the hard disk(s) is generally divided in data partitions, although it may be that all of the non-system critical data resides on one partition, for example when you perform a standard workstation installation. When non-critical data is separated on different partitions, it usually happens following a set pattern:</P
><P
></P
><UL
><LI
><P
>a partition for user programs (<EM
>/usr</EM
>)</P
></LI
><LI
><P
>a partition containing the users' personal data (<EM
>/home</EM
>)</P
></LI
><LI
><P
>a partition to store temporary data like print- and mail-queues (<EM
>/var</EM
>)</P
></LI
><LI
><P
>a partition for third party and extra software (<EM
>/opt</EM
>)</P
></LI
></UL
><P
>Once the partitions are made, you can only add more. Changing sizes or properties of existing partitions is possible but not advisable.</P
><P
>The division of hard disks into partitions is determined by the system administrator. On larger systems, he or she may even spread one partition over several hard disks, using the appropriate software. Most distributions allow for standard setups optimized for workstations (average users) and for general server purposes, but also accept customized partitions. During the installation process you can define your own partition layout using either your distribution specific tool, which is usually a straight forward graphical interface, or <B
CLASS="command"
>fdisk</B
>, a text-based tool for creating partitions and setting their properties.</P
><P
>A workstation or client installation is for use by mainly one and the same person. The selected software for installation reflects this and the stress is on common user packages, such as nice desktop themes, development tools, client programs for E-mail, multimedia software, web and other services. Everything is put together on one large partition, swap space twice the amount of RAM is added and your generic workstation is complete, providing the largest amount of disk space possible for personal use, but with the disadvantage of possible data integrity loss during problem situations.</P
><P
>On a server, system data tends to be separate from user data. Programs that offer services are kept in a different place than the data handled by this service. Different partitions will be created on such systems:</P
><P
></P
><UL
><LI
><P
>a partition with all data necessary to boot the machine</P
></LI
><LI
><P
>a partition with configuration data and server programs</P
></LI
><LI
><P
>one or more partitions containing the server data such as database tables, user mails, an ftp archive etc.</P
></LI
><LI
><P
>a partition with user programs and applications</P
></LI
><LI
><P
>one or more partitions for the user specific files (home directories)</P
></LI
><LI
><P
>one or more swap partitions (virtual memory)</P
></LI
></UL
><P
>Servers usually have more memory and thus more swap space. Certain server processes, such as databases, may require more swap space than usual; see the specific documentation for detailed information. For better performance, swap is often divided into different swap partitions.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_01_02_03"
></A
>3.1.2.3. Mount points</H3
><P
>All partitions are attached to the system via a mount point. The mount point defines the place of a particular data set in the file system. Usually, all partitions are connected through the <EM
>root</EM
> partition. On this partition, which is indicated with the slash (/), directories are created. These empty directories will be the starting point of the partitions that are attached to them. An example: given a partition that holds the following directories:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;videos/ cd-images/ pictures/
</PRE
></FONT
></TD
></TR
></TABLE
><P
>We want to attach this partition in the filesystem in a directory called <TT
CLASS="filename"
>/opt/media</TT
>. In order to do this, the system administrator has to make sure that the directory <TT
CLASS="filename"
>/opt/media</TT
> exists on the system. Preferably, it should be an empty directory. How this is done is explained later in this chapter. Then, using the <B
CLASS="command"
>mount</B
> command, the administrator can attach the partition to the system. When you look at the content of the formerly empty directory <TT
CLASS="filename"
>/opt/media</TT
>, it will contain the files and directories that are on the mounted medium (hard disk or partition of a hard disk, CD, DVD, flash card, USB or other storage device).</P
><P
>During system startup, all the partitions are thus mounted, as described in the file <TT
CLASS="filename"
>/etc/fstab</TT
>. Some partitions are not mounted by default, for instance if they are not constantly connected to the system, such like the storage used by your digital camera. If well configured, the device will be mounted as soon as the system notices that it is connected, or it can be user-mountable, i.e. you don't need to be system administrator to attach and detach the device to and from the system. There is an example in <A
HREF="#sect_09_03"
>Section 9.3</A
>.</P
><P
>On a running system, information about the partitions and their mount points can be displayed using the <B
CLASS="command"
>df</B
> command (which stands for <EM
>disk full</EM
> or <EM
>disk free</EM
>). In Linux, <B
CLASS="command"
>df</B
> is the GNU version, and supports the <TT
CLASS="option"
>-h</TT
> or <EM
>human readable</EM
> option which greatly improves readability. Note that commercial UNIX machines commonly have their own versions of <B
CLASS="command"
>df</B
> and many other commands. Their behavior is usually the same, though GNU versions of common tools often have more and better features.</P
><P
>The <B
CLASS="command"
>df</B
> command only displays information about active non-swap partitions. These can include partitions from other networked systems, like in the example below where the home directories are mounted from a file server on the network, a situation often encountered in corporate environments.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>freddy:~&#62;</TT
> <B
CLASS="command"
>df -h</B
>
Filesystem Size Used Avail Use% Mounted on
/dev/hda8 496M 183M 288M 39% /
/dev/hda1 124M 8.4M 109M 8% /boot
/dev/hda5 19G 15G 2.7G 85% /opt
/dev/hda6 7.0G 5.4G 1.2G 81% /usr
/dev/hda7 3.7G 2.7G 867M 77% /var
fs1:/home 8.9G 3.7G 4.7G 44% /.automount/fs1/root/home
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_01_03"
></A
>3.1.3. More file system layout</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_01_03_01"
></A
>3.1.3.1. Visual</H3
><P
>For convenience, the Linux file system is usually thought of in a tree structure. On a standard Linux system you will find the layout generally follows the scheme presented below.</P
><DIV
CLASS="figure"
><A
NAME="AEN1977"
></A
><P
><B
>Figure 3-1. Linux file system layout</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/FS-layout.png"></P
></DIV
></DIV
><P
>This is a layout from a RedHat system. Depending on the system admin, the operating system and the mission of the UNIX machine, the structure may vary, and directories may be left out or added at will. The names are not even required; they are only a convention.</P
><P
>The tree of the file system starts at the trunk or <EM
>slash</EM
>, indicated by a forward slash (/). This directory, containing all underlying directories and files, is also called the <EM
>root directory</EM
> or <SPAN
CLASS="QUOTE"
>"the root"</SPAN
> of the file system.</P
><P
>Directories that are only one level below the root directory are often preceded by a slash, to indicate their position and prevent confusion with other directories that could have the same name. When starting with a new system, it is always a good idea to take a look in the root directory. Let's see what you could run into:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>emmy:~&#62;</TT
> <B
CLASS="command"
>cd /</B
>
<TT
CLASS="prompt"
>emmy:/&#62;</TT
> <B
CLASS="command"
>ls</B
>
bin/ dev/ home/ lib/ misc/ opt/ root/ tmp/ var/
boot/ etc/ initrd/ lost+found/ mnt/ proc/ sbin/ usr/
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="table"
><A
NAME="AEN2004"
></A
><P
><B
>Table 3-2. Subdirectories of the root directory</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Directory</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Content</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/bin</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Common programs, shared by the system, the system administrator and the users.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/boot</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>The startup files and the kernel, <TT
CLASS="filename"
>vmlinuz</TT
>. In some recent distributions also <TT
CLASS="filename"
>grub</TT
> data. Grub is the <SPAN
CLASS="application"
>GRand Unified Boot</SPAN
> loader and is an attempt to get rid of the many different boot-loaders we know today.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/dev</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Contains references to all the CPU peripheral hardware, which are represented as files with special properties.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/etc</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Most important system configuration files are in <TT
CLASS="filename"
>/etc</TT
>, this directory contains data similar to those in the Control Panel in Windows</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/home</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Home directories of the common users.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/initrd</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>(on some distributions) Information for booting. Do not remove!</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/lib</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Library files, includes files for all kinds of programs needed by the system and the users.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/lost+found</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Every partition has a <TT
CLASS="filename"
>lost+found</TT
> in its upper directory. Files that were saved during failures are here.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/misc</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>For miscellaneous purposes.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/mnt</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/net</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Standard mount point for entire remote file systems</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/opt</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Typically contains extra and third party software.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/proc</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>A virtual file system containing information about system resources. More information about the meaning of the files in <TT
CLASS="filename"
>proc</TT
> is obtained by entering the command <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>proc</I
></TT
></B
> in a terminal window. The file <TT
CLASS="filename"
>proc.txt</TT
> discusses the virtual file system in detail.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/root</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>The administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the <EM
>root</EM
> user.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/sbin</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Programs for use by the system and the system administrator.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/tmp</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Temporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/usr</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Programs, libraries, documentation etc. for all user-related programs.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/var</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>How can you find out which partition a directory is on? Using the <B
CLASS="command"
>df</B
> command with a dot (.) as an option shows the partition the current directory belongs to, and informs about the amount of space used on this partition:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>sandra:/lib&#62;</TT
> <B
CLASS="command"
>df -h .</B
>
Filesystem Size Used Avail Use% Mounted on
/dev/hda7 980M 163M 767M 18% /
</PRE
></FONT
></TD
></TR
></TABLE
><P
>As a general rule, every directory under the root directory is on the root partition, unless it has a separate entry in the full listing from <B
CLASS="command"
>df</B
> (or <B
CLASS="command"
>df <TT
CLASS="option"
>-h</TT
></B
> with no other options).</P
><P
>Read more in <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>hier</I
></TT
></B
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_01_03_02"
></A
>3.1.3.2. The file system in reality</H3
><P
>For most users and for most common system administration tasks, it is enough to accept that files and directories are ordered in a tree-like structure. The computer, however, doesn't understand a thing about trees or tree-structures.</P
><P
>Every partition has its own file system. By imagining all those file systems together, we can form an idea of the tree-structure of the entire system, but it is not as simple as that. In a file system, a file is represented by an <EM
>inode</EM
>, a kind of serial number containing information about the actual data that makes up the file: to whom this file belongs, and where is it located on the hard disk.</P
><P
>Every partition has its own set of inodes; throughout a system with multiple partitions, files with the same inode number can exist.</P
><P
>Each inode describes a data structure on the hard disk, storing the properties of a file, including the physical location of the file data. When a hard disk is initialized to accept data storage, usually during the initial system installation process or when adding extra disks to an existing system, a fixed number of inodes per partition is created. This number will be the maximum amount of files, of all types (including directories, special files, links etc.) that can exist at the same time on the partition. We typically count on having 1 inode per 2 to 8 kilobytes of storage.</P
><P
>At the time a new file is created, it gets a free inode. In that inode is the following information:</P
><P
></P
><UL
><LI
><P
>Owner and group owner of the file.</P
></LI
><LI
><P
>File type (regular, directory, ...)</P
></LI
><LI
><P
>Permissions on the file <A
HREF="#sect_03_04_01"
>Section 3.4.1</A
></P
></LI
><LI
><P
>Date and time of creation, last read and change.</P
></LI
><LI
><P
>Date and time this information has been changed in the inode.</P
></LI
><LI
><P
>Number of links to this file (see later in this chapter).</P
></LI
><LI
><P
>File size</P
></LI
><LI
><P
>An address defining the actual location of the file data.</P
></LI
></UL
><P
>The only information not included in an inode, is the file name and directory. These are stored in the special directory files. By comparing file names and inode numbers, the system can make up a tree-structure that the user understands. Users can display inode numbers using the <TT
CLASS="option"
>-i</TT
> option to ls. The inodes have their own separate space on the disk.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_03_02"
></A
>3.2. Orientation in the file system</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_03_02_01"
></A
>3.2.1. The path</H2
><P
>When you want the system to execute a command, you almost never have to give the full path to that command. For example, we know that the <B
CLASS="command"
>ls</B
> command is in the <TT
CLASS="filename"
>/bin</TT
> directory (check with <B
CLASS="command"
>which <TT
CLASS="option"
>-a</TT
> <TT
CLASS="parameter"
><I
>ls</I
></TT
></B
>), yet we don't have to enter the command <B
CLASS="command"
>/bin/ls</B
> for the computer to list the content of the current directory.</P
><P
>The <TT
CLASS="varname"
>PATH</TT
> environment variable takes care of this. This variable lists those directories in the system where executable files can be found, and thus saves the user a lot of typing and memorizing locations of commands. So the path naturally contains a lot of directories containing <TT
CLASS="filename"
>bin</TT
> somewhere in their names, as the user below demonstrates. The <B
CLASS="command"
>echo</B
> command is used to display the content (<SPAN
CLASS="QUOTE"
>"$"</SPAN
>) of the variable <TT
CLASS="varname"
>PATH</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>rogier:&#62;</TT
> <B
CLASS="command"
>echo $PATH</B
>
/opt/local/bin:/usr/X11R6/bin:/usr/bin:/usr/sbin/:/bin
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In this example, the directories <TT
CLASS="filename"
>/opt/local/bin</TT
>, <TT
CLASS="filename"
>/usr/X11R6/bin</TT
>, <TT
CLASS="filename"
>/usr/bin</TT
>, <TT
CLASS="filename"
>/usr/sbin</TT
> and <TT
CLASS="filename"
>/bin</TT
> are subsequently searched for the required program. As soon as a match is found, the search is stopped, even if not every directory in the path has been searched. This can lead to strange situations. In the first example below, the user knows there is a program called <B
CLASS="command"
>sendsms</B
> to send an SMS message, and another user on the same system can use it, but she can't. The difference is in the configuration of the <TT
CLASS="varname"
>PATH</TT
> variable:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[jenny@blob jenny]$</TT
> <B
CLASS="command"
>sendsms</B
>
bash: sendsms: command not found
[jenny@blob jenny]$ echo $PATH
/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/home/jenny/bin
[jenny@blob jenny]$ su - tony
Password:
tony:~&#62;which sendsms
sendsms is /usr/local/bin/sendsms
tony:~&#62;echo $PATH
/home/tony/bin.Linux:/home/tony/bin:/usr/local/bin:/usr/local/sbin:\
/usr/X11R6/bin:/usr/bin:/usr/sbin:/bin:/sbin
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Note the use of the <B
CLASS="command"
>su</B
> (switch user) facility, which allows you to run a shell in the environment of another user, on the condition that you know the user's password.</P
><P
>A backslash indicates the continuation of a line on the next, without an <B
CLASS="keycap"
>Enter</B
> separating one line from the other.</P
><P
>In the next example, a user wants to call on the <B
CLASS="command"
>wc</B
> (word count) command to check the number of lines in a file, but nothing happens and he has to break off his action using the <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>C</B
> combination:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jumper:~&#62;</TT
> <B
CLASS="command"
>wc -l test</B
>
(Ctrl-C)
<TT
CLASS="prompt"
>jumper:~&#62;</TT
> <B
CLASS="command"
>which wc</B
>
wc is hashed (/home/jumper/bin/wc)
<TT
CLASS="prompt"
>jumper:~&#62;</TT
> <B
CLASS="command"
>echo $PATH</B
>
/home/jumper/bin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:\
/usr/bin:/usr/sbin:/bin:/sbin
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The use of the <B
CLASS="command"
>which</B
> command shows us that this user has a <TT
CLASS="filename"
>bin</TT
>-directory in his home directory, containing a program that is also called <B
CLASS="command"
>wc</B
>. Since the program in his home directory is found first when searching the paths upon a call for <B
CLASS="command"
>wc</B
>, this <SPAN
CLASS="QUOTE"
>"home-made"</SPAN
> program is executed, with input it probably doesn't understand, so we have to stop it. To resolve this problem there are several ways (there are always several ways to solve a problem in UNIX/Linux): one answer could be to rename the user's <B
CLASS="command"
>wc</B
> program, or the user can give the full path to the exact command he wants, which can be found by using the <TT
CLASS="option"
>-a</TT
> option to the <B
CLASS="command"
>which</B
> command.</P
><P
>If the user uses programs in the other directories more frequently, he can change his path to look in his own directories last:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jumper:~&#62;</TT
> <B
CLASS="command"
>export PATH=/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:\
/usr/bin:/usr/sbin:/bin:/sbin:/home/jumper/bin</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Changes are not permanent!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Note that when using the <B
CLASS="command"
>export</B
> command in a shell, the changes are temporary and only valid for this session (until you log out). Opening new sessions, even while the current one is still running, will not result in a new path in the new session. We will see in <A
HREF="#sect_07_02"
>Section 7.2</A
> how we can make these kinds of changes to the environment permanent, adding these lines to the shell configuration files.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_02_02"
></A
>3.2.2. Absolute and relative paths</H2
><P
>A path, which is the way you need to follow in the tree structure to reach a given file, can be described as starting from the trunk of the tree (the / or root directory). In that case, the path starts with a slash and is called an absolute path, since there can be no mistake: only one file on the system can comply.</P
><P
>In the other case, the path doesn't start with a slash and confusion is possible between <TT
CLASS="filename"
>~/bin/wc</TT
> (in the user's home directory) and <TT
CLASS="filename"
>bin/wc</TT
> in <TT
CLASS="filename"
>/usr</TT
>, from the previous example. Paths that don't start with a slash are always relative.</P
><P
>In relative paths we also use the . and .. indications for the current and the parent directory. A couple of practical examples:</P
><P
></P
><UL
><LI
><P
>When you want to compile source code, the installation documentation often instructs you to run the command <B
CLASS="command"
>./configure</B
>, which runs the <EM
>configure</EM
> program located in the current directory (that came with the new code), as opposed to running another configure program elsewhere on the system.</P
></LI
><LI
><P
>In HTML files, relative paths are often used to make a set of pages easily movable to another place:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;&#60;img alt="Garden with trees" src="../images/garden.jpg"&#62;
</PRE
></FONT
></TD
></TR
></TABLE
></LI
><LI
><P
>Notice the difference one more time:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>theo:~&#62;</TT
> <B
CLASS="command"
>ls /mp3</B
>
ls: /mp3: No such file or directory
theo:~&#62;ls mp3/
oriental/ pop/ sixties/
</PRE
></FONT
></TD
></TR
></TABLE
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_02_03"
></A
>3.2.3. The most important files and directories</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_02_03_01"
></A
>3.2.3.1. The kernel</H3
><P
>The kernel is the heart of the system. It manages the communication between the underlying hardware and the peripherals. The kernel also makes sure that processes and daemons (server processes) are started and stopped at the exact right times. The kernel has a lot of other important tasks, so many that there is a special kernel-development mailing list on this subject only, where huge amounts of information are shared. It would lead us too far to discuss the kernel in detail. For now it suffices to know that the kernel is the most important file on the system.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_02_03_02"
></A
>3.2.3.2. The shell</H3
><DIV
CLASS="sect4"
><H4
CLASS="sect4"
><A
NAME="AEN2296"
></A
>3.2.3.2.1. What is a shell?</H4
><P
>When I was looking for an appropriate explanation on the concept of a <EM
>shell</EM
>, it gave me more trouble than I expected. All kinds of definitions are available, ranging from the simple comparison that <SPAN
CLASS="QUOTE"
>"the shell is the steering wheel of the car"</SPAN
>, to the vague definition in the Bash manual which says that <SPAN
CLASS="QUOTE"
>"bash is an sh-compatible command language interpreter,"</SPAN
> or an even more obscure expression, <SPAN
CLASS="QUOTE"
>"a shell manages the interaction between the system and its users"</SPAN
>. A shell is much more than that.</P
><P
>A shell can best be compared with a way of talking to the computer, a language. Most users do know that other language, the point-and-click language of the desktop. But in that language the computer is leading the conversation, while the user has the passive role of picking tasks from the ones presented. It is very difficult for a programmer to include all options and possible uses of a command in the GUI-format. Thus, GUIs are almost always less capable than the command or commands that form the backend.</P
><P
>The shell, on the other hand, is an advanced way of communicating with the system, because it allows for two-way conversation and taking initiative. Both partners in the communication are equal, so new ideas can be tested. The shell allows the user to handle a system in a very flexible way. An additional asset is that the shell allows for task automation.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="AEN2308"
></A
>3.2.3.2.2. Shell types</H4
><P
>Just like people know different languages and dialects, the computer knows different shell types:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>sh</B
> or <SPAN
CLASS="application"
>Bourne Shell</SPAN
>: the original shell still used on UNIX systems and in UNIX related environments. This is the basic shell, a small program with few features. When in POSIX-compatible mode, <B
CLASS="command"
>bash</B
> will emulate this shell.</P
></LI
><LI
><P
><B
CLASS="command"
>bash</B
> or <SPAN
CLASS="application"
>Bourne Again SHell</SPAN
>: the standard GNU shell, intuitive and flexible. Probably most advisable for beginning users while being at the same time a powerful tool for the advanced and professional user. On Linux, <B
CLASS="command"
>bash</B
> is the standard shell for common users. This shell is a so-called <EM
>superset</EM
> of the <SPAN
CLASS="application"
>Bourne</SPAN
> shell, a set of add-ons and plug-ins. This means that the <SPAN
CLASS="application"
>Bourne Again SHell</SPAN
> is compatible with the <SPAN
CLASS="application"
>Bourne</SPAN
> shell: commands that work in <B
CLASS="command"
>sh</B
>, also work in <B
CLASS="command"
>bash</B
>. However, the reverse is not always the case. All examples and exercises in this book use <B
CLASS="command"
>bash</B
>.</P
></LI
><LI
><P
><B
CLASS="command"
>csh</B
> or <SPAN
CLASS="application"
>C Shell</SPAN
>: the syntax of this shell resembles that of the C programming language. Sometimes asked for by programmers.</P
></LI
><LI
><P
><B
CLASS="command"
>tcsh</B
> or <SPAN
CLASS="application"
>Turbo C Shell</SPAN
>: a superset of the common <SPAN
CLASS="application"
>C Shell</SPAN
>, enhancing user-friendliness and speed.</P
></LI
><LI
><P
><B
CLASS="command"
>ksh</B
> or the <SPAN
CLASS="application"
>Korn</SPAN
> shell: sometimes appreciated by people with a UNIX background. A superset of the <SPAN
CLASS="application"
>Bourne</SPAN
> shell; with standard configuration a nightmare for beginning users.</P
></LI
></UL
><P
>The file <TT
CLASS="filename"
>/etc/shells</TT
> gives an overview of known shells on a Linux system:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mia:~&#62;</TT
> <B
CLASS="command"
>cat /etc/shells</B
>
/bin/bash
/bin/sh
/bin/tcsh
/bin/csh
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Fake Bourne shell</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Note that <TT
CLASS="filename"
>/bin/sh</TT
> is usually a link to <SPAN
CLASS="application"
>Bash</SPAN
>, which will execute in <SPAN
CLASS="application"
>Bourne</SPAN
> shell compatible mode when called on this way.</P
></TD
></TR
></TABLE
></DIV
><P
>Your default shell is set in the <TT
CLASS="filename"
>/etc/passwd</TT
> file, like this line for user <EM
>mia</EM
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;mia:L2NOfqdlPrHwE:504:504:Mia Maya:/home/mia:/bin/bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
>To switch from one shell to another, just enter the name of the new shell in the active terminal. The system finds the directory where the name occurs using the <TT
CLASS="varname"
>PATH</TT
> settings, and since a shell is an executable file (program), the current shell activates it and it gets executed. A new prompt is usually shown, because each shell has its typical appearance:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mia:~&#62;</TT
> <B
CLASS="command"
>tcsh</B
>
<TT
CLASS="prompt"
>[mia@post21 ~]$</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="AEN2394"
></A
>3.2.3.2.3. Which shell am I using?</H4
><P
>If you don't know which shell you are using, either check the line for your account in <TT
CLASS="filename"
>/etc/passwd</TT
> or type the command</P
><P
><B
CLASS="command"
>echo <TT
CLASS="varname"
>$SHELL</TT
></B
> </P
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_02_03_03"
></A
>3.2.3.3. Your home directory</H3
><P
>Your home directory is your default destination when connecting to the system. In most cases it is a subdirectory of <TT
CLASS="filename"
>/home</TT
>, though this may vary. Your home directory may be located on the hard disk of a remote file server; in that case your home directory may be found in <TT
CLASS="filename"
>/nethome/your_user_name</TT
>. In another case the system administrator may have opted for a less comprehensible layout and your home directory may be on <TT
CLASS="filename"
>/disk6/HU/07/jgillard</TT
>.</P
><P
>Whatever the path to your home directory, you don't have to worry too much about it. The correct path to your home directory is stored in the <TT
CLASS="varname"
>HOME</TT
> environment variable, in case some program needs it. With the <B
CLASS="command"
>echo</B
> command you can display the content of this variable:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>orlando:~&#62;</TT
> <B
CLASS="command"
>echo $HOME</B
>
/nethome/orlando
</PRE
></FONT
></TD
></TR
></TABLE
><P
>You can do whatever you like in your home directory. You can put as many files in as many directories as you want, although the total amount of data and files is naturally limited because of the hardware and size of the partitions, and sometimes because the system administrator has applied a quota system. Limiting disk usage was common practice when hard disk space was still expensive. Nowadays, limits are almost exclusively applied in large environments. You can see for yourself if a limit is set using the <B
CLASS="command"
>quota</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>pierre@lamaison:/&#62;</TT
> <B
CLASS="command"
>quota -v</B
>
Diskquotas for user pierre (uid 501): none
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In case quotas have been set, you get a list of the limited partitions and their specific limitations. Exceeding the limits may be tolerated during a grace period with fewer or no restrictions at all. Detailed information can be found using the <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>quota</I
></TT
></B
> or <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>quota</I
></TT
></B
> commands.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>No Quota?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>If your system can not find the <B
CLASS="command"
>quota</B
>, then no limitation of file system usage is being applied.</P
></TD
></TR
></TABLE
></DIV
><P
>Your home directory is indicated by a tilde (~), shorthand for <TT
CLASS="filename"
>/path_to_home/user_name</TT
>. This same path is stored in the <TT
CLASS="varname"
>HOME</TT
> variable, so you don't have to do anything to activate it. A simple application: switch from <TT
CLASS="filename"
>/var/music/albums/arno/2001</TT
> to <TT
CLASS="filename"
>images</TT
> in your home directory using one elegant command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>rom:/var/music/albums/arno/2001&#62;</TT
> <B
CLASS="command"
>cd ~/images</B
>
<TT
CLASS="prompt"
>rom:~/images&#62;</TT
> <B
CLASS="command"
>pwd</B
>
/home/rom/images
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Later in this chapter we will talk about the commands for managing files and directories in order to keep your home directory tidy.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_02_04"
></A
>3.2.4. The most important configuration files</H2
><P
>As we mentioned before, most configuration files are stored in the <TT
CLASS="filename"
>/etc</TT
> directory. Content can be viewed using the <B
CLASS="command"
>cat</B
> command, which sends text files to the standard output (usually your monitor). The syntax is straight forward:</P
><P
><B
CLASS="command"
>cat <TT
CLASS="filename"
>file1</TT
> <TT
CLASS="filename"
>file2</TT
> ... <TT
CLASS="filename"
>fileN</TT
></B
> </P
><P
>In this section we try to give an overview of the most common configuration files. This is certainly not a complete list. Adding extra packages may also add extra configuration files in <TT
CLASS="filename"
>/etc</TT
>. When reading the configuration files, you will find that they are usually quite well commented and self-explanatory. Some files also have man pages which contain extra documentation, such as <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>group</I
></TT
></B
>.</P
><DIV
CLASS="table"
><A
NAME="AEN2485"
></A
><P
><B
>Table 3-3. Most common configuration files</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>File</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Information/service</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>aliases</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Mail aliases file for use with the Sendmail and Postfix mail server. Running a mail server on each and every system has long been common use in the UNIX world, and almost every Linux distribution still comes with a Sendmail package. In this file local user names are matched with real names as they occur in E-mail addresses, or with other local addresses.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>apache</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Config files for the Apache web server.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>bashrc</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>The system-wide configuration file for the Bourne Again SHell. Defines functions and aliases for all users. Other shells may have their own system-wide config files, like <TT
CLASS="filename"
>cshrc</TT
>.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>crontab</TT
> and the <TT
CLASS="filename"
>cron.*</TT
> directories
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration of tasks that need to be executed periodically - backups, updates of the system databases, cleaning of the system, rotating logs etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>default</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Default options for certain commands, such as <B
CLASS="command"
>useradd</B
>.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>filesystems</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Known file systems: ext3, vfat, iso9660 etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>fstab</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Lists partitions and their <EM
>mount points</EM
>.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>ftp*</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration of the ftp-server: who can connect, what parts of the system are accessible etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>group</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration file for user groups. Use the shadow utilities <B
CLASS="command"
>groupadd</B
>, <B
CLASS="command"
>groupmod</B
> and <B
CLASS="command"
>groupdel</B
> to edit this file. Edit manually only if you really know what you are doing.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>hosts</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>A list of machines that can be contacted using the network, but without the need for a domain name service. This has nothing to do with the system's network configuration, which is done in <TT
CLASS="filename"
>/etc/sysconfig</TT
>.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>inittab</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Information for booting: mode, number of text consoles etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>issue</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Information about the distribution (release version and/or kernel info).
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>ld.so.conf</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Locations of library files.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>lilo.conf</TT
>, <TT
CLASS="filename"
>silo.conf</TT
>, <TT
CLASS="filename"
>aboot.conf</TT
> etc.
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Boot information for the LInux LOader, the system for booting that is now gradually being replaced with GRUB.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>logrotate.*</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Rotation of the logs, a system preventing the collection of huge amounts of log files.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>mail</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Directory containing instructions for the behavior of the mail server.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>modules.conf</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration of modules that enable special features (drivers).
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>motd</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Message Of The Day: Shown to everyone who connects to the system (in text mode), may be used by the system admin to announce system services/maintenance etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>mtab</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Currently mounted file systems. It is advised to never edit this file.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>nsswitch.conf</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Order in which to contact the name resolvers when a process demands resolving of a host name.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>pam.d</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration of authentication modules.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>passwd</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Lists local users. Use the shadow utilities <B
CLASS="command"
>useradd</B
>, <B
CLASS="command"
>usermod</B
> and <B
CLASS="command"
>userdel</B
> to edit this file. Edit manually only when you really know what you are doing.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>printcap</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Outdated but still frequently used printer configuration file. Don't edit this manually unless you really know what you are doing.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>profile</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>System wide configuration of the shell environment: variables, default properties of new files, limitation of resources etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>rc*</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Directories defining active services for each run level.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>resolv.conf</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Order in which to contact DNS servers (Domain Name Servers only).
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>sendmail.cf</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Main config file for the Sendmail server.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>services</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Connections accepted by this machine (open ports).
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>sndconfig</TT
> or <TT
CLASS="filename"
>sound</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration of the sound card and sound events.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>ssh</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Directory containing the config files for secure shell client and server.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>sysconfig</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Directory containing the system configuration files: mouse, keyboard, network, desktop, system clock, power management etc. (specific to RedHat)
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>X11</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Settings for the graphical server, X. RedHat uses XFree, which is reflected in the name of the main configuration file, XFree86Config. Also contains the general directions for the window managers available on the system, for example <B
CLASS="command"
>gdm</B
>, <B
CLASS="command"
>fvwm</B
>, <B
CLASS="command"
>twm</B
>, etc.
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>xinetd.*</TT
> or <TT
CLASS="filename"
>inetd.conf</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configuration files for Internet services that are run from the system's (extended) Internet services daemon (servers that don't run an independent daemon).</TD
></TR
></TBODY
></TABLE
></DIV
><P
>Throughout this guide we will learn more about these files and study some of them in detail.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_02_05"
></A
>3.2.5. The most common devices</H2
><P
>Devices, generally every peripheral attachment of a PC that is not the CPU itself, is presented to the system as an entry in the <TT
CLASS="filename"
>/dev</TT
> directory. One of the advantages of this UNIX-way of handling devices is that neither the user nor the system has to worry much about the specification of devices.</P
><P
>Users that are new to Linux or UNIX in general are often overwhelmed by the amount of new names and concepts they have to learn. That is why a list of common devices is included in this introduction.</P
><DIV
CLASS="table"
><A
NAME="AEN2726"
></A
><P
><B
>Table 3-4. Common devices</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Device</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>cdrom</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>CD drive</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>console</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Special entry for the currently used console.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>cua*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Serial ports</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>dsp*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Devices for sampling and recording</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>fd*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Entries for most kinds of floppy drives, the default is <TT
CLASS="filename"
>/dev/fd0</TT
>, a floppy drive for 1.44 MB floppies.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>hd[a-t][1-16]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Standard support for IDE drives with maximum amount of partitions each.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>ir*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Infrared devices</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>isdn*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Management of ISDN connections</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>js*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Joystick(s)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>lp*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Printers</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>mem</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Memory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>midi*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>midi player</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>mixer*</TT
> and <TT
CLASS="filename"
>music</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Idealized model of a mixer (combines or adds signals)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>modem</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Modem</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>mouse</TT
> (also msmouse, logimouse, psmouse, input/mice, psaux)</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>All kinds of mouses</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>null</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Bottomless garbage can</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>par*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Entries for parallel port support</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>pty*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Pseudo terminals</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>radio*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>For Radio Amateurs (HAMs).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>ram*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>boot device</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>sd*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>SCSI disks with their partitions</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>sequencer</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>For audio applications using the synthesizer features of the sound card (MIDI-device controller)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>tty*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Virtual consoles simulating vt100 terminals.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>usb*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>USB card and scanner</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="filename"
>video*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>For use with a graphics card supporting video.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_02_06"
></A
>3.2.6. The most common variable files</H2
><P
>In the <TT
CLASS="filename"
>/var</TT
> directory we find a set of directories for storing specific non-constant data (as opposed to the ls program or the system configuration files, which change relatively infrequently or never at all). All files that change frequently, such as log files, mailboxes, lock files, spoolers etc. are kept in a subdirectory of <TT
CLASS="filename"
>/var</TT
>.</P
><P
>As a security measure these files are usually kept in separate parts from the main system files, so we can keep a close eye on them and set stricter permissions where necessary. A lot of these files also need more permissions than usual, like <TT
CLASS="filename"
>/var/tmp</TT
>, which needs to be writable for everyone. A lot of user activity might be expected here, which might even be generated by anonymous Internet users connected to your system. This is one reason why the <TT
CLASS="filename"
>/var</TT
> directory, including all its subdirectories, is usually on a separate partition. This way, there is for instance no risk that a mail bomb, for instance, fills up the rest of the file system, containing more important data such as your programs and configuration files.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>/var/tmp and /tmp</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Files in <TT
CLASS="filename"
>/tmp</TT
> can be deleted without notice, by regular system tasks or because of a system reboot. On some (customized) systems, also <TT
CLASS="filename"
>/var/tmp</TT
> might behave unpredictably. Nevertheless, since this is not the case by default, we advise to use the <TT
CLASS="filename"
>/var/tmp</TT
> directory for saving temporary files. When in doubt, check with your system administrator. If you manage your own system, you can be reasonably sure that this is a safe place if you did not consciously change settings on <TT
CLASS="filename"
>/var/tmp</TT
> (as root, a normal user can not do this).</P
><P
>Whatever you do, try to stick to the privileges granted to a normal user - don't go saving files directly under the root (/) of the file system, don't put them in <TT
CLASS="filename"
>/usr</TT
> or some subdirectory or in another reserved place. This pretty much limits your access to safe file systems.</P
></TD
></TR
></TABLE
></DIV
><P
>One of the main security systems on a UNIX system, which is naturally implemented on every Linux machine as well, is the log-keeping facility, which logs all user actions, processes, system events etc. The configuration file of the so-called <EM
>syslogdaemon</EM
> determines which and how long logged information will be kept. The default location of all logs is <TT
CLASS="filename"
>/var/log</TT
>, containing different files for access log, server logs, system messages etc.</P
><P
>In <TT
CLASS="filename"
>/var</TT
> we typically find server data, which is kept here to separate it from critical data such as the server program itself and its configuration files. A typical example on Linux systems is <TT
CLASS="filename"
>/var/www</TT
>, which contains the actual HTML pages, scripts and images that a web server offers. The FTP-tree of an FTP server (data that can be downloaded by a remote client) is also best kept in one of <TT
CLASS="filename"
>/var</TT
>'s subdirectories. Because this data is publicly accessible and often changeable by anonymous users, it is safer to keep it here, away from partitions or directories with sensitive data.</P
><P
>On most workstation installations, <TT
CLASS="filename"
>/var/spool</TT
> will at least contain an <TT
CLASS="filename"
>at</TT
> and a <TT
CLASS="filename"
>cron</TT
> directory, containing scheduled tasks. In office environments this directory usually contains <TT
CLASS="filename"
>lpd</TT
> as well, which holds the print queue(s) and further printer configuration files, as well as the printer log files.</P
><P
>On server systems we will generally find <TT
CLASS="filename"
>/var/spool/mail</TT
>, containing incoming mails for local users, sorted in one file per user, the user's <SPAN
CLASS="QUOTE"
>"inbox"</SPAN
>. A related directory is <TT
CLASS="filename"
>mqueue</TT
>, the spooler area for unsent mail messages. These parts of the system can be very busy on mail servers with a lot of users. News servers also use the <TT
CLASS="filename"
>/var/spool</TT
> area because of the enormous amounts of messages they have to process.</P
><P
>The <TT
CLASS="filename"
>/var/lib/rpm</TT
> directory is specific to RPM-based (RedHat Package Manager) distributions; it is where RPM package information is stored. Other package managers generally also store their data somewhere in <TT
CLASS="filename"
>/var</TT
>.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_03_03"
></A
>3.3. Manipulating files</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_03_03_01"
></A
>3.3.1. Viewing file properties</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_03_01_01"
></A
>3.3.1.1. More about ls</H3
><P
>Besides the name of the file, <B
CLASS="command"
>ls</B
> can give a lot of other information, such as the file type, as we already discussed. It can also show permissions on a file, file size, inode number, creation date and time, owners and amount of links to the file. With the <TT
CLASS="option"
>-a</TT
> option to <B
CLASS="command"
>ls</B
>, files that are normally hidden from view can be displayed as well. These are files that have a name starting with a dot. A couple of typical examples include the configuration files in your home directory. When you've worked with a certain system for a while, you will notice that tens of files and directories have been created that are not automatically listed in a directory index. Next to that, every directory contains a file named just dot (.) and one with two dots (..), which are used in combination with their inode number to determine the directory's position in the file system's tree structure.</P
><P
>You should really read the <SPAN
CLASS="application"
>Info</SPAN
> pages about <B
CLASS="command"
>ls</B
>, since it is a very common command with a lot of useful options. Options can be combined, as is the case with most UNIX commands and their options. A common combination is <B
CLASS="command"
>ls <TT
CLASS="option"
>-al</TT
></B
>; it shows a long list of files and their properties as well as the destinations that any symbolic links point to. <B
CLASS="command"
>ls <TT
CLASS="option"
>-latr</TT
></B
> displays the same files, only now in reversed order of the last change, so that the file changed most recently occurs at the bottom of the list. Here are a couple of examples:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>krissie:~/mp3&#62;</TT
> <B
CLASS="command"
>ls</B
>
Albums/ Radio/ Singles/ gene/ index.html
<TT
CLASS="prompt"
>krissie:~/mp3&#62;</TT
> <B
CLASS="command"
>ls -a</B
>
./ .thumbs Radio gene/
../ Albums/ Singles/ index.html
<TT
CLASS="prompt"
>krissie:~/mp3&#62;</TT
> <B
CLASS="command"
>ls -l Radio/</B
>
total 8
drwxr-xr-x 2 krissie krissie 4096 Oct 30 1999 Carolina/
drwxr-xr-x 2 krissie krissie 4096 Sep 24 1999 Slashdot/
<TT
CLASS="prompt"
>krissie:~/mp3&#62;</TT
> <B
CLASS="command"
>ls -ld Radio/</B
>
drwxr-xr-x 4 krissie krissie 4096 Oct 30 1999 Radio/
<TT
CLASS="prompt"
>krissie:~/mp3&#62;</TT
> <B
CLASS="command"
>ls -ltr</B
>
total 20
drwxr-xr-x 4 krissie krissie 4096 Oct 30 1999 Radio/
-rw-r--r-- 1 krissie krissie 453 Jan 7 2001 index.html
drwxrwxr-x 30 krissie krissie 4096 Oct 20 17:32 Singles/
drwxr-xr-x 2 krissie krissie 4096 Dec 4 23:22 gene/
drwxrwxr-x 13 krissie krissie 4096 Dec 21 11:40 Albums/
</PRE
></FONT
></TD
></TR
></TABLE
><P
>On most Linux versions <B
CLASS="command"
>ls</B
> is <EM
>aliased</EM
> to color-ls by default. This feature allows to see the file type without using any options to <B
CLASS="command"
>ls</B
>. To achieve this, every file type has its own color. The standard scheme is in <TT
CLASS="filename"
>/etc/DIR_COLORS</TT
>:</P
><DIV
CLASS="table"
><A
NAME="AEN3003"
></A
><P
><B
>Table 3-5. Color-ls default color scheme</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Color</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>File type</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>blue</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>directories</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>red</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>compressed archives</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>white</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>text files</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>pink</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>images</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>cyan</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>links</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>yellow</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>devices</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>green</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>executables</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>flashing red</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>broken links</TD
></TR
></TBODY
></TABLE
></DIV
><P
>More information is in the man page. The same information was in earlier days displayed using suffixes to every non-standard file name. For mono-color use (like printing a directory listing) and for general readability, this scheme is still in use:</P
><DIV
CLASS="table"
><A
NAME="AEN3039"
></A
><P
><B
>Table 3-6. Default suffix scheme for ls</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Character</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>File type</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>nothing</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>regular file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>/</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>*</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>executable file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>@</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>link</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>=</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>socket</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>|</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>named pipe</TD
></TR
></TBODY
></TABLE
></DIV
><P
>A description of the full functionality and features of the <B
CLASS="command"
>ls</B
> command can be read with <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>coreutils ls</I
></TT
></B
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_01_02"
></A
>3.3.1.2. More tools</H3
><P
>To find out more about the kind of data we are dealing with, we use the <B
CLASS="command"
>file</B
> command. By applying certain tests that check properties of a file in the file system, magic numbers and language tests, <B
CLASS="command"
>file</B
> tries to make an educated guess about the format of a file. Some examples:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file Documents/</B
>
Documents/: directory
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file high-tech-stats.pdf</B
>
high-tech-stats.pdf: PDF document, version 1.2
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file Nari-288.rm</B
>
Nari-288.rm: RealMedia file
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file bijlage10.sdw</B
>
bijlage10.sdw: Microsoft Office Document
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file logo.xcf</B
>
logo.xcf: GIMP XCF image data, version 0, 150 x 38, RGB Color
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file cv.txt</B
>
cv.txt: ISO-8859 text
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file image.png</B
>
image.png: PNG image data, 616 x 862, 8-bit grayscale, non-interlaced
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file figure</B
>
figure: ASCII text
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file me+tux.jpg</B
>
me+tux.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI),
"28 Jun 1999", 144 x 144
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file 42.zip.gz</B
>
42.zip.gz: gzip compressed data, deflated, original filename,
`42.zip', last modified: Thu Nov 1 23:45:39 2001, os: Unix
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file vi.gif</B
>
vi.gif: GIF image data, version 89a, 88 x 31
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file slide1</B
>
slide1: HTML document text
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file template.xls</B
>
template.xls: Microsoft Office Document
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file abook.ps</B
>
abook.ps: PostScript document text conforming at level 2.0
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file /dev/log</B
>
/dev/log: socket
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>file /dev/hda</B
>
/dev/hda: block special (3/0)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <B
CLASS="command"
>file</B
> command has a series of options, among others the <TT
CLASS="option"
>-z</TT
> option to look into compressed files. See <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>file</I
></TT
></B
> for a detailed description. Keep in mind that the results of <B
CLASS="command"
>file</B
> are not absolute, it is only a guess. In other words, <B
CLASS="command"
>file</B
> can be tricked.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Why all the fuss about file types and formats?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Shortly, we will discuss a couple of command-line tools for looking at <EM
>plain text files</EM
>. These tools will not work when used on the wrong type of files. In the worst case, they will crash your terminal and/or make a lot of beeping noises. If this happens to you, just close the terminal session and start a new one. But try to avoid it, because it is usually very disturbing for other people.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_03_02"
></A
>3.3.2. Creating and deleting files and directories</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_03_02_01"
></A
>3.3.2.1. Making a mess...</H3
><P
>... Is not a difficult thing to do. Today almost every system is networked, so naturally files get copied from one machine to another. And especially when working in a graphical environment, creating new files is a piece of cake and is often done without the approval of the user. To illustrate the problem, here's the full content of a new user's directory, created on a standard RedHat system:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[newuser@blob user]$</TT
> <B
CLASS="command"
>ls -al</B
>
total 32
drwx------ 3 user user 4096 Jan 16 13:32 .
drwxr-xr-x 6 root root 4096 Jan 16 13:32 ..
-rw-r--r-- 1 user user 24 Jan 16 13:32 .bash_logout
-rw-r--r-- 1 user user 191 Jan 16 13:32 .bash_profile
-rw-r--r-- 1 user user 124 Jan 16 13:32 .bashrc
drwxr-xr-x 3 user user 4096 Jan 16 13:32 .kde
-rw-r--r-- 1 user user 3511 Jan 16 13:32 .screenrc
-rw------- 1 user user 61 Jan 16 13:32 .xauthDqztLr
</PRE
></FONT
></TD
></TR
></TABLE
><P
>On first sight, the content of a <SPAN
CLASS="QUOTE"
>"used"</SPAN
> home directory doesn't look that bad either:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>olduser:~&#62;</TT
> <B
CLASS="command"
>ls</B
>
app-defaults/ crossover/ Fvwm@ mp3/ OpenOffice.org638/
articles/ Desktop/ GNUstep/ Nautilus/ staroffice6.0/
bin/ Desktop1/ images/ nqc/ training/
brol/ desktoptest/ Machines@ ns_imap/ webstart/
C/ Documents/ mail/ nsmail/ xml/
closed/ Emacs@ Mail/ office52/ Xrootenv.0
</PRE
></FONT
></TD
></TR
></TABLE
><P
>But when all the directories and files starting with a dot are included, there are 185 items in this directory. This is because most applications have their own directories and/or files, containing user-specific settings, in the home directory of that user. Usually these files are created the first time you start an application. In some cases you will be notified when a non-existent directory needs to be created, but most of the time everything is done automatically.</P
><P
>Furthermore, new files are created seemingly continuously because users want to save files, keep different versions of their work, use Internet applications, and download files and attachments to their local machine. It doesn't stop. It is clear that one definitely needs a scheme to keep an overview on things.</P
><P
>In the next section, we will discuss our means of keeping order. We only discuss text tools available to the shell, since the graphical tools are very intuitive and have the same look and feel as the well known point-and-click MS Windows-style file managers, including graphical help functions and other features you expect from this kind of applications. The following list is an overview of the most popular file managers for GNU/Linux. Most file managers can be started from the menu of your desktop manager, or by clicking your home directory icon, or from the command line, issuing these commands:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>nautilus</B
>: The default file manager in <SPAN
CLASS="application"
>Gnome</SPAN
>, the GNU desktop. Excellent documentation about working with this tool can be found at <A
HREF="http://www.gnome.org/learn/users-guide/latest/gosnautilus-1.html"
TARGET="_top"
>http://www.gnome.org</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>konqueror</B
>: The file manager typically used on a <SPAN
CLASS="application"
>KDE</SPAN
> desktop. The handbook is at <A
HREF="http://docs.kde.org/en/3.1/kdebase/konqueror/"
TARGET="_top"
>http://docs.kde.org</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>mc</B
>: <SPAN
CLASS="application"
>Midnight Commander</SPAN
>, the Unix file manager after the fashion of Norton Commander. All documentation available from <A
HREF="http://www.gnu.org/directory/midnightcommander.html"
TARGET="_top"
>http://gnu.org/directory/</A
> or a mirror, such as <A
HREF="http://www.ibiblio.org"
TARGET="_top"
>http://www.ibiblio.org</A
>.</P
></LI
></UL
><P
>These applications are certainly worth giving a try and usually impress newcomers to Linux, if only because there is such a wide variety: these are only the most popular tools for managing directories and files, and many other projects are being developed. Now let's find out about the internals and see how these graphical tools use common UNIX commands.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_02_03"
></A
>3.3.2.2. The tools</H3
><DIV
CLASS="sect4"
><H4
CLASS="sect4"
><A
NAME="AEN3176"
></A
>3.3.2.2.1. Creating directories</H4
><P
>A way of keeping things in place is to give certain files specific default locations by creating directories and subdirectories (or folders and sub-folders if you wish). This is done with the <B
CLASS="command"
>mkdir</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>richard:~&#62;</TT
> <B
CLASS="command"
>mkdir archive</B
>
<TT
CLASS="prompt"
>richard:~&#62;</TT
> <B
CLASS="command"
>ls -ld archive</B
>
drwxrwxrwx 2 richard richard 4096 Jan 13 14:09 archive/
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Creating directories and subdirectories in one step is done using the <TT
CLASS="option"
>-p</TT
> option:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>richard:~&#62;</TT
> <B
CLASS="command"
>cd archive</B
>
<TT
CLASS="prompt"
>richard:~/archive&#62;</TT
> <B
CLASS="command"
>mkdir 1999 2000 2001</B
>
<TT
CLASS="prompt"
>richard:~/archive&#62;</TT
> <B
CLASS="command"
>ls</B
>
1999/ 2000/ 2001/
<TT
CLASS="prompt"
>richard:~/archive&#62;</TT
> <B
CLASS="command"
>mkdir 2001/reports/Restaurants-Michelin/</B
>
mkdir: cannot create directory `2001/reports/Restaurants-Michelin/':
No such file or directory
<TT
CLASS="prompt"
>richard:~/archive&#62;</TT
> <B
CLASS="command"
>mkdir -p 2001/reports/Restaurants-Michelin/</B
>
<TT
CLASS="prompt"
>richard:~/archive&#62;</TT
> <B
CLASS="command"
>ls 2001/reports/</B
>
Restaurants-Michelin/
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If the new file needs other permissions than the default file creation permissions, the new access rights can be set in one move, still using the <B
CLASS="command"
>mkdir</B
> command, see the <SPAN
CLASS="application"
>Info</SPAN
> pages for more. We are going to discuss access modes in the next section on file security.</P
><P
>The name of a directory has to comply with the same rules as those applied on regular file names. One of the most important restrictions is that you can't have two files with the same name in one directory (but keep in mind that Linux is, like UNIX, a case sensitive operating system). There are virtually no limits on the length of a file name, but it is usually kept shorter than 80 characters, so it can fit on one line of a terminal. You can use any character you want in a file name, although it is advised to exclude characters that have a special meaning to the shell. When in doubt, check with <A
HREF="#app3"
>Appendix C</A
>.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="AEN3213"
></A
>3.3.2.2.2. Moving files</H4
><P
>Now that we have properly structured our home directory, it is time to clean up unclassified files using the <B
CLASS="command"
>mv</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>richard:~/archive&#62;</TT
> <B
CLASS="command"
>mv ../report[1-4].doc reports/Restaurants-Michelin/</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This command is also applicable when renaming files:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>richard:~&#62;</TT
> <B
CLASS="command"
>ls To_Do</B
>
-rw-rw-r-- 1 richard richard 2534 Jan 15 12:39 To_Do
<TT
CLASS="prompt"
>richard:~&#62;</TT
> <B
CLASS="command"
>mv To_Do done</B
>
<TT
CLASS="prompt"
>richard:~&#62;</TT
> <B
CLASS="command"
>ls -l done</B
>
-rw-rw-r-- 1 richard richard 2534 Jan 15 12:39 done
</PRE
></FONT
></TD
></TR
></TABLE
><P
>It is clear that only the name of the file changes. All other properties remain the same.</P
><P
>Detailed information about the syntax and features of the <B
CLASS="command"
>mv</B
> command can be found in the man or Info pages. The use of this documentation should always be your first reflex when confronted with a problem. The answer to your problem is likely to be in the system documentation. Even experienced users read man pages every day, so beginning users should read them all the time. After a while, you will get to know the most common options to the common commands, but you will still need the documentation as a primary source of information. Note that the information contained in the HOWTOs, FAQs, man pages and other sources is slowly being merged into the Info pages, which are today the most up-to-date source of online (as in readily available on the system) documentation.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="AEN3239"
></A
>3.3.2.2.3. Copying files</H4
><P
>Copying files and directories is done with the <B
CLASS="command"
>cp</B
> command. A useful option is recursive copy (copy all underlying files and subdirectories), using the <TT
CLASS="option"
>-R</TT
> option to <B
CLASS="command"
>cp</B
>. The general syntax is</P
><P
><B
CLASS="command"
>cp [<SPAN
CLASS="optional"
><TT
CLASS="option"
>-R</TT
></SPAN
>] <TT
CLASS="filename"
>fromfile</TT
> <TT
CLASS="filename"
>tofile</TT
></B
> </P
><P
>As an example the case of user <EM
>newguy</EM
>, who wants the same Gnome desktop settings user <EM
>oldguy</EM
> has. One way to solve the problem is to copy the settings of <EM
>oldguy</EM
> to the home directory of <EM
>newguy</EM
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>victor:~&#62;</TT
> <B
CLASS="command"
>cp -R ../oldguy/.gnome/ .</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This gives some errors involving file permissions, but all the errors have to do with private files that <EM
>newguy</EM
> doesn't need anyway. We will discuss in the next part how to change these permissions in case they really are a problem.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="AEN3266"
></A
>3.3.2.2.4. Removing files</H4
><P
>Use the <B
CLASS="command"
>rm</B
> command to remove single files, <B
CLASS="command"
>rmdir</B
> to remove empty directories. (Use <B
CLASS="command"
>ls <TT
CLASS="option"
>-a</TT
></B
> to check whether a directory is empty or not). The <B
CLASS="command"
>rm</B
> command also has options for removing non-empty directories with all their subdirectories, read the Info pages for these rather dangerous options.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>How empty can a directory be?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>It is normal that the directories . (dot) and .. (dot-dot) can't be removed, since they are also necessary in an empty directory to determine the directories ranking in the file system hierarchy.</P
></TD
></TR
></TABLE
></DIV
><P
>On Linux, just like on UNIX, there is no garbage can - at least not for the shell, although there are plenty of solutions for graphical use. So once removed, a file is really gone, and there is generally no way to get it back unless you have backups, or you are really fast and have a real good system administrator. To protect the beginning user from this malice, the interactive behavior of the <B
CLASS="command"
>rm</B
>, <B
CLASS="command"
>cp</B
> and <B
CLASS="command"
>mv</B
> commands can be activated using the <TT
CLASS="option"
>-i</TT
> option. In that case the system won't immediately act upon request. Instead it will ask for confirmation, so it takes an additional click on the <B
CLASS="keycap"
>Enter</B
> key to inflict the damage:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mary:~&#62;</TT
> <B
CLASS="command"
>rm -ri archive/</B
>
rm: descend into directory `archive'? <B
CLASS="command"
>y</B
>
rm: descend into directory `archive/reports'? <B
CLASS="command"
>y</B
>
rm: remove directory `archive/reports'? <B
CLASS="command"
>y</B
>
rm: descend into directory `archive/backup'? <B
CLASS="command"
>y</B
>
rm: remove `archive/backup/sysbup200112.tar'? <B
CLASS="command"
>y</B
>
rm: remove directory `archive/backup'? <B
CLASS="command"
>y</B
>
rm: remove directory `archive'? <B
CLASS="command"
>y</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>We will discuss how to make this option the default in <A
HREF="#chap_07"
>Chapter 7</A
>, which discusses customizing your shell environment.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_03_03"
></A
>3.3.3. Finding files</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_03_03_01"
></A
>3.3.3.1. Using shell features</H3
><P
>In the example on moving files we already saw how the shell can manipulate multiple files at once. In that example, the shell finds out automatically what the user means by the requirements between the square braces <SPAN
CLASS="QUOTE"
>"["</SPAN
> and <SPAN
CLASS="QUOTE"
>"]"</SPAN
>. The shell can substitute ranges of numbers and upper or lower case characters alike. It also substitutes as many characters as you want with an asterisk, and only one character with a question mark.</P
><P
>All sorts of substitutions can be used simultaneously; the shell is very logical about it. The <SPAN
CLASS="application"
>Bash</SPAN
> shell, for instance, has no problem with expressions like <B
CLASS="command"
>ls <TT
CLASS="parameter"
><I
>dirname/*/*/*[2-3]</I
></TT
></B
>.</P
><P
>In other shells, the asterisk is commonly used to minimize the efforts of typing: people would enter <B
CLASS="command"
>cd <TT
CLASS="parameter"
><I
>dir*</I
></TT
></B
> instead of <B
CLASS="command"
>cd <TT
CLASS="filename"
>directory</TT
></B
>. In <SPAN
CLASS="application"
>Bash</SPAN
> however, this is not necessary because the GNU shell has a feature called file name completion. It means that you can type the first few characters of a command (anywhere) or a file (in the current directory) and if no confusion is possible, the shell will find out what you mean. For example in a directory containing many files, you can check if there are any files beginning with the letter A just by typing <B
CLASS="command"
>ls <TT
CLASS="parameter"
><I
>A</I
></TT
></B
> and pressing the <B
CLASS="keycap"
>Tab</B
> key twice, rather than pressing <B
CLASS="keycap"
>Enter</B
>. If there is only one file starting with <SPAN
CLASS="QUOTE"
>"A"</SPAN
>, this file will be shown as the argument to <B
CLASS="command"
>ls</B
> (or any shell command, for that matter) immediately.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_03_02"
></A
>3.3.3.2. Which</H3
><P
>A very simple way of looking up files is using the <B
CLASS="command"
>which</B
> command, to look in the directories listed in the user's search path for the required file. Of course, since the search path contains only paths to directories containing executable programs, <B
CLASS="command"
>which</B
> doesn't work for ordinary files. The <B
CLASS="command"
>which</B
> command is useful when troubleshooting <SPAN
CLASS="QUOTE"
>"Command not Found"</SPAN
> problems. In the example below, user <EM
>tina</EM
> can't use the <B
CLASS="command"
>acroread</B
> program, while her colleague has no troubles whatsoever on the same system. The problem is similar to the <TT
CLASS="varname"
>PATH</TT
> problem in the previous part: Tina's colleague tells her that he can see the required program in <TT
CLASS="filename"
>/opt/acroread/bin</TT
>, but this directory is not in her path:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>which acroread</B
>
/usr/bin/which: no acroread in (/bin:/usr/bin:/usr/bin/X11)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The problem can be solved by giving the full path to the command to run, or by re-exporting the content of the <TT
CLASS="varname"
>PATH</TT
> variable:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>export PATH=$PATH:/opt/acroread/bin</B
>
<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>echo $PATH</B
>
/bin:/usr/bin:/usr/bin/X11:/opt/acroread/bin
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Using the <B
CLASS="command"
>which</B
> command also checks to see if a command is an alias for another command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>gerrit:~&#62;</TT
> <B
CLASS="command"
>which -a ls</B
>
ls is aliased to `ls -F --color=auto'
ls is /bin/ls
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If this does not work on your system, use the <B
CLASS="command"
>alias</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tille@www:~/mail$</TT
> <B
CLASS="command"
>alias ls</B
>
alias ls='ls --color'
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_03_03"
></A
>3.3.3.3. Find and locate</H3
><P
>These are the real tools, used when searching other paths beside those listed in the search path. The <B
CLASS="command"
>find</B
> tool, known from UNIX, is very powerful, which may be the cause of a somewhat more difficult syntax. GNU <B
CLASS="command"
>find</B
>, however, deals with the syntax problems. This command not only allows you to search file names, it can also accept file size, date of last change and other file properties as criteria for a search. The most common use is for finding file names:</P
><P
><B
CLASS="command"
>find <TT
CLASS="filename"
>&#60;path&#62;</TT
> <TT
CLASS="option"
>-name</TT
> <TT
CLASS="parameter"
><I
>&#60;searchstring&#62;</I
></TT
></B
> </P
><P
>This can be interpreted as <SPAN
CLASS="QUOTE"
>"Look in all files and subdirectories contained in a given path, and print the names of the files containing the search string in their name"</SPAN
> (not in their content).</P
><P
>Another application of <B
CLASS="command"
>find</B
> is for searching files of a certain size, as in the example below, where user <EM
>peter</EM
> wants to find all files in the current directory or one of its subdirectories, that are bigger than 5 MB:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>peter:~&#62;</TT
> <B
CLASS="command"
>find . -size +5000k</B
>
psychotic_chaos.mp3
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If you dig in the man pages, you will see that <B
CLASS="command"
>find</B
> can also perform operations on the found files. A common example is removing files. It is best to first test without the <TT
CLASS="option"
>-exec</TT
> option that the correct files are selected, after that the command can be rerun to delete the selected files. Below, we search for files ending in <TT
CLASS="filename"
>.tmp</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>peter:~&#62; </TT
> <B
CLASS="command"
>find . -name "*.tmp" -exec rm {} \;</B
>
<TT
CLASS="prompt"
>peter:~&#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Optimize!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>This command will call on <B
CLASS="command"
>rm</B
> as many times as a file answering the requirements is found. In the worst case, this might be thousands or millions of times. This is quite a load on your system.</P
><P
>A more realistic way of working would be the use of a pipe (|) and the <B
CLASS="command"
>xargs</B
> tool with <B
CLASS="command"
>rm</B
> as an argument. This way, the <B
CLASS="command"
>rm</B
> command is only called when the command line is full, instead of for every file. See <A
HREF="#chap_05"
>Chapter 5</A
> for more on using I/O redirection to ease everyday tasks.</P
></TD
></TR
></TABLE
></DIV
><P
>Later on (in 1999 according to the man pages, after 20 years of <B
CLASS="command"
>find</B
>), <B
CLASS="command"
>locate</B
> was developed. This program is easier to use, but more restricted than <B
CLASS="command"
>find</B
>, since its output is based on a file index database that is updated only once every day. On the other hand, a search in the <B
CLASS="command"
>locate</B
> database uses less resources than <B
CLASS="command"
>find</B
> and therefore shows the results nearly instantly.</P
><P
>Most Linux distributions use <B
CLASS="command"
>slocate</B
> these days, security enhanced locate, the modern version of <B
CLASS="command"
>locate</B
> that prevents users from getting output they have no right to read. The files in <EM
>root</EM
>'s home directory are such an example, these are not normally accessible to the public. A user who wants to find someone who knows about the <SPAN
CLASS="application"
>C shell</SPAN
> may issue the command <B
CLASS="command"
>locate <TT
CLASS="filename"
>.cshrc</TT
></B
>, to display all users who have a customized configuration file for the <SPAN
CLASS="application"
>C shell</SPAN
>. Supposing the users <EM
>root</EM
> and <EM
>jenny</EM
> are running <SPAN
CLASS="application"
>C shell</SPAN
>, then only the file <TT
CLASS="filename"
>/home/jenny/.cshrc</TT
> will be displayed, and not the one in <EM
>root</EM
>'s home directory. On most systems, <B
CLASS="command"
>locate</B
> is a symbolic link to the <B
CLASS="command"
>slocate</B
> program:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>billy:~&#62;</TT
> <B
CLASS="command"
>ls -l /usr/bin/locate</B
>
lrwxrwxrwx 1 root slocate 7 Oct 28 14:18 /usr/bin/locate -&#62; slocate*
</PRE
></FONT
></TD
></TR
></TABLE
><P
>User <EM
>tina</EM
> could have used <B
CLASS="command"
>locate</B
> to find the application she wanted:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>locate acroread</B
>
/usr/share/icons/hicolor/16x16/apps/acroread.png
/usr/share/icons/hicolor/32x32/apps/acroread.png
/usr/share/icons/locolor/16x16/apps/acroread.png
/usr/share/icons/locolor/32x32/apps/acroread.png
/usr/local/bin/acroread
/usr/local/Acrobat4/Reader/intellinux/bin/acroread
/usr/local/Acrobat4/bin/acroread
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Directories that don't contain the name <TT
CLASS="filename"
>bin</TT
> can't contain the program - they don't contain executable files. There are three possibilities left. The file in <TT
CLASS="filename"
>/usr/local/bin</TT
> is the one <EM
>tina</EM
> would have wanted: it is a link to the shell script that starts the actual program:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>file /usr/local/bin/acroread</B
>
/usr/local/bin/acroread: symbolic link to ../Acrobat4/bin/acroread
<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>file /usr/local/Acrobat4/bin/acroread</B
>
/usr/local/Acrobat4/bin/acroread: Bourne shell script text executable
<TT
CLASS="prompt"
>tina:~&#62;</TT
> <B
CLASS="command"
>file /usr/local/Acrobat4/Reader/intellinux/bin/acroread</B
>
/usr/local/Acrobat4/Reader/intellinux/bin/acroread: ELF 32-bit LSB
executable, Intel 80386, version 1, dynamically linked (uses
shared libs), not stripped
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In order to keep the path as short as possible, so the system doesn't have to search too long every time a user wants to execute a command, we add <TT
CLASS="filename"
>/usr/local/bin</TT
> to the path and not the other directories, which only contain the binary files of one specific program, while <TT
CLASS="filename"
>/usr/local/bin</TT
> contains other useful programs as well.</P
><P
>Again, a description of the full features of <B
CLASS="command"
>find</B
> and <B
CLASS="command"
>locate</B
> can be found in the <SPAN
CLASS="application"
>Info</SPAN
> pages.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_03_04"
></A
>3.3.3.4. The grep command</H3
><DIV
CLASS="sect4"
><H4
CLASS="sect4"
><A
NAME="sect_03_03_03_04_01"
></A
>3.3.3.4.1. General line filtering</H4
><P
>A simple but powerful program, <B
CLASS="command"
>grep</B
> is used for filtering input lines and returning certain patterns to the output. There are literally thousands of applications for the <B
CLASS="command"
>grep</B
> program. In the example below, <EM
>jerry</EM
> uses <B
CLASS="command"
>grep</B
> to see how he did the thing with <B
CLASS="command"
>find</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jerry:~&#62;</TT
> <B
CLASS="command"
>grep -a find .bash_history</B
>
find . -name userinfo
man find
find ../ -name common.cfg
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Search history</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Also useful in these cases is the search function in <B
CLASS="command"
>bash</B
>, activated by pressing <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>R</B
> at once, such as in the example where we want to check how we did that last <B
CLASS="command"
>find</B
> again:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>thomas ~&#62;</TT
> <B
CLASS="command"
>^R</B
>
(reverse-i-search)`find': find `/home/thomas` -name *.xml
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Type your search string at the search prompt. The more characters you type, the more restricted the search gets. This reads the command history for this shell session (which is written to <TT
CLASS="filename"
>.bash_history</TT
> in your home directory when you quit that session). The most recent occurrence of your search string is shown. If you want to see previous commands containing the same string, type <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>R</B
> again.</P
><P
>See the <SPAN
CLASS="application"
>Info</SPAN
> pages on <B
CLASS="command"
>bash</B
> for more.</P
></TD
></TR
></TABLE
></DIV
><P
>All UNIXes with just a little bit of decency have an online dictionary. So does Linux. The dictionary is a list of known words in a file named <TT
CLASS="filename"
>words</TT
>, located in <TT
CLASS="filename"
>/usr/share/dict</TT
>. To quickly check the correct spelling of a word, no graphical application is needed:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>william:~&#62;</TT
> <B
CLASS="command"
>grep pinguin /usr/share/dict/words</B
>
<TT
CLASS="prompt"
>william:~&#62;</TT
> <B
CLASS="command"
>grep penguin /usr/share/dict/words</B
>
penguin
penguins
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Dictionary vs. word list</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Some distributions offer the <B
CLASS="command"
>dict</B
> command, which offers more features than simply searching words in a list.</P
></TD
></TR
></TABLE
></DIV
><P
>Who is the owner of that home directory next to mine? Hey, there's his telephone number!</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>lisa:~&#62;</TT
> <B
CLASS="command"
>grep gdbruyne /etc/passwd</B
>
gdbruyne:x:981:981:Guy Debruyne, tel 203234:/home/gdbruyne:/bin/bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
>And what was the E-mail address of Arno again?</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>serge:~/mail&#62;</TT
> <B
CLASS="command"
>grep -i arno *</B
>
sent-mail: To: &#60;Arno.Hintjens@celeb.com&#62;
sent-mail: On Mon, 24 Dec 2001, Arno.Hintjens@celeb.com wrote:
</PRE
></FONT
></TD
></TR
></TABLE
><P
><B
CLASS="command"
>find</B
> and <B
CLASS="command"
>locate</B
> are often used in combination with <B
CLASS="command"
>grep</B
> to define some serious queries. For more information, see <A
HREF="#chap_05"
>Chapter 5</A
> on I/O redirection.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="sect_03_03_03_04_02"
></A
>3.3.3.4.2. Special characters</H4
><P
>Characters that have a special meaning to the shell have to be <EM
>escaped</EM
>. The escape character in <SPAN
CLASS="application"
>Bash</SPAN
> is backslash, as in most shells; this takes away the special meaning of the following character. The shell knows about quite some special characters, among the most common /, ., ? and *. A full list can be found in the Info pages and documentation for your shell.</P
><P
>For instance, say that you want to display the file <SPAN
CLASS="QUOTE"
>"*"</SPAN
> instead of all the files in a directory, you would have to use </P
><P
><B
CLASS="command"
>less <TT
CLASS="filename"
>\*</TT
></B
> </P
><P
>The same goes for filenames containing a space:</P
><P
><B
CLASS="command"
>cat <TT
CLASS="filename"
>This\ File</TT
></B
> </P
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_03_04"
></A
>3.3.4. More ways to view file content</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_03_04_01"
></A
>3.3.4.1. General</H3
><P
>Apart from <B
CLASS="command"
>cat</B
>, which really doesn't do much more than sending files to the standard output, there are other tools to view file content.</P
><P
>The easiest way of course would be to use graphical tools instead of command line tools. In the introduction we already saw a glimpse of an office application, <SPAN
CLASS="application"
>OpenOffice.org</SPAN
>. Other examples are the <SPAN
CLASS="application"
>GIMP</SPAN
> (start up with <B
CLASS="command"
>gimp</B
> from the command line), the GNU Image Manipulation Program; <B
CLASS="command"
>xpdf</B
> to view Portable Document Format files (PDF); <SPAN
CLASS="application"
>GhostView</SPAN
> (<B
CLASS="command"
>gv</B
>) for viewing PostScript files; <SPAN
CLASS="application"
>Mozilla/FireFox</SPAN
>, <B
CLASS="command"
>links</B
> (a text mode browser), <SPAN
CLASS="application"
>Konqueror</SPAN
>, <SPAN
CLASS="application"
>Opera</SPAN
> and many others for web content; XMMS, <SPAN
CLASS="application"
>CDplay</SPAN
> and others for multimedia file content; <SPAN
CLASS="application"
>AbiWord</SPAN
>, <SPAN
CLASS="application"
>Gnumeric</SPAN
>, <SPAN
CLASS="application"
>KOffice</SPAN
> etc. for all kinds of office applications and so on. There are thousands of Linux applications; to list them all would take days.</P
><P
>Instead we keep concentrating on shell- or text-mode applications, which form the basics for all other applications. These commands work best in a text environment on files containing text. When in doubt, check first using the <B
CLASS="command"
>file</B
> command.</P
><P
>So let's see what text tools we have that are useful to look inside files.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Font problems</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Plain text tools such as the ones we will now be discussing, often have problems with <SPAN
CLASS="QUOTE"
>"plain"</SPAN
> text files because of the font encoding used in those files. Special characters, such as accented alphabetical characters, Chinese characters and other characters from languages using different character sets than the default <EM
>en_US</EM
> encoding and so on, are then displayed the wrong way or replaced by unreadable rubbish. These problems are discussed in <A
HREF="#sect_07_05"
>Section 7.4</A
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_04_02"
></A
>3.3.4.2. <SPAN
CLASS="QUOTE"
>"<B
CLASS="command"
>less</B
> is <B
CLASS="command"
>more</B
>"</SPAN
></H3
><P
>Undoubtedly you will hear someone say this phrase sooner or later when working in a UNIX environment. A little bit of UNIX history explains this:</P
><P
></P
><UL
><LI
><P
>First there was <B
CLASS="command"
>cat</B
>. Output was streamed in an uncontrollable way.</P
></LI
><LI
><P
>Then there was <B
CLASS="command"
>pg</B
>, which may still be found on older UNIXes. This command puts text to the output one page at the time.</P
></LI
><LI
><P
>The <B
CLASS="command"
>more</B
> program was a revised version of <B
CLASS="command"
>pg</B
>. This command is still available on every Linux system.</P
></LI
><LI
><P
><B
CLASS="command"
>less</B
> is the GNU version of more and has extra features allowing highlighting of search strings, scrolling back etc. The syntax is very simple:</P
><P
><B
CLASS="command"
>less <TT
CLASS="filename"
>name_of_file</TT
></B
> </P
><P
>More information is located in the <SPAN
CLASS="application"
>Info</SPAN
> pages.</P
></LI
></UL
><P
>You already know about pagers by now, because they are used for viewing the man pages.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_04_03"
></A
>3.3.4.3. The head and tail commands</H3
><P
>These two commands display the n first/last lines of a file respectively. To see the last ten commands entered:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tony:~&#62;</TT
> <B
CLASS="command"
>tail -10 .bash_history </B
>
locate configure | grep bin
man bash
cd
xawtv &#38;
grep usable /usr/share/dict/words
grep advisable /usr/share/dict/words
info quota
man quota
echo $PATH
frm
</PRE
></FONT
></TD
></TR
></TABLE
><P
><B
CLASS="command"
>head</B
> works similarly. The <B
CLASS="command"
>tail</B
> command has a handy feature to continuously show the last n lines of a file that changes all the time. This <TT
CLASS="option"
>-f</TT
> option is often used by system administrators to check on log files. More information is located in the system documentation files.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_03_05"
></A
>3.3.5. Linking files</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_03_05_01"
></A
>3.3.5.1. Link types</H3
><P
>Since we know more about files and their representation in the file system, understanding links (or shortcuts) is a piece of cake. A link is nothing more than a way of matching two or more file names to the same set of file data. There are two ways to achieve this:</P
><P
></P
><UL
><LI
><P
>Hard link: Associate two or more file names with the same inode. Hard links share the same data blocks on the hard disk, while they continue to behave as independent files.</P
><P
>There is an immediate disadvantage: hard links can't span partitions, because inode numbers are only unique within a given partition.</P
></LI
><LI
><P
>Soft link or symbolic link (or for short: symlink): a small file that is a pointer to another file. A symbolic link contains the path to the target file instead of a physical location on the hard disk. Since inodes are not used in this system, soft links can span across partitions.</P
></LI
></UL
><P
>The two link types behave similar, but are not the same, as illustrated in the scheme below:</P
><DIV
CLASS="figure"
><A
NAME="AEN3699"
></A
><P
><B
>Figure 3-2. Hard and soft link mechanism</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/links.png"></P
></DIV
></DIV
><P
>Note that removing the target file for a symbolic link makes the link useless.</P
><P
>Each regular file is in principle a hardlink. Hardlinks can not span across partitions, since they refer to inodes, and inode numbers are only unique within a given partition.</P
><P
>It may be argued that there is a third kind of link, the <EM
>user-space</EM
> link, which is similar to a shortcut in MS Windows. These are files containing meta-data which can only be interpreted by the graphical file manager. To the kernel and the shell these are just normal files. They may end in a <EM
>.desktop</EM
> or <EM
>.lnk</EM
> suffix; an example can be found in <TT
CLASS="filename"
>~/.gnome-desktop</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[dupont@boulot .gnome-desktop]$</TT
> <B
CLASS="command"
>cat La\ Maison\ Dupont</B
>
[Desktop Entry]
Encoding=Legacy-Mixed
Name=La Maison Dupont
Type=X-nautilus-home
X-Nautilus-Icon=temp-home
URL=file:///home/dupont
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This example is from a <SPAN
CLASS="application"
>KDE</SPAN
> desktop:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[lena@venus Desktop]$</TT
> <B
CLASS="command"
>cat camera</B
>
[Desktop Entry]
Dev=/dev/sda1
FSType=auto
Icon=memory
MountPoint=/mnt/camera
Type=FSDevice
X-KDE-Dynamic-Device=true
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Creating this kind of link is easy enough using the features of your graphical environment. Should you need help, your system documentation should be your first resort.</P
><P
>In the next section, we will study the creation of UNIX-style symbolic links using the command line.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_03_05_02"
></A
>3.3.5.2. Creating symbolic links</H3
><P
>The symbolic link is particularly interesting for beginning users: they are fairly obvious to see and you don't need to worry about partitions.</P
><P
>The command to make links is <B
CLASS="command"
>ln</B
>. In order to create symlinks, you need to use the <TT
CLASS="option"
>-s</TT
> option:</P
><P
><B
CLASS="command"
>ln <TT
CLASS="option"
>-s</TT
> <TT
CLASS="filename"
>targetfile</TT
> <TT
CLASS="filename"
>linkname</TT
></B
> </P
><P
>In the example below, user <EM
>freddy</EM
> creates a link in a subdirectory of his home directory to a directory on another part of the system:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>freddy:~/music&#62;</TT
> <B
CLASS="command"
>ln -s /opt/mp3/Queen/ Queen</B
>
<TT
CLASS="prompt"
>freddy:~/music&#62;</TT
> <B
CLASS="command"
>ls -l</B
>
lrwxrwxrwx 1 freddy freddy 17 Jan 22 11:07 Queen -&#62; /opt/mp3/Queen
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Symbolic links are always very small files, while hard links have the same size as the original file.</P
><P
>The application of symbolic links is widespread. They are often used to save disk space, to make a copy of a file in order to satisfy installation requirements of a new program that expects the file to be in another location, they are used to fix scripts that suddenly have to run in a new environment and can generally save a lot of work. A system admin may decide to move the home directories of the users to a new location, <TT
CLASS="filename"
>disk2</TT
> for instance, but if he wants everything to work like before, like the <TT
CLASS="filename"
>/etc/passwd</TT
> file, with a minimum of effort he will create a symlink from <TT
CLASS="filename"
>/home</TT
> to the new location <TT
CLASS="filename"
>/disk2/home</TT
>.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_03_04"
></A
>3.4. File security</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_03_04_01"
></A
>3.4.1. Access rights: Linux's first line of defense</H2
><P
>The Linux security model is based on the one used on UNIX systems, and is as rigid as the UNIX security model (and sometimes even more), which is already quite robust. On a Linux system, every file is owned by a user and a group user. There is also a third category of users, those that are not the user owner and don't belong to the group owning the file. For each category of users, read, write and execute permissions can be granted or denied.</P
><P
>We already used the <EM
>long</EM
> option to list files using the <B
CLASS="command"
>ls <TT
CLASS="option"
>-l</TT
></B
> command, though for other reasons. This command also displays file permissions for these three user categories; they are indicated by the nine characters that follow the first character, which is the file type indicator at the beginning of the file properties line. As seen in the examples below, the first three characters in this series of nine display access rights for the actual user that owns the file. The next three are for the group owner of the file, the last three for other users. The permissions are always in the same order: read, write, execute for the user, the group and the others. Some examples:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>marise:~&#62;</TT
> <B
CLASS="command"
>ls -l To_Do</B
>
-rw-rw-r-- 1 marise users 5 Jan 15 12:39 To_Do
<TT
CLASS="prompt"
>marise:~&#62;</TT
> <B
CLASS="command"
>ls -l /bin/ls</B
>
-rwxr-xr-x 1 root root 45948 Aug 9 15:01 /bin/ls*
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The first file is a regular file (first dash). Users with user name <EM
>marise</EM
> or users belonging to the group <EM
>users</EM
> can read and write (change/move/delete) the file, but they can't execute it (second and third dash). All other users are only allowed to read this file, but they can't write or execute it (fourth and fifth dash).</P
><P
>The second example is an executable file, the difference: everybody can run this program, but you need to be <EM
>root</EM
> to change it.</P
><P
>The Info pages explain how the <B
CLASS="command"
>ls</B
> command handles display of access rights in detail, see the section <EM
>What information is listed</EM
>.</P
><P
>For easy use with commands, both access rights or modes and user groups have a code. See the tables below.</P
><DIV
CLASS="table"
><A
NAME="AEN3805"
></A
><P
><B
>Table 3-7. Access mode codes</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Code</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>0 or -</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>The access right that is supposed to be on this place is not granted.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>4 or r</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>read access is granted to the user category defined in this place</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>2 or w</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>write permission is granted to the user category defined in this place</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>1 or x</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>execute permission is granted to the user category defined in this place</TD
></TR
></TBODY
></TABLE
></DIV
><DIV
CLASS="table"
><A
NAME="AEN3825"
></A
><P
><B
>Table 3-8. User group codes</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Code</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>u</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>user permissions</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>g</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>group permissions</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>o</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>permissions for others</TD
></TR
></TBODY
></TABLE
></DIV
><P
>This straight forward scheme is applied very strictly, which allows a high level of security even without network security. Among other functions, the security scheme takes care of user access to programs, it can serve files on a need-to-know basis and protect sensitive data such as home directories and system configuration files.</P
><P
>You should know what your user name is. If you don't, it can be displayed using the <B
CLASS="command"
>id</B
> command, which also displays the default group you belong to and eventually other groups of which you are a member:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tilly:~&#62;</TT
> <B
CLASS="command"
>id</B
>
uid=504(tilly) gid=504(tilly) groups=504(tilly),100(users),2051(org)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Your user name is also stored in the environment variable <TT
CLASS="varname"
>USER</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tilly:~&#62;</TT
> <B
CLASS="command"
>echo $USER</B
>
tilly
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_04_02"
></A
>3.4.2. The tools</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_03_04_02_01"
></A
>3.4.2.1. The chmod command</H3
><P
>A normal consequence of applying strict file permissions, and sometimes a nuisance, is that access rights will need to be changed for all kinds of reasons. We use the <B
CLASS="command"
>chmod</B
> command to do this, and eventually <EM
>to chmod</EM
> has become an almost acceptable English verb, meaning the changing of the access mode of a file. The <B
CLASS="command"
>chmod</B
> command can be used with alphanumeric or numeric options, whatever you like best.</P
><P
>The example below uses alphanumeric options in order to solve a problem that commonly occurs with new users:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>./hello</B
>
bash: ./hello: bad interpreter: Permission denied
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>cat hello</B
>
#!/bin/bash
echo "Hello, World"
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>ls -l hello</B
>
-rw-rw-r-- 1 asim asim 32 Jan 15 16:29 hello
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>chmod u+x hello</B
>
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>./hello</B
>
Hello, World
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>ls -l hello</B
>
-rwxrw-r-- 1 asim asim 32 Jan 15 16:29 hello*
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <B
CLASS="command"
>+</B
> and <B
CLASS="command"
>-</B
> operators are used to grant or deny a given right to a given group. Combinations separated by commas are allowed. The Info and man pages contain useful examples. Here's another one, which makes the file from the previous example a private file to user <EM
>asim</EM
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>chmod u+rwx,go-rwx hello</B
>
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>ls -l hello</B
>
-rwx------ 1 asim asim 32 Jan 15 16:29 hello*
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The kind of problem resulting in an error message saying that permission is denied somewhere is usually a problem with access rights in most cases. Also, comments like, <SPAN
CLASS="QUOTE"
>"It worked yesterday,"</SPAN
> and <SPAN
CLASS="QUOTE"
>"When I run this as root it works,"</SPAN
> are most likely caused by the wrong file permissions.</P
><P
>When using <B
CLASS="command"
>chmod</B
> with numeric arguments, the values for each granted access right have to be counted together per group. Thus we get a 3-digit number, which is the symbolic value for the settings <B
CLASS="command"
>chmod</B
> has to make. The following table lists the most common combinations:</P
><DIV
CLASS="table"
><A
NAME="AEN3908"
></A
><P
><B
>Table 3-9. File protection with chmod</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>400</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>To protect a file against accidental overwriting.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>500</I
></TT
> <TT
CLASS="filename"
>directory</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>To protect yourself from accidentally removing, renaming or moving files from this directory.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>600</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>A private file only changeable by the user who entered this command.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>644</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>A publicly readable file that can only be changed by the issuing user.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>660</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Users belonging to your group can change this file, others don't have any access to it at all.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>700</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Protects a file against any access from other users, while the issuing user still has full access.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>755</I
></TT
> <TT
CLASS="filename"
>directory</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>For files that should be readable and executable by others, but only changeable by the issuing user.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>775</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Standard file sharing mode for a group.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>777</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Everybody can do everything to this file.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>If you enter a number with less than three digits as an argument to <B
CLASS="command"
>chmod</B
>, omitted characters are replaced with zeros starting from the left. There is actually a fourth digit on Linux systems, that precedes the first three and sets special access modes. Everything about these and many more are located in the Info pages.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_04_02_02"
></A
>3.4.2.2. Logging on to another group</H3
><P
>When you type <B
CLASS="command"
>id</B
> on the command line, you get a list of all the groups that you can possibly belong to, preceded by your user name and ID and the group name and ID that you are currently connected with. However, on many Linux systems you can only be actively logged in to one group at the time. By default, this active or <EM
>primary group</EM
> is the one that you get assigned from the <TT
CLASS="filename"
>/etc/passwd</TT
> file. The fourth field of this file holds users' primary group ID, which is looked up in the <TT
CLASS="filename"
>/etc/group</TT
> file. An example:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>id</B
>
uid=501(asim) gid=501(asim) groups=100(users),501(asim),3400(web)
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>asim</I
></TT
> <TT
CLASS="filename"
>/etc/passwd</TT
></B
>
asim:x:501:501:Asim El Baraka:/home/asim:/bin/bash
<TT
CLASS="prompt"
>asim:~&#62;</TT
> <B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>501</I
></TT
> <TT
CLASS="filename"
>/etc/group</TT
></B
>
asim:x:501:
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The fourth field in the line from <TT
CLASS="filename"
>/etc/passwd</TT
> contains the value <SPAN
CLASS="QUOTE"
>"501"</SPAN
>, which represents the group <EM
>asim</EM
> in the above example. From <TT
CLASS="filename"
>/etc/group</TT
> we can get the name matching this group ID. When initially connecting to the system, this is the group that <EM
>asim</EM
> will belong to.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>User private group scheme</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>In order to allow more flexibility, most Linux systems follow the so-called <EM
>user private group scheme</EM
>, that assigns each user primarily to his or her own group. This group is a group that only contains this particular user, hence the name <SPAN
CLASS="QUOTE"
>"private group"</SPAN
>. Usually this group has the same name as the user login name, which can be a bit confusing.</P
></TD
></TR
></TABLE
></DIV
><P
>Apart from his own private group, user <EM
>asim</EM
> can also be in the groups <EM
>users</EM
> and <EM
>web</EM
>. Because these are secondary groups to this user, he will need to use the <B
CLASS="command"
>newgrp</B
> to log into any of these groups (use <B
CLASS="command"
>gpasswd</B
> for setting the group password first). In the example, <EM
>asim</EM
> needs to create files that are owned by the group <EM
>web</EM
>.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>asim:/var/www/html&#62;</TT
> <B
CLASS="command"
>newgrp <TT
CLASS="parameter"
><I
>web</I
></TT
></B
>
<TT
CLASS="prompt"
>asim:/var/www/html&#62;</TT
> <B
CLASS="command"
>id</B
>
uid=501(asim) gid=3400(web) groups=100(users),501(asim),3400(web)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>When <EM
>asim</EM
> creates new files now, they will be in group ownership of the group <EM
>web</EM
> instead of being owned by the group <EM
>asim</EM
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>asim:/var/www/html&#62;</TT
> <B
CLASS="command"
>touch <TT
CLASS="filename"
>test</TT
></B
>
<TT
CLASS="prompt"
>asim:/var/www/html&#62;</TT
> <B
CLASS="command"
>ls <TT
CLASS="option"
>-l</TT
> <TT
CLASS="filename"
>test</TT
></B
>
-rw-rw-r-- 1 asim web 0 Jun 10 15:38 test
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Logging in to a new group prevents you from having to use <B
CLASS="command"
>chown</B
> (see <A
HREF="#sect_03_04_02_04"
>Section 3.4.2.4</A
>) or calling your system administrator to change ownerships for you.</P
><P
>See the manpage for <B
CLASS="command"
>newgrp</B
> for more information.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_04_02_03"
></A
>3.4.2.3. The file mask</H3
><P
>When a new file is saved somewhere, it is first subjected to the standard security procedure. Files without permissions don't exist on Linux. The standard file permission is determined by the <EM
>mask</EM
> for new file creation. The value of this mask can be displayed using the <B
CLASS="command"
>umask</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bert:~&#62;</TT
> <B
CLASS="command"
>umask</B
>
0002
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Instead of adding the symbolic values to each other, as with <B
CLASS="command"
>chmod</B
>, for calculating the permission on a new file they need to be subtracted from the total possible access rights. In the example above, however, we see 4 values displayed, yet there are only 3 permission categories: <EM
>user</EM
>, <EM
>group</EM
> and <EM
>other</EM
>. The first zero is part of the special file attributes settings, which we will discuss in <A
HREF="#sect_03_04_02_04"
>Section 3.4.2.4</A
> and <A
HREF="#sect_04_01_06"
>Section 4.1.6</A
>. It might just as well be that this first zero is not displayed on your system when entering the <B
CLASS="command"
>umask</B
> command, and that you only see 3 numbers representing the default file creation mask.</P
><P
>Each UNIX-like system has a system function for creating new files, which is called each time a user uses a program that creates new files, for instance, when downloading a file from the Internet, when saving a new text document and so on. This function creates both new files and new directories. Full read, write and execute permission is granted to everybody when creating a new directory. When creating a new file, this function will grant read and write permissions for everybody, but set execute permissions to none for all user categories. This, before the mask is applied, a directory has permissions <EM
>777</EM
> or <EM
>rwxrwxrwx</EM
>, a plain file <EM
>666</EM
> or <EM
>rw-rw-rw-</EM
>.</P
><P
>The <EM
>umask</EM
> value is subtracted from these default permissions after the function has created the new file or directory. Thus, a directory will have permissions of <EM
>775</EM
> by default, a file <EM
>664</EM
>, if the mask value is <EM
>(0)002</EM
>. This is demonstrated in the example below:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bert:~&#62;</TT
> <B
CLASS="command"
>mkdir newdir</B
>
<TT
CLASS="prompt"
>bert:~&#62;</TT
> <B
CLASS="command"
>ls -ld newdir</B
>
drwxrwxr-x 2 bert bert 4096 Feb 28 13:45 newdir/
<TT
CLASS="prompt"
>bert:~&#62;</TT
> <B
CLASS="command"
>touch newfile</B
>
<TT
CLASS="prompt"
>bert:~&#62;</TT
> <B
CLASS="command"
>ls -l newfile</B
>
-rw-rw-r-- 1 bert bert 0 Feb 28 13:52 newfile
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Files versus directories</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>A directory gets more permissions by default: it always has the <EM
>execute</EM
> permission. If it wouldn't have that, it would not be accessible. Try this out by chmodding a directory 644!</P
></TD
></TR
></TABLE
></DIV
><P
>If you log in to another group using the <B
CLASS="command"
>newgrp</B
> command, the mask remains unchanged. Thus, if it is set to <EM
>002</EM
>, files and directories that you create while being in the new group will also be accessible to the other members of that group; you don't have to use <B
CLASS="command"
>chmod</B
>.</P
><P
>The <EM
>root</EM
> user usually has stricter default file creation permissions:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;[root@estoban root]# umask
022
</PRE
></FONT
></TD
></TR
></TABLE
><P
>These defaults are set system-wide in the shell resource configuration files, for instance <TT
CLASS="filename"
>/etc/bashrc</TT
> or <TT
CLASS="filename"
>/etc/profile</TT
>. You can change them in your own shell configuration file, see <A
HREF="#chap_07"
>Chapter 7</A
> on customizing your shell environment.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_04_02_04"
></A
>3.4.2.4. Changing user and group ownership</H3
><P
>When a file is owned by the wrong user or group, the error can be repaired with the <B
CLASS="command"
>chown</B
> (change owner) and <B
CLASS="command"
>chgrp</B
> (change group) commands. Changing file ownership is a frequent system administrative task in environments where files need to be shared in a group. Both commands are very flexible, as you can find out by using the <TT
CLASS="option"
>--help</TT
> option.</P
><P
>The <B
CLASS="command"
>chown</B
> command can be applied to change both user and group ownership of a file, while <B
CLASS="command"
>chgrp</B
> only changes group ownership. Of course the system will check if the user issuing one of these commands has sufficient permissions on the file(s) she wants to change.</P
><P
>In order to only change the user ownership of a file, use this syntax:</P
><P
><B
CLASS="command"
>chown <TT
CLASS="parameter"
><I
>newuser</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
> </P
><P
>If you use a colon after the user name (see the Info pages), group ownership will be changed as well, to the primary group of the user issuing the command. On a Linux system, each user has his own group, so this form can be used to make files private:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>id</B
>
uid=1304(jacky) gid=(1304) groups=1304(jacky),2034(pproject)
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>ls -l my_report</B
>
-rw-rw-r-- 1 jacky project 29387 Jan 15 09:34 my_report
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>chown jacky: my_report</B
>
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>chmod o-r my_report</B
>
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>ls -l my_report</B
>
-rw-rw---- 1 jacky jacky 29387 Jan 15 09:34 my_report
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If <EM
>jacky</EM
> would like to share this file, without having to give everybody permission to write it, he can use the <B
CLASS="command"
>chgrp</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>ls -l report-20020115.xls</B
>
-rw-rw---- 1 jacky jacky 45635 Jan 15 09:35 report-20020115.xls
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>chgrp project report-20020115.xls</B
>
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>chmod o= report-20020115.xls</B
>
<TT
CLASS="prompt"
>jacky:~&#62;</TT
> <B
CLASS="command"
>ls -l report-20020115.xls</B
>
-rw-rw---- 1 jacky project 45635 Jan 15 09:35 report-20020115.xls
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This way, users in the group <EM
>project</EM
> will be able to work on this file. Users not in this group have no business with it at all.</P
><P
>Both <B
CLASS="command"
>chown</B
> and <B
CLASS="command"
>chgrp</B
> can be used to change ownership recursively, using the <TT
CLASS="option"
>-R</TT
> option. In that case, all underlying files and subdirectories of a given directory will belong to the given user and/or group.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Restrictions</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>On most systems, the use of the <B
CLASS="command"
>chown</B
> and <B
CLASS="command"
>chgrp</B
> commands is restricted for non-privileged users. If you are not the administrator of the system, you can not change user nor group ownerships for security reasons. If the usage of these commands would not be restricted, malicious users could assign ownership of files to other users and/or groups and change behavior of those users' environments and even cause damage to other users' files.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_03_04_02_05"
></A
>3.4.2.5. Special modes</H3
><P
>For the system admin to not be bothered solving permission problems all the time, special access rights can be given to entire directories, or to separate programs. There are three special modes:</P
><P
></P
><UL
><LI
><P
>Sticky bit mode: After execution of a job, the command is kept in the system memory. Originally this was a feature used a lot to save memory: big jobs are loaded into memory only once. But these days memory is inexpensive and there are better techniques to manage it, so it is not used anymore for its optimizing capabilities on single files. When applied to an entire directory, however, the sticky bit has a different meaning. In that case, a user can only change files in this directory when she is the user owner of the file or when the file has appropriate permissions. This feature is used on directories like <TT
CLASS="filename"
>/var/tmp</TT
>, that have to be accessible for everyone, but where it is not appropriate for users to change or delete each other's data. The sticky bit is indicated by a <EM
>t</EM
> at the end of the file permission field:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mark:~&#62;</TT
> <B
CLASS="command"
>ls -ld /var/tmp</B
>
drwxrwxrwt 19 root root 8192 Jan 16 10:37 /var/tmp/
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The sticky bit is set using the command <B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>o+t</I
></TT
> <TT
CLASS="filename"
>directory</TT
></B
>. The historic origin of the <SPAN
CLASS="QUOTE"
>"t"</SPAN
> is in UNIX' <EM
>save Text access</EM
> feature.</P
></LI
><LI
><P
>SUID (set user ID) and SGID (set group ID): represented by the character <EM
>s</EM
> in the user or group permission field. When this mode is set on an executable file, it will run with the user and group permissions on the file instead of with those of the user issuing the command, thus giving access to system resources. We will discuss this further in <A
HREF="#chap_04"
>Chapter 4</A
>.</P
></LI
><LI
><P
>SGID (set group ID) on a directory: in this special case every file created in the directory will have the same group owner as the directory itself (while normal behavior would be that new files are owned by the users who create them). This way, users don't need to worry about file ownership when sharing directories:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mimi:~&#62;</TT
> <B
CLASS="command"
>ls -ld /opt/docs</B
>
drwxrws--- 4 root users 4096 Jul 25 2001 docs/
<TT
CLASS="prompt"
>mimi:~&#62;</TT
> <B
CLASS="command"
>ls -l /opt/docs</B
>
-rw-rw---- 1 mimi users 345672 Aug 30 2001-Council.doc
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This is the standard way of sharing files in UNIX.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Existing files are left unchanged!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Files that are being moved to a SGID directory but were created elsewhere keep their original user and group owner. This may be confusing.</P
></TD
></TR
></TABLE
></DIV
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_03_05"
></A
>3.5. Summary</H1
><P
>On UNIX, as on Linux, all entities are in some way or another presented to the system as files with the appropriate file properties. Use of (predefined) paths allows the users and the system admin to find, read and manipulate files.</P
><P
>We've made our first steps toward becoming an expert: we discussed the real and the fake structure of the file system, and we know about the Linux file security model, as well as several other security precautions that are taken on every system by default.</P
><P
>The shell is the most important tool for interaction with the system. We learned several shell commands in this chapter, which are listed in the table below.</P
><DIV
CLASS="table"
><A
NAME="AEN4247"
></A
><P
><B
>Table 3-10. New commands in chapter 3: Files and the file system</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>bash</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>GNU shell program.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cat <TT
CLASS="filename"
>file(s)</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Send content of file(s) to standard output.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cd <TT
CLASS="filename"
>directory</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Enter <TT
CLASS="filename"
>directory</TT
>. <B
CLASS="command"
>cd</B
> is a <B
CLASS="command"
>bash</B
> built-in command.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chgrp <TT
CLASS="parameter"
><I
>newgroup</I
></TT
> <TT
CLASS="filename"
>file(s)</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change the group ownership of <TT
CLASS="filename"
>file(s)</TT
> to <EM
>newgroup</EM
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>mode</I
></TT
> <TT
CLASS="filename"
>file(s)</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change access permissions on <TT
CLASS="filename"
>file(s)</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>chown <TT
CLASS="parameter"
><I
>newowner</I
></TT
>[<SPAN
CLASS="optional"
>:[<SPAN
CLASS="optional"
>newgroup</SPAN
>]</SPAN
>] <TT
CLASS="filename"
>file(s)</TT
> </B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change file owner and group ownership.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cp <TT
CLASS="filename"
>sourcefile</TT
> <TT
CLASS="filename"
>targetfile</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Copy <TT
CLASS="filename"
>sourcefile</TT
> to <TT
CLASS="filename"
>targetfile</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>df <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Reports on used disk space on the partition containing <TT
CLASS="filename"
>file</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>echo <TT
CLASS="parameter"
><I
>string</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display a line of text</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>export</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Part of <B
CLASS="command"
>bash</B
> that announces variables and their values to the system.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>file <TT
CLASS="filename"
>filename</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Determine file type of <TT
CLASS="filename"
>filename</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>find <TT
CLASS="parameter"
><I
>path</I
></TT
> <TT
CLASS="parameter"
><I
>expression</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Find files in the file system hierarchy</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>PATTERN</I
></TT
> <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print lines in <TT
CLASS="filename"
>file</TT
> containing the search pattern.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>head <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Send the first part of <TT
CLASS="filename"
>file</TT
> to standard output</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>id</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Prints real and effective user name and groups.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Read documentation about <B
CLASS="command"
>command</B
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>less <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>View <TT
CLASS="filename"
>file</TT
> with a powerful viewer.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ln <TT
CLASS="filename"
>targetfile</TT
> <TT
CLASS="filename"
>linkname</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Make a link with name <TT
CLASS="filename"
>linkname</TT
> to <TT
CLASS="filename"
>targetfile</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>locate <TT
CLASS="parameter"
><I
>searchstring</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print all accessible files matching the search pattern.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ls <TT
CLASS="filename"
>file(s)</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Prints directory content.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Format and display online (system) manual pages for <B
CLASS="command"
>command</B
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mkdir <TT
CLASS="filename"
>newdir</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Make a new empty directory.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mv <TT
CLASS="filename"
>oldfile</TT
> <TT
CLASS="filename"
>newfile</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Rename or move <TT
CLASS="filename"
>oldfile</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>newgrp <TT
CLASS="parameter"
><I
>groupname</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Log in to a new group.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>pwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print the present or current working directory.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>quota</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show disk usage and limits.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>rm <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Removes files and directories.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>rmdir <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Removes directories.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>tail <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print the last part of <TT
CLASS="filename"
>file</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>umask [<SPAN
CLASS="optional"
><TT
CLASS="parameter"
><I
>value</I
></TT
></SPAN
>]</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show or change new file creation mode.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>wc <TT
CLASS="filename"
>file</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Counts lines, words and characters in <TT
CLASS="filename"
>file</TT
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>which <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Shows the full path to <B
CLASS="command"
>command</B
>.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>We also stressed the fact that you should READ THE MAN PAGES. This documentation is your first-aid kit and contains the answers to many questions. The above list contains the basic commands that you will use on a daily basis, but they can do much more than the tasks we've discussed here. Reading the documentation will give you the control you need.</P
><P
>Last but not least, a handy overview of file permissions:</P
><DIV
CLASS="table"
><A
NAME="AEN4445"
></A
><P
><B
>Table 3-11. File permissions</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Who\What</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>r(ead)</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>w(rite)</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>(e)x(ecute)</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>u(ser)</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>4</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>2</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>1</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>g(roup)</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>4</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>2</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>1</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>o(ther)</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>4</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>2</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>1</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_03_06"
></A
>3.6. Exercises</H1
><P
>Just login with your common user ID.</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_06_01"
></A
>3.6.1. Partitions</H2
><P
></P
><UL
><LI
><P
>On which partition is your home directory?</P
></LI
><LI
><P
>How many partitions are on your system?</P
></LI
><LI
><P
>What is the total size of your Linux installation?</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_06_02"
></A
>3.6.2. Paths</H2
><P
></P
><UL
><LI
><P
>Display your search path.</P
></LI
><LI
><P
>Export a senseless path by entering, for instance, <B
CLASS="command"
>export <TT
CLASS="varname"
>PATH</TT
>=<TT
CLASS="replaceable"
><I
>blah</I
></TT
></B
> and try listing directory content.</P
></LI
><LI
><P
>What is the path to your home directory? How would another user reach your home directory starting from his own home directory, using a relative path?</P
></LI
><LI
><P
>Go to the <TT
CLASS="filename"
>tmp</TT
> directory in <TT
CLASS="filename"
>/var</TT
>.</P
></LI
><LI
><P
>Now go to <TT
CLASS="filename"
>share</TT
> in <TT
CLASS="filename"
>/usr</TT
> using only one command. Change to <TT
CLASS="filename"
>doc</TT
>. What is your present working directory?</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_06_03"
></A
>3.6.3. Tour of the system</H2
><P
></P
><UL
><LI
><P
>Change to the <TT
CLASS="filename"
>/proc</TT
> directory.</P
></LI
><LI
><P
>What CPU(s) is the system running on?</P
></LI
><LI
><P
>How much RAM does it currently use?</P
></LI
><LI
><P
>How much swap space do you have?</P
></LI
><LI
><P
>What drivers are loaded?</P
></LI
><LI
><P
>How many hours has the system been running?</P
></LI
><LI
><P
>Which filesystems are known by your system?</P
></LI
><LI
><P
>Change to <TT
CLASS="filename"
>/etc/rc.d | /etc/init.d | /etc/runlevels</TT
> and choose the directory appropriate for your run level.</P
></LI
><LI
><P
>What services should be running in this level?</P
></LI
><LI
><P
>Which services run in graphical mode that don't run in text mode?</P
></LI
><LI
><P
>Change to <TT
CLASS="filename"
>/etc</TT
></P
></LI
><LI
><P
>How long does the system keep the log file in which user logins are monitored?</P
></LI
><LI
><P
>Which release are you running?</P
></LI
><LI
><P
>Are there any issues or messages of the day?</P
></LI
><LI
><P
>How many users are defined on your system? Don't count them, let the computer do it for you!</P
></LI
><LI
><P
>How many groups?</P
></LI
><LI
><P
>Where is the time zone information kept?</P
></LI
><LI
><P
>Are the HOWTOs installed on your system?</P
></LI
><LI
><P
>Change to <TT
CLASS="filename"
>/usr/share/doc</TT
>.</P
></LI
><LI
><P
>Name three programs that come with the GNU <EM
>coreutils</EM
> package.</P
></LI
><LI
><P
>Which version of <B
CLASS="command"
>bash</B
> is installed on this system?</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_06_04"
></A
>3.6.4. Manipulating files</H2
><P
></P
><UL
><LI
><P
>Create a new directory in your home directory.</P
></LI
><LI
><P
>Can you move this directory to the same level as your home directory?</P
></LI
><LI
><P
>Copy all XPM files from <TT
CLASS="filename"
>/usr/share/pixmaps</TT
> to the new directory. What does XPM mean?</P
></LI
><LI
><P
>List the files in reverse alphabetical order.</P
></LI
><LI
><P
>Change to your home directory. Create a new directory and copy all the files of the <TT
CLASS="filename"
>/etc</TT
> directory into it. Make sure that you also copy the files and directories which are in the subdirectories of <TT
CLASS="filename"
>/etc</TT
>! (recursive copy)</P
></LI
><LI
><P
>Change into the new directory and make a directory for files starting with an upper case character and one for files starting with a lower case character. Move all the files to the appropriate directories. Use as few commands as possible.</P
></LI
><LI
><P
>Remove the remaining files.</P
></LI
><LI
><P
>Delete the directory and its entire content using a single command.</P
></LI
><LI
><P
>Use <B
CLASS="command"
>grep</B
> to find out which script starts the Font Server in the graphical run level.</P
></LI
><LI
><P
>Where is the <EM
>sendmail</EM
> server program?</P
></LI
><LI
><P
>Make a symbolic link in your home directory to <TT
CLASS="filename"
>/var/tmp</TT
>. Check that it really works.</P
></LI
><LI
><P
>Make another symbolic link in your home directory to this link. Check that it works. Remove the first link and list directory content. What happened to the second link?</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_03_06_05"
></A
>3.6.5. File permissions</H2
><P
></P
><UL
><LI
><P
>Can you change file permissions on <TT
CLASS="filename"
>/home</TT
>?</P
></LI
><LI
><P
>What is your standard file creation mode?</P
></LI
><LI
><P
>Change ownership of <TT
CLASS="filename"
>/etc</TT
> to your own user and group.</P
></LI
><LI
><P
>Change file permissions of <TT
CLASS="filename"
>~/.bashrc</TT
> so that only you and your primary group can read it.</P
></LI
><LI
><P
>Issue the command <B
CLASS="command"
>locate <TT
CLASS="filename"
>root</TT
></B
>. Do you notice anything special?</P
></LI
><LI
><P
>Make a symbolic link to <TT
CLASS="filename"
>/root</TT
>. Can it be used?</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_04"
></A
>Chapter 4. Processes</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN4610"
></A
><P
></P
><P
>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:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Multi-user processing and multi-tasking</P
></LI
><LI
><P
>Process types</P
></LI
><LI
><P
>Controlling processes with different signals</P
></LI
><LI
><P
>Process attributes</P
></LI
><LI
><P
>The life cycle of a process</P
></LI
><LI
><P
>System startup and shutdown</P
></LI
><LI
><P
>SUID and SGID</P
></LI
><LI
><P
>System speed and response</P
></LI
><LI
><P
>Scheduling processes</P
></LI
><LI
><P
>The Vixie cron system</P
></LI
><LI
><P
>How to get the most out of your system</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_04_01"
></A
>4.1. Processes inside out</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_04_01_01"
></A
>4.1.1. Multi-user and multi-tasking</H2
><P
>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 <B
CLASS="command"
>mozilla</B
>; others, like <B
CLASS="command"
>ls</B
>, are executed as a single command.</P
><P
>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.</P
><P
>We will explain the structure of Linux processes in the next sections.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_01_02"
></A
>4.1.2. Process types</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_04_01_02_01"
></A
>4.1.2.1. Interactive processes</H3
><P
>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 mainly focussed on programs running in the foreground - the length of time taken to run them was too short to notice - but viewing a file with the <B
CLASS="command"
>less</B
> 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.</P
><P
>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.</P
><P
>The shell offers a feature called <EM
>job control</EM
> 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.</P
><P
>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:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>billy:~&#62;</TT
> <B
CLASS="command"
>xterm &#38;</B
>
[1] 26558
<TT
CLASS="prompt"
>billy:~&#62;</TT
> <B
CLASS="command"
>jobs</B
>
[1]+ Running xterm &#38;
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The full job control features are explained in detail in the <B
CLASS="command"
>bash</B
> <SPAN
CLASS="application"
>Info</SPAN
> pages, so only the frequently used job control applications are listed here:</P
><DIV
CLASS="table"
><A
NAME="AEN4685"
></A
><P
><B
>Table 4-1. Controlling processes</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>(part of) command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>regular_command</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Runs this command in the foreground.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>command &#38;</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Run this command in the background (release the terminal)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>jobs</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show commands running in the background.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>Z</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Suspend (stop, but not quit) a process running in the foreground (suspend).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>C</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Interrupt (terminate and quit) a process running in the foreground.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="parameter"
><I
>%n</I
></TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>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, for instance <B
CLASS="command"
>fg <TT
CLASS="parameter"
><I
>%2</I
></TT
></B
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>bg</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Reactivate a suspended program in the background.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>fg</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Puts the job back in the foreground.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>kill</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>End a process (also see Shell Builtin Commands in the Info pages of <B
CLASS="command"
>bash</B
>)</TD
></TR
></TBODY
></TABLE
></DIV
><P
>More practical examples can be found in the exercises.</P
><P
>Most UNIX systems are likely to be able to run <B
CLASS="command"
>screen</B
>, which is useful when you actually want another shell to execute commands. Upon calling <B
CLASS="command"
>screen</B
>, 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 <EM
>screen</EM
> up again any time you like.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_01_02_02"
></A
>4.1.2.2. Automatic processes</H3
><P
>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 (first-in, first-out) basis. Such tasks can be executed using one of two criteria:</P
><P
></P
><UL
><LI
><P
>At a certain date and time: done using the <B
CLASS="command"
>at</B
> command, which we will discuss in the second part of this chapter.</P
></LI
><LI
><P
>At times when the total system load is low enough to accept extra jobs: done using the <B
CLASS="command"
>batch</B
> 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.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_01_02_03"
></A
>4.1.2.3. Daemons</H3
><P
>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, <EM
>xinetd</EM
>, 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.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_01_03"
></A
>4.1.3. Process attributes</H2
><P
>A process has a series of characteristics, which can be viewed with the <B
CLASS="command"
>ps</B
> command:</P
><P
></P
><UL
><LI
><P
>The process ID or PID: a unique identification number used to refer to the process.</P
></LI
><LI
><P
>The parent process ID or PPID: the number of the process (PID) that started this process.</P
></LI
><LI
><P
>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).</P
></LI
><LI
><P
>Terminal or TTY: terminal to which the process is connected.</P
></LI
><LI
><P
>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 <B
CLASS="command"
>mozilla</B
> in <TT
CLASS="filename"
>/usr/bin</TT
> is owned by user <EM
>root</EM
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>theo:~&#62;</TT
> <B
CLASS="command"
>ls -l /usr/bin/mozilla</B
>
-rwxr-xr-x 1 root root 4996 Nov 20 18:28 /usr/bin/mozilla*
<TT
CLASS="prompt"
>theo:~&#62;</TT
> <B
CLASS="command"
>mozilla &#38;</B
>
[1] 26595
<TT
CLASS="prompt"
>theo:~&#62;</TT
> <B
CLASS="command"
>ps -af</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>When user <EM
>theo</EM
> starts this program, the process itself and all processes started by the initial process, will be owned by user <EM
>theo</EM
> and not by the system administrator. When <B
CLASS="command"
>mozilla</B
> needs access to certain files, that access will be determined by <EM
>theo</EM
>'s permissions and not by <EM
>root</EM
>'s.</P
></LI
><LI
><P
>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.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_01_04"
></A
>4.1.4. Displaying process information</H2
><P
>The <B
CLASS="command"
>ps</B
> command is one of the tools for visualizing processes. This command has several options which can be combined to display different process attributes.</P
><P
>With no options specified, <B
CLASS="command"
>ps</B
> only gives information about the current shell and eventual processes:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>theo:~&#62;</TT
> <B
CLASS="command"
>ps</B
>
PID TTY TIME CMD
4245 pts/7 00:00:00 bash
5314 pts/7 00:00:00 ps
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Since this does not give enough information - generally, at least a hundred processes are running on your system - we will usually select particular processes out of the list of all processes, using the <B
CLASS="command"
>grep</B
> command in a <EM
>pipe</EM
>, see <A
HREF="#sect_05_01_02_01"
>Section 5.1.2.1</A
>, as in this line, which will select and display all processes owned by a particular user:</P
><P
><B
CLASS="command"
>ps <TT
CLASS="option"
>-ef</TT
> | grep <TT
CLASS="parameter"
><I
>username</I
></TT
></B
> </P
><P
>This example shows all processes with a process name of <B
CLASS="command"
>bash</B
>, the most common login shell on Linux systems:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>theo:&#62;</TT
> <B
CLASS="command"
>ps auxw | grep bash</B
>
brenda 31970 0.0 0.3 6080 1556 tty2 S Feb23 0:00 -bash
root 32043 0.0 0.3 6112 1600 tty4 S Feb23 0:00 -bash
theo 32581 0.0 0.3 6384 1864 pts/1 S Feb23 0:00 bash
theo 32616 0.0 0.3 6396 1896 pts/2 S Feb23 0:00 bash
theo 32629 0.0 0.3 6380 1856 pts/3 S Feb23 0:00 bash
theo 2214 0.0 0.3 6412 1944 pts/5 S 16:18 0:02 bash
theo 4245 0.0 0.3 6392 1888 pts/7 S 17:26 0:00 bash
theo 5427 0.0 0.1 3720 548 pts/7 S 19:22 0:00 grep bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In these cases, the <B
CLASS="command"
>grep</B
> command finding lines containing the string <EM
>bash</EM
> is often displayed as well on systems that have a lot of idletime. If you don't want this to happen, use the <B
CLASS="command"
>pgrep</B
> command.</P
><P
>Bash shells are a special case: this process list also shows which ones are login shells (where you have to give your username and password, such as when you log in in textmode or do a remote login, as opposed to non-login shells, started up for instance by clicking a terminal window icon). Such login shells are preceded with a dash (-).</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>|?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>We will explain about the | operator in the next chapter, see <A
HREF="#chap_05"
>Chapter 5</A
>.</P
></TD
></TR
></TABLE
></DIV
><P
>More info can be found the usual way: <B
CLASS="command"
>ps <TT
CLASS="option"
>--help</TT
></B
> or <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>ps</I
></TT
></B
>. GNU <B
CLASS="command"
>ps</B
> supports different styles of option formats; the above examples don't contain errors.</P
><P
>Note that <B
CLASS="command"
>ps</B
> only gives a momentary state of the active processes, it is a one-time recording. The <B
CLASS="command"
>top</B
> program displays a more precise view by updating the results given by <B
CLASS="command"
>ps</B
> (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 <TT
CLASS="filename"
>proc</TT
> file system:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13; 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&#60; 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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The first line of <B
CLASS="command"
>top</B
> contains the same information displayed by the <B
CLASS="command"
>uptime</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jeff:~&#62;</TT
> <B
CLASS="command"
>uptime</B
>
3:30pm, up 12 days, 23:29, 6 users, load average: 0.01, 0.02, 0.00
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The data for these programs is stored among others in <TT
CLASS="filename"
>/var/run/utmp</TT
> (information about currently connected users) and in the virtual file system <TT
CLASS="filename"
>/proc</TT
>, for example <TT
CLASS="filename"
>/proc/loadavg</TT
> (average load information). There are all sorts of graphical applications to view this data, such as the <SPAN
CLASS="application"
>Gnome System Monitor</SPAN
> and <EM
>lavaps</EM
>. Over at <A
HREF="http://www.freshmeat.net"
TARGET="_top"
>FreshMeat</A
> and <A
HREF="http://www.sourceforge.org"
TARGET="_top"
>SourceForge</A
> you will find tens of applications that 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.</P
><P
>The relations between processes can be visualized using the <B
CLASS="command"
>pstree</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>sophie:~&#62;</TT
> <B
CLASS="command"
>pstree</B
>
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-helper
|-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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <TT
CLASS="option"
>-u</TT
> and <TT
CLASS="option"
>-a</TT
> options give additional information. For more options and what they do, refer to the <SPAN
CLASS="application"
>Info</SPAN
> pages.</P
><P
>In the next section, we will see how one process can create another.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_01_05"
></A
>4.1.5. Life and death of a process</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_04_01_05_01"
></A
>4.1.5.1. Process creation</H3
><P
>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 <EM
>forking</EM
>.</P
><P
>After the forking process, the address space of the child process is overwritten with the new process data. This is done through an <EM
>exec</EM
> call to the system.</P
><P
>The <EM
>fork-and-exec</EM
> 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, <B
CLASS="command"
>init</B
>, with process ID 1, is forked during the boot procedure in the so-called <EM
>bootstrapping</EM
> procedure.</P
><P
>This scheme illustrates the fork-and-exec mechanism. The process ID changes after the fork procedure:</P
><DIV
CLASS="figure"
><A
NAME="AEN4957"
></A
><P
><B
>Figure 4-1. Fork-and-exec mechanism</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/fork-and-exec.png"></P
></DIV
></DIV
><P
>There are a couple of cases in which <B
CLASS="command"
>init</B
> becomes the parent of a process, while the process was not started by <B
CLASS="command"
>init</B
>, as we already saw in the <B
CLASS="command"
>pstree</B
> example. Many programs, for instance, <EM
>daemonize</EM
> 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 <B
CLASS="command"
>xterm</B
> process that generates a shell that accepts commands. The window manager then denies any further responsibility and passes the child process to <B
CLASS="command"
>init</B
>. Using this mechanism, it is possible to change window managers without interrupting running applications.</P
><P
>Every now and then things go wrong, even in good families. In an exceptional case, a process might finish while the parent does not wait for the completion of this process. Such an unburied process is called a <EM
>zombie</EM
> process.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_01_05_02"
></A
>4.1.5.2. Ending processes</H3
><P
>When a process ends normally (it is not killed or otherwise unexpectedly interrupted), the program returns its <EM
>exit status</EM
> 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.</P
><P
>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 <B
CLASS="command"
>grep</B
> command returns <TT
CLASS="computeroutput"
>-1</TT
> if no matches are found, upon which a message on the lines of <SPAN
CLASS="QUOTE"
>"No files found"</SPAN
> can be printed. Another example is the <SPAN
CLASS="application"
>Bash</SPAN
> builtin command <B
CLASS="command"
>true</B
>, which does nothing except return an exit status of 0, meaning success.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_01_05_03"
></A
>4.1.5.3. Signals</H3
><P
>Processes end because they receive a signal. There are multiple signals that you can send to a process. Use the <B
CLASS="command"
>kill</B
> command to send a signal to a process. The command <B
CLASS="command"
>kill <TT
CLASS="option"
>-l</TT
></B
> shows a list of signals. Most signals are for internal use by the system, or for programmers when they write code. As a user, you will need the following signals:</P
><DIV
CLASS="table"
><A
NAME="AEN5016"
></A
><P
><B
>Table 4-2. Common signals</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Signal name</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Signal number</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>SIGTERM</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>15</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Terminate the process in an orderly way.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>SIGINT</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>2</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Interrupt the process. A process can ignore this signal.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>SIGKILL</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>9</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Interrupt the process. A process can not ignore this signal.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>SIGHUP</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>1</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>For daemons: reread the configuration file.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>You can read more about default actions that are taken when sending a signal to a process in <B
CLASS="command"
>man <TT
CLASS="option"
>7</TT
> <TT
CLASS="parameter"
><I
>signal</I
></TT
></B
>.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_01_06"
></A
>4.1.6. SUID and SGID</H2
><P
>As promised in the previous chapter, we will now discuss the special modes SUID and SGID 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 <B
CLASS="command"
>ps</B
> version, for example, uses the information stored in the <TT
CLASS="filename"
>/proc</TT
> 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 <B
CLASS="command"
>ps</B
> program needed access to files such as <TT
CLASS="filename"
>/dev/mem</TT
> and <TT
CLASS="filename"
>/dev/kmem</TT
>, which had disadvantages because of the permissions and ownerships on these files:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>rita:~&#62;</TT
> <B
CLASS="command"
>ls -l /dev/*mem</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>With older versions of <B
CLASS="command"
>ps</B
>, it was not possible to start the program as a common user, unless special modes were applied to it.</P
><P
>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 <TT
CLASS="filename"
>/etc/passwd</TT
> file, which has these access permissions and owners:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bea:~&#62;</TT
> <B
CLASS="command"
>ls -l /etc/passwd</B
>
-rw-r--r-- 1 root root 1267 Jan 16 14:43 /etc/passwd
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Still, users need to be able to change their own information in this file. This is achieved by giving the <B
CLASS="command"
>passwd</B
> program special permissions:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mia:~&#62;</TT
> <B
CLASS="command"
>which passwd</B
>
passwd is /usr/bin/passwd
<TT
CLASS="prompt"
>mia:~&#62;</TT
> <B
CLASS="command"
>ls -l /usr/bin/passwd</B
>
-r-s--x--x 1 root root 13476 Aug 7 06:03 /usr/bin/passwd*
</PRE
></FONT
></TD
></TR
></TABLE
><P
>When called, the <B
CLASS="command"
>passwd</B
> command will run using the access permissions of <EM
>root</EM
>, thus enabling a common user to edit the password file which is owned by the system admin.</P
><P
>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 <B
CLASS="command"
>write</B
> and <B
CLASS="command"
>wall</B
> programs, which are used to send messages to other users' terminals (ttys). The <B
CLASS="command"
>write</B
> command writes a message to a single user, while <B
CLASS="command"
>wall</B
> writes to all connected users.</P
><P
>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 <B
CLASS="command"
>write</B
> and <B
CLASS="command"
>wall</B
> commands are granted SGID permissions, the commands will run using the access rights as applicable to this group, <EM
>tty</EM
> 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.</P
><P
>In the example below, user <EM
>joe</EM
> first finds out on which terminal his correspondent is connected, using the <B
CLASS="command"
>who</B
> command. Then he sends her a message using the <B
CLASS="command"
>write</B
> command. Also illustrated are the access rights on the <B
CLASS="command"
>write</B
> 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, except for the group owner, which can write to it.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>which write</B
>
write is /usr/bin/write
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>ls -l /usr/bin/write</B
>
-rwxr-sr-x 1 root tty 8744 Dec 5 00:55 /usr/bin/write*
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>who</B
>
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)
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>ls -l /dev/tty1</B
>
crw--w---- 1 jenny tty 4, 1 Jan 23 11:41 /dev/tty1
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>write jenny tty1</B
>
hey Jenny, shall we have lunch together?
^C
</PRE
></FONT
></TD
></TR
></TABLE
><P
>User <EM
>jenny</EM
> gets this on her screen:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;Message from joe@lo.callhost.org on ptys/1 at 12:36 ...
hey Jenny, shall we have lunch together?
EOF
</PRE
></FONT
></TD
></TR
></TABLE
><P
>After receiving a message, the terminal can be cleared using the <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>L</B
> key combination. In order to receive no messages at all (except from the system administrator), use the <B
CLASS="command"
>mesg</B
> command. To see which connected users accept messages from others use <B
CLASS="command"
>who <TT
CLASS="option"
>-w</TT
></B
>. All features are fully explained in the <SPAN
CLASS="application"
>Info</SPAN
> pages of each command.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Group names may vary</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The group scheme is specific to the distribution. Other distributions may use other names or other solutions.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_04_02"
></A
>4.2. Boot process, Init and shutdown</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_04_02_01"
></A
>4.2.1. Introduction</H2
><P
> 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.</P
><P
> 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.</P
><P
>A lot of Linux systems use <B
CLASS="command"
>lilo</B
>, the <SPAN
CLASS="application"
>LInux LOader</SPAN
> for booting operating systems. We will only discuss GRUB, however, which is easier to use and more flexible. Should you need information about <B
CLASS="command"
>lilo</B
>, 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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_02_02"
></A
>4.2.2. The boot process</H2
><P
>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.</P
><P
> 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.</P
><P
> 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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_02_03"
></A
>4.2.3. GRUB features</H2
><P
>This boot method is called <EM
>direct loading</EM
> 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.</P
><P
>&#13;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.</P
><P
>GRUB contains a number of other features; the most important include:</P
><P
></P
><UL
><LI
><P
>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.</P
></LI
><LI
><P
>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.</P
></LI
><LI
><P
>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.</P
></LI
></UL
><P
>A full description of GRUB may be found by issuing the <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>grub</I
></TT
></B
> command or at <A
HREF="http://www.gnu.org/software/grub/"
TARGET="_top"
>the GRUB site</A
>. The Linux Documentation Project has a <A
HREF="http://www.tldp.org/HOWTO/mini/Multiboot-with-GRUB.html"
TARGET="_top"
>Multiboot with GRUB Mini-HOWTO</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_02_04"
></A
>4.2.4. Init</H2
><P
>The kernel, once it is loaded, finds <B
CLASS="command"
>init</B
> in <TT
CLASS="filename"
>sbin</TT
> and executes it.</P
><P
>When <B
CLASS="command"
>init</B
> starts, it becomes the parent or grandparent of all of the processes that start up automatically on your Linux system. The first thing <B
CLASS="command"
>init</B
> does, is reading its initialization file, <TT
CLASS="filename"
>/etc/inittab</TT
>. This instructs <B
CLASS="command"
>init</B
> to read an initial configuration script for the environment, which sets the path, starts swapping, checks the file systems, and so on. Basically, this step takes care of everything that your system needs to have done at system initialization: setting the clock, initializing serial ports and so forth.</P
><P
> Then <B
CLASS="command"
>init</B
> continues to read the <TT
CLASS="filename"
>/etc/inittab</TT
> file, which describes how the system should be set up in each run level and sets the default <EM
>run level</EM
>. A run level is a configuration of processes. All UNIX-like systems can be run in different process configurations, such as the single user mode, which is referred to as run level 1 or run level S (or s). In this mode, only the system administrator can connect to the system. It is used to perform maintenance tasks without risks of damaging the system or user data. Naturally, in this configuration we don't need to offer user services, so they will all be disabled. Another run level is the reboot run level, or run level 6, which shuts down all running services according to the appropriate procedures and then restarts the system.</P
><P
>Use the <B
CLASS="command"
>who</B
> to check what your current run level is:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>willy@ubuntu:~$ </TT
><B
CLASS="command"
>who <TT
CLASS="option"
>-r</TT
></B
>
run-level 2 2006-10-17 23:22 last=S
</PRE
></FONT
></TD
></TR
></TABLE
><P
>More about run levels in the next section, see <A
HREF="#sect_04_02_05"
>Section 4.2.5</A
>.</P
><P
>After having determined the default run level for your system, <B
CLASS="command"
>init</B
> starts all of the background processes necessary for the system to run by looking in the appropriate <TT
CLASS="filename"
>rc</TT
> directory for that run level. <B
CLASS="command"
>init</B
> 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 <B
CLASS="command"
>/etc/init.d/httpd <TT
CLASS="parameter"
><I
>stop</I
></TT
></B
> or <B
CLASS="command"
>service <TT
CLASS="parameter"
><I
>httpd</I
></TT
> <TT
CLASS="parameter"
><I
>stop</I
></TT
></B
> logged in as <EM
>root</EM
>, in this case stopping the web server.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Special case</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Note that on system startup, the scripts in <TT
CLASS="filename"
>rc2.d</TT
> and <TT
CLASS="filename"
>rc3.d</TT
> are usually executed. In that case, no services are stopped (at least not permanently). There are only services that are started.</P
></TD
></TR
></TABLE
></DIV
><P
> None of the scripts that actually start and stop the services are located in <TT
CLASS="filename"
>/etc/rc&#60;x&#62;.d</TT
>. Rather, all of the files in <TT
CLASS="filename"
>/etc/rc&#60;x&#62;.d</TT
> are symbolic links that point to the actual scripts located in <TT
CLASS="filename"
>/etc/init.d</TT
>. 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, as in the example below, listing the content of <TT
CLASS="filename"
>/etc/rc5.d</TT
>, where <B
CLASS="command"
>crond</B
> and <B
CLASS="command"
>xfs</B
> are both started from a linkname starting with <SPAN
CLASS="QUOTE"
>"S90"</SPAN
>. In this case, the scripts are started in alphabetical order.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[jean@blub /etc/rc5.d]</TT
> <B
CLASS="command"
>ls</B
>
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@
</PRE
></FONT
></TD
></TR
></TABLE
><P
>After <B
CLASS="command"
>init</B
> has progressed through the run levels to get to the default run level, the <TT
CLASS="filename"
>/etc/inittab</TT
> script forks a <B
CLASS="command"
>getty</B
> process for each virtual console (login prompt in text mode). <B
CLASS="command"
>getty</B
> 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. By default, most systems offer 6 virtual consoles, but as you can see from the <TT
CLASS="filename"
>inittab</TT
> file, this is configurable.</P
><P
>&#13;<TT
CLASS="filename"
>/etc/inittab</TT
> can also tell <B
CLASS="command"
>init</B
> how it should handle a user pressing <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>Alt</B
>+<B
CLASS="keycap"
>Delete</B
> at the console. As the system should be properly shut down and restarted rather than immediately power-cycled, <B
CLASS="command"
>init</B
> is told to execute the command <B
CLASS="command"
>/sbin/shutdown <TT
CLASS="option"
>-t3 -r</TT
> <TT
CLASS="parameter"
><I
>now</I
></TT
></B
>, for instance, when a user hits those keys. In addition, <TT
CLASS="filename"
>/etc/inittab</TT
> states what <B
CLASS="command"
>init</B
> should do in case of power failures, if your system has a UPS unit attached to it.</P
><P
>&#13;On most RPM-based systems the graphical login screen is started in run level 5, where <TT
CLASS="filename"
>/etc/inittab</TT
> runs a script called <TT
CLASS="filename"
>/etc/X11/prefdm</TT
>. The <TT
CLASS="filename"
>prefdm</TT
> script runs the preferred X display manager, based on the contents of the <TT
CLASS="filename"
>/etc/sysconfig/desktop</TT
> directory. This is typically <B
CLASS="command"
>gdm</B
> if you run GNOME or <B
CLASS="command"
>kdm</B
> if you run KDE, but they can be mixed, and there's also the <B
CLASS="command"
>xdm</B
> that comes with a standard X installation.</P
><P
>But there are other possibilities as well. On Debian, for instance, there is an initscript for each of the display managers, and the content of the <TT
CLASS="filename"
>/etc/X11/default-display-manager</TT
> is used to determine which one to start. More about the graphical interface can be read in <A
HREF="#sect_07_03"
>Section 7.3</A
>. Ultimately, your system documentation will explain the details about the higher level aspects of <B
CLASS="command"
>init</B
>.</P
><P
>The <TT
CLASS="filename"
>/etc/default</TT
> and/or <TT
CLASS="filename"
>/etc/sysconfig</TT
> directories contain entries for a range of functions and services, these are all read at boot time. The location of the directory containing system defaults might be somewhat different depending on your Linux distribution.</P
><P
>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.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Other procedures</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>We explained how SysV <B
CLASS="command"
>init</B
> works on x86 based machines. Startup procedures may vary on other architectures and distributions. Other systems may use the BSD-style <B
CLASS="command"
>init</B
>, where startup files are not split up into multiple <TT
CLASS="filename"
>/etc/rc&#60;LEVEL&#62;.d</TT
> directories. It might also be possible that your system uses <TT
CLASS="filename"
>/etc/rc.d/init.d</TT
> instead of <TT
CLASS="filename"
>/etc/init.d</TT
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_02_05"
></A
>4.2.5. Init run levels</H2
><P
> 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 <EM
>mode</EM
>, such as being ready for more than one user or having networking available.</P
><P
>&#13;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.</P
><P
>Available run levels are generally described in <TT
CLASS="filename"
>/etc/inittab</TT
>, which is partially shown below:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
# Default run level. The run levels 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:
&#60;--cut--&#62;
</PRE
></FONT
></TD
></TR
></TABLE
><P
> Feel free to configure unused run levels (commonly run level 4) as you see fit. Many users configure those run levels in a way that makes the most sense for them while leaving the standard run levels as they are by default. This allows them to quickly move in and out of their custom configuration without disturbing the normal set of features at the standard run levels.</P
><P
> If your machine gets into a state where it will not boot due to a bad <TT
CLASS="filename"
>/etc/inittab</TT
> or will not let you log in because you have a corrupted <TT
CLASS="filename"
>/etc/passwd</TT
> file (or if you have simply forgotten your password), boot into single-user mode.</P
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>No graphics?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>When you are working in text mode because you didn't get presented a graphical login screen on the console of your machine, you can normally switch to console 7 or up to have a graphical login. If this is not the case, check the current run level using the command <B
CLASS="command"
>who <TT
CLASS="option"
>-r</TT
></B
>. If it is set to something else than the original default from <TT
CLASS="filename"
>/etc/inittab</TT
>, chances are that the system does not start up in graphical mode by default. Contact your system administrator or read <B
CLASS="command"
>man init</B
> in that case. Note that switching run levels is done preferably using the <B
CLASS="command"
>telinit</B
> command; switching from a text to a graphical console or vice versa does not involve a run level switch.</P
></TD
></TR
></TABLE
></DIV
><P
>The discussion of run levels, scripts and configurations in this guide tries to be as general as possible. Lots of variations exist. For instance, Gentoo Linux stores scripts in <TT
CLASS="filename"
>/etc/run levels</TT
>. Other systems might first run through (a) lower run level(s) and execute all the scripts in there before arriving at the final run level and executing those scripts. Refer to your system documentation for more information. You might also read through the scripts that are refered to in <TT
CLASS="filename"
>/etc/inittab</TT
> to get a better comprehension of what happens on your system.</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_02_05_01"
></A
>4.2.5.1. Tools</H3
><P
>The <B
CLASS="command"
>chkconfig</B
> or <B
CLASS="command"
>update-rc.d</B
> utilities, when installed on your system, provide a simple command-line tool for maintaining the <TT
CLASS="filename"
>/etc/init.d</TT
> directory hierarchy. These relieve system administrators from having to directly manipulate the numerous symbolic links in the directories under <TT
CLASS="filename"
>/etc/rc[x].d</TT
>.</P
><P
>&#13;In addition, some systems offer the <B
CLASS="command"
>ntsysv</B
> tool, which provides a text-based interface; you may find this easier to use than <B
CLASS="command"
>chkconfig</B
>'s command-line interface. On SuSE Linux, you will find the <B
CLASS="command"
>yast</B
> and <B
CLASS="command"
>insserv</B
> tools. For Mandrake easy configuration, you may want to try <SPAN
CLASS="application"
>DrakConf</SPAN
>, which allows among other features switching between run levels 3 and 5. In Mandriva this became the <SPAN
CLASS="application"
>Mandriva Linux Control Center</SPAN
>.</P
><P
>&#13;Most distributions provide a graphical user interface for configuring processes, check with your system documentation.</P
><P
>&#13;All of these utilities must be run as root. The system administrator may also manually create the appropriate links in each run level directory in order to start or stop a service in a certain run level.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_02_06"
></A
>4.2.6. Shutdown</H2
><P
>UNIX was not made to be shut down, but if you really must, use the <B
CLASS="command"
>shutdown</B
> command. After completing the shutdown procedure, the <TT
CLASS="option"
>-h</TT
> option will halt the system, while <TT
CLASS="option"
>-r</TT
> will reboot it.</P
><P
>The <B
CLASS="command"
>reboot</B
> and <B
CLASS="command"
>halt</B
> commands are now able to invoke <B
CLASS="command"
>shutdown</B
> if run when the system is in run levels 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.</P
><P
>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.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_04_03"
></A
>4.3. Managing processes</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_04_03_01"
></A
>4.3.1. Work for the system admin</H2
><P
>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.</P
><P
>We will explain a little bit on a theoretical level about system performance, though not as far as hardware optimization and other advanced procedures. 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.</P
><DIV
CLASS="figure"
><A
NAME="AEN5442"
></A
><P
><B
>Figure 4-2. Can't you go faster?</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/trappen.png"></P
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_03_02"
></A
>4.3.2. How long does it take?</H2
><P
>Bash offers a built-in <B
CLASS="command"
>time</B
> 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:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tilly:~/xml/src&#62;</TT
> <B
CLASS="command"
>time make</B
>
Output written on abook.pdf (222 pages, 1619861 bytes).
Transcript written on abook.log.
real 1m41.056s
user 1m31.190s
sys 0m1.880s
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The GNU <B
CLASS="command"
>time</B
> command in <TT
CLASS="filename"
>/usr/bin</TT
> (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 <B
CLASS="command"
>time</B
> gives this output:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tilly:~/xml/src&#62;</TT
> <B
CLASS="command"
>/usr/bin/time make</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Refer again to the Info pages for all the information.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_03_03"
></A
>4.3.3. Performance</H2
><P
>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 <B
CLASS="command"
>time</B
> command:</P
><P
></P
><UL
><LI
><P
>the program executing is badly written or doesn't use the computer appropriately</P
></LI
><LI
><P
>access to disks, controllers, display, all kinds of interfaces, etc.</P
></LI
><LI
><P
>reachability of remote systems (network performance)</P
></LI
><LI
><P
>amount of users on the system, amount of users actually working simultaneously</P
></LI
><LI
><P
>time of day</P
></LI
><LI
><P
>...</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_03_04"
></A
>4.3.4. Load</H2
><P
>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.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_03_05"
></A
>4.3.5. Can I do anything as a user?</H2
><P
>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 more of those settings that are usually made <SPAN
CLASS="QUOTE"
>"on the fly"</SPAN
>, the system will need more time to search and read data.</P
><P
>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.</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_01"
></A
>4.3.5.1. Priority</H3
><P
>The priority or importance of a job is defined by it's <EM
>nice</EM
> 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.</P
><P
>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 the like). 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.</P
><P
>Defining the priority of a program is done with the <B
CLASS="command"
>nice</B
> command.</P
><P
>Most systems also provide the BSD <B
CLASS="command"
>renice</B
> command, which allows you to change the <EM
>niceness</EM
> of a running command. Again, read the man page for your system-specific information.</P
><DIV
CLASS="caution"
><P
></P
><TABLE
CLASS="caution"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Interactive programs</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>It is NOT a good idea to <B
CLASS="command"
>nice</B
> or <B
CLASS="command"
>renice</B
> an interactive program or a job running in the foreground.</P
></TD
></TR
></TABLE
></DIV
><P
>Use of these commands is usually a task for the system administrator. Read the man page for more info on extra functionality available to the system administrator.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_02"
></A
>4.3.5.2. CPU resources</H3
><P
>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 <B
CLASS="command"
>uptime</B
> 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:</P
><P
></P
><UL
><LI
><P
>Run heavy programs when the load is low. This may be the case on your system during the night. See next section for scheduling.</P
></LI
><LI
><P
>Prevent the system from doing unnecessary work: stop daemons and programs that you don't use, use <B
CLASS="command"
>locate</B
> instead of a heavy <B
CLASS="command"
>find</B
>, ...</P
></LI
><LI
><P
>Run big jobs with a low priority</P
></LI
></UL
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_03"
></A
>4.3.5.3. Memory resources</H3
><P
>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 <EM
>swapping</EM
>, 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 <B
CLASS="command"
>top</B
> command can be used to display memory and swap use. Systems using glibc offer the <B
CLASS="command"
>memusage</B
> and <B
CLASS="command"
>memusagestat</B
> commands to visualize memory usage.</P
><P
>If you find that a lot of memory and swap space are being used, you can try:</P
><P
></P
><UL
><LI
><P
>Killing, stopping or renicing those programs that use a big chunk of memory</P
></LI
><LI
><P
>Adding more memory (and in some cases more swap space) to the system.</P
></LI
><LI
><P
>Tuning system performance, which is beyond the scope of this document. See the reading list in <A
HREF="#app1"
>Appendix A</A
> for more.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_04"
></A
>4.3.5.4. I/O resources</H3
><P
>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 <B
CLASS="command"
>ps</B
>, <B
CLASS="command"
>vmstat</B
> and <B
CLASS="command"
>top</B
> tools give some indication about how many programs are waiting for I/O; <B
CLASS="command"
>netstat</B
> displays network interface statistics, but there are virtually no tools available to measure the I/O response to system load, and the <B
CLASS="command"
>iostat</B
> 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.</P
><P
>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.</P
><P
>Network I/O problems:</P
><P
></P
><UL
><LI
><P
>Network overload:</P
><P
>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 (for example use of subnets, replacing hubs with switches, upgrading interfaces and equipment).</P
></LI
><LI
><P
>Network integrity problems:</P
><P
>Occurs when data is transferred incorrectly. Solving this kind of problem can only be done by isolating the faulty element and replacing it.</P
></LI
></UL
><P
>Disk I/O problems:</P
><P
></P
><UL
><LI
><P
>per-process transfer rate too low:</P
><P
>Read or write speed for a single process is not sufficient.</P
></LI
><LI
><P
>aggregate transfer rate too low:</P
><P
>The maximum total bandwidth that the system can provide to all programs that run is not enough.</P
></LI
></UL
><P
>This kind of problem is more difficult to detect, and usually takes extra hardware in order to re-divide data streams over buses, controllers 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.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_05"
></A
>4.3.5.5. Users</H3
><P
>Users can be divided in several classes, depending on their behavior with resource usage:</P
><P
></P
><UL
><LI
><P
>Users who run a (large) number of small jobs: you, the beginning Linux user, for instance.</P
></LI
><LI
><P
>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.</P
></LI
><LI
><P
>Users who run few jobs but use a lot of CPU time (developers and the like).</P
></LI
></UL
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_06"
></A
>4.3.5.6. Graphical tools</H3
><P
>For the graphical environment, there are a whole bunch of monitoring tools available. Below is a screen shot of the <SPAN
CLASS="application"
>Gnome System Monitor</SPAN
>, which has features for displaying and searching process information, and monitoring system resources:</P
><DIV
CLASS="figure"
><A
NAME="AEN5639"
></A
><P
><B
>Figure 4-3. Gnome System Monitor</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/system-monitor.png"></P
></DIV
></DIV
><P
>There are also a couple of handy icons you can install in the task bar, such as a disk, memory and load monitor. <B
CLASS="command"
>xload</B
> is another small X application for monitoring system load. Find your favorite!</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_04_03_05_07"
></A
>4.3.5.7. Interrupting your processes</H3
><P
>As a non-privileged user, you can only influence your own processes. We already saw how you can display processes and filter out processes that belong to a particular user, and what possible restrictions can occur. When you see that one of your processes is eating too much of the system's resources, there are two things that you can do:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>Make the process use less resources without interrupting it;</P
></LI
><LI
><P
>Stop the process altogether.</P
></LI
></OL
><P
>In the case that you want the process to continue to run, but you also want to give the other processes on the system a chance, you can <B
CLASS="command"
>renice</B
> the process. Appart from using the <B
CLASS="command"
>nice</B
> or <B
CLASS="command"
>renice</B
> commands, <B
CLASS="command"
>top</B
> is an easy way of spotting the troublesome process(es) and reducing priority.</P
><P
>Identify the process in the <SPAN
CLASS="QUOTE"
>"NI"</SPAN
> column, it will most likely have a negative priority. Type <B
CLASS="command"
>r</B
> and enter the process ID of the process that you want to renice. Then enter the nice value, for instance <SPAN
CLASS="QUOTE"
>"20"</SPAN
>. That means that from now on, this process will take 1/5 of the CPU cycles at the most.</P
><P
>Examples of processes that you want to keep on running are emulators, virtual machines, compilers and so on.</P
><P
>If you want to stop a process because it hangs or is going totally berserk in the way of I/O consumption, file creation or use of other system resources, use the <B
CLASS="command"
>kill</B
> command. If you have the opportunity, first try to kill the process softly, sending it the <EM
>SIGTERM</EM
> signal. This is an instruction to terminate whatever it is doing, according to procedures as described in the code of the program:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>ps <TT
CLASS="option"
>-ef</TT
></B
> | <B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>mozilla</I
></TT
></B
>
joe 25822 1 0 Mar11 ? 00:34:04 /usr/lib/mozilla-1.4.1/mozilla-
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>kill <TT
CLASS="option"
>-15</TT
> <TT
CLASS="parameter"
><I
>25822</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In the example above, user <EM
>joe</EM
> stopped his Mozilla browser because it hung.</P
><P
>Some processes are a little bit harder to get rid of. If you have the time, you might want to send them the SIGINT signal to interrupt them. If that does not do the trick either, use the strongest signal, SIGKILL. In the example below, <EM
>joe</EM
> stops a <SPAN
CLASS="application"
>Mozilla</SPAN
> that is frozen:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>ps <TT
CLASS="option"
>-ef</TT
></B
> | <B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>mozilla</I
></TT
></B
>
joe 25915 1 0 Mar11 ? 00:15:06 /usr/lib/mozilla-1.4.1/mozilla-
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>kill <TT
CLASS="option"
>-9</TT
> <TT
CLASS="parameter"
><I
>25915</I
></TT
></B
>
<TT
CLASS="prompt"
>joe:~&#62;</TT
> <B
CLASS="command"
>ps <TT
CLASS="option"
>-ef</TT
></B
> | <B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>25915</I
></TT
></B
>
joe 2634 32273 0 18:09 pts/4 00:00:00 grep 25915
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In such cases, you might want to check that the process is really dead, using the <B
CLASS="command"
>grep</B
> filter again on the PID. If this only returns the <B
CLASS="command"
>grep</B
> process, you can be sure that you succeeded in stopping the process.</P
><P
>Among processes that are hard to kill is your shell. And that is a good thing: if they would be easy to kill, you woud loose your shell every time you type <B
CLASS="keycap"
>Ctrl</B
>-<B
CLASS="keycap"
>C</B
> on the command line accidentally, since this is equivalent to sending a SIGINT.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>UNIX without pipes is almost unthinkable</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The usage of pipes (|) for using output of one command as input of another is explained in the next chapter, <A
HREF="#chap_05"
>Chapter 5</A
>.</P
></TD
></TR
></TABLE
></DIV
><P
>In a graphical environment, the <B
CLASS="command"
>xkill</B
> program is very easy to use. Just type the name of the command, followed by an <B
CLASS="keycap"
>Enter</B
> and select the window of the application that you want to stop. It is rather dangerous because it sends a SIGKILL by default, so only use it when an application hangs.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_04_04"
></A
>4.4. Scheduling processes</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_04_04_01"
></A
>4.4.1. Use that idle time!</H2
><P
>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.</P
><P
>There are three types of delayed execution:</P
><P
></P
><UL
><LI
><P
>Waiting a little while and then resuming job execution, using the <B
CLASS="command"
>sleep</B
> command. Execution time depends on the system time at the moment of submission.</P
></LI
><LI
><P
>Running a command at a specified time, using the <B
CLASS="command"
>at</B
> command. Execution of the job(s) depends on system time, not the time of submission.</P
></LI
><LI
><P
>Regularly running a command on a monthly, weekly, daily or hourly basis, using the <B
CLASS="command"
>cron</B
> facilities.</P
></LI
></UL
><P
>The following sections discuss each possibility.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_04_02"
></A
>4.4.2. The sleep command</H2
><P
>The Info page on sleep is probably one of the shortest there is. All <B
CLASS="command"
>sleep</B
> does is wait. By default the time to wait is expressed in seconds.</P
><P
>So why does it exist? Some practical examples:</P
><P
>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:</P
><P
><B
CLASS="command"
>(sleep <TT
CLASS="parameter"
><I
>1800</I
></TT
>; echo <TT
CLASS="parameter"
><I
>"Lunch time.."</I
></TT
>) &#38;</B
> </P
><P
>When you can't use the <B
CLASS="command"
>at</B
> 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:</P
><P
><B
CLASS="command"
>(sleep <TT
CLASS="parameter"
><I
>10000</I
></TT
>; myprogram) &#38;</B
> </P
><P
>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 <B
CLASS="command"
>screen</B
> session.</P
><P
>When you run a series of printouts of large files, but you want other users to be able to print in between:</P
><P
><B
CLASS="command"
>lp <TT
CLASS="filename"
>lotoftext</TT
>; sleep <TT
CLASS="parameter"
><I
>900</I
></TT
>; lp <TT
CLASS="filename"
>hugefile</TT
>; sleep <TT
CLASS="parameter"
><I
>900</I
></TT
>; lp <TT
CLASS="filename"
>anotherlargefile</TT
></B
> </P
><P
>Printing files is discussed in <A
HREF="#chap_08"
>Chapter 8</A
>.</P
><P
>Programmers often use the sleep command to halt script or program execution for a certain time.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_04_03"
></A
>4.4.3. The at command</H2
><P
>The <B
CLASS="command"
>at</B
> command executes commands at a given time, using your default shell unless you tell the command otherwise (see the man page).</P
><P
>The options to <B
CLASS="command"
>at</B
> are rather user-friendly, which is demonstrated in the examples below:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>steven@home:~&#62;</TT
> <B
CLASS="command"
>at tomorrow + 2 days</B
>
warning: commands will be executed using (in order) a) $SHELL
b) login shell c) /bin/sh
<TT
CLASS="prompt"
>at&#62;</TT
> <B
CLASS="command"
> cat reports | mail myboss@mycompany</B
>
<TT
CLASS="prompt"
>at&#62;</TT
> &#60;EOT&#62;
job 1 at 2001-06-16 12:36
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Typing <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>D</B
> quits the <B
CLASS="command"
>at</B
> utility and generates the <SPAN
CLASS="QUOTE"
>"EOT"</SPAN
> message.</P
><P
>User <EM
>steven</EM
> does a strange thing here combining two commands; we will study this sort of practice in <A
HREF="#chap_05"
>Chapter 5</A
>, Redirecting Input and Output.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>steven@home:~&#62;</TT
> <B
CLASS="command"
>at 0237</B
>
warning: commands will be executed using (in order) a) $SHELL
b) login shell c) /bin/sh
<TT
CLASS="prompt"
>at&#62;</TT
> <B
CLASS="command"
> cd new-programs</B
>
<TT
CLASS="prompt"
>at&#62;</TT
> <B
CLASS="command"
> ./configure; make</B
>
<TT
CLASS="prompt"
>at&#62;</TT
> &#60;EOT&#62;
job 2 at 2001-06-14 02:00
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <TT
CLASS="option"
>-m</TT
> option sends mail to the user when the job is done, or explains when a job can't be done. The command <B
CLASS="command"
>atq</B
> lists jobs; perform this command before submitting jobs in order prevent them from starting at the same time as others. With the <B
CLASS="command"
>atrm</B
> command you can remove scheduled jobs if you change your mind.</P
><P
>It is a good idea to pick strange execution times, because system jobs are often run at <SPAN
CLASS="QUOTE"
>"round"</SPAN
> hours, as you can see in <A
HREF="#sect_04_04_04"
>Section 4.4.4</A
> 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 <B
CLASS="command"
>batch</B
> 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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_04_04_04"
></A
>4.4.4. Cron and crontab</H2
><P
>The cron system is managed by the <B
CLASS="command"
>cron</B
> 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.</P
><P
>At system startup the cron daemon searches <TT
CLASS="filename"
>/var/spool/cron/</TT
> for crontab entries which are named after accounts in <TT
CLASS="filename"
>/etc/passwd</TT
>, it searches <TT
CLASS="filename"
>/etc/cron.d/</TT
> and it searches <TT
CLASS="filename"
>/etc/crontab</TT
>, 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.</P
><P
>On systems using <SPAN
CLASS="application"
>Vixie</SPAN
> cron, jobs that occur hourly, daily, weekly and monthly are kept in separate directories in <TT
CLASS="filename"
>/etc</TT
> to keep an overview, as opposed to the standard UNIX cron function, where all tasks are entered into one big file.</P
><P
>Example of a <SPAN
CLASS="application"
>Vixie</SPAN
> crontab file:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[root@blob /etc]#</TT
> <B
CLASS="command"
>more crontab</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Alternative</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>You could also use the <B
CLASS="command"
>crontab <TT
CLASS="option"
>-l</TT
></B
> command to display crontabs.</P
></TD
></TR
></TABLE
></DIV
><P
>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 number 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.</P
><P
>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 <B
CLASS="command"
>run-parts</B
> 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 <B
CLASS="command"
>locate</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>billy@ahost cron.daily]$</TT
> <B
CLASS="command"
>cat slocate.cron</B
>
#!/bin/sh
renice +19 -p $$ &#62;/dev/null 2&#62;&#38;1
/usr/bin/updatedb -f "nfs,smbfs,ncpfs,proc,devpts" -e \
"/tmp,/var/tmp, /usr/tmp,/afs,/net"
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Users are supposed to edit their crontabs in a safe way using the <B
CLASS="command"
>crontab <TT
CLASS="option"
>-e</TT
></B
> command. This will prevent a user from accidentally opening more than one copy of his/her crontab file. The default editor is <B
CLASS="command"
>vi</B
> (see <A
HREF="#chap_06"
>Chapter 6</A
>, but you can use any text editor, such as <B
CLASS="command"
>gvim</B
> or <B
CLASS="command"
>gedit</B
> if you feel more comfortable with a GUI editor.</P
><P
>When you quit, the system will tell you that a new crontab is installed.</P
><P
>This crontab entry reminds <EM
>billy</EM
> to go to his sports club every Thursday night:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>billy:~&#62;</TT
> <B
CLASS="command"
>crontab -l</B
>
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.20264 installed on Sun Jul 20 22:35:14 2003)
# (Cron version -- $Id: chap4.xml,v 1.28 2007/09/19 12:22:26 tille Exp $)
38 16 * * 3 mail -s "sports evening" billy
</PRE
></FONT
></TD
></TR
></TABLE
><P
>After adding a new scheduled task, the system will tell you that a new crontab is installed. You do not need to restart the <B
CLASS="command"
>cron</B
> daemon for the changes to take effect. In the example, <EM
>billy</EM
> added a new line pointing to a backup script:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>billy:~&#62;</TT
> <B
CLASS="command"
>crontab -e</B
>
45 15 * * 3 mail -s "sports evening" billy
4 4 * * 4,7 /home/billy/bin/backup.sh
&#60;--write and quit--&#62;
crontab: installing new crontab
<TT
CLASS="prompt"
>billy:~&#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <TT
CLASS="filename"
>backup.sh</TT
> script is executed every Thursday and Sunday. See <A
HREF="#sect_07_02_07"
>Section 7.2.5</A
> for an introduction to shell scripting. Keep in mind that output of commands, if any, is mailed to the owner of the crontab file. If no mail service is configured, you might find the output of your commands in your local mailbox, <TT
CLASS="filename"
>/var/spool/mail/&#60;your_username&#62;</TT
>, a plain text file.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Who runs my commands?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>You don't have to specify the user who should run the commands. They are executed with the user's own permissions by default.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_04_05"
></A
>4.5. Summary</H1
><P
>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:</P
><DIV
CLASS="table"
><A
NAME="AEN5938"
></A
><P
><B
>Table 4-3. New commands in chapter 4: Processes</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>at</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Queue jobs for later execution.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>atq</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Lists the user's pending jobs.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>atrm</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Deletes jobs, determined by their job number.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>batch</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Executes commands when system load level permits.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>crontab</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Maintain crontab files for individual users.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>halt</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Stop the system.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>init <TT
CLASS="parameter"
><I
>run level</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Process control initialization.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>jobs</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Lists currently executing jobs.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>kill</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Terminate a process.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mesg</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Control write access to your terminal.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>netstat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display network connections, routing tables, interface statistics, masquerade connections and multicast memberships.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>nice</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Run a program with modified scheduling priority.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>pgrep</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display processes.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ps</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Report process status.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>pstree</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display a tree of processes.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>reboot</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Stop the system.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>renice</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Alter priority of running processes.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>shutdown</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Bring the system down.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>sleep</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Delay for a specified time.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>time</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Time a command or report resource usage.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>top</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display top CPU processes.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>uptime</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show how long the system has been running.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>vmstat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Report virtual memory statistics.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>w</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show who is logged on and what they are doing.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>wall</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Send a message to everybody's terminals.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>who</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show who is logged on.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>write</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Send a message to another user.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_04_06"
></A
>4.6. Exercises</H1
><P
>These are some exercises that will help you get the feel for processes running on your system.</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN6058"
></A
>4.6.1. General</H2
><P
></P
><UL
><LI
><P
>Run <B
CLASS="command"
>top</B
> in one terminal while you do the exercises in another.</P
></LI
><LI
><P
>Run the <B
CLASS="command"
>ps</B
> command.</P
></LI
><LI
><P
>Read the man pages to find out how to display all your processes.</P
></LI
><LI
><P
>Run the command <B
CLASS="command"
>find <TT
CLASS="filename"
>/</TT
></B
>. What effect does it have on system load? Stop this command.</P
></LI
><LI
><P
>In graphical mode, start the <B
CLASS="command"
>xclock</B
> program in the foreground. Then let it run in the background. Stop the program using the <B
CLASS="command"
>kill</B
> command.</P
></LI
><LI
><P
>Run the <B
CLASS="command"
>xcalc</B
> directly in the background, so that the prompt of the issuing terminal is released.</P
></LI
><LI
><P
>What does <B
CLASS="command"
>kill <TT
CLASS="option"
>-9 -1</TT
></B
> do?</P
></LI
><LI
><P
>Open two terminals or terminal windows again and use <B
CLASS="command"
>write</B
> to send a message from one to the other.</P
></LI
><LI
><P
>Issue the <B
CLASS="command"
>dmesg</B
> command. What does it tell?</P
></LI
><LI
><P
>How long does it take to execute <B
CLASS="command"
>ls</B
> in the current directory?</P
></LI
><LI
><P
>Based on process entries in <TT
CLASS="filename"
>/proc</TT
>, owned by your UID, how would you work to find out which processes these actually represent?</P
></LI
><LI
><P
>How long has your system been running?</P
></LI
><LI
><P
>Which is your current TTY?</P
></LI
><LI
><P
>Name 3 processes that couldn't have had <B
CLASS="command"
>init</B
> as an initial parent.</P
></LI
><LI
><P
>Name 3 commands which use SUID mode. Explain why this is so.</P
></LI
><LI
><P
>Name the commands that are generally causing the highest load on your system.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN6107"
></A
>4.6.2. Booting, init etc.</H2
><P
></P
><UL
><LI
><P
>Can you reboot the system as a normal user? Why is that?</P
></LI
><LI
><P
>According to your current run level, name the steps that are taken during shutdown.</P
></LI
><LI
><P
>How do you change the system run level? Switch from your default run level to run level 1 and vice versa.</P
></LI
><LI
><P
>Make a list of all the services and daemons that are started up when your system has booted.</P
></LI
><LI
><P
>Which kernel is currently load at startup?</P
></LI
><LI
><P
>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 <TT
CLASS="filename"
>deliver_pizza</TT
> 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?</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN6123"
></A
>4.6.3. Scheduling</H2
><P
></P
><UL
><LI
><P
>Use <B
CLASS="command"
>sleep</B
> to create a reminder that your pasta is ready in ten minutes.</P
></LI
><LI
><P
>Create an <B
CLASS="command"
>at</B
> job that copies all files in your home directory to <TT
CLASS="filename"
>/var/tmp</TT
> within half an hour. You may want to create a sub-directory in <TT
CLASS="filename"
>/var/tmp</TT
>.</P
></LI
><LI
><P
>Make a cronjob that does this task every Monday to Friday during lunch.</P
></LI
><LI
><P
>Check that it works.</P
></LI
><LI
><P
>Make a mistake in the crontab entry, like issuing the nonexistent command <B
CLASS="command"
>coppy</B
> instead of <B
CLASS="command"
>cp</B
>. What happens upon execution of the task?</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_05"
></A
>Chapter 5. I/O redirection</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN6144"
></A
><P
></P
><P
>This chapter describes more about the powerful UNIX mechanism of redirecting input, output and errors. Topics include:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Standard input, output and errors</P
></LI
><LI
><P
>Redirection operators</P
></LI
><LI
><P
>How to use output of one command as input for another</P
></LI
><LI
><P
>How to put output of a command in a file for later referrence</P
></LI
><LI
><P
>How to append output of multiple commands to a file</P
></LI
><LI
><P
>Input redirection</P
></LI
><LI
><P
>Handling standard error messages</P
></LI
><LI
><P
>Combining redirection of input, output and error streams</P
></LI
><LI
><P
>Output filters</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_05_01"
></A
>5.1. Simple redirections</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_05_01_01"
></A
>5.1.1. What are standard input and standard output?</H2
><P
>&#13;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 <EM
>standard input</EM
> (stdin) device, and the screen or a particular terminal window is the <EM
>standard output</EM
> (stdout) device.
</P
><P
>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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_05_01_02"
></A
>5.1.2. The redirection operators</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_05_01_02_01"
></A
>5.1.2.1. Output redirection with &#62; and |</H3
><P
>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 <SPAN
CLASS="QUOTE"
>"&#62;"</SPAN
> (greater-than symbol), or using the <SPAN
CLASS="QUOTE"
>"|"</SPAN
> (pipe) operator which sends the standard output of one command to another command as standard input.</P
><P
>As we saw before, the <B
CLASS="command"
>cat</B
> 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.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>cat test1</B
>
some words
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>cat test2</B
>
some other words
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>cat test1 test2 &#62; test3</B
>
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>cat test3</B
>
some words
some other words
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Don't overwrite!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Be careful not to overwrite existing (important) files when redirecting output. Many shells, including <SPAN
CLASS="application"
>Bash</SPAN
>, have a built-in feature to protect you from that risk: <B
CLASS="command"
>noclobber</B
>. See the <SPAN
CLASS="application"
>Info</SPAN
> pages for more information. In <SPAN
CLASS="application"
>Bash</SPAN
>, you would want to add the <B
CLASS="command"
>set <TT
CLASS="option"
>-o</TT
> <TT
CLASS="parameter"
><I
>noclobber</I
></TT
></B
> command to your <TT
CLASS="filename"
>.bashrc</TT
> configuration file in order to prevent accidental overwriting of files.</P
></TD
></TR
></TABLE
></DIV
><P
>Redirecting <SPAN
CLASS="QUOTE"
>"nothing"</SPAN
> to an existing file is equal to emptying the file:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>ls -l list</B
>
-rw-rw-r-- 1 nancy nancy 117 Apr 2 18:09 list
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>&#62; list</B
>
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>ls -l list</B
>
-rw-rw-r-- 1 nancy nancy 0 Apr 4 12:01 list
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This process is called <EM
>truncating</EM
>.</P
><P
>The same redirection to an nonexistent file will create a new empty file with the given name:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>ls -l newlist</B
>
ls: newlist: No such file or directory
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>&#62; newlist</B
>
<TT
CLASS="prompt"
>nancy:~&#62;</TT
> <B
CLASS="command"
>ls -l newlist</B
>
-rw-rw-r-- 1 nancy nancy 0 Apr 4 12:05 newlist
</PRE
></FONT
></TD
></TR
></TABLE
><P
><A
HREF="#chap_07"
>Chapter 7</A
> gives some more examples on the use of this sort of redirection.</P
><P
>Some examples using piping of commands:</P
><P
>To find a word within some text, display all lines matching <SPAN
CLASS="QUOTE"
>"pattern1"</SPAN
>, and exclude lines also matching <SPAN
CLASS="QUOTE"
>"pattern2"</SPAN
> from being displayed:</P
><P
><B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>pattern1</I
></TT
> <TT
CLASS="filename"
>file</TT
> | grep <TT
CLASS="option"
>-v</TT
> <TT
CLASS="parameter"
><I
>pattern2</I
></TT
></B
> </P
><P
>To display output of a directory listing one page at a time:</P
><P
><B
CLASS="command"
>ls <TT
CLASS="option"
>-la</TT
> | less</B
> </P
><P
>To find a file in a directory:</P
><P
><B
CLASS="command"
>ls <TT
CLASS="option"
>-l</TT
> | grep <TT
CLASS="parameter"
><I
>part_of_file_name</I
></TT
></B
> </P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_05_01_02_02"
></A
>5.1.2.2. Input redirection</H3
><P
>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 <SPAN
CLASS="QUOTE"
>"&#60;"</SPAN
> (less-than symbol) operator.</P
><P
>Below is an example of sending a file to somebody, using input redirection.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>mail mike@somewhere.org &#60; to_do</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If the user <EM
>mike</EM
> 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 <B
CLASS="command"
>mail</B
>.</P
><P
>This reads a bit more difficult than the beginner's <B
CLASS="command"
>cat <TT
CLASS="filename"
>file</TT
> | mail <TT
CLASS="parameter"
><I
>someone</I
></TT
></B
>, but it is of course a much more elegant way of using the available tools.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_05_01_02_03"
></A
>5.1.2.3. Combining redirections</H3
><P
>The following example combines input and output redirection. The file <TT
CLASS="filename"
>text.txt</TT
> is first checked for spelling mistakes, and the output is redirected to an error log file:</P
><P
><B
CLASS="command"
>spell &#60; <TT
CLASS="filename"
>text.txt</TT
> &#62; <TT
CLASS="filename"
>error.log</TT
></B
></P
><P
>The following command lists all commands that you can issue to examine another file when using <B
CLASS="command"
>less</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>less --help | grep -i examine</B
>
:e [file] Examine a new file.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <TT
CLASS="option"
>-i</TT
> option is used for case-insensitive searches - remember that UNIX systems are very case-sensitive.</P
><P
>If you want to save output of this command for future reference, redirect the output to a file:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>less --help | grep -i examine &#62; examine-files-in-less</B
>
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>cat examine-files-in-less</B
>
:e [file] Examine a new file.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Output of one command can be piped into another command virtually as many times as you want, just as long as these commands would normally read input from standard input and write output to the standard output. Sometimes they don't, but then there may be special options that instruct these commands to behave according to the standard definitions; so read the documentation (man and <SPAN
CLASS="application"
>Info</SPAN
> pages) of the commands you use if you should encounter errors.</P
><P
>Again, make sure you don't use names of existing files that you still need. Redirecting output to existing files will replace the content of those files.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_05_01_02_04"
></A
>5.1.2.4. The &#62;&#62; operator</H3
><P
>Instead of overwriting file data, you can also append text to an existing file using two subsequent greater-than signs:</P
><P
>Example:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>cat <TT
CLASS="filename"
>wishlist</TT
></B
>
more money
less work
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>date &#62;&#62; <TT
CLASS="filename"
>wishlist</TT
></B
>
<TT
CLASS="prompt"
>mike:~&#62;</TT
> <B
CLASS="command"
>cat <TT
CLASS="filename"
>wishlist</TT
></B
>
more money
less work
Thu Feb 28 20:23:07 CET 2002
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <B
CLASS="command"
>date</B
> command would normally put the last line on the screen; now it is appended to the file <TT
CLASS="filename"
>wishlist</TT
>.
</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_05_02"
></A
>5.2. Advanced redirection features</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_05_02_01"
></A
>5.2.1. Use of file descriptors</H2
><P
>There are three types of I/O, which each have their own identifier, called a file descriptor:</P
><P
></P
><UL
><LI
><P
>standard input: 0</P
></LI
><LI
><P
>standard output: 1</P
></LI
><LI
><P
>standard error: 2</P
></LI
></UL
><P
>In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is &#60;, the redirection refers to the standard input (file descriptor 0). If the first character of the redirection operator is &#62;, the redirection refers to the standard output (file descriptor 1).</P
><P
>Some practical examples will make this more clear:</P
><P
><B
CLASS="command"
>ls &#62; <TT
CLASS="filename"
>dirlist</TT
> 2&#62;&#38;1</B
> </P
><P
>will direct both standard output and standard error to the file <TT
CLASS="filename"
>dirlist</TT
>, while the command</P
><P
><B
CLASS="command"
>ls 2&#62;&#38;1 &#62; <TT
CLASS="filename"
>dirlist</TT
></B
> </P
><P
>will only direct standard output to <TT
CLASS="filename"
>dirlist</TT
>. This can be a useful option for programmers.</P
><P
>Things are getting quite complicated here, don't confuse the use of the ampersand here with the use of it in <A
HREF="#sect_04_01_02_01"
>Section 4.1.2.1</A
>, where the ampersand is used to run a process in the background. Here, it merely serves as an indication that the number that follows is not a file name, but rather a location that the data stream is pointed to. Also note that the bigger-than sign should not be separated by spaces from the number of the file descriptor. If it would be separated, we would be pointing the output to a file again. The example below demonstrates this:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[nancy@asus /var/tmp]$ </TT
><B
CLASS="command"
>ls 2&#62; <TT
CLASS="filename"
>tmp</TT
></B
>
<TT
CLASS="prompt"
>[nancy@asus /var/tmp]$ </TT
><B
CLASS="command"
>ls -l <TT
CLASS="filename"
>tmp</TT
></B
>
-rw-rw-r-- 1 nancy nancy 0 Sept 7 12:58 tmp
<TT
CLASS="prompt"
>[nancy@asus /var/tmp]$ </TT
><B
CLASS="command"
>ls 2 &#62; <TT
CLASS="filename"
>tmp</TT
></B
>
ls: 2: No such file or directory
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The first command that <EM
>nancy</EM
> executes is correct (eventhough no errors are generated and thus the file to which standard error is redirected is empty). The second command expects that <TT
CLASS="filename"
>2</TT
> is a file name, which does not exist in this case, so an error is displayed.</P
><P
>All these features are explained in detail in the Bash Info pages.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_05_02_02"
></A
>5.2.2. Examples</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_05_02_02_01"
></A
>5.2.2.1. Analyzing errors</H3
><P
>If your process generates a lot of errors, this is a way to thoroughly examine them:</P
><P
><B
CLASS="command"
>command 2&#62;&#38;1 | less</B
> </P
><P
>This is often used when creating new software using the <B
CLASS="command"
>make</B
> command, such as in:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>andy:~/newsoft&#62;</TT
> <B
CLASS="command"
>make all 2&#62;&#38;1 | less</B
>
--output ommitted--
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_05_02_02_02"
></A
>5.2.2.2. Separating standard output from standard error</H3
><P
>Constructs like these are often used by programmers, so that output is displayed in one terminal window, and errors in another. Find out which pseudo terminal you are using issuing the <B
CLASS="command"
>tty</B
> command first:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>andy:~/newsoft&#62;</TT
> <B
CLASS="command"
>make all 2&#62; /dev/pts/7</B
>
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_05_02_02_03"
></A
>5.2.2.3. Writing to output and files simultaneously</H3
><P
>You can use the <B
CLASS="command"
>tee</B
> command to copy input to standard output and one or more output files in one move. Using the <TT
CLASS="option"
>-a</TT
> option to <B
CLASS="command"
>tee</B
> results in appending input to the file(s). This command is useful if you want to both see and save output. The <B
CLASS="command"
>&#62;</B
> and <B
CLASS="command"
>&#62;&#62;</B
> operators do not allow to perform both actions simultaneously.</P
><P
>This tool is usually called on through a pipe (<B
CLASS="command"
>|</B
>), as demonstrated in the example below:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>mireille ~/test&#62;</TT
> <B
CLASS="command"
>date | tee <TT
CLASS="filename"
>file1 file2</TT
></B
>
Thu Jun 10 11:10:34 CEST 2004
<TT
CLASS="prompt"
>mireille ~/test&#62;</TT
> <B
CLASS="command"
>cat <TT
CLASS="filename"
>file1</TT
></B
>
Thu Jun 10 11:10:34 CEST 2004
<TT
CLASS="prompt"
>mireille ~/test&#62;</TT
> <B
CLASS="command"
>cat <TT
CLASS="filename"
>file2</TT
></B
>
Thu Jun 10 11:10:34 CEST 2004
<TT
CLASS="prompt"
>mireille ~/test&#62;</TT
> <B
CLASS="command"
>uptime | tee <TT
CLASS="option"
>-a</TT
> <TT
CLASS="filename"
>file2</TT
></B
>
11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26
<TT
CLASS="prompt"
>mireille ~/test&#62;</TT
> <B
CLASS="command"
>cat <TT
CLASS="filename"
>file2</TT
></B
>
Thu Jun 10 11:10:34 CEST 2004
11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_05_03"
></A
>5.3. Filters</H1
><P
>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.</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_05_03_01"
></A
>5.3.1. More about grep</H2
><P
>As we saw in <A
HREF="#sect_03_03_03_04"
>Section 3.3.3.4</A
>, <B
CLASS="command"
>grep</B
> 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 <TT
CLASS="option"
>-v</TT
> option.
</P
><P
>Some examples: suppose we want to know which files in a certain directory have been modified in February:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jenny:~&#62;</TT
> <B
CLASS="command"
>ls -la | grep Feb</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <B
CLASS="command"
>grep</B
> command, like most commands, is case sensitive. Use the <TT
CLASS="option"
>-i</TT
> option to make no difference between upper and lower case. A lot of GNU extensions are available as well, such as <TT
CLASS="option"
>--colour</TT
>, which is helpful to highlight searchterms in long lines, and <TT
CLASS="option"
>--after-context</TT
>, which prints the number of lines after the last matching line. You can issue a recursive <B
CLASS="command"
>grep</B
> that searches all subdirectories of encountered directories using the <TT
CLASS="option"
>-r</TT
> option. As usual, options can be combined.</P
><P
>Regular expressions can be used to further detail the exact character matches you want to select out of all the input lines. The best way to start with regular expressions is indeed to read the <B
CLASS="command"
>grep</B
> documentation. An excellent chapter is included in the <B
CLASS="command"
>grep</B
> <SPAN
CLASS="application"
>Info</SPAN
> page. Since it would lead us too far discussing the ins and outs of regular expressions, it is strongly advised to start here if you want to know more about them.</P
><P
>Play around a bit with <B
CLASS="command"
>grep</B
>, it will be worth the trouble putting some time in this most basic but very powerful filtering command. The exercises at the end of this chapter will help you to get started, see <A
HREF="#sect_05_05"
>Section 5.5</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_05_03_02"
></A
>5.3.2. Filtering output</H2
><P
>The command <B
CLASS="command"
>sort</B
> arranges lines in alphabetical order by default:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>thomas:~&#62;</TT
> <B
CLASS="command"
>cat people-I-like | sort</B
>
Auntie Emmy
Boyfriend
Dad
Grandma
Mum
My boss
</PRE
></FONT
></TD
></TR
></TABLE
><P
>But there are many more things <B
CLASS="command"
>sort</B
> can do. Looking at the file size, for instance. With this command, directory content is sorted smallest files first, biggest files last:</P
><P
><B
CLASS="command"
>ls <TT
CLASS="option"
>-la</TT
> | sort <TT
CLASS="option"
>-nk</TT
> <TT
CLASS="parameter"
><I
>5</I
></TT
></B
> </P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Old sort syntax</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>You might obtain the same result with <B
CLASS="command"
>ls <TT
CLASS="option"
>-la</TT
> | sort <TT
CLASS="option"
>+4n</TT
></B
>, but this is an old form which does not comply with the current standards.</P
></TD
></TR
></TABLE
></DIV
><P
>The <B
CLASS="command"
>sort</B
> command is also used in combination with the <B
CLASS="command"
>uniq</B
> program (or <B
CLASS="command"
>sort <TT
CLASS="option"
>-u</TT
></B
>) to sort output and filter out double entries:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>thomas:~&#62; </TT
><B
CLASS="command"
>cat <TT
CLASS="filename"
>itemlist</TT
></B
>
1
4
2
5
34
567
432
567
34
555
<TT
CLASS="prompt"
>thomas:~&#62; </TT
><B
CLASS="command"
>sort <TT
CLASS="filename"
>itemlist</TT
> | uniq</B
>
1
2
34
4
432
5
555
567
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_05_04"
></A
>5.4. Summary</H1
><P
>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.</P
><P
>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.</P
><P
>The most commonly used redirections are <B
CLASS="command"
>&#62;</B
> and <B
CLASS="command"
>|</B
>. Refer to <A
HREF="#app3"
>Appendix C</A
> for an overview of redirection commands and other shell constructs.</P
><DIV
CLASS="table"
><A
NAME="AEN6552"
></A
><P
><B
>Table 5-1. New commands in chapter 5: I/O redirection</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>date</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display time and date information.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>set</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configure shell options.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>sort</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Sort lines of text.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>uniq</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Remove duplicate lines from a sorted file.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_05_05"
></A
>5.5. Exercises</H1
><P
>These exercises give more examples on how to combine commands. The main goal is to try and use the <B
CLASS="keycap"
>Enter</B
> key as little as possible.</P
><P
>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!</P
><P
></P
><UL
><LI
><P
>Use the <B
CLASS="command"
>cut</B
> command on the output of a long directory listing in order to display only the file permissions. Then pipe this output to <B
CLASS="command"
>sort</B
> and <B
CLASS="command"
>uniq</B
> to filter out any double lines. Then use the <B
CLASS="command"
>wc</B
> to count the different permission types in this directory.</P
></LI
><LI
><P
>Put the output of <B
CLASS="command"
>date</B
> in a file. Append the output of <B
CLASS="command"
>ls</B
> to this file. Send this file to your local mailbox (don't specify anything <TT
CLASS="email"
>&#60;<A
HREF="mailto:@domain"
>@domain</A
>&#62;</TT
>, just the user name will do). When using Bash, you will see a new mail notice upon success.</P
></LI
><LI
><P
>List the devices in <TT
CLASS="filename"
>/dev</TT
> which are currently used by your UID. Pipe through <B
CLASS="command"
>less</B
> to view them properly.</P
></LI
><LI
><P
>Issue the following commands as a non-privileged user. Determine standard input, output and error for each command.</P
><P
></P
><UL
><LI
><P
><P
><B
CLASS="command"
>cat <TT
CLASS="filename"
>nonexistentfile</TT
></B
> </P
></P
></LI
><LI
><P
><P
><B
CLASS="command"
>file <TT
CLASS="filename"
>/sbin/ifconfig</TT
></B
> </P
></P
></LI
><LI
><P
><P
><B
CLASS="command"
>grep <TT
CLASS="parameter"
><I
>root</I
></TT
> <TT
CLASS="filename"
>/etc/passwd /etc/nofiles</TT
> &#62; <TT
CLASS="filename"
>grepresults</TT
></B
> </P
></P
></LI
><LI
><P
><P
><B
CLASS="command"
>/etc/init.d/sshd <TT
CLASS="parameter"
><I
>start</I
></TT
> &#62; <TT
CLASS="filename"
>/var/tmp/output</TT
></B
> </P
></P
></LI
><LI
><P
><P
><B
CLASS="command"
>/etc/init.d/crond <TT
CLASS="parameter"
><I
>start</I
></TT
> &#62; <TT
CLASS="filename"
>/var/tmp/output</TT
> 2&#62;&#38;1</B
> </P
></P
></LI
><LI
><P
>Now check your results by issuing the commands again, now redirecting standardoutput to the file <TT
CLASS="filename"
>/var/tmp/output</TT
> and standard error to the file <TT
CLASS="filename"
>/var/tmp/error</TT
>.</P
></LI
></UL
></LI
><LI
><P
>How many processes are you currently running?</P
></LI
><LI
><P
>How many invisible files are in your home directory?</P
></LI
><LI
><P
>Use <B
CLASS="command"
>locate</B
> to find documentation about the kernel.</P
></LI
><LI
><P
>Find out which file contains the following entry:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;root:x:0:0:root:/root:/bin/bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
>And this one:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;system: root
</PRE
></FONT
></TD
></TR
></TABLE
></LI
><LI
><P
>See what happens upon issuing this command:</P
><P
><B
CLASS="command"
>&#62; time; date &#62;&#62; time; cat &#60; time</B
> </P
></LI
><LI
><P
>What command would you use to check which script in <TT
CLASS="filename"
>/etc/init.d</TT
> starts a given process?</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_06"
></A
>Chapter 6. Text editors</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN6654"
></A
><P
></P
><P
>In this chapter, we will discuss the importance of mastering an editor. We will focus mainly on the Improved <B
CLASS="command"
>vi</B
> editor.</P
><P
>After finishing this chapter, you will be able to:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Open and close files in text mode</P
></LI
><LI
><P
>Edit files</P
></LI
><LI
><P
>Search text</P
></LI
><LI
><P
>Undo errors</P
></LI
><LI
><P
>Merge files</P
></LI
><LI
><P
>Recover lost files</P
></LI
><LI
><P
>Find a program or suite for office use</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_06_01"
></A
>6.1. Text editors</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_06_01_01"
></A
>6.1.1. Why should I use an editor?</H2
><P
>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.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_06_01_02"
></A
>6.1.2. Which editor should I use?</H2
><P
>Our focus is on text editors, which can also be used on systems without a graphical environment and in terminal windows. 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.</P
><P
>There are, as usual, multiple ways to handle the problem. Let's see what editors are commonly available:</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_06_01_02_02"
></A
>6.1.2.1. GNU Emacs</H3
><P
><SPAN
CLASS="application"
>Emacs</SPAN
> 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. <SPAN
CLASS="application"
>Emacs</SPAN
> 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.</P
><P
><EM
>Self-documenting</EM
> means that at any time you can type a special character, <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>H</B
>, 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. <EM
>Customizable</EM
> means that you can change the definitions of <SPAN
CLASS="application"
>Emacs</SPAN
> commands in little ways. For example, if you use a programming language in which comments start with <SPAN
CLASS="QUOTE"
>"&#60;**"</SPAN
> and end with <SPAN
CLASS="QUOTE"
>"**&#62;"</SPAN
>, you can tell the <SPAN
CLASS="application"
>Emacs</SPAN
> 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.</P
><P
><EM
>Extensible</EM
> means that you can go beyond simple customization and write entirely new commands, programs in the Lisp language that are run by <SPAN
CLASS="application"
>Emacs</SPAN
>'s own <SPAN
CLASS="application"
>Lisp</SPAN
> interpreter. <SPAN
CLASS="application"
>Emacs</SPAN
> is an <EM
>online</EM
> 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 <SPAN
CLASS="application"
>Emacs</SPAN
> can be replaced without making a separate copy of all of <SPAN
CLASS="application"
>Emacs</SPAN
>. Most of the editing commands of <SPAN
CLASS="application"
>Emacs</SPAN
> are written in <SPAN
CLASS="application"
>Lisp</SPAN
> already; the few exceptions could have been written in <SPAN
CLASS="application"
>Lisp</SPAN
> but are written in C for efficiency. Although only a programmer can write an extension, anybody can use it afterward.</P
><P
>When run under the X Window System (started as <B
CLASS="command"
>xemacs</B
>) <SPAN
CLASS="application"
>Emacs</SPAN
> provides its own menus and convenient bindings to mouse buttons. But <SPAN
CLASS="application"
>Emacs</SPAN
> 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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_06_01_02_03"
></A
>6.1.2.2. Vi(m)</H3
><P
><SPAN
CLASS="application"
>Vim</SPAN
> stands for <SPAN
CLASS="QUOTE"
>"Vi IMproved"</SPAN
>. It used to be <SPAN
CLASS="QUOTE"
>"Vi IMitation"</SPAN
>, but there are so many improvements that a name change was appropriate. <SPAN
CLASS="application"
>Vim</SPAN
> is a text editor which includes almost all the commands from the UNIX program <B
CLASS="command"
>vi</B
> and a lot of new ones.</P
><P
>Commands in the <B
CLASS="command"
>vi</B
> 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.</P
><P
>We will refer to <B
CLASS="command"
>vi</B
> or <B
CLASS="command"
>vim</B
> throughout this book for editing files, while you are of course free to use the editor of your choice. However, we recommend to at least get the <B
CLASS="command"
>vi</B
> basics in the fingers, because it is the standard text editor on almost all UNIX systems, while <B
CLASS="command"
>emacs</B
> 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 <B
CLASS="command"
>vi</B
>, you can survive on any UNIX system.</P
><P
>Apart from the <B
CLASS="command"
>vim</B
> command, the <SPAN
CLASS="application"
>vIm</SPAN
> packages may also provide <B
CLASS="command"
>gvim</B
>, the <SPAN
CLASS="application"
>Gnome</SPAN
> version of <B
CLASS="command"
>vim</B
>. Beginning users might find this easier to use, because the menus offer help when you forgot or don't know how to perform a particular editing task using the standard <B
CLASS="command"
>vim</B
> commands.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_06_02"
></A
>6.2. Using the Vim editor</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_06_02_01"
></A
>6.2.1. Two modes</H2
><P
>The <B
CLASS="command"
>vi</B
> editor is a very powerful tool and has a very extensive built-in manual, which you can activate using the <B
CLASS="command"
>:help</B
> command when the program is started (instead of using <B
CLASS="command"
>man</B
> or <B
CLASS="command"
>info</B
>, which don't contain nearly as much information). We will only discuss the very basics here to get you started.</P
><P
>What makes <B
CLASS="command"
>vi</B
> 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.</P
><P
>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.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Pronunciation</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>It's pronounced <SPAN
CLASS="QUOTE"
>"vee-eye"</SPAN
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_06_02_02"
></A
>6.2.2. Basic commands</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_06_02_02_01"
></A
>6.2.2.1. Moving through the text</H3
><P
>Moving through the text is usually possible with the arrow keys. If not, try:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>h</B
> to move the cursor to the left</P
></LI
><LI
><P
><B
CLASS="command"
>l</B
> to move it to the right</P
></LI
><LI
><P
><B
CLASS="command"
>k</B
> to move up</P
></LI
><LI
><P
><B
CLASS="command"
>j</B
> to move down</P
></LI
></UL
><P
>SHIFT-G will put the prompt at the end of the document.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_06_02_02_02"
></A
>6.2.2.2. Basic operations</H3
><P
>These are some popular <B
CLASS="command"
>vi</B
> commands:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>n dd</B
> will delete n lines starting from the current cursor position.</P
></LI
><LI
><P
><B
CLASS="command"
>n dw</B
> will delete n words at the right side of the cursor.</P
></LI
><LI
><P
><B
CLASS="command"
>x</B
> will delete the character on which the cursor is positioned</P
></LI
><LI
><P
><B
CLASS="command"
>:n</B
> moves to line n of the file.</P
></LI
><LI
><P
><B
CLASS="command"
>:w</B
> will save (write) the file</P
></LI
><LI
><P
><B
CLASS="command"
>:q</B
> will exit the editor.</P
></LI
><LI
><P
><B
CLASS="command"
>:q!</B
> forces the exit when you want to quit a file containing unsaved changes.</P
></LI
><LI
><P
><B
CLASS="command"
>:wq</B
> will save and exit</P
></LI
><LI
><P
><B
CLASS="command"
>:w newfile</B
> will save the text to <TT
CLASS="filename"
>newfile</TT
>.</P
></LI
><LI
><P
><B
CLASS="command"
>:wq!</B
> overrides read-only permission (if you have the permission to override permissions, for instance when you are using the <EM
>root</EM
> account.</P
></LI
><LI
><P
><B
CLASS="command"
>/astring</B
> will search the string in the file and position the cursor on the first match below its position.</P
></LI
><LI
><P
><B
CLASS="command"
>/</B
> will perform the same search again, moving the cursor to the next match.</P
></LI
><LI
><P
><B
CLASS="command"
>:1, $s/word/anotherword/g</B
> will replace <TT
CLASS="filename"
>word</TT
> with <TT
CLASS="filename"
>anotherword</TT
> throughout the file.</P
></LI
><LI
><P
><B
CLASS="command"
>yy</B
> will copy a block of text.</P
></LI
><LI
><P
><B
CLASS="command"
>n p</B
> will paste it n times.</P
></LI
><LI
><P
><B
CLASS="command"
>:recover</B
> will recover a file after an unexpected interruption.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_06_02_02_03"
></A
>6.2.2.3. Commands that switch the editor to insert mode</H3
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>a</B
> will append: it moves the cursor one position to the right before switching to insert mode</P
></LI
><LI
><P
><B
CLASS="command"
>i</B
> will insert</P
></LI
><LI
><P
><B
CLASS="command"
>o</B
> will insert a blank line under the current cursor position and move the cursor to that line.</P
></LI
></UL
><P
>Pressing the <B
CLASS="keycap"
>Esc</B
> key switches back to command mode. If you're not sure what mode you're in because you use a really old version of <B
CLASS="command"
>vi</B
> that doesn't display an <SPAN
CLASS="QUOTE"
>"INSERT"</SPAN
> message, type <B
CLASS="keycap"
>Esc</B
> 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 <B
CLASS="keycap"
>Esc</B
>, by beeping or giving a visual bell (a flash on the screen). This is normal behavior.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_06_02_03"
></A
>6.2.3. The easy way</H2
><P
>Instead of reading the text, which is quite boring, you can use the vimtutor to learn you first <SPAN
CLASS="application"
>Vim</SPAN
> commands. This is a thirty minute tutorial that teaches the most basic <SPAN
CLASS="application"
>Vim</SPAN
> functionality in eight easy exercises. While you can't learn everything about <B
CLASS="command"
>vim</B
> 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.</P
><P
>In UNIX and MS Windows, if <SPAN
CLASS="application"
>Vim</SPAN
> has been properly installed, you can start this program from the shell or command line, entering the <B
CLASS="command"
>vimtutor</B
> 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 <B
CLASS="command"
>vimtutor <TT
CLASS="parameter"
><I
>fr</I
></TT
></B
> (if installed on the system).</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_06_03"
></A
>6.3. Linux in the office</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_06_03_01"
></A
>6.3.1. History</H2
><P
>Throughout the last decade the office domain has typically been dominated by <SPAN
CLASS="application"
>MS Office</SPAN
>, and, let's face it: the Microsoft <SPAN
CLASS="application"
>Word</SPAN
>, <SPAN
CLASS="application"
>Excel</SPAN
> and <SPAN
CLASS="application"
>PowerPoint</SPAN
> formats are industry standards that you will have to deal with sooner or later.</P
><P
>This monopoly situation of Microsoft proved to be a big disadvantage for getting new users to Linux, so a group of German developers started the StarOffice project, that was, and is still, aimed at making an MS Office clone. Their company, StarDivision, was acquired by Sun Microsystems by the end of the 1990s, just before the 5.2 release. Sun continues development but restricted access to the sources. Nevertheless, development on the original set of sources continues in the Open Source community, which had to rename the project to <SPAN
CLASS="application"
>OpenOffice</SPAN
>. <SPAN
CLASS="application"
>OpenOffice</SPAN
> is now available for a variety of platforms, including MS Windows, Linux, MacOS and Solaris. There is a screenshot in <A
HREF="#sect_01_03_02"
>Section 1.3.2</A
>.</P
><P
>Almost simultaneously, a couple of other quite famous projects took off. Also a very common alternative to using MS Office is <SPAN
CLASS="application"
>KOffice</SPAN
>, the office suite that used to be popular among SuSE users. Like the original, this clone incorporates an MS <SPAN
CLASS="application"
>Word</SPAN
> and <SPAN
CLASS="application"
>Excel</SPAN
> compatible program, and much more.</P
><P
>Smaller projects deal with particular programs of the MS example suite, such as <SPAN
CLASS="application"
>Abiword</SPAN
> and MS <SPAN
CLASS="application"
>Wordview</SPAN
> for compatibility with MS <SPAN
CLASS="application"
>Word</SPAN
> documents, and <SPAN
CLASS="application"
>Gnumeric</SPAN
> for viewing and creating <SPAN
CLASS="application"
>Excel</SPAN
> compatible spreadsheets.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_06_03_02"
></A
>6.3.2. Suites and programs</H2
><P
>Current distributions usually come with all the necessary tools. Since these provide excellent guidelines and searchable indexes in the <SPAN
CLASS="guimenu"
>Help</SPAN
> menus, we won't discuss them in detail. For references, see you system documentation or the web sites of the projects, such as</P
><P
></P
><UL
><LI
><P
><A
HREF="http://www.openoffice.org"
TARGET="_top"
>http://www.openoffice.org</A
></P
></LI
><LI
><P
><A
HREF="http://www.koffice.org"
TARGET="_top"
>http://www.koffice.org</A
></P
></LI
><LI
><P
><A
HREF="http://freshmeat.net"
TARGET="_top"
>Freshmeat</A
> and <A
HREF="http://sourceforge.org"
TARGET="_top"
>SourceForge</A
> for various other projects.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_06_03_03"
></A
>6.3.3. Remarks</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_06_03_03_01"
></A
>6.3.3.1. General use of office documents</H3
><P
>Try to limit the use of office documents for the purposes they were meant for: the office.</P
><P
>An example: it drives most Linux users crazy if you send them a mail that says in the body something like: <SPAN
CLASS="QUOTE"
>"Hello, I want to tell you something, see attach"</SPAN
>, and then the attachement proves to be an MS Word compatible document like: <SPAN
CLASS="QUOTE"
>"Hello my friend, how is your new job going and will you have time to have lunch with me tomorrow?"</SPAN
> Also a bad idea is the attachment of your signature in such a file, for instance. If you want to sign messages or files, use GPG, the PGP-compatible <SPAN
CLASS="application"
>GNU Privacy Guard</SPAN
> or SSL (Secure Socket Layer) certificates.</P
><P
>These users are not annoyed because they are unable to read these documents, or because they are worried that these formats typically generate much larger files, but rather because of the implication that they are using MS Windows, and possibly because of the extra work of starting some additional programs.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_06_03_03_02"
></A
>6.3.3.2. System and user configuration files</H3
><P
>In the next chapter, we start configuring our environment, and this might include editing all kinds of files that determine how a program behave.</P
><P
><EM
>Don't edit these files with any office component!</EM
></P
><P
>The default file format specification would make the program add several lines of code, defining the format of the file and the fonts used. These lines won't be interpreted in the correct way by the programs depending on them, resulting in errors or a crash of the program reading the file. In some cases, you can save the file as plain text, but you'll run into trouble when making this a habit.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_06_03_03_03"
></A
>6.3.3.3. But I want a graphical text editor!</H3
><P
>If you really insist, try <B
CLASS="command"
>gedit</B
>, <B
CLASS="command"
>kedit</B
>, <B
CLASS="command"
>kwrite</B
> or <B
CLASS="command"
>xedit</B
>; these programs only do text files, which is what we will be needing. If you plan on doing anything serious, though, stick to a real text mode editor such as <B
CLASS="command"
>vim</B
> or <B
CLASS="command"
>emacs</B
>.</P
><P
>An acceptable alternative is <B
CLASS="command"
>gvim</B
>, the <SPAN
CLASS="application"
>Gnome</SPAN
> version of <B
CLASS="command"
>vim</B
>. You still need to use <B
CLASS="command"
>vi</B
> commands, but if you are stuck, you can look them up in the menus.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_06_04"
></A
>6.4. Summary</H1
><P
>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.</P
><P
>The <B
CLASS="command"
>vi</B
> editor is available on every UNIX system.</P
><P
>Most Linux distributions include an office suite and a graphical text editor.</P
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_06_05"
></A
>6.5. Exercises</H1
><P
>This chapter has only one exercise: start the <SPAN
CLASS="application"
>Vim</SPAN
> tutor by entering <B
CLASS="command"
>vimtutor</B
> in a terminal session, and get started.</P
><P
>You may alternatively start <B
CLASS="command"
>emacs</B
> and type <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>H</B
> and then <B
CLASS="keycap"
>T</B
> to invoke the self-paced <SPAN
CLASS="application"
>Emacs</SPAN
> tutorial.</P
><P
>Practice is the only way!</P
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_07"
></A
>Chapter 7. Home sweet /home</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN6995"
></A
><P
></P
><P
>This chapter is about configuring your environment. Now that we know 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:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Organizing your environment</P
></LI
><LI
><P
>Common shell setup files</P
></LI
><LI
><P
>Shell configuration</P
></LI
><LI
><P
>Configuring the prompt</P
></LI
><LI
><P
>Configuring the graphical environment</P
></LI
><LI
><P
>Sound and video applications</P
></LI
><LI
><P
>Display and window managers</P
></LI
><LI
><P
>How the X client-server system works</P
></LI
><LI
><P
>Language and font settings</P
></LI
><LI
><P
>Installing new software</P
></LI
><LI
><P
>Updating existing packages</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_01"
></A
>7.1. General good housekeeping</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_07_01_01"
></A
>7.1.1. Introduction</H2
><P
>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:</P
><P
></P
><UL
><LI
><P
>Make a <TT
CLASS="filename"
>bin</TT
> directory for your program files and scripts.</P
></LI
><LI
><P
>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.</P
></LI
><LI
><P
>Make directories private with the <B
CLASS="command"
>chmod <TT
CLASS="parameter"
><I
>700</I
></TT
> <TT
CLASS="filename"
>dirname</TT
></B
> command.</P
></LI
><LI
><P
>Give your files sensible names, such as <TT
CLASS="filename"
>Complaint to the prime minister 050302</TT
> rather than <TT
CLASS="filename"
>letter1</TT
>.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_01_02"
></A
>7.1.2. Make space</H2
><P
>On some systems, the <B
CLASS="command"
>quota</B
> 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 <B
CLASS="command"
>rm</B
> command, to reclaim disk space.</P
><P
>Run the <B
CLASS="command"
>quota <TT
CLASS="option"
>-v</TT
></B
> command to see how much space is left.</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_01_02_01"
></A
>7.1.2.1. Emptying files</H3
><P
>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 <SPAN
CLASS="application"
>Bourne</SPAN
> and <SPAN
CLASS="application"
>Bash</SPAN
> shells:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>cat wishlist &#62; placeholder</B
>
<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>ls -la placeholder</B
>
-rw-rw-r-- 1 andy andy 200 Jun 12 13:34 placeholder
<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
> &#62; placeholder</B
>
<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>ls -la placeholder</B
>
-rw-rw-r-- 1 andy andy 0 Jun 12 13:35 placeholder
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The process of reducing an existing file to a file with the same name that is 0 bytes large is called <EM
>truncating</EM
>.</P
><P
>For creating a new empty file, the same effect is obtained with the <B
CLASS="command"
>touch</B
> command. On an existing file, <B
CLASS="command"
>touch</B
> will only update the timestamp. See the <SPAN
CLASS="application"
>Info</SPAN
> pages on <B
CLASS="command"
>touch</B
> for more details.</P
><P
>To <SPAN
CLASS="QUOTE"
>"almost"</SPAN
> empty a file, use the <B
CLASS="command"
>tail</B
> command. Suppose user <EM
>andy</EM
>'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:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>tail -5 wishlist &#62; newlist</B
>
<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>cat newlist &#62; wishlist</B
>
<TT
CLASS="prompt"
>andy:~&#62;</TT
> <B
CLASS="command"
>rm newlist</B
>
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_01_02_02"
></A
>7.1.2.2. More about log files</H3
><P
>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:</P
><P
></P
><UL
><LI
><P
>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.</P
></LI
><LI
><P
>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 log files.</P
></LI
><LI
><P
>Try making smaller log files by logging only the information that is relevant to you, or by logging only significant information.</P
></LI
><LI
><P
>Try replacing the log file with a symbolic link to <TT
CLASS="filename"
>/dev/null</TT
>; 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 <A
HREF="#chap_04"
>Chapter 4</A
>). These programs might replace the symbolic link with a small file that starts growing again.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_01_02_03"
></A
>7.1.2.3. Mail</H3
><P
>Regularly clean out your mailbox, make sub-folders and automatic redirects using <B
CLASS="command"
>procmail</B
> (see the <SPAN
CLASS="application"
>Info</SPAN
> pages) or the filters of your favorite mail reading application. If you have a trash folder, clean it out on a regular basis.</P
><P
>To redirect mail, use the <TT
CLASS="filename"
>.forward</TT
> 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 <TT
CLASS="filename"
>.forward</TT
> may look like this:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>webmaster@www ~/&#62;</TT
> <B
CLASS="command"
>cat .forward</B
>
mike@pandora.be
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_01_02_04"
></A
>7.1.2.4. Save space with a link</H3
><P
>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.</P
><P
>Multiple symbolic links may have different names, e.g. a link may be called <TT
CLASS="filename"
>monfichier</TT
> in one user's directory, and <TT
CLASS="filename"
>mylink</TT
> in another's. Multiple links (different names) to the same file may also occur in the same directory. This is often done in the <TT
CLASS="filename"
>/lib</TT
> directory: when issuing the command</P
><P
><B
CLASS="command"
>ls <TT
CLASS="option"
>-l</TT
> <TT
CLASS="filename"
>/lib</TT
></B
> </P
><P
>you will see that this directory is plenty of links pointing to the same files. These are created so that programs searching for one name would not get stuck, so they are pointed to the correct/current name of the libraries they need.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_01_02_05"
></A
>7.1.2.5. Limit file sizes</H3
><P
>The shell contains a built-in command to limit file sizes, <B
CLASS="command"
>ulimit</B
>, which can also be used to display limitations on system resources:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>cindy:~&#62;</TT
> <B
CLASS="command"
>ulimit -a</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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 <B
CLASS="command"
>ulimit</B
> command. Read the <SPAN
CLASS="application"
>Info</SPAN
> pages on <B
CLASS="command"
>bash</B
> for a detailed explanation.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Core file?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>A core file or <EM
>core dump</EM
> is sometimes generated when things go wrong with a program during its execution. The core file contains a copy of the system's memory, as it was at the time that the error occured.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_01_02_06"
></A
>7.1.2.6. Compressed files</H3
><P
>Compressed files are useful because they take less space on your hard disk. Another advantage is that it takes less bandwidth to send a compressed file over your network. A lot of files, such as the man pages, are stored in a compressed format on your system. Yet unpacking these to get a little bit of information and then having to compress them again is rather time-consuming. You don't want to unpack a man page, for instance, read about an option to a command and then compress the man page again. Most people will probably forget to clean up after they found the information they needed.</P
><P
>So we have tools that work on compressed files, by uncompressing them only in memory. The actual compressed file stays on your disk as it is. Most systems support <B
CLASS="command"
>zgrep</B
>, <B
CLASS="command"
>zcat</B
>, <B
CLASS="command"
>bzless</B
> and other members of the z-family to prevent unnecessary decompressing/compressing actions. See your system's binary directory and the Info pages.</P
><P
>See <A
HREF="#chap_09"
>Chapter 9</A
> for more on the actual compressing of files and examples on making archives.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_02"
></A
>7.2. Your text environment</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_07_02_1"
></A
>7.2.1. Environment variables</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_02_01"
></A
>7.2.1.1. General</H3
><P
>We already mentioned a couple of environment variables, such as <TT
CLASS="varname"
>PATH</TT
> and <TT
CLASS="varname"
>HOME</TT
>. 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.</P
><P
>What other information do programs need apart from paths and home directories?</P
><P
>A lot of programs want to know about the kind of terminal you are using; this information is stored in the <TT
CLASS="varname"
>TERM</TT
> variable. In text mode, this will be the <EM
>linux</EM
> terminal emulation, in graphical mode you are likely to use <EM
>xterm</EM
>. 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 <TT
CLASS="varname"
>SHELL</TT
> variable, the operating system type in <TT
CLASS="varname"
>OS</TT
> and so on. A list of all variables currently defined for your session can be viewed entering the <B
CLASS="command"
>printenv</B
> command.</P
><P
>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.</P
><P
>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 <TT
CLASS="varname"
>PATH</TT
> and <TT
CLASS="varname"
>HOME</TT
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_02"
></A
>7.2.1.2. Exporting variables</H3
><P
>An individual variable's content is usually displayed using the <B
CLASS="command"
>echo</B
> command, as in these examples:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>echo $PATH</B
>
/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bin
<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>echo $MANPATH</B
>
/usr/man:/usr/share/man/:/usr/local/man:/usr/X11R6/man
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If you want to change the content of a variable in a way that is useful to other programs, you have to export the new value from your environment into the environment that runs these programs. A common example is exporting the <TT
CLASS="varname"
>PATH</TT
> variable. You may declare it as follows, in order to be able to play with the flight simulator software that is in <TT
CLASS="filename"
>/opt/FlightGear/bin</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>PATH=$PATH:/opt/FlightGear/bin</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This instructs the shell to not only search programs in the current path, <TT
CLASS="varname"
>$PATH</TT
>, but also in the additional directory <TT
CLASS="filename"
>/opt/FlightGear/bin</TT
>.</P
><P
>However, as long as the new value of the <TT
CLASS="varname"
>PATH</TT
> variable is not known to the environment, things will still not work:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>runfgfs</B
>
bash: runfgfs: command not found
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Exporting variables is done using the shell built-in command <B
CLASS="command"
>export</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>export PATH</B
>
<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>runfgfs</B
>
--flight simulator starts--
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In <SPAN
CLASS="application"
>Bash</SPAN
>, we normally do this in one elegant step:</P
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>VARIABLE</TT
>=<TT
CLASS="replaceable"
><I
>value</I
></TT
></B
> </P
><P
>The same technique is used for the <TT
CLASS="varname"
>MANPATH</TT
> variable, that tells the <B
CLASS="command"
>man</B
> command where to look for compressed man pages. If new software is added to the system in new or unusual directories, the documentation for it will probably also be in an unusual directory. If you want to read the man pages for the new software, extend the <TT
CLASS="varname"
>MANPATH</TT
> variable:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>export MANPATH=$MANPATH:/opt/FlightGear/man</B
>
<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>echo $MANPATH</B
>
/usr/man:/usr/share/man:/usr/local/man:/usr/X11R6/man:/opt/FlightGear/man
</PRE
></FONT
></TD
></TR
></TABLE
><P
>You can avoid retyping this command in every window you open by adding it to one of your shell setup files, see <A
HREF="#sect_07_02_04"
>Section 7.2.2</A
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_03"
></A
>7.2.1.3. Reserved variables</H3
><P
>The following table gives an overview of the most common predefined variables:</P
><DIV
CLASS="table"
><A
NAME="AEN7272"
></A
><P
><B
>Table 7-1. Common environment variables</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Variable name</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Stored information</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>DISPLAY</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>used by the X Window system to identify the display server</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>DOMAIN</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>domain name</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>EDITOR</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>stores your favorite line editor</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>HISTSIZE</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>size of the shell history file in number of lines</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>HOME</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>path to your home directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>HOSTNAME</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>local host name</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>INPUTRC</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>location of definition file for input devices such as keyboard</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>LANG</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>preferred language</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>LD_LIBRARY_PATH</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>paths to search for libraries</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>LOGNAME</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>login name</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>MAIL</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>location of your incoming mail folder</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>MANPATH</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>paths to search for man pages</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>OS</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>string describing the operating system</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>OSTYPE</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>more information about version etc.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>PAGER</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>used by programs like <B
CLASS="command"
>man</B
> which need to know what to do in case output is more than one terminal window.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>PATH</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>search paths for commands</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>PS1</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>primary prompt</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>PS2</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>secondary prompt</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>PWD</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>present working directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>SHELL</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>current shell</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>TERM</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>terminal type</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>UID</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>user ID</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>USER(NAME)</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>user name</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>VISUAL</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>your favorite full-screen editor</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>XENVIRONMENT</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>location of your personal settings for X behavior</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="varname"
>XFILESEARCHPATH</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>paths to search for graphical libraries</TD
></TR
></TBODY
></TABLE
></DIV
><P
>A lot of variables are not only predefined but also preset, using configuration files. We discuss these in the next section.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_02_04"
></A
>7.2.2. Shell setup files</H2
><P
>When entering the <B
CLASS="command"
>ls <TT
CLASS="option"
>-al</TT
></B
> 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 <EM
>rc</EM
>. For the case of <B
CLASS="command"
>bash</B
>, this is <TT
CLASS="filename"
>.bashrc</TT
>. This is the counterpart of the system-wide configuration file <TT
CLASS="filename"
>/etc/bashrc</TT
>.</P
><P
>When logging into an interactive login shell, <B
CLASS="command"
>login</B
> will do the authentication, set the environment and start your shell. In the case of <B
CLASS="command"
>bash</B
>, the next step is reading the general <TT
CLASS="filename"
>profile</TT
> from <TT
CLASS="filename"
>/etc</TT
>, if that file exists. <B
CLASS="command"
>bash</B
> then looks for <TT
CLASS="filename"
>~/.bash_profile</TT
>, <TT
CLASS="filename"
>~/.bash_login</TT
> and <TT
CLASS="filename"
>~/.profile</TT
>, in that order, and reads and executes commands from the first one that exists and is readable. If none exists, <TT
CLASS="filename"
>/etc/bashrc</TT
> is applied.</P
><P
>When a login shell exits, <B
CLASS="command"
>bash</B
> reads and executes commands from the file <TT
CLASS="filename"
>~/.bash_logout</TT
>, if it exists.
</P
><P
>This procedure is explained in detail in the <B
CLASS="command"
>login</B
> and <B
CLASS="command"
>bash</B
> man pages.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_02_05"
></A
>7.2.3. A typical set of setup files</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_02_05_01"
></A
>7.2.3.1. /etc/profile example</H3
><P
>Let's look at some of these config files. First <TT
CLASS="filename"
>/etc/profile</TT
> is read, in which important variables such as <TT
CLASS="varname"
>PATH</TT
>, <TT
CLASS="varname"
>USER</TT
> and <TT
CLASS="varname"
>HOSTNAME</TT
> are set:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>cat /etc/profile</B
>
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# Path manipulation
if [ `id -u` = 0 ] &#38;&#38; ! echo $PATH | /bin/grep -q "/sbin" ; then
PATH=/sbin:$PATH
fi
if [ `id -u` = 0 ] &#38;&#38; ! echo $PATH | /bin/grep -q "/usr/sbin" ; then
PATH=/usr/sbin:$PATH
fi
if [ `id -u` = 0 ] &#38;&#38; ! 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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>These lines check the path to set: if <EM
>root</EM
> opens a shell (user ID 0), it is checked that <TT
CLASS="filename"
>/sbin</TT
>, <TT
CLASS="filename"
>/usr/sbin</TT
> and <TT
CLASS="filename"
>/usr/local/sbin</TT
> are in the path. If not, they are added. It is checked for everyone that <TT
CLASS="filename"
>/usr/X11R6/bin</TT
> is in the path.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;# No core files by default
ulimit -S -c 0 &#62; /dev/null 2&#62;&#38;1
</PRE
></FONT
></TD
></TR
></TABLE
><P
>All trash goes to <TT
CLASS="filename"
>/dev/null</TT
> if the user doesn't change this setting.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Here general variables are assigned their proper values.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If the variable <TT
CLASS="varname"
>INPUTRC</TT
> is not set, and there is no <TT
CLASS="filename"
>.inputrc</TT
> in the user's home directory, then the default input control file is loaded. </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
</PRE
></FONT
></TD
></TR
></TABLE
><P
>All variables are exported, so that they are available to other programs requesting information about your environment.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_05_02"
></A
>7.2.3.2. The profile.d directory</H3
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;for i in /etc/profile.d/*.sh ; do
if [ -r $i ]; then
. $i
fi
done
unset i
</PRE
></FONT
></TD
></TR
></TABLE
><P
>All readable shell scripts from the <TT
CLASS="filename"
>/etc/profile.d</TT
> directory are read and executed. These do things like enabling <EM
>color-ls</EM
>, aliasing <B
CLASS="command"
>vi</B
> to <B
CLASS="command"
>vim</B
>, setting locales etc. The temporary variable <TT
CLASS="varname"
>i</TT
> is unset to prevent it from disturbing shell behavior later on.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_05_03"
></A
>7.2.3.3. .bash_profile example</H3
><P
>Then <B
CLASS="command"
>bash</B
> looks for a <TT
CLASS="filename"
>.bash_profile</TT
> in the user's home directory:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>cat .bash_profile </B
>
#################################################################
# #
# .bash_profile file #
# #
# Executed from the bash shell when you log in. #
# #
#################################################################
source ~/.bashrc
source ~/.bash_login
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This very straight forward file instructs your shell to first read <TT
CLASS="filename"
>~/.bashrc</TT
> and then <TT
CLASS="filename"
>~/.bash_login</TT
>. You will encounter the <B
CLASS="command"
>source</B
> built-in shell command regularly when working in a shell environment: it is used to apply configuration changes to the current environment.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_05_04"
></A
>7.2.3.4. .bash_login example</H3
><P
>The <TT
CLASS="filename"
>~/.bash_login</TT
> file defines default file protection by setting the <B
CLASS="command"
>umask</B
> value, see <A
HREF="#sect_03_04_02_02"
>Section 3.4.2.2</A
>. The <TT
CLASS="filename"
>~/.bashrc</TT
> file is used to define a bunch of user-specific aliases and functions and personal environment variables. It first reads <TT
CLASS="filename"
>/etc/bashrc</TT
>, which describes the default prompt (<TT
CLASS="varname"
>PS1</TT
>) and the default umask value. After that, you can add your own settings. If no <TT
CLASS="filename"
>~/.bashrc</TT
> exists, <TT
CLASS="filename"
>/etc/bashrc</TT
> is read by default.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_05_05"
></A
>7.2.3.5. /etc/bashrc example</H3
><P
>Your <TT
CLASS="filename"
>/etc/bashrc</TT
> file might look like this:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>cat /etc/bashrc</B
>
# /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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>These lines set the <B
CLASS="command"
>umask</B
> value. Then, depending on the type of shell, the prompt is set:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;# 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 ] &#38;&#38; PROMPT_COMMAND=\
/etc/sysconfig/bash-prompt-default
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] &#38;&#38; 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
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_05_06"
></A
>7.2.3.6. .bash_logout example</H3
><P
>Upon logout, the commands in <TT
CLASS="filename"
>~/.bash_logout</TT
> are executed, which can for instance clear the terminal, so that you have a clean window upon logging out of a remote session, or upon leaving the system console:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>cat .bash_logout</B
>
# ~/.bash_logout
clear
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Let's take a closer look at how these scripts work in the next section. Keep <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>bash</I
></TT
></B
> close at hand.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_02_06"
></A
>7.2.4. The Bash prompt</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_02_06_01"
></A
>7.2.4.1. Introduction</H3
><P
>&#13;The <SPAN
CLASS="application"
>Bash</SPAN
> 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.</P
><P
>Before we begin, however, we will save our current prompt in another environment variable:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[jerry@nowhere jerry]$</TT
> <B
CLASS="command"
>MYPROMPT=$PS1</B
>
<TT
CLASS="prompt"
>[jerry@nowhere jerry]$</TT
> <B
CLASS="command"
>echo $MYPROMPT</B
>
[\u@\h \W]\$
<TT
CLASS="prompt"
>[jerry@nowhere jerry]$</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>When we change the prompt now, for example by issuing the command <B
CLASS="command"
><TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"-&#62;"</I
></TT
></B
>, we can always get our original prompt back with the command <B
CLASS="command"
><TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="varname"
>$MYPROMPT</TT
></B
>. 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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_06_02"
></A
>7.2.4.2. Some examples</H3
><P
>In order to understand these prompts and the escape sequences used, we refer to the <SPAN
CLASS="application"
>Bash Info</SPAN
> or man pages.</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"[\t \j] "</I
></TT
></B
></P
><P
>Displays time of day and number of running jobs</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"[\d][\u@\h \w] : "</I
></TT
></B
></P
><P
>Displays date, user name, host name and current working directory. Note that \W displays only base names of the present working directory.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"{\!} "</I
></TT
></B
></P
><P
>Displays history number for each command.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"\[\033[1;35m\]\u@\h\[\033[0m\] "</I
></TT
></B
></P
><P
>Displays user@host in pink.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] "</I
></TT
></B
></P
><P
>Sets the user name in pink and the present working directory in blue.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"\[\033[1;44m\]$USER is in \w\[\033[0m\] "</I
></TT
></B
></P
><P
>Prompt for people who have difficulties seeing the difference between the prompt and what they type.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"\[\033[4;34m\]\u@\h \w \[\033[0m\]"</I
></TT
></B
></P
><P
>Underlined prompt.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"\[\033[7;34m\]\u@\h \w \[\033[0m\] "</I
></TT
></B
></P
><P
>White characters on a blue background.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=<TT
CLASS="replaceable"
><I
>"\[\033[3;35m\]\u@\h \w \[\033[0m\]\a"</I
></TT
></B
></P
><P
>Pink prompt in a lighter font that alerts you when your commands have finished.</P
></LI
><LI
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>PS1</TT
>=...</B
></P
></LI
></UL
><P
>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, <TT
CLASS="filename"
>~/.bashrc</TT
>.</P
><P
>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 gets boring pretty soon. More information can be found in the <A
HREF="http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/"
TARGET="_top"
>Bash-Prompt HOWTO</A
>.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_02_07"
></A
>7.2.5. Shell scripts</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_02_07_01"
></A
>7.2.5.1. What are scripts?</H3
><P
>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 <SPAN
CLASS="application"
>Bash</SPAN
>, and neither the <TT
CLASS="option"
>-c</TT
> nor <TT
CLASS="option"
>-s</TT
> option is supplied, <SPAN
CLASS="application"
>Bash</SPAN
> reads and executes commands from the file, then exits. This mode of operation creates a non-interactive shell. When <SPAN
CLASS="application"
>Bash</SPAN
> runs a shell script, it sets the special parameter <TT
CLASS="varname"
>0</TT
> to the name of the file, rather than the name of the shell, and the positional parameters (everything following the name of the script) are set to the remaining arguments, if any are given. If no additional arguments are supplied, the positional parameters are unset.</P
><P
>A shell script may be made executable by using the <B
CLASS="command"
>chmod</B
> command to turn on the execute bit. When <SPAN
CLASS="application"
>Bash</SPAN
> finds such a file while searching the <TT
CLASS="varname"
>PATH</TT
> for a command, it spawns a sub-shell to execute it. In other words, executing</P
><P
><B
CLASS="command"
>filename <TT
CLASS="parameter"
><I
>ARGUMENTS</I
></TT
></B
> </P
><P
>is equivalent to executing</P
><P
><B
CLASS="command"
>bash <TT
CLASS="parameter"
><I
>filename</I
></TT
> <TT
CLASS="parameter"
><I
>ARGUMENTS</I
></TT
></B
> </P
><P
>if <SPAN
CLASS="QUOTE"
>"filename"</SPAN
> 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 <B
CLASS="command"
>hash</B
> in the <SPAN
CLASS="application"
>Info</SPAN
> pages) are retained by the child.</P
><P
>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 <SPAN
CLASS="QUOTE"
>"#!"</SPAN
>, the remainder of the line specifies an interpreter for the program. Thus, you can specify <B
CLASS="command"
>bash</B
>, <B
CLASS="command"
>awk</B
>, <B
CLASS="command"
>perl</B
> or some other interpreter or shell and write the rest of the script file in that language.</P
><P
>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. <SPAN
CLASS="application"
>Bash</SPAN
> will perform this action on operating systems that do not handle it themselves.</P
><P
><SPAN
CLASS="application"
>Bash</SPAN
> scripts often begin with</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;#! /bin/bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
>(assuming that <SPAN
CLASS="application"
>Bash</SPAN
> has been installed in <TT
CLASS="filename"
>/bin</TT
>), since this ensures that <SPAN
CLASS="application"
>Bash</SPAN
> will be used to interpret the script, even if it is executed under another shell.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_02_07_02"
></A
>7.2.5.2. Some simple examples</H3
><P
>A very simple script consisting of only one command, that says hello to the user executing it:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[jerry@nowhere ~]</TT
> <B
CLASS="command"
>cat hello.sh</B
>
#!/bin/bash
echo "Hello $USER"
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The script actually consists of only one command, <B
CLASS="command"
>echo</B
>, which uses the <EM
>value of</EM
> ($) the <TT
CLASS="varname"
>USER</TT
> environment variable to print a string customized to the user issuing the command.</P
><P
>Another one-liner, used for displaying connected users:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;#!/bin/bash
who | cut -d " " -f 1 | sort -u
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Here is a script consisting of some more lines, that I use to make backup copies of all files in a directory.
The script first makes a list of all the files in the current directory and puts it in the variable <TT
CLASS="varname"
>LIST</TT
>. Then it sets the name of the copy for each file, and then it copies the file. For each file, a message is printed:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>tille:~&#62;</TT
> <B
CLASS="command"
>cat <TT
CLASS="filename"
>bin/makebackupfiles.sh</TT
></B
>
#!/bin/bash
# make copies of all files in a directory
LIST=`ls`
for i in $LIST; do
ORIG=$i
DEST=$i.old
cp $ORIG $DEST
echo "copied $i"
done
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Just entering a line like <B
CLASS="command"
>mv <TT
CLASS="parameter"
><I
>*</I
></TT
> <TT
CLASS="parameter"
><I
>*.old</I
></TT
></B
> won't work, as you will notice when trying this on a set of test files. An <B
CLASS="command"
>echo</B
> command was added in order to display some activity. <B
CLASS="command"
>echo</B
>'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.</P
><P
>The <TT
CLASS="filename"
>/etc/rc.d/init.d</TT
> directory contains loads of examples. Let's look at this script that controls the fictive ICanSeeYou server:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;#!/bin/sh
# description: ICanSeeYou allows you to see networked people
# process name: ICanSeeYou
# pidfile: /var/run/ICanSeeYou/ICanSeeYou.pid
# config: /etc/ICanSeeYou.cfg
# Source function library.
. /etc/rc.d/init.d/functions
# See how (with which arguments) we were called.
case "$1" in
start)
echo -n "Starting ICanSeeYou: "
daemon ICanSeeYou
echo
touch /var/lock/subsys/ICanSeeYou
;;
stop)
echo -n "Shutting down ICanSeeYou: "
killproc ICanSeeYou
echo
rm -f /var/lock/subsys/ICanSeeYou
rm -f /var/run/ICanSeeYou/ICanSeeYou.pid
;;
status)
status ICanSeeYou
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
</PRE
></FONT
></TD
></TR
></TABLE
><P
>First, with the <B
CLASS="command"
>.</B
> command (dot) a set of shell functions, used by almost all shell scripts in <TT
CLASS="filename"
>/etc/rc.d/init.d</TT
>, is loaded. Then a <B
CLASS="command"
>case</B
> command is issued, which defines 4 different ways the script can execute. An example might be <B
CLASS="command"
>ICanSeeYou <TT
CLASS="parameter"
><I
>start</I
></TT
></B
>. The decision of which case to apply is made by reading the (first) argument to the script, with the expression <EM
>$1</EM
>.</P
><P
>When no compliant input is given, the default case, marked with an asterisk, is applied, upon which the script gives an error message. The <B
CLASS="command"
>case</B
> list is ended with the <B
CLASS="command"
>esac</B
> statement. In the <EM
>start</EM
> case the server program is started as a daemon, and a process ID and lock are assigned. In the <EM
>stop</EM
> case, the server process is traced down and stopped, and the lock and the PID are removed. Options, such as the <TT
CLASS="option"
>daemon</TT
> option, and functions like <TT
CLASS="option"
>killproc</TT
>, are defined in the <TT
CLASS="filename"
>/etc/rc.d/init.d/functions</TT
> file. This setup is specific to the distribution used in this example. The initscripts on your system might use other functions, defined in other files, or none at all.</P
><P
>Upon success, the script returns an exit code of zero to its parent.</P
><P
>&#13;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 <B
CLASS="command"
>sh</B
> instead of <B
CLASS="command"
>bash</B
>, to make them useful on a wider range of systems. On a Linux system, calling <B
CLASS="command"
>bash</B
> as <B
CLASS="command"
>sh</B
> results in the shell running in POSIX-compliant mode.</P
><P
>The <B
CLASS="command"
>bash</B
> man pages contain more information about combining commands, <B
CLASS="command"
>for</B
>- and <B
CLASS="command"
>while</B
>-loops and regular expressions, as well as examples. A comprehensible <SPAN
CLASS="application"
>Bash</SPAN
> course for system administrators and power users, with exercises, from the same author as this Introduction to Linux guide, is at <A
HREF="http://tille.garrels.be/training/bash/"
TARGET="_top"
>http://tille.garrels.be/training/bash/</A
>. Detailed description of <SPAN
CLASS="application"
>Bash</SPAN
> features and applications is in the reference guide <A
HREF="http://tldp.org/LDP/abs/html/index.html"
TARGET="_top"
>Advanced Bash Scripting</A
>.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_03"
></A
>7.3. The graphical environment</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_07_03_01"
></A
>7.3.1. Introduction</H2
><P
>The average user may not care too much about his login settings, but Linux offers a wide variety of flashy window and desktop managers for use under X, the graphical environment. The use and configuration of window managers and desktops is straightforward and may even resemble the standard MS Windows, Apple or UNIX CDE environment, although many Linux users prefer flashier desktops and fancier 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.</P
><P
>We will, however, take a closer look at the underlying system.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_03_02"
></A
>7.3.2. The X Window System</H2
><P
>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 X 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 <A
HREF="#chap_10"
>Chapter 10</A
> on networking and remote applications.</P
><P
>X supports overlapping hierarchical sub-windows and text and graphics operations, on both monochrome and color displays. The number of X client programs that use the X server is quite large. Some of the programs provided in the core X Consortium distribution include:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>xterm</B
>: a terminal emulator</P
></LI
><LI
><P
><B
CLASS="command"
>twm</B
>: a minimalistic window manager</P
></LI
><LI
><P
><B
CLASS="command"
>xdm</B
>: a display manager</P
></LI
><LI
><P
><B
CLASS="command"
>xconsole</B
>: a console redirect program</P
></LI
><LI
><P
><B
CLASS="command"
>bitmap</B
>: a bitmap editor</P
></LI
><LI
><P
><B
CLASS="command"
>xauth</B
>, <B
CLASS="command"
>xhost</B
> and <B
CLASS="command"
>iceauth</B
>: access control programs</P
></LI
><LI
><P
><B
CLASS="command"
>xset</B
>, <B
CLASS="command"
>xmodmap</B
> and many others: user preference setting programs</P
></LI
><LI
><P
><B
CLASS="command"
>xclock</B
>: a clock</P
></LI
><LI
><P
><B
CLASS="command"
>xlsfonts</B
> and others: a font displayer, utilities for listing information about fonts, windows and displays</P
></LI
><LI
><P
><B
CLASS="command"
>xfs</B
>: a font server</P
></LI
><LI
><P
>...</P
></LI
></UL
><P
>We refer again to the man pages of these commands for detailed information. More explanations on available functions can be found in the <EM
>Xlib - C language X Interface</EM
> manual that comes with your X distribution, the <EM
>X Window System Protocol</EM
> specification, and the various manuals and documentation of X toolkits. The <TT
CLASS="filename"
>/usr/share/doc</TT
> directory contains references to these documents and many others.</P
><P
>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 <A
HREF="http://www.x.org"
TARGET="_top"
>http://www.x.org</A
> and <A
HREF="http://www.xfree.org"
TARGET="_top"
>http://www.xfree.org</A
>.</P
><P
>Furthermore, all your graphical applications, such as your browser, your E-mail program, your image viewing programs, sound playing tools and so on, are all clients to your X server. Note that in normal operation, that is in graphical mode, X clients and the X server on Linux run on the same machine.</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_03_02_01"
></A
>7.3.2.1. Display names</H3
><P
>From the user's perspective, every X server has a <EM
>display name</EM
> in the form of:</P
><P
><B
CLASS="command"
><TT
CLASS="parameter"
><I
>hostname</I
></TT
>:<TT
CLASS="parameter"
><I
>displaynumber</I
></TT
>.<TT
CLASS="parameter"
><I
>screennumber</I
></TT
></B
> </P
><P
>This information is used by the application to determine how it should connect to the X server and which screen it should use by default (on displays with multiple monitors):</P
><P
></P
><UL
><LI
><P
><EM
>hostname</EM
>: The host name specifies the name of the client 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.</P
></LI
><LI
><P
><EM
>displaynumber</EM
>: The phrase <SPAN
CLASS="QUOTE"
>"display"</SPAN
> 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 <EM
>display number</EM
> (beginning at 0) when the X server for that display is started. The display number must always be given in a display name.</P
></LI
><LI
><P
><EM
>screen number</EM
>: 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 <EM
>screen number</EM
> (beginning at 0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.</P
></LI
></UL
><P
>On POSIX systems, the default display name is stored in your <TT
CLASS="varname"
>DISPLAY</TT
> environment variable. This variable is set automatically by the <B
CLASS="command"
>xterm</B
> terminal emulator. However, when you log into another machine on a network, you might need to set <TT
CLASS="varname"
>DISPLAY</TT
> by hand to point to your display, see <A
HREF="#sect_10_05_03_02"
>Section 10.4.3.2</A
>.</P
><P
>More information can be found in the X man pages.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_03_02_02"
></A
>7.3.2.2. Window and desktop managers</H3
><P
>The layout of windows on the screen is controlled by special programs called <EM
>window managers</EM
>. 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).</P
><P
>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 <B
CLASS="command"
>twm</B
>, but most users prefer something more fancy when system resources permit. Sawfish and Enlightenment are popular examples which allow each user to have a desktop according to mood and style.</P
><P
>A desktop manager makes use of one window manager or another for arranging your graphical desktop in a convenient way, with menubars, drop-down menus, informative messages, a clock, a program manager, a file manager and so on. Among the most popular desktop managers are <SPAN
CLASS="application"
>Gnome</SPAN
> and <SPAN
CLASS="application"
>KDE</SPAN
>, which both run on almost any Linux distribution and many other UNIX systems.</P
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>KDE applications in Gnome/Gnome applications in KDE</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>You don't need to start your desktop in <SPAN
CLASS="application"
>KDE</SPAN
> in order to be able to run <SPAN
CLASS="application"
>KDE</SPAN
> applications. If you have the <SPAN
CLASS="application"
>KDE</SPAN
> libraries installed (the <SPAN
CLASS="application"
>kdelibs</SPAN
> package), you can run these applications from the <SPAN
CLASS="application"
>Gnome</SPAN
> menus or start them from a <SPAN
CLASS="application"
>Gnome</SPAN
> terminal.</P
><P
>Running <SPAN
CLASS="application"
>Gnome</SPAN
> applications in a <SPAN
CLASS="application"
>KDE</SPAN
> environment is a bit more tricky, because there is no single set of base-libraries in <SPAN
CLASS="application"
>Gnome</SPAN
>. However, the dependencies and thus extra packages you might have to install will become clear when running or installing such an application.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_03_03"
></A
>7.3.3. X server configuration</H2
><P
>The X distribution that used to come with Linux, <EM
>XFree86</EM
>, uses the configuration file <TT
CLASS="filename"
>XF86Config</TT
> for its initial setup. This file configures your video card and is searched for in a number of locations, although it is usually in <TT
CLASS="filename"
>/etc/X11</TT
>.</P
><P
>If you see that the file <TT
CLASS="filename"
>/etc/X11/XF86Config</TT
> is present on your system, a full description can be found in the <SPAN
CLASS="application"
>Info</SPAN
> or man pages about <TT
CLASS="filename"
>XF86Config</TT
>.</P
><P
>Because of licensing issues with XFree86, newer systems usually come with the <EM
>X.Org</EM
> distribution of the X server and tools. The main configuration file here is <TT
CLASS="filename"
>xorg.conf</TT
>, usually also in <TT
CLASS="filename"
>/etc/X11</TT
>. The file consists of a number of sections that may occur in any order. The sections contain information about your monitor, your video adaptor, the screen configuration, your keyboard etcetera. 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.</P
><P
>Should you need to change graphical server settings, however, you can run the configuration tools or edit the configuration files that set up the infrastructure to use the XFree86 server. See the man pages for more information; your distribution might have its own tools. Since misconfiguration may result in unreadable garbage in graphical mode, you may want to make a backup copy of the configuration file before attempting to change it, just to be on the safe side.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_05"
></A
>7.4. Region specific settings</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_07_05_01"
></A
>7.4.1. Keyboard setup</H2
><P
>Setting the keyboard layout is done using the <B
CLASS="command"
>loadkeys</B
> command for text consoles. Use your local X configuration tool or edit the <EM
>Keyboard</EM
> section in <TT
CLASS="filename"
>XF86Config</TT
> manually to configure the layout for graphical mode. The <TT
CLASS="varname"
>XkbdLayout</TT
> is the one you want to set:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13; XkbLayout "us"
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This is the default. Change it to your local settings by replacing the quoted value with any of the names listed in the subdirectories of your <TT
CLASS="filename"
>keymaps</TT
> directory. If you can't find the keymaps, try displaying their location on your system issuing the command</P
><P
><B
CLASS="command"
>locate <TT
CLASS="filename"
>keymaps</TT
></B
> </P
><P
>It is possible to combine layout settings, like in this example:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;Xkblayout "us,ru"
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Make a backup of the <TT
CLASS="filename"
>/etc/X11/XF86Config</TT
> file before editing it! You will need to use the <EM
>root</EM
> account to do this.</P
><P
>Log out and reconnect in order to reload X settings.</P
><P
>The <SPAN
CLASS="application"
>Gnome Keyboard Applet</SPAN
> enables real-time switching between layouts; no special pemissions are needed for using this program. <SPAN
CLASS="application"
>KDE</SPAN
> has a similar tool for switching between keyboard layouts.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_05_02"
></A
>7.4.2. Fonts</H2
><P
>Use the <B
CLASS="command"
>setfont</B
> tool to load fonts in text mode. Most systems come with a standard <TT
CLASS="filename"
>inputrc</TT
> file which enables combining of characters, such as the French <SPAN
CLASS="QUOTE"
>"<22>"</SPAN
> (meta characters). The system admin should then add the line</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;export INPUTRC="/etc/inputrc"
</PRE
></FONT
></TD
></TR
></TABLE
><P
>to the <TT
CLASS="filename"
>/etc/bashrc</TT
> file.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_05_03"
></A
>7.4.3. Date and time zone</H2
><P
>Setting time information is usually done at installation time. After that, it can be kept up to date using an <EM
>NTP</EM
> (Network Time Protocol) client. Most Linux systems run <B
CLASS="command"
>ntpd</B
> by default:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>ps -ef | grep ntpd</B
>
ntp 24678 1 0 2002 ? 00:00:33 ntpd -U ntp
</PRE
></FONT
></TD
></TR
></TABLE
><P
>You can run <B
CLASS="command"
>ntpdate</B
> manually to set the time, on condition that you can reach a time server. The <B
CLASS="command"
>ntpd</B
> daemon should not be running when you adjust the time using <B
CLASS="command"
>ntpdate</B
>. Use a time server as argument to the command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>root@box:~# </TT
><B
CLASS="command"
>ntpdate <TT
CLASS="parameter"
><I
>10.2.5.200</I
></TT
></B
>
26 Oct 14:35:42 ntpdate[20364]: adjust time server 10.2.5.200 offset
-0.008049 sec
</PRE
></FONT
></TD
></TR
></TABLE
><P
>See your system manual and the documentation that comes with the NTP package. Most desktop managers include tools to set the system time, providing that you have access to the system administrator's account.</P
><P
>For setting the time zone correct, you can use <B
CLASS="command"
>tzconfig</B
> or <B
CLASS="command"
>timezone</B
> commands. Timezone information is usually set during the installation of your machine. Many systems have distribution-specific tools to configure it, see your system documentation.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_05_04"
></A
>7.4.4. Language</H2
><P
>If you'd rather get your messages from the system in Dutch or French, you may want to set the <TT
CLASS="varname"
>LANG</TT
> and <TT
CLASS="varname"
>LANGUAGE</TT
> environment variables, thus enabling locale support for the desired language and eventually the fonts related to character conventions in that language.</P
><P
>With most graphical login systems, such as <B
CLASS="command"
>gdm</B
> or <B
CLASS="command"
>kdm</B
>, you have the possibility to configure these language settings before logging in.</P
><P
>Note that on most systems, the default tends to be <EM
>en_US.UTF-8</EM
> these days. This is not a problem, because systems where this is the default, will also come with all the programs supporting this encoding. Thus, <B
CLASS="command"
>vi</B
> can edit all the files on your system, <B
CLASS="command"
>cat</B
> won't behave strange and so on.</P
><P
>Trouble starts when you connect to an older system not supporting this font encoding, or when you open a <EM
>UTF-8</EM
> encoded file on a system supporting only 1-byte character fonts. The <B
CLASS="command"
>recode</B
> utility might come in handy to convert files from one character set to another. Read the man pages for an overview of features and usage. Another solution might be to temporarily work with another encoding definition, by setting the <TT
CLASS="varname"
>LANG</TT
> environment variable:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>acroread /var/tmp/51434s.pdf</B
>
Warning: charset "UTF-8" not supported, using "ISO8859-1".
Aborted
<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>set | grep UTF</B
>
LANG=en_US.UTF-8
<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>export LANG=en_US</B
>
<TT
CLASS="prompt"
>debby:~&#62;</TT
> <B
CLASS="command"
>acroread /var/tmp/51434s.pdf</B
>
&#60;--new window opens--&#62;
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Refer to the <A
HREF="http://www.mozilla.org/"
TARGET="_top"
>Mozilla</A
> web site for guidance on how to get <SPAN
CLASS="application"
>Firefox</SPAN
> in your language. The <A
HREF="http://www.openoffice.org/"
TARGET="_top"
>OpenOffice.org</A
> web site has information on localization of your <SPAN
CLASS="application"
>OpenOffice.org</SPAN
> suite.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_05_06"
></A
>7.4.5. Country-specific Information</H2
><P
>The <A
HREF="http://www.tldp.org/HOWTO/HOWTO-INDEX/howtos.html"
TARGET="_top"
>list of HOWTOs</A
> contains references to Bangla, Belarusian, Chinese, Esperanto, Finnish, Francophone, Hebrew, Hellenic, Latvian, Polish, Portugese, Serbian, Slovak, Slovenian, Spanish, Thai and Turkish localization instructions.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_06"
></A
>7.5. Installing new software</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_07_06_01"
></A
>7.5.1. General</H2
><P
>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 and other network client programs are included in the main distributions. Even so, an initial installation might not meet your requirements.</P
><P
>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.</P
><P
>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 contains instructions about how to install it on your type of Linux, see <A
HREF="#app1"
>Appendix A</A
>. Always read the documentation that comes with new software, and any installation guidelines the package might contain. All software comes with a <TT
CLASS="filename"
>README</TT
> file, which you are very strongly advised to read.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_06_02"
></A
>7.5.2. Package formats</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_06_02_01"
></A
>7.5.2.1. RPM packages</H3
><DIV
CLASS="sect4"
><H4
CLASS="sect4"
><A
NAME="sect_07_06_02_01_01"
></A
>7.5.2.1.1. What is RPM?</H4
><P
>RPM, the <SPAN
CLASS="application"
>RedHat Package Manager</SPAN
>, 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.</P
><P
>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.</P
><P
>Many other distributions support RPM packages, among the popular ones RedHat Enterprise Linux, Mandriva (former Mandrake), Fedora Core and SuSE Linux. Apart from the advice for your distribution, you will want to read <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>rpm</I
></TT
></B
>.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="sect_07_06_02_01_02"
></A
>7.5.2.1.2. RPM examples</H4
><P
>Most packages are simply installed with the upgrade option, <TT
CLASS="option"
>-U</TT
>, 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. The typical usage is as follows:</P
><P
><B
CLASS="command"
>rpm <TT
CLASS="option"
>-Uvh</TT
> <TT
CLASS="filename"
>/path/to/rpm-package(s)</TT
></B
> </P
><P
>The <TT
CLASS="option"
>-v</TT
> option generates more verbose output, and <TT
CLASS="option"
>-h</TT
> makes <B
CLASS="command"
>rpm</B
> print a progress bar:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[root@jupiter tmp]#</TT
> <B
CLASS="command"
>rpm -Uvh totem-0.99.5-1.fr.i386.rpm</B
>
Preparing... ########################################### [100%]
1:totem ########################################### [100%]
<TT
CLASS="prompt"
>[root@jupiter tmp]#</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>New kernel packages, however, are installed with the install option <TT
CLASS="option"
>-i</TT
>, which does not overwrite existing version(s) of the package. That way, you will still be able to boot your system with the old kernel if the new one does not work.</P
><P
>You can also use <B
CLASS="command"
>rpm</B
> to check whether a package is installed on your system:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>rpm -qa | grep vim</B
>
vim-minimal-6.1-29
vim-X11-6.1-29
vim-enhanced-6.1-29
vim-common-6.1-29
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Or you can find out which package contains a certain file or executable:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>rpm -qf /etc/profile</B
>
setup-2.5.25-1
<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>which cat</B
>
cat is /bin/cat
<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>rpm -qf /bin/cat</B
>
coreutils-4.5.3-19
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Note that you need not have access to administrative privileges in order to use <B
CLASS="command"
>rpm</B
> to query the RPM database. You only need to be <EM
>root</EM
> when adding, modifying or deleting packages.</P
><P
>Below is one last example, demonstrating how to uninstall a package using <B
CLASS="command"
>rpm</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[root@jupiter root]#</TT
> <B
CLASS="command"
>rpm -e totem</B
>
<TT
CLASS="prompt"
>[root@jupiter root]#</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Note that uninstalling is not that verbose by default, it is normal that you don't see much happening. When in doubt, use <B
CLASS="command"
>rpm <TT
CLASS="option"
>-qa</TT
></B
> again to verify that the package has been removed.</P
><P
>RPM can do much more than the couple of basic functions we discussed in this introduction; the <A
HREF="http://www.tldp.org/HOWTO/RPM-HOWTO/index.html"
TARGET="_top"
>RPM HOWTO</A
> contains further references.</P
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_06_02_02"
></A
>7.5.2.2. DEB (.deb) packages</H3
><DIV
CLASS="sect4"
><H4
CLASS="sect4"
><A
NAME="sect_07_06_02_02_01"
></A
>7.5.2.2.1. What are Debian packages?</H4
><P
>This package format is the default on Debian GNU/Linux, where <B
CLASS="command"
>dselect</B
>, and, nowadays more common, <B
CLASS="command"
>aptitude</B
>, 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.</P
><P
>The <A
HREF="http://debian.org"
TARGET="_top"
>Debian web site</A
> contains all information you need, including a <SPAN
CLASS="QUOTE"
>"dselect Documentation for Beginners"</SPAN
>.</P
><P
>According to the latest news, the Debian package format is becoming more and more popular. At the time of this writing, 5 of the top-10 distributions use it. Also <B
CLASS="command"
>apt-get</B
> (see <A
HREF="#sect_07_06_03_02"
>Section 7.5.3.2</A
> is becoming extremely popular, also on non-DEB systems.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="sect_07_06_02_02_02"
></A
>7.5.2.2.2. Examples with DEB tools</H4
><P
>Checking whether a package is installed is done using the <B
CLASS="command"
>dpkg</B
> command. For instance, if you want to know which version of the <SPAN
CLASS="application"
>Gallery</SPAN
> software is installed on your machine:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>nghtwsh@gorefest:~$ </TT
><B
CLASS="command"
>dpkg <TT
CLASS="option"
>-l</TT
> <TT
CLASS="parameter"
><I
>*gallery*</I
></TT
></B
>
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name Version Description
+++-==============-==============-============================================
ii gallery 1.5-1sarge2 a web-based photo album written in php
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <SPAN
CLASS="QUOTE"
>"ii"</SPAN
> prefix means the package is installed. Should you see <SPAN
CLASS="QUOTE"
>"un"</SPAN
> as a prefix, that means that the package is known in the list that your computer keeps, but that it is not installed.</P
><P
>Searching which package a file belongs to is done using the <TT
CLASS="option"
>-S</TT
> to <B
CLASS="command"
>dpkg</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>nghtwsh@gorefest:~$ </TT
><B
CLASS="command"
>dpkg <TT
CLASS="option"
>-S</TT
> <TT
CLASS="parameter"
><I
>/bin/cat</I
></TT
></B
>
coreutils: /bin/cat
</PRE
></FONT
></TD
></TR
></TABLE
><P
>More information can be found in the <SPAN
CLASS="application"
>Info</SPAN
> pages for <B
CLASS="command"
>dpkg</B
>.</P
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_06_02_03"
></A
>7.5.2.3. Source packages</H3
><P
>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 for a program can be downloaded from its web site, often as a compressed tarball (<TT
CLASS="filename"
>program-version.tar.gz</TT
> or similar). For RPM-based distributions, the source is often provided in the <TT
CLASS="filename"
>program-version.src.rpm</TT
>. Debian, and most distributions based on it, provide themselves the adapted source which can be obtained using <B
CLASS="command"
>apt-get <TT
CLASS="parameter"
><I
>source</I
></TT
></B
>.</P
><P
>Specific requirements, dependencies and installation instructions are provided in the <TT
CLASS="filename"
>README</TT
> file. You will probably need a C compiler, <B
CLASS="command"
>gcc</B
>. This GNU C compiler is included in most Linux systems and is ported to many other platforms.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_06_03"
></A
>7.5.3. Automating package management and updates</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_06_03_01"
></A
>7.5.3.1. General remarks</H3
><P
>The first thing you do after installing a new system is applying updates;
this applies to all operating systems and Linux is not different.</P
><P
>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 <A
HREF="#app1"
>Appendix A</A
>.</P
><P
>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 version of your distribution, 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.</P
><P
>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 <EM
>package manager managers.</EM
> 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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_06_03_02"
></A
>7.5.3.2. APT</H3
><P
>The <SPAN
CLASS="application"
>Advanced Package Tool</SPAN
> is a management system for software packages. The command line tool for handling packages is <B
CLASS="command"
>apt-get</B
>, 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.</P
><P
>Generally, when first using <B
CLASS="command"
>apt-get</B
>, you will need to get an index of the available packages. This is done using the command</P
><P
><B
CLASS="command"
>apt-get <TT
CLASS="parameter"
><I
>update</I
></TT
></B
> </P
><P
>After that, you can use <B
CLASS="command"
>apt-get</B
> to upgrade your system:</P
><P
><B
CLASS="command"
>apt-get <TT
CLASS="parameter"
><I
>upgrade</I
></TT
></B
> </P
><P
>Do this often, it's an easy way to keep your system up-to-date and thus safe.</P
><P
>Apart from this general usage, <B
CLASS="command"
>apt-get</B
> is also very fast for installing individual packages. This is how it works:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>su - -c "apt-get install xsnow"</B
>
Password:
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
xsnow
0 packages upgraded, 1 newly installed, 0 removed and 3 not upgraded.
Need to get 33.6kB of archives.
After unpacking 104kB of additional disk space will be used.
Get:1 http://ayo.freshrpms.net redhat/9/i386/os xsnow 1.42-10 [33.6kB]
Fetched 33.6kB in 0s (106kB/s)
Executing RPM (-Uvh)...
Preparing... ########################################### [100%]
1:xsnow ########################################### [100%]
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Note the <TT
CLASS="option"
>-c</TT
> option to the <B
CLASS="command"
>su</B
> command, which indicates to the root shell to only execute this command, and then return to the user's environment. This way, you cannot forget to quit the root account.</P
><P
>If there are any dependencies on other packages, <B
CLASS="command"
>apt-get</B
> will download and install these supporting packages.</P
><P
>More information can be found in the <A
HREF="http://www.debian.org/doc/user-manuals#apt-howto"
TARGET="_top"
>APT HOWTO</A
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_06_03_03"
></A
>7.5.3.3. Systems using RPM packages</H3
><P
><SPAN
CLASS="application"
>Update Agent</SPAN
>, which originally only supported RedHat RPM packages, is now ported to a wider set of software, including non-RedHat repositories. This tool provides a complete system for updating the RPM packages on a RedHat or Fedora Core system. On the command line, type <B
CLASS="command"
>up2date</B
> to update your system. On the desktop, by default a small icon is activated, telleng you whether or not there are updates available for your system.</P
><P
><SPAN
CLASS="application"
>Yellowdog's Updater Modified</SPAN
> (<B
CLASS="command"
>yum</B
>) is another tool that recently became more popular. It is an interactive but automated update program for installing, updating or removing RPM packages on a system. It is the tool of choice on Fedora systems.</P
><P
>On SuSE Linux, everything is done with <SPAN
CLASS="application"
>YaST</SPAN
>, 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 <SPAN
CLASS="application"
>YOU</SPAN
>, Yast Online Update.</P
><P
>Mandrake Linux and Mandriva provide so-called URPMI tools, a set of wrapper programs that make installing new software easier for the user. These tools combine with <SPAN
CLASS="application"
>RPMDrake</SPAN
> and <SPAN
CLASS="application"
>MandrakeUpdate</SPAN
> 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. See <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>urpmi</I
></TT
></B
>, among others, for more info.</P
><P
>Also the <SPAN
CLASS="application"
>KDE</SPAN
> and <SPAN
CLASS="application"
>Gnome</SPAN
> desktop suites have their own (graphical) versions of package managers.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_06_04"
></A
>7.5.4. Upgrading your kernel</H2
><P
>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.</P
><P
>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.</P
><P
>Then create a dual boot system that will allow you to choose which kernel to boot by updating your boot loader configuration file <TT
CLASS="filename"
>grub.conf</TT
>. This is a simple example:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making config changes.
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, e.g.
# 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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_06_05"
></A
>7.5.5. Installing extra packages from the installation CDs</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_07_06_05_01"
></A
>7.5.5.1. Mounting a CD</H3
><P
>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 because the <B
CLASS="command"
>automount</B
> daemon is started up at boot time. If your CD is not made available automatically, issue the <B
CLASS="command"
>mount</B
> command in a terminal window. Depending on your actual system configuration, a line similar to this one will usually do the trick:</P
><P
><P
><B
CLASS="command"
>mount <TT
CLASS="filename"
>/dev/cdrom /mnt/cdrom</TT
></B
> </P
></P
><P
>On some systems, only <EM
>root</EM
> can mount removable media; this depends on the configuration.</P
><P
>For automation purposes, the CD drive usually has an entry in <TT
CLASS="filename"
>/etc/fstab</TT
>, which lists the file systems and their mount points, that make up your file system tree. This is such a line:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>grep cdrom /etc/fstab</B
>
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This indicates that the system will understand the command <B
CLASS="command"
>mount <TT
CLASS="filename"
>/mnt/cdrom</TT
></B
>. The <TT
CLASS="option"
>noauto</TT
> option means that on this system, CDs are not mounted at boot time.</P
><P
>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 <B
CLASS="command"
>mount</B
> command with no arguments:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[david@jupiter ~]</TT
> <B
CLASS="command"
>mount | grep cdrom</B
>
/dev/cdrom on /mnt/cdrom type iso9660 (ro,nosuid,nodev)
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_06_05_02"
></A
>7.5.5.2. Using the CD</H3
><P
>After mounting the CD, you can change directories, usually to the mount point <TT
CLASS="filename"
>/mnt/cdrom</TT
>, where you can access the content of the CD-ROM. Use the same commands for dealing with files and directories as you would use for files on the hard disk.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_07_06_05_03"
></A
>7.5.5.3. Ejecting the CD</H3
><P
>In order to get the CD out of the drive after you've finished using it, the file system on the CD should be unused. Even being in one of the subdirectories of the mount point, <TT
CLASS="filename"
>/mnt/cdrom</TT
> in our example, will be considered as <SPAN
CLASS="QUOTE"
>"using the file system"</SPAN
>, so you should get out of there. Do this for instance by typing <B
CLASS="command"
>cd</B
> with no arguments, which will put you back in your home directory. After that, you can either use the command</P
><P
><B
CLASS="command"
>umount <TT
CLASS="filename"
>/mnt/cdrom</TT
></B
> </P
><P
>or</P
><P
><B
CLASS="command"
>eject <TT
CLASS="parameter"
><I
>cdrom</I
></TT
></B
> </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Blocked drives</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
><EM
>NEVER</EM
> force the drive. The trick with the paperclip is a bad idea, because this will eventually expunge the CD, but your system will think the CD is still there because normal procedures were not followed. Chances are likely that you will have to reboot to get the system back in a consistent state.</P
><P
>If you keep getting <SPAN
CLASS="QUOTE"
>"device busy"</SPAN
> messages, check first that all shell sessions have left the CD file system and that no graphical applications are using it anymore. When in doubt, use the <B
CLASS="command"
>lsof</B
> tool to trace down the process(es) still using the CD resource.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_07"
></A
>7.6. Summary</H1
><P
>When everything has its place, that means already half the work is done.</P
><P
>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.</P
><P
>Regional settings such as keyboard setup, installing appropriate fonts and language support are best done at installation time.</P
><P
>Software is managed either automatically or manually using a package system.</P
><P
>The following commands were introduced in this chapter:</P
><DIV
CLASS="table"
><A
NAME="AEN8431"
></A
><P
><B
>Table 7-2. New commands in chapter 7: Making yourself at home</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>aptitude</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Manage packages Debian-style.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>automount</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>automatically include newly inserted file systems.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>dpkg</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Debian package manager.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>dselect</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Manage packages Debian-style.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>loadkeys</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Load keyboard configuration.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>lsof</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Identify processes.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mount</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Include a new file system into the existing file system tree.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ntpdate</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set the system time and date using a time server.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>quota</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display information about allowed disk space usage.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>recode</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Convert files to another character set.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>rpm</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Manage RPM packages.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>setfont</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Choose a font.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>timezone</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set the timezone.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>tzconfig</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set the timezone.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ulimit</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set or display resource limits.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>up2date</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Manage RPM packages.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>urpmi</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Manage RPM packages.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>yum</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Manage RPM packages.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_07_08"
></A
>7.7. Exercises</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_07_08_01"
></A
>7.7.1. Shell environment</H2
><P
></P
><UL
><LI
><P
>Print out your environment settings. Which variable may be used to store the CPU type of your machine?</P
></LI
><LI
><P
>Make a script that can say something on the lines of <SPAN
CLASS="QUOTE"
>"hello, world."</SPAN
> Give it appropriate permissions so it can be run. Test your script.</P
></LI
><LI
><P
>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.</P
></LI
><LI
><P
>Create subdirectories in your home directory to store various files, for instance a directory <TT
CLASS="filename"
>music</TT
> to keep audio files, a directory <TT
CLASS="filename"
>documents</TT
> for your notes, and so on. And use them!</P
></LI
><LI
><P
>Create a personalized prompt.</P
></LI
><LI
><P
>Display limits on resource usage. Can you change them?</P
></LI
><LI
><P
>Try to read compressed man pages without decompressing them first.</P
></LI
><LI
><P
>Make an alias <B
CLASS="command"
>lll</B
> which actually executes <B
CLASS="command"
>ls <TT
CLASS="option"
>-la</TT
></B
>.</P
></LI
><LI
><P
>Why does the command <B
CLASS="command"
>tail <TT
CLASS="filename"
>testfile</TT
> &#62; <TT
CLASS="filename"
>testfile</TT
></B
> not work?</P
></LI
><LI
><P
>Mount a data CD, such as your Linux installation CD, and have a look around. Don't forget to unmount when you don't need it anymore.</P
></LI
><LI
><P
>The script from <A
HREF="#sect_07_02_07_02"
>Section 7.2.5.2</A
> is not perfect. It generates errors for files that are directories. Adapt the script so that it only selects plain files for copying. Use <B
CLASS="command"
>find</B
> to make the selection. Do not forget to make the script executable before you try to run it.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_07_08_02"
></A
>7.7.2. Graphical environment</H2
><P
></P
><UL
><LI
><P
>Try all the mouse buttons in different regions (terminal, background, task bar).</P
></LI
><LI
><P
>Explore the menus.</P
></LI
><LI
><P
>Customize your terminal window.</P
></LI
><LI
><P
>Use the mouse buttons to copy and paste text from one terminal to another.</P
></LI
><LI
><P
>Find out how to configure your window manager; try different workspaces (virtual screens).</P
></LI
><LI
><P
>Add an applet, such as a load monitor, to the task bar.</P
></LI
><LI
><P
>Apply a different theme.</P
></LI
><LI
><P
>Enable the so-called <EM
>sloppy</EM
> focus - this is when a window is activated by just moving the mouse over it, so that you do not need to click the window in order to be able to use it.</P
></LI
><LI
><P
>Switch to a different window manager.</P
></LI
><LI
><P
>Log out and select a different session type, like KDE if you were using Gnome before. Repeat the previous steps.</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_08"
></A
>Chapter 8. Printers and printing</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN8575"
></A
><P
></P
><P
>In this chapter we will learn more about printers and printing files. After reading this part, you will be able to:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Format documents</P
></LI
><LI
><P
>Preview documents before sending them to the printer</P
></LI
><LI
><P
>Choose a good printer that works with your Linux system</P
></LI
><LI
><P
>Print files and check on printer status</P
></LI
><LI
><P
>Troubleshoot printing problems</P
></LI
><LI
><P
>Find necessary documentation to install a printer</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_08_01"
></A
>8.1. Printing files</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_08_01_01"
></A
>8.1.1. Command line printing</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_08_01_01_01"
></A
>8.1.1.1. Getting the file to the printer</H3
><P
>Printing from within an application is very easy, selecting the <SPAN
CLASS="guimenuitem"
>Print</SPAN
> option from the menu.</P
><P
>From the command line, use the <B
CLASS="command"
>lp</B
> or <B
CLASS="command"
>lpr</B
> command.</P
><P
><B
CLASS="command"
>lp <TT
CLASS="filename"
>file(s)</TT
></B
> </P
><P
><B
CLASS="command"
>lpr <TT
CLASS="filename"
>file(s)</TT
></B
> </P
><P
>These commands can read from a pipe, so you can print the output of commands using</P
><P
><B
CLASS="command"
>command | lp</B
> </P
><P
>There are many options available to tune the page layout, the number of copies, the printer that you want to print to if you have more than one available, paper size, one-side or double-sided printing if your printer supports this feature, margins and so on. Read the man pages for a complete overview.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_08_01_01_02"
></A
>8.1.1.2. Status of your print jobs</H3
><P
>Once the file is accepted in the print queue, an identification number for the print job is assigned:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>lp /etc/profile</B
>
request id is blob-253 (1 file(s))
</PRE
></FONT
></TD
></TR
></TABLE
><P
>To view (query) the print queue, use the <B
CLASS="command"
>lpq</B
> or <B
CLASS="command"
>lpstat</B
> command. When entered without arguments, it displays the contents of the default print queue.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>lpq</B
>
blob is ready and printing
Rank Owner Job File(s) Total Size
active davy 253 profile 1024 bytes
<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>lpstat</B
>
blob-253 davy 1024 Tue 25 Jul 2006 10:20_01 AM CEST
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_08_01_01_03"
></A
>8.1.1.3. Status of your printer</H3
><P
>Which is the default printer on a system that has access to multiple printers?</P
><P
><B
CLASS="command"
>lpstat <TT
CLASS="option"
>-d</TT
></B
> </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>lpstat <TT
CLASS="option"
>-d</TT
></B
>
system default destination: blob
</PRE
></FONT
></TD
></TR
></TABLE
><P
>What is the status of my printer(s)?</P
><P
><B
CLASS="command"
>lpstat <TT
CLASS="option"
>-p</TT
></B
> </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>lpstat <TT
CLASS="option"
>-p</TT
></B
>
printer blob now printing blob-253. enabled since Jan 01 18:01
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_08_01_01_04"
></A
>8.1.1.4. Removing jobs from the print queue</H3
><P
>If you don't like what you see from the status commands, use <B
CLASS="command"
>lprm</B
> or <B
CLASS="command"
>cancel</B
> to delete jobs.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>lprm <TT
CLASS="parameter"
><I
>253</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In the graphical environment, you may see a popup window telling you that the job has been canceled.</P
><P
>In larger environments, <B
CLASS="command"
>lpc</B
> may be used to control multiple printers. See the <SPAN
CLASS="application"
>Info</SPAN
> or man pages on each command.</P
><P
>There are many GUI print tools used as a front-end to <B
CLASS="command"
>lp</B
>, and most graphical applications have a print function that uses <B
CLASS="command"
>lp</B
>. See the built-in Help functions and program specific documentation for more.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Why are there two commands for every task related to printing?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Printing on UNIX and alikes has a long history. There used to be two rather different approaches: the BSD-style printing and the SystemV-style printing. For compatibility, Linux with CUPS supports the commands from both styles. Also note that <B
CLASS="command"
>lp</B
> does not behave exactly like <B
CLASS="command"
>lpr</B
>, <B
CLASS="command"
>lpq</B
> has somewhat different options than <B
CLASS="command"
>lpstat</B
> and <B
CLASS="command"
>lprm</B
> is almost, but not quite, like <B
CLASS="command"
>cancel</B
>. Which one you use is not important, just pick the commands that you are comfortable with, or that you may know from previous experiences with UNIX-like systems.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_08_01_02"
></A
>8.1.2. Formatting</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_08_01_02_01"
></A
>8.1.2.1. Tools and languages</H3
><P
>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.</P
><P
>Modern Linux systems support direct printing, without any formatting by the user, of a range of file types: text, PDF, PostScript and several image formats like PNG, JPEG, BMP and GIF.</P
><P
>For those file formats that do need formatting, Linux comes with a lot of formatting tools, such as the <B
CLASS="command"
>pdf2ps</B
>, <B
CLASS="command"
>fax2ps</B
> and <B
CLASS="command"
>a2ps</B
> commands, that convert other formats to PostScript. These commands can create files that can then be used on other systems that don't have all the conversion tools installed.</P
><P
>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: <SPAN
CLASS="application"
>OpenOffice.org</SPAN
>, <SPAN
CLASS="application"
>KOffice</SPAN
>, <SPAN
CLASS="application"
>AbiWord</SPAN
>, <SPAN
CLASS="application"
>WordPerfect</SPAN
>, etc.</P
><P
>The following are common languages in a printing context:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>groff</B
>: GNU version of the UNIX <B
CLASS="command"
>roff</B
> command. It is a front-end to the groff document formatting system. Normally it runs the <B
CLASS="command"
>troff</B
> command and a post-processor appropriate for the selected device. It allows generation of PostScript files.</P
></LI
><LI
><P
><SPAN
CLASS="application"
>TeX</SPAN
> and the macro package <SPAN
CLASS="application"
>LaTeX</SPAN
>: one of the most widely used markup languages on UNIX systems. Usually invoked as <B
CLASS="command"
>tex</B
>, it formats files and outputs a corresponding device-independent representation of the typeset document.</P
><P
>Technical works are <EM
>still</EM
> frequently written in <SPAN
CLASS="application"
>LaTeX</SPAN
> because of its support for mathematic formulas, although efforts are being made at <A
HREF="http://www.w3.org"
TARGET="_top"
>W3C</A
> (the World Wide Web Consortium) to include this feature in other applications.</P
></LI
><LI
><P
>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).</P
></LI
></UL
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Printing documentation</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The man pages contain pre-formatted <B
CLASS="command"
>troff</B
> data which has to be formatted before it can roll out of your printer. Printing is done using the <TT
CLASS="option"
>-t</TT
> option to the <B
CLASS="command"
>man</B
> command:</P
><P
><B
CLASS="command"
>man <TT
CLASS="option"
>-t</TT
> <TT
CLASS="parameter"
><I
>command</I
></TT
> &#62; <TT
CLASS="filename"
>man-command.ps</TT
></B
> </P
><P
>Then print the PostScript file. If a default print destination is configured for your system/account, you can just issue the command <B
CLASS="command"
>man <TT
CLASS="option"
>-t</TT
> <TT
CLASS="parameter"
><I
>command</I
></TT
></B
> to send the formatted page to the printer directly.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_08_01_02_02"
></A
>8.1.2.2. Previewing formatted files</H3
><P
>Anything that 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:</P
><P
></P
><UL
><LI
><P
>PostScript files: with the <B
CLASS="command"
>gv</B
> (GhostView) command.</P
></LI
><LI
><P
>TeX dvi files: with <B
CLASS="command"
>xdvi</B
>, or with <SPAN
CLASS="application"
>KDE</SPAN
>'s <B
CLASS="command"
>kdvi</B
>.</P
></LI
><LI
><P
>PDF files: <B
CLASS="command"
>xpdf</B
>, <B
CLASS="command"
>kpdf</B
>, <B
CLASS="command"
>gpdf</B
> or Adobe's viewer, <B
CLASS="command"
>acroread</B
>, which is also available for free but is not free software. Adobe's reader supports PDF 1.6, the others only support PDF versions up to 1.5. The version of a PDF file can be determined using the <B
CLASS="command"
>file</B
> command.</P
></LI
><LI
><P
>From within applications, such as Firefox or OpenOffice, you can usually select <SPAN
CLASS="guimenu"
>Print Preview</SPAN
> from one of the menus.</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_08_02"
></A
>8.2. The server side</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_08_02_01"
></A
>8.2.1. General</H2
><P
>Until a couple of years ago, the choice for Linux users was simple: everyone ran the same old LPD from BSD's Net-2 code. Then <SPAN
CLASS="application"
>LPRng</SPAN
> became more popular, but nowadays most modern Linux distributions use <A
HREF="http://www.cups.org"
TARGET="_top"
>CUPS</A
>, the Common UNIX Printing System. <SPAN
CLASS="application"
>CUPS</SPAN
> is 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. CUPS is also the default print system on MacOS X.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_08_02_02"
></A
>8.2.2. Graphical printer configuration</H2
><P
>Most distributions come with a GUI for configuring networked and local (parallel port or USB) printers. They let you choose the printer type from a list and allow easy testing. You don't have to bother about syntax and location of configuration files. Check your system documentation before you attempt installing your printer.</P
><P
>CUPS can also be configured using a web interface that runs on port 631 on your computer. To check if this feature is enabled, try browsing to <A
HREF="localhost:631/help"
TARGET="_top"
>localhost:631/help</A
> or <A
HREF="localhost:631/"
TARGET="_top"
>localhost:631/</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_08_02_04"
></A
>8.2.3. Buying a printer for Linux</H2
><P
>As more and more printer vendors make drivers for CUPS available, CUPS will allow easy connection with almost any printer that you can plug into a serial, parallel, or USB port, plus any printer on the network. CUPS will ensure a uniform presentation to you and your applications of all different types of printers.</P
><P
>Printers that only come with a Win9x driver could be problematic if they have no other support. Check with <A
HREF="http://linuxprinting.org/"
TARGET="_top"
>http://linuxprinting.org/</A
> when in doubt.</P
><P
>In the past, your best choice would have been 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 and you're always 100% sure that they will work. These days, however, the importance of this rule of thumb is dwindling.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_08_03"
></A
>8.3. Print problems</H1
><P
>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.</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_08_03_01"
></A
>8.3.1. Wrong file</H2
><P
>If you print the wrong file, the job may be canceled using the command <B
CLASS="command"
>lprm <TT
CLASS="parameter"
><I
>jobID</I
></TT
></B
>, where jobID is in the form <EM
>printername-printjobnumber</EM
> (get it from information displayed by <B
CLASS="command"
>lpq</B
> or <B
CLASS="command"
>lpstat</B
>). 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.</P
><P
>What you can try in those cases, or in cases where the wrong print driver is configured and only rubbish comes out of the printer, is power off the printer. However, that might not be the best course of action, as you might cause paper jams and other irregularities.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_08_03_02"
></A
>8.3.2. My print hasn't come out</H2
><P
>Use the <B
CLASS="command"
>lpq</B
> command and see if you can spot your job:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>elly:~&#62;</TT
> <B
CLASS="command"
>lpq</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Lots of printers have web interfaces these days, which can display status information by typing the printer's IP address in your web browser:</P
><DIV
CLASS="figure"
><A
NAME="AEN8864"
></A
><P
><B
>Figure 8-1. Printer Status through web interface</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/brother-webinterface.png"></P
></DIV
></DIV
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>CUPS web interface versus printer web interface</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Note that this is not the CUPS web interface and only works for printers supporting this feature. Check the documentation of your printer.</P
></TD
></TR
></TABLE
></DIV
><P
>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.</P
><P
>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.</P
><P
>In the case of a network printer, try printing from another host. If the printer is reachable from your own host (see <A
HREF="#chap_10"
>Chapter 10</A
> for the <B
CLASS="command"
>ping</B
> utility), you may try to put the formatted file on it, like <TT
CLASS="filename"
>file.ps</TT
> 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.</P
><P
>The <A
HREF="http://www.linuxprinting.org"
TARGET="_top"
>GNU/Linux Printing site</A
> contains more tips and tricks.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_08_05"
></A
>8.4. Summary</H1
><P
>The Linux print service comes with a set of printing tools based on the standard UNIX LPD tools, whether it be the SystemV or BSD implementation. Below is a list of print-related commands.</P
><DIV
CLASS="table"
><A
NAME="AEN8887"
></A
><P
><B
>Table 8-1. New commands in chapter 8: Printing</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>lpr</B
> or <B
CLASS="command"
>lp</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>lpq</B
> or <B
CLASS="command"
>lpstat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Query print queue</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>lprm</B
> or <B
CLASS="command"
>cancel</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Remove print job</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>acroread</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PDF viewer</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>groff</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Formatting tool</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>gv</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PostScript viewer</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>printconf</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configure printers</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>xdvi</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>DVI viewer</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>xpdf</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PDF viewer</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>*2ps</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Convert file to PostScript</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_08_06"
></A
>8.5. Exercises</H1
><P
>Configuring and testing printers involves being in the possession of one, and having access to the <EM
>root</EM
> account. If so, you may try:</P
><P
></P
><UL
><LI
><P
>Installing the printer using the GUI on your system.</P
></LI
><LI
><P
>Printing a test page using the GUI.</P
></LI
><LI
><P
>Printing a test page using the <B
CLASS="command"
>lp</B
> command.</P
></LI
><LI
><P
>Print from within an application, for example Mozilla or OpenOffice, by choosing <SPAN
CLASS="guimenu"
>File</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>Print</SPAN
> from the menu.</P
></LI
><LI
><P
>Disconnect the printer from the network or the local machine/print-server. What happens when you try to print something?</P
></LI
></UL
><P
>The following exercises can be done without printer or root access.</P
><P
></P
><UL
><LI
><P
>Try to make PostScript files from different source files, (e.g. HTML, PDF, man pages). Test the results with the <B
CLASS="command"
>gv</B
> viewer.</P
></LI
><LI
><P
>Check that the print daemon is running.</P
></LI
><LI
><P
>Print the files anyway. What happens?</P
></LI
><LI
><P
>Make a PostScript file using Mozilla. Test it with <B
CLASS="command"
>gv</B
>.</P
></LI
><LI
><P
>Convert it to PDF format. Test with <B
CLASS="command"
>xpdf</B
>.</P
></LI
><LI
><P
>How would you go about printing a GIF file from the command line?</P
></LI
><LI
><P
>Use <B
CLASS="command"
>a2ps</B
> to print the <TT
CLASS="filename"
>/etc/profile</TT
> file to an output file. Test again with <B
CLASS="command"
>gv</B
>. What happens if you don't specify an output file?</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_09"
></A
>Chapter 9. Fundamental Backup Techniques</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN8981"
></A
><P
></P
><P
>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.</P
><P
>Upon completion of this chapter, you will know how to:</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Make, query and unpack file archives</P
></LI
><LI
><P
>Handle floppy disks and make a boot disk for your system</P
></LI
><LI
><P
>Write CD-ROMs</P
></LI
><LI
><P
>Make incremental backups</P
></LI
><LI
><P
>Create Java archives</P
></LI
><LI
><P
>Find documentation to use other backup devices and programs</P
></LI
><LI
><P
>Encrypt your data</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_09_01"
></A
>9.1. Introduction</H1
><P
>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 or disk failure, is the cause, so it's always a good idea to keep an extra copy of sensitive and/or important data.</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_01_01"
></A
>9.1.1. Preparing your data</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_09_01_01_01"
></A
>9.1.1.1. Archiving with tar</H3
><P
>In most cases, we will first collect all the data to back up in a single archive file, which we will compress later on. The process of archiving involves concatenating all listed files and taking out unnecessary blanks. In Linux, this is commonly done with the <B
CLASS="command"
>tar</B
> command. <B
CLASS="command"
>tar</B
> was originally designed to archive data on tapes, but it can also make archives, known as <EM
>tarballs</EM
>.</P
><P
><B
CLASS="command"
>tar</B
> has many options, the most important ones are cited below:</P
><P
></P
><UL
><LI
><P
><TT
CLASS="option"
>-v</TT
>: verbose</P
></LI
><LI
><P
><TT
CLASS="option"
>-t</TT
>: test, shows content of a tarball</P
></LI
><LI
><P
><TT
CLASS="option"
>-x</TT
>: extract archive</P
></LI
><LI
><P
><TT
CLASS="option"
>-c</TT
>: create archive</P
></LI
><LI
><P
><TT
CLASS="option"
>-f</TT
> <TT
CLASS="filename"
>archivedevice</TT
>: use <TT
CLASS="filename"
>archivedevice</TT
> as source/destination for the tarball, the device defaults to the first tape device (usually <TT
CLASS="filename"
>/dev/st0</TT
> or something similar)</P
></LI
><LI
><P
><TT
CLASS="option"
>-j</TT
>: filter through <B
CLASS="command"
>bzip2</B
>, see <A
HREF="#sect_09_01_01_02"
>Section 9.1.1.2</A
></P
></LI
></UL
><P
>It is common to leave out the dash-prefix with <B
CLASS="command"
>tar</B
> options, as you can see from the examples below.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Use GNU tar for compatibility</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The archives made with a proprietary <B
CLASS="command"
>tar</B
> version on one system, may be incompatible with <B
CLASS="command"
>tar</B
> 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 <B
CLASS="command"
>tar</B
> 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 <B
CLASS="command"
>tar <TT
CLASS="option"
>--help</TT
></B
> to find out which version you are using. Contact your system admin if you don't see the word GNU somewhere.</P
></TD
></TR
></TABLE
></DIV
><P
>In the example below, an archive is created and unpacked.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>ls images/</B
>
me+tux.jpg nimf.jpg
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>tar cvf images-in-a-dir.tar images/</B
>
images/
images/nimf.jpg
images/me+tux.jpg
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>cd images</B
>
<TT
CLASS="prompt"
>gaby:~/images&#62;</TT
> <B
CLASS="command"
>tar cvf images-without-a-dir.tar *.jpg</B
>
me+tux.jpg
nimf.jpg
<TT
CLASS="prompt"
>gaby:~/images&#62;</TT
> <B
CLASS="command"
>cd</B
>
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>ls */*.tar</B
>
images/images-without-a-dir.tar
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>ls *.tar</B
>
images-in-a-dir.tar
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>tar xvf images-in-a-dir.tar </B
>
images/
images/nimf.jpg
images/me+tux.jpg
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>tar tvf images/images-without-dir.tar </B
>
-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
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>tar xvf images/images-without-a-dir.tar </B
>
me+tux.jpg
nimf.jpg
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>ls *.jpg</B
>
me+tux.jpg nimf.jpg
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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 were already there and which are the ones from the archive).</P
><P
>When a tape drive is connected to your machine and configured by your system administrator, the file names ending in <TT
CLASS="filename"
>.tar</TT
> are replaced with the tape device name, for example:</P
><P
><B
CLASS="command"
>tar <TT
CLASS="option"
>cvf</TT
> <TT
CLASS="filename"
>/dev/tape</TT
> <TT
CLASS="filename"
>mail/</TT
></B
></P
><P
>The directory <TT
CLASS="filename"
>mail</TT
> 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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_09_01_01_02"
></A
>9.1.1.2. Incremental backups with tar</H3
><P
>The <B
CLASS="command"
>tar</B
> tool supports the creation of incremental backups, using the <TT
CLASS="option"
>-N</TT
> option. With this option, you can specify a date, and <B
CLASS="command"
>tar</B
> will check modification time of all specified files against this date. If files are changed more recent than date, they will be included in the backup. The example below uses the timestamp on a previous archive as the date value. First, the initial archive is created and the timestamp on the initial backup file is shown. Then a new file is created, upon which we take a new backup, containing only this new file:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>tar cvpf /var/tmp/javaproggies.tar java/*.java</B
>
java/btw.java
java/error.java
java/hello.java
java/income2.java
java/income.java
java/inputdevice.java
java/input.java
java/master.java
java/method1.java
java/mood.java
java/moodywaitress.java
java/test3.java
java/TestOne.java
java/TestTwo.java
java/Vehicle.java
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>ls -l /var/tmp/javaproggies.tar</B
>
-rw-rw-r-- 1 jimmy jimmy 10240 Jan 21 11:58 /var/tmp/javaproggies.tar
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>touch java/newprog.java</B
>
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>tar -N /var/tmp/javaproggies.tar \
-cvp /var/tmp/incremental1-javaproggies.tar java/*.java 2&#62; /dev/null</B
>
java/newprog.java
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>cd /var/tmp/</B
>
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>tar xvf incremental1-javaproggies.tar</B
>
java/newprog.java
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Standard errors are redirected to <TT
CLASS="filename"
>/dev/null</TT
>. If you don't do this, <B
CLASS="command"
>tar</B
> will print a message for each unchanged file, telling you it won't be dumped.</P
><P
>This way of working has the disadvantage that it looks at timestamps on files. Say that you download an archive into the directory containing your backups, and the archive contains files that have been created two years ago. When checking the timestamps of those files against the timestamp on the initial archive, the new files will actually seem old to <B
CLASS="command"
>tar</B
>, and will not be included in an incremental backup made using the <TT
CLASS="option"
>-N</TT
> option.</P
><P
>A better choice would be the <TT
CLASS="option"
>-g</TT
> option, which will create a list of files to backup. When making incremental backups, files are checked against this list. This is how it works:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>tar cvpf work-20030121.tar -g snapshot-20030121 work/</B
>
work/
work/file1
work/file2
work/file3
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>file snapshot-20030121</B
>
snapshot-20030121: ASCII text
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The next day, user <EM
>jimmy</EM
> works on <TT
CLASS="filename"
>file3</TT
> a bit more, and creates <TT
CLASS="filename"
>file4</TT
>. At the end of the day, he makes a new backup:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>tar cvpf work-20030122.tar -g snapshot-20030121 work/</B
>
work/
work/file3
work/file4
</PRE
></FONT
></TD
></TR
></TABLE
><P
>These are some very simple examples, but you could also use this kind of command in a cronjob (see <A
HREF="#sect_04_04_04"
>Section 4.4.4</A
>), which specifies for instance a snapshot file for the weekly backup and one for the daily backup. Snapshot files should be replaced when taking full backups, in that case.</P
><P
>More information can be found in the <B
CLASS="command"
>tar</B
> documentation.</P
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>The real stuff</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>As you could probably notice, <B
CLASS="command"
>tar</B
> is OK when we are talking about a simple directory, a set of files that belongs together. There are tools that are easier to manage, however, when you want to archive entire partitions or disks or larger projects. We just explain about <B
CLASS="command"
>tar</B
> here because it is a very popular tool for distributing archives. It will happen quite often that you need to install a software that comes in a so-called <SPAN
CLASS="QUOTE"
>"compressed tarball"</SPAN
>. See <A
HREF="#sect_09_03"
>Section 9.3</A
> for an easier way to perform regular backups.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_09_01_01_03"
></A
>9.1.1.3. Compressing and unpacking with <B
CLASS="command"
>gzip</B
> or <B
CLASS="command"
>bzip2</B
></H3
><P
>&#13;Data, including tarballs, can be compressed using zip tools. The <B
CLASS="command"
>gzip</B
> command will add the suffix .gz to the file name and remove the original file.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>ls -la | grep tar</B
>
-rw-rw-r-- 1 jimmy jimmy 61440 Jun 6 14:08 images-without-dir.tar
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>gzip images-without-dir.tar</B
>
<TT
CLASS="prompt"
>jimmy:~&#62;</TT
> <B
CLASS="command"
>ls -la images-without-dir.tar.gz </B
>
-rw-rw-r-- 1 jimmy jimmy 50562 Jun 6 14:08 images-without-dir.tar.gz
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Uncompress gzipped files with the <TT
CLASS="option"
>-d</TT
> option.</P
><P
><B
CLASS="command"
>bzip2</B
> works in a similar way, but uses an improved compression algorithm, thus creating smaller files. See the <B
CLASS="command"
>bzip2</B
> info pages for more.</P
><P
>Linux software packages are often distributed in a gzipped tarball. The sensible thing to do after unpacking that kind of archives is find the <TT
CLASS="filename"
>README</TT
> and read it. It will generally contain guidelines to installing the package.</P
><P
>The GNU <B
CLASS="command"
>tar</B
> command is aware of gzipped files. Use the command</P
><P
><B
CLASS="command"
>tar <TT
CLASS="option"
>zxvf</TT
> <TT
CLASS="filename"
>file.tar.gz</TT
></B
> </P
><P
>for unzipping and untarring <TT
CLASS="filename"
>.tar.gz</TT
> or <TT
CLASS="filename"
>.tgz</TT
> files. Use</P
><P
><B
CLASS="command"
>tar <TT
CLASS="option"
>jxvf</TT
> <TT
CLASS="filename"
>file.tar.bz2</TT
></B
> </P
><P
>for unpacking <B
CLASS="command"
>tar</B
> archives that were compressed with <B
CLASS="command"
>bzip2</B
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_09_01_01_04"
></A
>9.1.1.4. Java archives</H3
><P
>The GNU project provides us with the <B
CLASS="command"
>jar</B
> tool for creating Java archives. It is a Java application that combines multiple files into a single JAR archive file. While also being a general purpose archiving and compression tool, based on ZIP and the ZLIB compression format, <B
CLASS="command"
>jar</B
> was mainly designed to facilitate the packing of Java code, applets and/or applications in a single file. When combined in a single archive, the components of a Java application, can be downloaded much faster.</P
><P
>Unlike <B
CLASS="command"
>tar</B
>, <B
CLASS="command"
>jar</B
> compresses by default, independent from other tools - because it is basically the Java version of <B
CLASS="command"
>zip</B
>. In addition, it allows individual entries in an archive to be signed by the author, so that origins can be authenticated.</P
><P
>The syntax is almost identical as for the <B
CLASS="command"
>tar</B
> command, we refer to <B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>jar</I
></TT
></B
> for specific differences.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>tar, jar and symbolic links</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>One noteworthy feature not really mentioned in the standard documentation is that <B
CLASS="command"
>jar</B
> will follow symbolic links. Data to which these links are pointing will be included in the archive. The default in <B
CLASS="command"
>tar</B
> is to only backup the symbolic link, but this behavior can be changed using the <TT
CLASS="option"
>-h</TT
> to <B
CLASS="command"
>tar</B
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_09_01_01_05"
></A
>9.1.1.5. Transporting your data</H3
><P
>Saving copies of your data on another host is a simple but accurate way of making backups. See <A
HREF="#chap_10"
>Chapter 10</A
> for more information on <B
CLASS="command"
>scp</B
>, <B
CLASS="command"
>ftp</B
> and more.</P
><P
>In the next section we'll discuss local backup devices.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_09_02"
></A
>9.2. Moving your data to a backup device</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_09_02_01"
></A
>9.2.1. Making a copy on a floppy disk</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_09_02_01_01"
></A
>9.2.1.1. Formatting the floppy</H3
><P
>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 some systems, there will likely be a link <TT
CLASS="filename"
>/dev/floppy</TT
> pointing to the right device, probably <TT
CLASS="filename"
>/dev/fd0</TT
> (the auto-detecting floppy device) or <TT
CLASS="filename"
>/dev/fd0H1440</TT
> (set for 1,44MB floppies).</P
><P
>&#13;<B
CLASS="command"
>fdformat</B
> is the low-level floppy disk formatting tool. It has the device name of the floppy disk as an option. <B
CLASS="command"
>fdformat</B
> will display an error when the floppy is write-protected.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>emma:~&#62;</TT
> <B
CLASS="command"
>fdformat /dev/fd0H1440</B
>
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done
Verifying ... done
<TT
CLASS="prompt"
>emma:~&#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <B
CLASS="command"
>mformat</B
> command (from the mtools package) is used to create DOS-compatible floppies which can then be accessed using the <B
CLASS="command"
>mcopy</B
>, <B
CLASS="command"
>mdir</B
> and other m-commands.</P
><P
>Graphical tools are also available.</P
><DIV
CLASS="figure"
><A
NAME="AEN9268"
></A
><P
><B
>Figure 9-1. Floppy formatter</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/formatfloppy.png"></P
></DIV
></DIV
><P
>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 <TT
CLASS="filename"
>/mnt/floppy</TT
> entry.</P
><P
>Should you need it, install the <B
CLASS="command"
>mkbootdisk</B
> utility, which makes a floppy from which the current system can boot.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_09_02_01_02"
></A
>9.2.1.2. Using the <B
CLASS="command"
>dd</B
> command to dump data</H3
><P
>The <B
CLASS="command"
>dd</B
> 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:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>dd if=images-without-dir.tar.gz of=/dev/fd0H1440</B
>
98+1 records in
98+1 records out
<TT
CLASS="prompt"
>gaby~&#62;</TT
> <B
CLASS="command"
>dd if=/dev/fd0H1440 of=/var/tmp/images.tar.gz</B
>
2880+0 records in
2880+0 records out
<TT
CLASS="prompt"
>gaby:~&#62;</TT
> <B
CLASS="command"
>ls /var/tmp/images*</B
>
/var/tmp/images.tar.gz
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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 <B
CLASS="command"
>dd</B
>, read the man pages.</P
><P
>This tool is part of the GNU <EM
>coreutils</EM
> package.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Dumping disks</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The <B
CLASS="command"
>dd</B
> command can also be used to make a raw dump of an entire hard disk.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_02_02"
></A
>9.2.2. Making a copy with a CD-writer</H2
><P
>On some systems users are allowed to use the CD-writer device. Your data will need to be formatted first. Use the <B
CLASS="command"
>mkisofs</B
> command to do this in the directory containing the files you want to backup. Check with <B
CLASS="command"
>df</B
> that enough disk space is available, because a new file about the same size as the entire current directory will be created:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[rose@blob recordables]</TT
> <B
CLASS="command"
>df -h .</B
>
Filesystem Size Used Avail Use% Mounted on
/dev/hde5 19G 15G 3.2G 82% /home
<TT
CLASS="prompt"
>[rose@blob recordables]</TT
> <B
CLASS="command"
>du -h -s .</B
>
325M .
<TT
CLASS="prompt"
>[rose@blob recordables]</TT
> <B
CLASS="command"
>mkisofs -J -r -o cd.iso .</B
>
&#60;--snap--&#62;
making a lot of conversions
&#60;--/snap--&#62;
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)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <TT
CLASS="option"
>-J</TT
> and <TT
CLASS="option"
>-r</TT
> 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 <B
CLASS="command"
>cdrecord</B
> tool with appropriate options:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[rose@blob recordables]</TT
> <B
CLASS="command"
>cdrecord -dev 0,0,0 -speed=8 cd.iso</B
>
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 '
Identification : '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.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Depending on your CD-writer, you now have the time to smoke^H^H^H^H^H eat a healthy piece of fruit and/or get a cup of coffee. Upon finishing the job, you will get a confirmation message:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;Track 01: Total bytes read/written: 341540864/341540864
(166768 sectors).
</PRE
></FONT
></TD
></TR
></TABLE
><P
>There are some graphical tools available to make it easier on you. One of the popular ones is <B
CLASS="command"
>xcdroast</B
>, which is freely available from <A
HREF="http://www.xcdroast.org/"
TARGET="_top"
>the X-CD-Roast web site</A
> and is included on most systems and in the GNU directory. Both the KDE and Gnome desktop managers have facilities to make your own CDs.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_02_03"
></A
>9.2.3. Backups on/from jazz drives, USB devices and other removables</H2
><P
>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.</P
><P
>In the example below, images are copied from a USB camera to the hard disk:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>robin:~&#62;</TT
> <B
CLASS="command"
>mount <TT
CLASS="filename"
>/mnt/camera</TT
></B
>
<TT
CLASS="prompt"
>robin:~&#62;</TT
> <B
CLASS="command"
>mount | grep <TT
CLASS="parameter"
><I
>camera</I
></TT
></B
>
/dev/sda1 on /mnt/camera type vfat (rw,nosuid,nodev)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>If the camera is the only USB storage device that you ever connect to your system, this is safe. But keep in mind that USB devices are assigned entries in <TT
CLASS="filename"
>/dev</TT
> as they are connected to the system. Thus, if you first connect a USB stick to your system, it will be on the <TT
CLASS="filename"
>/dev/sda</TT
> entry, and if you connect your camera after that, it will be assigned to <TT
CLASS="filename"
>/dev/sdb</TT
> - provided that you do not have any SCSI disks, which are also on <TT
CLASS="filename"
>/dev/sd*</TT
>. On newer systems, since kernel 2.6, a hotplug system called HAL (Hardware Abstraction Layer) ensures that users don't have to deal with this burden. If you want to check where your device is, type <B
CLASS="command"
>dmesg</B
> after inserting it.</P
><P
>You can now copy the files:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>robin:~&#62;</TT
> <B
CLASS="command"
>cp -R /mnt/camera/* images/</B
>
<TT
CLASS="prompt"
>robin:~&#62;</TT
> <B
CLASS="command"
>umount /mnt/camera</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Likewise, a jazz drive may be mounted on <TT
CLASS="filename"
>/mnt/jazz</TT
>.</P
><P
>Appropriate lines should be added in <TT
CLASS="filename"
>/etc/modules.conf</TT
> and <TT
CLASS="filename"
>/etc/fstab</TT
> to make this work. Refer to specific hardware HOWTOs for more information. On systems with a 2.6.x kernel or higher, you may also want to check the man pages for <B
CLASS="command"
>modprobe</B
> and <TT
CLASS="filename"
>modprobe.conf</TT
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_02_04"
></A
>9.2.4. Backing up data using a tape device</H2
><P
>This is done using <B
CLASS="command"
>tar</B
> (see above). The <B
CLASS="command"
>mt</B
> tool is used for controlling the magnetic tape device, like <TT
CLASS="filename"
>/dev/st0</TT
>. Entire books have been written about tape backup, therefore, refer to our reading-list in <A
HREF="#app2"
>Appendix B</A
> for more information. Keep in mind that databases might need other backup procedures because of their architecture.</P
><P
>The appropriate backup commands are usually put in one of the <EM
>cron</EM
> directories in order to have them executed on a regular basis. In larger environments, the freely available <A
HREF="http://www.amanda.org"
TARGET="_top"
>Amanda</A
> 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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_02_05"
></A
>9.2.5. Tools from your distribution</H2
><P
>Most Linux distributions offer their own tools for making your life easy. A short overview:</P
><P
></P
><UL
><LI
><P
>SuSE: <SPAN
CLASS="application"
>YaST</SPAN
> now includes expanded backup and restore modules.</P
></LI
><LI
><P
>RedHat: the <SPAN
CLASS="application"
>File Roller</SPAN
> tool provides visual management of (compressed) archives. They seem to be in favour of the X-CD-Roast tool for moving backups to an external device.</P
></LI
><LI
><P
>Mandrake: X-CD-Roast.</P
></LI
><LI
><P
>Most distributions come with the BSD <B
CLASS="command"
>dump</B
> and <B
CLASS="command"
>restore</B
> utilities for making backups of <EM
>ext2</EM
> and <EM
>ext3</EM
> file systems. This tool can write to a variety of devices and literally dumps the file(s) or file system bit per bit onto the specified device. Like <B
CLASS="command"
>dd</B
>, this allows for backing up special file types such as the ones in <TT
CLASS="filename"
>/dev</TT
>.</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_09_03"
></A
>9.3. Using rsync</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_09_03_01"
></A
>9.3.1. Introduction</H2
><P
>The <B
CLASS="command"
>rsync</B
> program is a fast and flexible tool for remote backup. It is common on UNIX and UNIX-like systems, easy to configure and use in scripts. While the <EM
>r</EM
> in <B
CLASS="command"
>rsync</B
> stands for <SPAN
CLASS="QUOTE"
>"remote"</SPAN
>, you do not need to take this all too literally. Your <SPAN
CLASS="QUOTE"
>"remote"</SPAN
> device might just as well be a USB storage device or another partition on your hard disk, you do not need to have two separated machines.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_03_02"
></A
>9.3.2. An example: rsync to a USB storage device</H2
><P
>As discussed in <A
HREF="#sect_03_01_02_03"
>Section 3.1.2.3</A
>, we will first have to mount the device. Possibly, this should be done as <EM
>root</EM
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>root@theserver# </TT
><B
CLASS="command"
>mkdir <TT
CLASS="filename"
>/mnt/usbstore</TT
></B
>
<TT
CLASS="prompt"
>root@theserver# </TT
><B
CLASS="command"
>mount <TT
CLASS="option"
>-t vfat</TT
> <TT
CLASS="filename"
>/dev/sda1 /mnt/usbstore</TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Userfriendly</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>More and more distributions give access to removable devices for non-prilileged users and mount USB devices, CD-ROMs and other removable devices automatically.</P
></TD
></TR
></TABLE
></DIV
><P
>Note that this guideline requires USB support to be installed on your system. See <A
HREF="http://www.linux-usb.org/USB-guide/"
TARGET="_top"
>the USB Guide</A
> for help if this does not work. Check with <B
CLASS="command"
>dmesg</B
> that <TT
CLASS="filename"
>/dev/sda1</TT
> is indeed the device to mount.</P
><P
>Then you can start the actual backup, for instance of the <TT
CLASS="filename"
>/home/karl</TT
> directory:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>karl@theserver:~&#62; </TT
><B
CLASS="command"
>rsync <TT
CLASS="option"
>-avz</TT
> <TT
CLASS="filename"
>/home/karl/ /mnt/usbstore</TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>As usual, refer to the man pages for more.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_09_04"
></A
>9.4. Encryption</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_09_04_01"
></A
>9.4.1. General remarks</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_09_04_01_01"
></A
>9.4.1.1. Why should you encrypt data?</H3
><P
>Encryption is synonym to secrecy. In the context of backups, encryption can be very useful, for instance if you need to leave your backed up data in a place where you can not control access, such as the server of your provider.</P
><P
>Apart from that, encryption can be applied to E-mails as well: normally, mail is not encrypted and it is often sent in the open over the netwerk or the Internet. If your message contains sensitive information, better encrypt it.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_09_04_01_02"
></A
>9.4.1.2. GNU Privacy Guard</H3
><P
>On Linux systems you will find <SPAN
CLASS="application"
>GnuPG</SPAN
>, the <SPAN
CLASS="application"
>GNU Privacy Guard</SPAN
>, which is a suite of programs that are compatible with the PGP (<SPAN
CLASS="application"
>Pretty Good Privacy</SPAN
>) tools that are commercially available.</P
><P
>In this guide we will only discuss the very simple usage of the encryption tools and show what you will need in order to generate an encryption key and use it to encrypt data for yourself, which you can then safely store in a public place. More advanced usage directions can be found in the man pages of the various commands.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_04_02"
></A
>9.4.2. Generate a key</H2
><P
>Before you can start encrypting your data, you need to create a pair of keys. The pair consists of a private and a public key. You can send the public key to correspondents, who can use it to encrypt data for you, which you decrypt with your private key. You always keep the private key, never share it with somebody else, or they will be able to decrypt data that is only destined for you. Just to make sure that no accidents happen, the private key is protected with a password. The key pair is created using this command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>willy@ubuntu:~$ </TT
><B
CLASS="command"
>gpg <TT
CLASS="option"
>--key-gen</TT
></B
>
gpg (GnuPG) 1.4.2.2; Copyright (C) 2005 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.
gpg: directory `/home/willy.gnupg' created
gpg: new configuration file `/home/willy/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/willy/.gnupg/gpg.conf' are not yet
active during this run
gpg: keyring `/home/willy/.gnupg/secring.gpg' created
gpg: keyring `/home/willy/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection? <B
CLASS="command"
>1</B
>
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) <B
CLASS="command"
>4096</B
>
Requested keysize is 4096 bits
Please specify how long the key should be valid.
0 = key does not expire
&#60;n&#62; = key expires in n days
&#60;n&#62;w = key expires in n weeks
&#60;n&#62;m = key expires in n month
&#60;n&#62;y = key expires in n years
Key is valid for? (0) <B
CLASS="command"
>0</B
>
Key does not expire at all
Is this correct? (y/N) <B
CLASS="command"
>y</B
>
You need a user ID to identify your key; the software constructs the
user ID from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) &#60;heinrichh@duesseldorf.de&#62;"
Real name: <B
CLASS="command"
>Willy De Wandel</B
>
Email address: <B
CLASS="command"
>wdw@mvg.vl</B
>
Comment: <B
CLASS="command"
>Willem</B
>
You selected this USER-ID:
"Willy De Wandel (Willem) &#60;wdw@mvg.vl&#62;"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? <B
CLASS="command"
>O</B
>
You need a Passphrase to protect your secret key.
Passphrase:
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Now enetr your password. This can be a phrase, the longer, the better, the only condition is that you should be able to remember it at all times. For verification, you need to enter the same phrase again.</P
><P
>Now the key pair is generated by a program that spawns random numbers and that is, among other factors, fed with the activity data of the system. So it is a good idea to start some programs now, to move the mouse cursor or to type some random characters in a terminal window. That way, the chances to generate a number that contains lots of different digits will be much bigger and the key will be more difficult to crack.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_04_03"
></A
>9.4.3. About your key</H2
><P
>When your key has been created, you will get a message about the <EM
>fingerprint</EM
>. This is a sequence of 40 hexadecimal numbers, which is so long that it is very, very hard to generate the same key twice, on any computer. You can be rather sure that this is a unique sequence. The short form of this key consists of your name, followed by the last 8 hexadecimal numbers.</P
><P
>You can get information about your key as follows:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>willy@ubuntu:~$ </TT
><B
CLASS="command"
>gpg <TT
CLASS="option"
>--list-keys</TT
></B
>
/home/willy/.gnupg/pubring.gpg
------------------------------
pub 1024D/BF5C3DBB 2006-08-08
uid Willy De Wandel (Willem) &#60;wdw@mvg.vl&#62;
sub 4096g/A3449CF7 2006-08-08
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <EM
>key ID</EM
> of this key is <SPAN
CLASS="QUOTE"
>"BF5C3DBB"</SPAN
>. You can send your key ID and your name to a <EM
>key server</EM
>, so that other people can get this info about you and use it to encrypt data for you. Alternatively, you can send your public key directly to the people who need it. The public part of your key is the long series of numbers that you see when using the <TT
CLASS="option"
>--export</TT
> option to the <B
CLASS="command"
>gpg</B
> command:</P
><P
><B
CLASS="command"
>gpg <TT
CLASS="option"
>--export -a</TT
></B
> </P
><P
>However, as far is this guide is concerned, we assume that you only need your key in order to encrypt and decrypt data for yourself. Read the <B
CLASS="command"
>gpg</B
> man pages if you want to know more.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_04_04"
></A
>9.4.4. Encrypt data</H2
><P
>Now you can encrypt a <TT
CLASS="filename"
>.tar</TT
> archive or a compressed archive, prior to saving it to a backup medium or transporting it to the backup server. Use the <B
CLASS="command"
>gpg</B
> command like this:</P
><P
><B
CLASS="command"
>gpg <TT
CLASS="option"
>-e -r</TT
> <TT
CLASS="parameter"
><I
>(part of) uid</I
></TT
> <TT
CLASS="filename"
>archive</TT
></B
> </P
><P
>The <TT
CLASS="option"
>-e</TT
> option tells <B
CLASS="command"
>gpg</B
> to encrypt, the <TT
CLASS="option"
>-r</TT
> option indicates who to encrypt for. Keep in mind that only only the user name(s) following this <TT
CLASS="option"
>-r</TT
> option will be able to decrypt the data again. An example:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>willy@ubuntu:~$ </TT
><B
CLASS="command"
>gpg <TT
CLASS="option"
>-e -r</TT
> <TT
CLASS="parameter"
><I
>Willy</I
></TT
> <TT
CLASS="filename"
>/var/tmp/home-willy-20060808.tar</TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_09_04_05"
></A
>9.4.5. Decrypting files</H2
><P
>Using the <TT
CLASS="option"
>-d</TT
> option, you can decrypt files that have been encrypted for you. The data will scroll over your screen, but an encrypted copy will remain on disk. So for file formats other than plain text, you will want to save the decrypted data, so that you can view them with the appropriate program. This is done using the <TT
CLASS="option"
>-o</TT
> option to the <B
CLASS="command"
>gpg</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>willy@ubuntu:~$ </TT
><B
CLASS="command"
>gpg <TT
CLASS="option"
>-d -o</TT
> <TT
CLASS="filename"
>/var/tmp/home-willy-decrypt.tar /var/tmp/home-willy-20060808.tar.gpg</TT
></B
>
You need a passphrase to unlock the secret key for
user: "Willy De Wandel (Willem) &#60;wdw@mvg.vl&#62;"
4096 ELG-E key, ID A3449CF7, created 2006-08-08 (main key ID BF5C3DBB)
gpg: encrypted with 4096-bit ELG-E key, ID A3449CF7, created 2006-08-08
"Willy De Wandel (Willem) &#60;wdw@mvg.vl&#62;"
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>No password = no data</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>If you can not remember your password, the data is lost. Not even the system administrator will be able to decrypt the data. That is why a copy of important keys is sometimes kept in a sealed vault in a bank.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_09_05"
></A
>9.5. Summary</H1
><P
>Here's a list of the commands involving file backup:</P
><DIV
CLASS="table"
><A
NAME="AEN9615"
></A
><P
><B
>Table 9-1. New commands in chapter 9: Backup</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>bzip2</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>A block-sorting file compressor.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cdrecord</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Record audio or data Compact Disks from a master.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>dd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Convert and copy a file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>fdformat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Low-level formats a floppy disk.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>gpg</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Encrypt and decrypt data.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>gzip</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Compress or expand files.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mcopy</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Copy MSDOS files to/from UNIX.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mdir</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display an MSDOS directory.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mformat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Add an MSDOS file system to a low-level formatted floppy disk.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mkbootdisk</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Creates a stand-alone boot floppy for the running system.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mount</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Mount a file system (integrate it with the current file system by connecting it to a mount point).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>rsync</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Synchronize directories.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>tar</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Tape archiving utility, also used for making archives on disk instead of on tape.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>umount</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Unmount file systems.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_09_06"
></A
>9.6. Exercises</H1
><P
></P
><UL
><LI
><P
>Make a backup copy of your home directory in <TT
CLASS="filename"
>/var/tmp</TT
> using the <B
CLASS="command"
>tar</B
> command. Then further compress the file using <B
CLASS="command"
>gzip</B
> or <B
CLASS="command"
>bzip2</B
>. Make it a clean tarred file, one that doesn't make a mess when unpacking.</P
></LI
><LI
><P
>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.</P
></LI
><LI
><P
>DOS format the floppy. Use the <EM
>mtools</EM
> to put and delete files on it.</P
></LI
><LI
><P
>What happens to an unformatted floppy when you want to mount it into the file system?</P
></LI
><LI
><P
>If you have any USB storage, try to put a file on it.</P
></LI
><LI
><P
>Using <B
CLASS="command"
>rsync</B
>, make a copy of your home directory to another local or remote file system.</P
></LI
><LI
><P
>When leaving files on a network server, it's best to encrypt them. Make a <TT
CLASS="filename"
>tar</TT
> archive of your home directory and encrypt it.</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_10"
></A
>Chapter 10. Networking</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN9705"
></A
><P
></P
><P
>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.</P
><P
>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 more about</P
><P
>&#13;<P
></P
><UL
><LI
><P
>Supported networking protocols</P
></LI
><LI
><P
>Network configuration files</P
></LI
><LI
><P
>Commands for configuring and probing the network</P
></LI
><LI
><P
>Daemons and client programs enabling different network applications</P
></LI
><LI
><P
>File sharing and printing</P
></LI
><LI
><P
>Remote execution of commands and applications</P
></LI
><LI
><P
>Basic network interconnection</P
></LI
><LI
><P
>Secure execution of remote applications</P
></LI
><LI
><P
>Firewalls and intrusion detection</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_01"
></A
>10.1. Networking Overview</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_10_01_01"
></A
>10.1.1. The OSI Model</H2
><P
>A protocol is, simply put, a set of rules for communication.</P
><P
>In order to get data over the network, for instance an E-mail from your computer to some computer at the other end of the world, lots of different hard- and software needs to work together.</P
><P
>All these pieces of hardware and the different software programs speak different languages. Imagine your E-mail program: it is able to talk to the computer operating system, through a specific protocol, but it is not able to talk to the computer hardware. We need a special program in the operating system that performs this function. In turn, the computer needs to be able to communicate with the telephone line or other Internet hookup method. And behind the scenes, network connection hardware needs to be able to communicate in order to pass your E-mail from one appliance to the other, all the way to the destination computer.</P
><P
>All these different types of communication protocols are classified in 7 layers, which are known as the <EM
>Open Systems Interconnection Reference Model</EM
>, the <EM
>OSI Model</EM
> for short. For easy understanding, this model is reduced to a 4-layer protocol description, as described in the table below:</P
><DIV
CLASS="table"
><A
NAME="layered_model"
></A
><P
><B
>Table 10-1. The simplified OSI Model</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Layer name</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Layer Protocols</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Application layer</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>HTTP, DNS, SMTP, POP, ...</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Transport layer</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>TCP, UDP</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Network layer</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>IP, IPv6</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Network access layer</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PPP, PPPoE, Ethernet</TD
></TR
></TBODY
></TABLE
></DIV
><P
>Each layer can only use the functionality of the layer below; each layer can only export functionality to the layer above. In other words: layers communicate only with adjacent layers. Let's take the example of your E-mail message again: you enter it through the application layer. In your computer, it travels down the transport and network layer. Your computer puts it on the network through the network access layer. That is also the layer that will move the message around the world. At the destination, the receiving computer will accept the message through it's own network layer, and will display it to the recepient using the transport and application layer.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>It's really much more complicated</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The above and following sections are included because you will come across some networking terms sooner or later; they will give you some starting points, should you want to find out about the details.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_01_02"
></A
>10.1.2. Some popular networking protocols</H2
><P
>Linux supports many different networking protocols. We list only the most important:</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_01"
></A
>10.1.2.1. TCP/IP</H3
><P
>The <EM
>Transport Control Protocol</EM
> and the <EM
>Internet Protocol</EM
> are the two most popular ways of communicating on the Internet. A lot of applications, such as your browser and E-mail program, are built on top of this protocol suite.</P
><P
>Very simply put, IP provides a solution for sending packets of information from one machine to another, while TCP ensures that the packets are arranged in streams, so that packets from different applications don't get mixed up, and that the packets are sent and received in the correct order.</P
><P
>A good starting point for learning more about TCP and IP is in the following documents:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>man <TT
CLASS="option"
>7</TT
> <TT
CLASS="parameter"
><I
>ip</I
></TT
></B
>: Describes the IPv4 protocol implementation on Linux (version 4 currently being the most wide-spread edition of the IP protocol).</P
></LI
><LI
><P
><B
CLASS="command"
>man <TT
CLASS="option"
>7</TT
> <TT
CLASS="parameter"
><I
>tcp</I
></TT
></B
>: Implementation of the TCP protocol.</P
></LI
><LI
><P
>RFC793, RFC1122, RFC2001 for TCP, and RFC791, RFC1122 and RFC1112 for IP.</P
><P
>The <A
HREF="http://www.ietf.org/rtf/"
TARGET="_top"
>Request For Comments</A
> documents contain the descriptions of networking standards, protocols, applications and implementation. These documents are managed by the Internet Engineering Task Force, an international community concerned with the smooth operation of the Internet and the evolution and development of the Internet architecture.</P
><P
>Your ISP usually has an RFC archive available, or you can browse the RFCs via <A
HREF="http://www.ietf.org/rfc.html"
TARGET="_top"
>http://www.ietf.org/rfc.html</A
>.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_02"
></A
>10.1.2.2. TCP/IPv6</H3
><P
>Nobody expected the Internet to grow as fast as it does. IP proved to have quite some disadvantages when a really large number of computers is in a network, the most important being the availability of unique addresses to assign to each machine participating. Thus, IP version 6 was deviced to meet the needs of today's Internet.</P
><P
>Unfortunately, not all applications and services support IPv6, yet. A migration is currently being set in motion in many environments that can benefit from an upgrade to IPv6. For some applications, the old protocol is still used, for applications that have been reworked the new version is already active. So when checking your network configuration, sometimes it might be a bit confusing since all kinds of measures can be taken to hide one protocol from the other so as the two don't mix up connections.</P
><P
>More information can be found in the following documents:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>man <TT
CLASS="option"
>7</TT
> <TT
CLASS="parameter"
><I
>ipv6</I
></TT
></B
>: the Linux IPv6 protocol implementation.</P
></LI
><LI
><P
>RFC1883 describing the IPv6 protocol.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_03"
></A
>10.1.2.3. PPP, SLIP, PLIP, PPPOE</H3
><P
>The Linux kernel has built-in support for PPP (Point-to-Point-Protocol), SLIP (Serial Line IP), PLIP (Parallel Line IP) and PPPP Over EThernet. PPP is the most popular way individual users access their ISP (Internet Service Provider), although in densely populated areas it is often being replaced by PPPOE, the protocol used for ADSL (Asymmetric Digital Subscriber Line) connections.</P
><P
>Most Linux distributions provide easy-to-use tools for setting up an Internet connection. The only thing you basically need is a username and password to connect to your Internet Service Provider (ISP), and a telephone number in the case of PPP. These data are entered in the graphical configuration tool, which will likely also allow for starting and stopping the connection to your provider.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_04"
></A
>10.1.2.4. ISDN</H3
><P
>The Linux kernel has built-in ISDN capabilities. Isdn4linux controls ISDN PC cards and can emulate a modem with the Hayes command set (<SPAN
CLASS="QUOTE"
>"AT"</SPAN
> commands). The possibilities range from simply using a terminal program to full connection to the Internet.</P
><P
>Check your system documentation.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_05"
></A
>10.1.2.5. AppleTalk</H3
><P
>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.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_07"
></A
>10.1.2.6. SMB/NMB</H3
><P
>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.</P
><P
>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.</P
><P
>Most Linux distributions provide a <EM
>samba</EM
> package, which does most of the server setup and starts up <B
CLASS="command"
>smbd</B
>, the Samba server, and <B
CLASS="command"
>nmbd</B
>, the netbios name server, at boot time by default. Samba can be configured graphically, via a web interface or via the command line and text configuration files. The daemons make a Linux machine appear as an MS Windows host in an MS Windows My Network Places/Network Neighbourhood window; a share from a Linux machine will be indistinguishable from a share on any other host in an MS Windows environment.</P
><P
>More information can be found at the following locations:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>man <TT
CLASS="filename"
>smb.conf</TT
></B
>: describes the format of the main Samba configuration file.</P
></LI
><LI
><P
>The <A
HREF="http://www.samba.org/"
TARGET="_top"
>Samba Project Documentation</A
> (or check your local samba.org mirror) contains an easy to read installation and testing guide, which also explains how to configure your Samba server as a Primary Domain Controller. All the man pages are also available here.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_01_02_08"
></A
>10.1.2.7. Miscellaneous protocols</H3
><P
>Linux also has support for Amateur Radio, WAN internetworking (X25, Frame Relay, ATM), InfraRed and other wireless connections, but since these protocols usually require special hardware, we won't discuss them in this document.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_02"
></A
>10.2. Network configuration and information</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_10_02_01"
></A
>10.2.1. Configuration of network interfaces</H2
><P
>All the big, userfriendly Linux distributions come with various graphical tools, allowing for easy setup of the computer in a local network, for connecting it to an Internet Service Provider or for wireless access. These tools can be started up from the command line or from a menu:</P
><P
></P
><UL
><LI
><P
>Ubuntu configuration is done selecting <SPAN
CLASS="guimenu"
>System</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>Administration</SPAN
>-&gt;<SPAN
CLASS="guisubmenu"
>Networking</SPAN
>.</P
></LI
><LI
><P
>RedHat Linux comes with <B
CLASS="command"
>redhat-config-network</B
>, which has both a graphical and a text mode interface.</P
></LI
><LI
><P
>Suse's YAST or YAST2 is an all-in-one configuration tool.</P
></LI
><LI
><P
>Mandrake/Mandriva comes with a Network and Internet Configuration Wizard, which is preferably started up from Mandrake's Control Center.</P
></LI
><LI
><P
>On Gnome systems: <B
CLASS="command"
>gnome-network-preferences</B
>.</P
></LI
><LI
><P
>On KDE systems: <B
CLASS="command"
>knetworkconf</B
>.</P
></LI
></UL
><P
>Your system documentation provides plenty of advice and information about availability and use of tools.</P
><P
>Information that you will need to provide:</P
><P
></P
><UL
><LI
><P
>For connecting to the local network, for instance with your home computers, or at work: hostname, domainname and IP address. If you want to set up your own network, best do some more reading first. At work, this information is likely to be given to your computer automatically when you boot it up. When in doubt, it is better not to specify any information than making it up.</P
></LI
><LI
><P
>For connecting to the Internet: username and password for your ISP, telephone number when using a modem. Your ISP usually automatically assigns you an IP address and all the other things necessary for your Internet applications to work.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_02_02"
></A
>10.2.2. Network configuration files</H2
><P
>The graphical helper tools edit a specific set of network configuration files, using a couple of basic commands. The exact names of the configuration files and their location in the file system is largely dependent on your Linux distribution and version. However, a couple of network configuration files are common on all UNIX systems:</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_02_01"
></A
>10.2.2.1. /etc/hosts</H3
><P
>The <TT
CLASS="filename"
>/etc/hosts</TT
> file always contains the <EM
>localhost</EM
> IP address, 127.0.0.1, which is used for interprocess communication. Never remove this line! Sometimes contains addresses of additional hosts, which can be contacted without using an external naming service such as DNS (the Domain Name Server).</P
><P
>A sample <TT
CLASS="filename"
>hosts</TT
> file for a small home network:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.52.10 tux.mylan.com tux
192.168.52.11 winxp.mylan.com winxp
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Read more in <B
CLASS="command"
>man <TT
CLASS="filename"
>hosts</TT
></B
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_02_02"
></A
>10.2.2.2. /etc/resolv.conf</H3
><P
>The <TT
CLASS="filename"
>/etc/resolv.conf</TT
> file configures access to a DNS server, see <A
HREF="#sect_10_04_07"
>Section 10.3.7</A
>. This file contains your domain name and the name server(s) to contact:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;search mylan.com
nameserver 193.134.20.4
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Read more in the <TT
CLASS="filename"
>resolv.conf</TT
> man page.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_02_03"
></A
>10.2.2.3. /etc/nsswitch.conf</H3
><P
>The <TT
CLASS="filename"
>/etc/nsswitch.conf</TT
> file defines the order in which to contact different name services. For Internet use, it is important that <EM
>dns</EM
> shows up in the <SPAN
CLASS="QUOTE"
>"hosts"</SPAN
> line:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[bob@tux ~]</TT
> <B
CLASS="command"
>grep hosts /etc/nsswitch.conf</B
>
hosts: files dns
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This instructs your computer to look up hostnames and IP addresses first in the <TT
CLASS="filename"
>/etc/hosts</TT
> file, and to contact the DNS server if a given host does not occur in the local <TT
CLASS="filename"
>hosts</TT
> file. Other possible name services to contact are LDAP, NIS and NIS+.</P
><P
>More in <B
CLASS="command"
>man <TT
CLASS="filename"
>nsswitch.conf</TT
></B
>.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_02_03"
></A
>10.2.3. Network configuration commands</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_02_03_01"
></A
>10.2.3.1. The ip command</H3
><P
>The distribution-specific scripts and graphical tools are front-ends to <B
CLASS="command"
>ip</B
> (or <B
CLASS="command"
>ifconfig</B
> and <B
CLASS="command"
>route</B
> on older systems) to display and configure the kernel's networking configuration.</P
><P
>The <B
CLASS="command"
>ip</B
> command is used for assigning IP addresses to interfaces, for setting up routes to the Internet and to other networks, for displaying TCP/IP configurations etcetera.</P
><P
>The following commands show IP address and routing information:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>benny@home benny&#62;</TT
> <B
CLASS="command"
>ip addr show</B
>
1: lo: &#60;LOOPBACK,UP&#62; 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: &#60;BROADCAST,MULTICAST,UP&#62; 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
<TT
CLASS="prompt"
>benny@home benny&#62;</TT
> <B
CLASS="command"
>ip route show</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Things to note:</P
><P
></P
><UL
><LI
><P
>two network interfaces, even on a system that has only one network interface card: <SPAN
CLASS="QUOTE"
>"lo"</SPAN
> is the local loop, used for internal network communication; <SPAN
CLASS="QUOTE"
>"eth0"</SPAN
> is a common name for a <EM
>real</EM
> interface. Do not ever change the local loop configuration, or your machine will start mallfunctioning! Wireless interfaces are usually defined as <SPAN
CLASS="QUOTE"
>"wlan0"</SPAN
>; modem interfaces as <SPAN
CLASS="QUOTE"
>"ppp0"</SPAN
>, but there might be other names as well.</P
></LI
><LI
><P
>IP addresses, marked with <SPAN
CLASS="QUOTE"
>"inet"</SPAN
>: the local loop always has 127.0.0.1, the physical interface can have any other combination.</P
></LI
><LI
><P
>The hardware address of your interface, which might be required as part of the authentication procedure to connect to a network, is marked with <SPAN
CLASS="QUOTE"
>"ether"</SPAN
>. The local loop has 6 pairs of all zeros, the physical loop has 6 pairs of hexadecimal characters, of which the first 3 pairs are vendor-specific.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_03_02"
></A
>10.2.3.2. The ifconfig command</H3
><P
>While <B
CLASS="command"
>ip</B
> is the most novel way to configure a Linux system, <B
CLASS="command"
>ifconfig</B
> is still very popular. Use it without option for displaying network interface information:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>els@asus:~$</TT
> <B
CLASS="command"
>/sbin/ifconfig</B
>
eth0 Link encap:Ethernet HWaddr 00:50:70:31:2C:14
inet addr:60.138.67.31 Bcast:66.255.255.255 Mask:255.255.255.192
inet6 addr: fe80::250:70ff:fe31:2c14/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31977764 errors:0 dropped:0 overruns:0 frame:0
TX packets:51896866 errors:0 dropped:0 overruns:0 carrier:0
collisions:802207 txqueuelen:1000
RX bytes:2806974916 (2.6 GiB) TX bytes:2874632613 (2.6 GiB)
Interrupt:11 Base address:0xec00
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:765762 errors:0 dropped:0 overruns:0 frame:0
TX packets:765762 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:624214573 (595.2 MiB) TX bytes:624214573 (595.2 MiB)
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Here, too, we note the most important aspects of the interface configuration:</P
><P
></P
><UL
><LI
><P
>The IP address is marked with <SPAN
CLASS="QUOTE"
>"inet addr"</SPAN
>.</P
></LI
><LI
><P
>The hardware address follows the <SPAN
CLASS="QUOTE"
>"HWaddr"</SPAN
> tag.</P
></LI
></UL
><P
>Both <B
CLASS="command"
>ifconfig</B
> and <B
CLASS="command"
>ip</B
> display more detailed configuration information and a number of statistics about each interface and, maybe most important, whether it is <SPAN
CLASS="QUOTE"
>"UP"</SPAN
> and <SPAN
CLASS="QUOTE"
>"RUNNING"</SPAN
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_03_03"
></A
>10.2.3.3. PCMCIA commands</H3
><P
>On your laptop which you usually connect to the company network using the onboard Ethernet connection, but which you are now to configure for dial-in at home or in a hotel, you might need to activate the PCMCIA card. This is done using the <B
CLASS="command"
>cardctl</B
> control utility, or the <B
CLASS="command"
>pccardctl</B
> on newer distributions.</P
><P
>A usage example:</P
><P
><B
CLASS="command"
>cardctl <TT
CLASS="parameter"
><I
>insert</I
></TT
></B
> </P
><P
>Now the card can be configured, either using the graphical or the command line interface. Prior to taking the card out, use this command:</P
><P
><B
CLASS="command"
>cardctl <TT
CLASS="parameter"
><I
>eject</I
></TT
></B
> </P
><P
>However, a good distribution should provide PCMCIA support in the network configuration tools, preventing users from having to execute PCMCIA commands manually.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_03_04"
></A
>10.2.3.4. More information</H3
><P
>Further discussion of network configuration is out of the scope of this document. Your primary source for extra information is the man pages for the services you want to set up. Additional reading:</P
><P
></P
><UL
><LI
><P
><A
HREF="http://www.tldp.org/HOWTO/Modem-HOWTO.html"
TARGET="_top"
>The Modem-HOWTO</A
>: Help with selecting, connecting, configuring, trouble-shooting, and understanding analog modems for a PC.</P
></LI
><LI
><P
><A
HREF="http://www.tldp.org/HOWTO/HOWTO-INDEX/networking.html#NETGENERAL"
TARGET="_top"
>LDP HOWTO Index, section 4.4</A
>: categorized list of HOWTOs about general networking, protocols, dial-up, DNS, VPNs, bridging, routinfg, security and more.</P
></LI
><LI
><P
>Most systems have a version of the <TT
CLASS="filename"
>ip-cref</TT
> file (locate it using the <B
CLASS="command"
>locate</B
> command); the PS format of this file is viewable with for instance <B
CLASS="command"
>gv</B
>.</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_02_04"
></A
>10.2.4. Network interface names</H2
><P
>On a Linux machine, the device name <EM
>lo</EM
> or the <EM
>local loop</EM
> is linked with the internal 127.0.0.1 address. The computer will have a hard time making your applications work if this device is not present; it is always there, even on computers which are not networked.</P
><P
>The first ethernet device, <EM
>eth0</EM
> in the case of a standard network interface card, points to your local LAN IP address. Normal client machines only have one network interface card. Routers, connecting networks together, have one network device for each network they serve.</P
><P
>If you use a modem to connect to the Internet, your network device will probably be named <EM
>ppp0</EM
>.</P
><P
>There are many more names, for instance for Virtual Private Network interfaces (VPNs), and multiple interfaces can be active simultaneously, so that the output of the <B
CLASS="command"
>ifconfig</B
> or <B
CLASS="command"
>ip</B
> commands might become quite extensive when no options are used. Even multiple interfaces of the same type can be active. In that case, they are numbered sequentially: the first will get the number 0, the second will get a suffix of 1, the third will get 2, and so on. This is the case on many application servers, on machines which have a failover configuration, on routers, firewalls and many more.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_02_05"
></A
>10.2.5. Checking the host configuration with netstat</H2
><P
>Apart from the <B
CLASS="command"
>ip</B
> command for displaying the network configuration, there's the common <B
CLASS="command"
>netstat</B
> command which has a lot of options and is generally useful on any UNIX system.</P
><P
>Routing information can be displayed with the <TT
CLASS="option"
>-nr</TT
> option to the <B
CLASS="command"
>netstat</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bob:~&#62;</TT
> <B
CLASS="command"
>netstat -nr</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This is a typical client machine in an IP network. It only has one network device, <EM
>eth0</EM
>. The <EM
>lo</EM
> interface is the local loop.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>The modern way</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The novel way to get this info from your system is by using the <B
CLASS="command"
>ip</B
> command:</P
><P
><B
CLASS="command"
>ip <TT
CLASS="parameter"
><I
>route show</I
></TT
></B
> </P
></TD
></TR
></TABLE
></DIV
><P
>When this machine tries to contact a host that is on another network than its own, indicated by the line starting with 0.0.0.0, it will send the connection requests to the machine (router) with IP address 192.168.42.1, and it will use its primary interface, eth0, to do this.</P
><P
>Hosts that are on the same network, the line starting with 192.168.42.0, will also be contacted through the primary network interface, but no router is necessary, the data are just put on the network.</P
><P
>Machines can have much more complicated routing tables than this one, with lots of different <SPAN
CLASS="QUOTE"
>"Destination-Gateway"</SPAN
> pairs to connect to different networks. If you have the occasion to connect to an application server, for instance at work, it is most educating to check the routing information.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_02_06"
></A
>10.2.6. Other hosts</H2
><P
>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.</P
><P
>We will only discuss some common UNIX/Linux text tools in this section.</P
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_06_01"
></A
>10.2.6.1. The host command</H3
><P
>To display information on hosts or domains, use the <B
CLASS="command"
>host</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[emmy@pc10 emmy]$</TT
> <B
CLASS="command"
>host www.eunet.be</B
>
www.eunet.be. has address 193.74.208.177
<TT
CLASS="prompt"
>[emmy@pc10 emmy]$</TT
> <B
CLASS="command"
>host -t any eunet.be</B
>
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.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Similar information can be displayed using the <B
CLASS="command"
>dig</B
> command, which gives additional information about how records are stored in the name server.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_06_02"
></A
>10.2.6.2. The ping command</H3
><P
>To check if a host is alive, use <B
CLASS="command"
>ping</B
>. If your system is configured to send more than one packet, interrupt <B
CLASS="command"
>ping</B
> with the <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>C</B
> key combination:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[emmy@pc10 emmy]$</TT
> <B
CLASS="command"
>ping a.host.be </B
>
PING a.host.be (1.2.8.3) from 80.20.84.26: 56(84) bytes of data.
64 bytes from a.host.be(1.2.8.3):icmp_seq=0 ttl=244 time=99.977msec
--- 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
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_06_03"
></A
>10.2.6.3. The traceroute command</H3
><P
>To check the route that packets follow to a network host, use the <B
CLASS="command"
>traceroute</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[emmy@pc10 emmy]$</TT
> <B
CLASS="command"
>/usr/sbin/traceroute www.eunet.be</B
>
traceroute to www.eunet.be(193.74.208.177),30 hops max,38b packets
1 blob (10.0.0.1)
0.297ms 0.257ms 0.174ms
2 adsl-65.myprovider.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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>On some systems, <B
CLASS="command"
>traceroute</B
> has been renamed to <B
CLASS="command"
>tracepath</B
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_02_06_04"
></A
>10.2.6.4. The whois command</H3
><P
>Specific domain name information can be queried using the <B
CLASS="command"
>whois</B
> command, as is explained by many <B
CLASS="command"
>whois</B
> servers, like the one below:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[emmy@pc10 emmy]$</TT
> <B
CLASS="command"
>whois cnn.com</B
>
[whois.crsnic.net]
Whois Server Version 1.3
$&#60;--snap server message--&#62;
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
&#62;&#62;&#62; Last update of whois database: Fri, 5 Apr 2002 05:04:55 EST &#60;&#60;&#60;
The Registry database contains ONLY .COM, .NET, .ORG, .EDU domains
and Registrars.
[whois.networksolutions.com]
$&#60;--snap server message--&#62;
Registrant:
Turner Broadcasting (CNN-DOM)
1 CNN Center
Atlanta, GA 30303
Domain Name: CNN.COM
Administrative Contact:
$&#60;--snap contactinfo--&#62;
Technical Contact:
$&#60;--snap contactinfo--&#62;
Billing Contact:
$&#60;--snap contactinfo--&#62;
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>For other domain names than .com, .net, .org and .edu, you might need to specify the whois server, such as this one for .be domains:</P
><P
><B
CLASS="command"
>whois <TT
CLASS="parameter"
><I
>domain.be@whois.dns.be</I
></TT
></B
> </P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_04"
></A
>10.3. Internet/Intranet applications</H1
><P
>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.</P
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_01"
></A
>10.3.1. Server types</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_04_01_01"
></A
>10.3.1.1. Standalone server</H3
><P
>Offering a service to users can be approached in two ways. A daemon or service can run in standalone mode, or it can be dependent on another service to be activated.</P
><P
>Network services that are heavily and/or continuously used, usually run in the standalone mode: they are independent program daemons that are always running. They are most likely started up at system boot time, and they wait for requests on the specific connection points or ports for which they are set up to listen. When a request comes, it is processed, and the listening continues until the next request. A web server is a typical example: you want it to be available 24 hours a day, and if it is too busy it should create more listening instances to serve simultaneous users. Other examples are the large software archives such as <A
HREF="http://sourceforge.net"
TARGET="_top"
>Sourceforge</A
> or <A
HREF="http://tucows.com"
TARGET="_top"
>your Tucows mirror</A
>, which must handle thousands of FTP requests per day.</P
><P
>An example of a standalone network service on your home computer might be the <B
CLASS="command"
>named</B
> (name daemon), a caching name server. Standalone services have their own processes running, you can check any time using <B
CLASS="command"
>ps</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bob:~&#62;</TT
> <B
CLASS="command"
>ps auxw | grep named</B
>
named 908 0.0 1.0 14876 5108 ? S Mar14 0:07 named -u named
</PRE
></FONT
></TD
></TR
></TABLE
><P
>However, there are some services that you can use on your PC, even if there is no server process running for that services. Examples could be the FTP service, the secure copy service or the finger service. Those services have the Internet Daemon (<B
CLASS="command"
>inetd</B
>) listening in their place.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_01_02"
></A
>10.3.1.2. (x)inetd</H3
><P
>On your home PC, things are usually a bit calmer. You may have a small network, for instance, and you may have to transfer files from one PC to another from time to time, using FTP or Samba (for connectivity with MS Windows machines). In those cases, starting all the services which you only need occasionally and having them run all the time would be a waste of resources. So in smaller setups, you will find the necessary daemons dependent on a central program, that listen on all the ports of the services for which it is responsible.</P
><P
>This super-server, the Internet services daemon, is started up at system initialization time. There are two common implementations: <B
CLASS="command"
>inetd</B
> and <B
CLASS="command"
>xinetd</B
> (the extended Internet services daemon). One or the other is usually running on every Linux system:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bob:~&#62;</TT
> <B
CLASS="command"
>ps -ef | grep inet</B
>
root 926 1 0 Mar14 ? 00:00:00 xinetd-ipv6 -stayalive -reuse \
-pidfile /var/run/xinetd.pid
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The services for which the Internet daemon is responsible, are listed in its configuration file, <TT
CLASS="filename"
>/etc/inetd.conf</TT
>, for <B
CLASS="command"
>inetd</B
>, and in the directory <TT
CLASS="filename"
>/etc/xinetd.d</TT
> for <B
CLASS="command"
>xinetd</B
>. Commonly managed services include file share and print services, SSH, FTP, telnet, the Samba configuration daemon, talk and time services.</P
><P
>As soon as a connection request is received, the central server will start an instance of the required server. Thus, in the example below, when user <EM
>bob</EM
> starts an FTP session to the local host, an FTP daemon is running as long as the session is active:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bob:~&#62;</TT
> <B
CLASS="command"
>ps auxw | grep ftp</B
>
bob 793 0.1 0.2 3960 1076 pts/6 S 16:44 0:00 ncftp localhost
ftp 794 0.7 0.5 5588 2608 ? SN 16:44 0:00 ftpd:
localhost.localdomain: anonymous/bob@his.server.com: IDLE
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Of course, the same happens when you open connections to remote hosts: either a daemon answers directly, or a remote <B
CLASS="command"
>(x)inetd</B
> starts the service you need and stops it when you quit.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_02"
></A
>10.3.2. Mail</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_04_02_01"
></A
>10.3.2.1. Servers</H3
><P
><SPAN
CLASS="application"
>Sendmail</SPAN
> 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 <SPAN
CLASS="application"
>Sendmail</SPAN
> is included with the <SPAN
CLASS="application"
>sendmail</SPAN
> and <SPAN
CLASS="application"
>sendmail-cf</SPAN
> packages, you may want to read the <TT
CLASS="filename"
>README</TT
> and <TT
CLASS="filename"
>README.cf</TT
> files in <TT
CLASS="filename"
>/usr/share/doc/sendmail</TT
>. The <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>sendmail</I
></TT
></B
> and <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>aliases</I
></TT
></B
> are also useful.</P
><P
><SPAN
CLASS="application"
>Qmail</SPAN
> is another mail server, gaining popularity because it claims to be more secure than <SPAN
CLASS="application"
>Sendmail</SPAN
>. While <SPAN
CLASS="application"
>Sendmail</SPAN
> is a monolithic program, <SPAN
CLASS="application"
>Qmail</SPAN
> consists of smaller interacting program parts that can be better secured. <SPAN
CLASS="application"
>Postfix</SPAN
> is another mail server which is gaining popularity.</P
><P
>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 <SPAN
CLASS="application"
>Mailman</SPAN
>, <SPAN
CLASS="application"
>Listserv</SPAN
>, <SPAN
CLASS="application"
>Majordomo</SPAN
> and <SPAN
CLASS="application"
>EZmlm</SPAN
>. See the web page of your favorite virus scanner for information on Linux client and server support. <SPAN
CLASS="application"
>Amavis</SPAN
> and <SPAN
CLASS="application"
>Spamassassin</SPAN
> are free implementations of a virus scanner and a spam scanner.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_02_02"
></A
>10.3.2.2. Remote mail servers</H3
><P
>The most popular protocols to access mail remotely are <EM
>POP3</EM
> and <EM
>IMAP4</EM
>. IMAP and POP both allow offline operation, remote access to new mail and they both rely on an SMTP server to send mail.</P
><P
>While POP is a simple protocol, easy to implement and supported by almost any mail client, IMAP is to be preferred because:</P
><P
></P
><UL
><LI
><P
>It can manipulate persistent message status flags.</P
></LI
><LI
><P
>It can store as well as fetch mail messages.</P
></LI
><LI
><P
>It can access and manage multiple mailboxes.</P
></LI
><LI
><P
>It supports concurrent updates and shared mailboxes.</P
></LI
><LI
><P
>It is also suitable for accessing Usenet messages and other documents.</P
></LI
><LI
><P
>IMAP works both on-line and off-line.</P
></LI
><LI
><P
>it is optimized for on-line performance, especially over low-speed links.</P
></LI
></UL
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_02_03"
></A
>10.3.2.3. Mail user-agents</H3
><P
>There are plenty of both text and graphical E-mail clients, we'll just name a few of the common ones. Pick your favorite.</P
><P
>The UNIX <B
CLASS="command"
>mail</B
> 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 etcetera.</P
><P
>While it is not commonly used as a client anymore, the <B
CLASS="command"
>mail</B
> program is still useful, for example to mail the output of a command to somebody:</P
><P
><B
CLASS="command"
>mail <TT
CLASS="email"
>&#60;<A
HREF="mailto:future.employer@whereIwant2work.com"
>future.employer@whereIwant2work.com</A
>&#62;</TT
> &#60; <TT
CLASS="filename"
>cv.txt</TT
></B
> </P
><P
>The <B
CLASS="command"
>elm</B
> mail reader is a much needed improvement to <B
CLASS="command"
>mail</B
>, and so is <B
CLASS="command"
>pine</B
> (Pine Is Not ELM). The <B
CLASS="command"
>mutt</B
> mail reader is even more recent and offers features like threading.</P
><P
>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 for new users are Mozilla Mail/Thunderbird, which has easy anti-spam configuring options, and Evolution, the MS Outlook clone. Kmail is popular among KDE users.</P
><DIV
CLASS="figure"
><A
NAME="AEN10332"
></A
><P
><B
>Figure 10-1. Evolution mail and news reader</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/evolution.png"></P
></DIV
></DIV
><P
>There are also tens of web mail applications available, such as <SPAN
CLASS="application"
>Squirrelmail</SPAN
>, <SPAN
CLASS="application"
>Yahoo!</SPAN
> mail, <SPAN
CLASS="application"
>gmail</SPAN
> from Google and <SPAN
CLASS="application"
>Hotmail</SPAN
>.</P
><P
>An overview is available via the <A
HREF="http://www.tldp.org/HOWTO/Mail-User-HOWTO/index.html"
TARGET="_top"
>Linux Mail User HOWTO</A
>.</P
><P
>Most Linux distributions include <B
CLASS="command"
>fetchmail</B
>, 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 <TT
CLASS="filename"
>/usr/share/doc/fetchmail[-&#60;version&#62;]</TT
> contains a full list of features and a FAQ for beginners.</P
><P
>The <B
CLASS="command"
>procmail</B
> filter can be used for filtering incoming mail, to create mailing lists, to pre-process mail, to selectively forward mail and more. The accompanying <B
CLASS="command"
>formail</B
> 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 <TT
CLASS="filename"
>/usr/share/doc/procmail[-&#60;version&#62;]</TT
> directory and in the man pages.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>A note on E-mail Etiquette</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Some people these days seem to think that an E-mail message shouldn't be too formal. That depends, of course. If you are writing to someone you don't know, best to keep some distance, just like you would do in a traditional letter. And don't forget: people you don't know might be male or female...
</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_03"
></A
>10.3.3. Web</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_04_03_01"
></A
>10.3.3.1. The Apache Web Server</H3
><P
><SPAN
CLASS="application"
>Apache</SPAN
> is by far the most popular web server, used on more than half of all Internet web servers. Most Linux distributions include <SPAN
CLASS="application"
>Apache</SPAN
>. <SPAN
CLASS="application"
>Apache</SPAN
>'s advantages include its modular design, SSL support, stability and speed. Given the appropriate hardware and configuration it can support the highest loads.</P
><P
>On Linux systems, the server configuration is usually done in the <TT
CLASS="filename"
>/etc/httpd</TT
> directory. The most important configuration file is <TT
CLASS="filename"
>httpd.conf</TT
>; it is rather self-explanatory. Should you need help, you can find it in the <B
CLASS="command"
>httpd</B
> man page or on the <A
HREF="http://www.apache.org"
TARGET="_top"
>Apache website</A
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_03_02"
></A
>10.3.3.2. Web browsers</H3
><P
>A number of web browsers, both free and commercial, exist for the Linux platform. <SPAN
CLASS="application"
>Netscape Navigator</SPAN
> as the only decent option has long been a thing of the past, as <SPAN
CLASS="application"
>Mozilla/Firefox</SPAN
> offers a competitive alternative running on many other operating systems, like MS Windows and MacOS X as well.</P
><P
>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 <B
CLASS="command"
>nautilus</B
>.</P
><P
>Among the popular text based browsers are <B
CLASS="command"
>lynx</B
> and <B
CLASS="command"
>links</B
>. You may need to define proxy servers in your shell, by setting the appropriate variables. Text browsers are fast and handy when no graphical environment is available, such as when used in scripts.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_03_03"
></A
>10.3.3.3. Proxy servers</H3
><DIV
CLASS="sect4"
><H4
CLASS="sect4"
><A
NAME="sect_10_04_03_03_01"
></A
>10.3.3.3.1. What is a proxy server?</H4
><P
>Companies and organizations often want their users to use a proxy server. Especially in environments with lots of users, a proxy server can enable faster downloads of web pages. The proxy server stores web pages. When a user asks for a web page that has already been requested previously, the proxy server will give that page to the user directly, so that s/he does not need to get it from the Internet, which would take longer. Of course, measures can be taken so that the proxy server does a quick check and always serves the most recent version of a page. In some environments, usage of the proxy server is compulsory, in other environments you may have the choice whether or not to use it.</P
></DIV
><DIV
CLASS="sect4"
><HR><H4
CLASS="sect4"
><A
NAME="sect_10_04_03_03_02"
></A
>10.3.3.3.2. Proxy configuration</H4
><P
>If you have the proxy server name and port, it should be rather obvious to feed that information into your browser. However, many (command line) applications depend on the variables <TT
CLASS="varname"
>http_proxy</TT
> and <TT
CLASS="varname"
>ftp_proxy</TT
> for correct functioning. For your convenience, you might want to add a line like the following to your <TT
CLASS="filename"
>~/.bashrc</TT
>:</P
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>http_proxy</TT
>=<TT
CLASS="parameter"
><I
>http://username:password@proxy_server_name:port_number</I
></TT
></B
> </P
><P
>For instance:</P
><P
><B
CLASS="command"
>export <TT
CLASS="varname"
>http_proxy</TT
>=<TT
CLASS="parameter"
><I
>http://willy:Appelsi3ntj3@proxy:80</I
></TT
></B
> </P
><P
>If you do not need to give a username and password, simply leave out everything before the <SPAN
CLASS="QUOTE"
>"@"</SPAN
> sign, this sign included.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_04"
></A
>10.3.4. File Transfer Protocol</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_04_04_01"
></A
>10.3.4.1. FTP servers</H3
><P
>On a Linux system, an FTP server is typically run from <B
CLASS="command"
>xinetd</B
>, using the <SPAN
CLASS="application"
>WU-ftpd</SPAN
> server, although the FTP server may be configured as a stand-alone server on systems with heavy FTP traffic. See the exercises.</P
><P
>Other FTP servers include among others <SPAN
CLASS="application"
>vsftpd</SPAN
>, <SPAN
CLASS="application"
>Ncftpd</SPAN
> and <SPAN
CLASS="application"
>Proftpd</SPAN
>.</P
><P
>Most Linux distributions contain the <SPAN
CLASS="application"
>anonftp</SPAN
> package, which sets up an anonymous FTP server tree and accompanying configuration files.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_04_02"
></A
>10.3.4.2. FTP clients</H3
><P
>Most Linux distributions include <B
CLASS="command"
>ncftp</B
>, an improved version of the common UNIX <B
CLASS="command"
>ftp</B
> command, which you may also know from the Windows command line. The <B
CLASS="command"
>ncftp</B
> 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:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>thomas:~&#62;</TT
> <B
CLASS="command"
>ncftp blob</B
>
NcFTP 3.0.3 (April 15, 2001) by Mike Gleason (ncftp@ncftp.com).
Connecting to blob...
blob.some.net FTP server (Version wu-2.6.1-20) ready.
Logging in...
Guest login ok, access restrictions apply.
Logged in to blob.
<TT
CLASS="prompt"
>ncftp / &#62;</TT
> <B
CLASS="command"
>help</B
>
Commands may be abbreviated. 'help showall' shows hidden and
unsupported commands.
'help &#60;command&#62;' gives a brief description of &#60;command&#62;.
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
<TT
CLASS="prompt"
>ncftp / &#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Excellent help with lot of examples can be found in the man pages. And again, a number of GUI applications are available.</P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>FTP is insecure!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Don't use the File Transfer Protocol for non-anonymous login unless you know what you are doing. Your user name and password might be captured by malevolent fellow network users! Use secure FTP instead; the <B
CLASS="command"
>sftp</B
> program comes with the Secure SHell suite, see <A
HREF="#sect_10_05_04_04"
>Section 10.4.4.4</A
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_05"
></A
>10.3.5. Chatting and conferencing</H2
><P
>Various clients and systems are available in each distribution, replacing the old-style IRC text-based chat. A short and incomplete list of the most popular programs:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>gaim</B
>: multi-protocol instant messaging client for Linux, Windows and Mac, compatible with MSN Messenger, ICQ, IRC and much more; see the Info pages or <A
HREF="http://gaim.sourceforge.net"
TARGET="_top"
>the Gaim site</A
> for more.</P
></LI
><LI
><P
><B
CLASS="command"
>xchat</B
>: IRC client for the X window system:</P
><DIV
CLASS="figure"
><A
NAME="AEN10492"
></A
><P
><B
>Figure 10-2. X-Chat</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/xchat.png"></P
></DIV
></DIV
><P
>The home page is at <A
HREF="http://sourceforge.net/projects/xchat/"
TARGET="_top"
>SourceForge</A
>.</P
></LI
><LI
><P
>aMSN: an MSN clone.</P
></LI
><LI
><P
><B
CLASS="command"
>Konversation</B
>, <B
CLASS="command"
>kopete</B
>, <B
CLASS="command"
>KVIrc</B
> and many other K-tools from the KDE suite.</P
></LI
><LI
><P
><B
CLASS="command"
>gnomemeeting</B
>: videoconferencing program for UNIX (now <SPAN
CLASS="application"
>Ekiga</SPAN
>).</P
></LI
><LI
><P
><B
CLASS="command"
>jabber</B
>: Open Source Instant Messenging platform, compatible with ICQ, AIM, Yahoo, MSN, IRC, SMTP and much more.</P
></LI
><LI
><P
><B
CLASS="command"
>psi</B
>: jabber client, see <A
HREF="http://psi.affinix.com/"
TARGET="_top"
>the PSI Jabber Client Homepage</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>skype</B
>: program for making telephone-like calls over the Internet to other <SPAN
CLASS="application"
>Skype</SPAN
> users, see <A
HREF="http://www.skype.com"
TARGET="_top"
>http://www.skype.com</A
> for more info. <SPAN
CLASS="application"
>Skype</SPAN
> is free but not open.</P
></LI
><LI
><P
><SPAN
CLASS="application"
>Gizmo</SPAN
>: a free (but not open) phone for your computer, see <A
HREF="http://www.gizmoproject.com"
TARGET="_top"
>http://www.gizmoproject.com</A
>.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_06"
></A
>10.3.6. News services</H2
><P
>Running a <SPAN
CLASS="application"
>Usenet</SPAN
> server involves a lot of expertise and fine-tuning, so refer to the <A
HREF="http://www.isc.org"
TARGET="_top"
>INN homepage</A
> for more information.</P
><P
>There are a couple of interesting newsgroups in the <EM
>comp.*</EM
> 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 <B
CLASS="command"
>tin</B
>, <B
CLASS="command"
>slrnn</B
> and <B
CLASS="command"
>mutt</B
>, or download Mozilla or one of a number of other graphical clients.</P
><P
><A
HREF="http://deja.com"
TARGET="_top"
>Deja.com</A
> keeps a searchable archive of all newsgroups, powered by Google. This is a very powerful instrument for getting help: chances are very high that somebody has encountered your problem, found a solution and posted it in one of the newsgroups.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_07"
></A
>10.3.7. The Domain Name System</H2
><P
>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 <B
CLASS="command"
>named</B
>, which is part of the BIND (<SPAN
CLASS="application"
>Berkeley Internet Name Domain</SPAN
>) package distributed by the Internet Software Consortium. It can run as a stand-alone caching <EM
>nameserver</EM
>, which is often done on Linux systems in order to speed up network access.</P
><P
>Your main client configuration file is <TT
CLASS="filename"
>/etc/resolv.conf</TT
>, which determines the order in which Domain Name Servers are contacted:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;search somewhere.org
nameserver 192.168.42.1
nameserver 193.74.208.137
</PRE
></FONT
></TD
></TR
></TABLE
><P
>More information can be found in the Info pages on <B
CLASS="command"
>named</B
>, in the <TT
CLASS="filename"
>/usr/share/doc/bind[-&#60;version&#62;]</TT
> files and on the <A
HREF="http://www.isc.org/products/BIND"
TARGET="_top"
>Bind project</A
> homepage. The <A
HREF="http://www.tldp.org/HOWTO/DNS-HOWTO.html"
TARGET="_top"
>DNS HOWTO</A
> covers the use of BIND as a DNS server.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_08"
></A
>10.3.8. DHCP</H2
><P
>DHCP is the <SPAN
CLASS="application"
>Dynamic Host Configuration Protocol</SPAN
>, which is gradually replacing good old <B
CLASS="command"
>bootp</B
> 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 <B
CLASS="command"
>bootp</B
>. For configuring the server, you will need to read the HOWTO.</P
><P
>DHCP client machines will usually be configured using a GUI that configures the <B
CLASS="command"
>dhcpcd</B
>, the DHCP client daemon. Check your system documentation if you need to configure your machine as a DHCP client.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_04_09"
></A
>10.3.9. Authentication services</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_04_09_01"
></A
>10.3.9.1. Traditional</H3
><P
>Traditionally, users are authenticated locally, using the information stored in <TT
CLASS="filename"
>/etc/passwd</TT
> and <TT
CLASS="filename"
>/etc/shadow</TT
> on each system. But even when using a network service for authenticating, the local files will always be present to configure system accounts for administrative use, such as the root account, the daemon accounts and often accounts for additional programs and purposes.</P
><P
>These files are often the first candidates for being examined by hackers, so make sure the permissions and ownerships are strictly set as should be:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bob:~&#62;</TT
> <B
CLASS="command"
>ls -l /etc/passwd /etc/shadow</B
>
-rw-r--r-- 1 root root 1803 Mar 10 13:08 /etc/passwd
-r-------- 1 root root 1116 Mar 10 13:08 /etc/shadow
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_09_02"
></A
>10.3.9.2. PAM</H3
><P
>Linux can use PAM, the <SPAN
CLASS="application"
>Pluggable Authentication Module</SPAN
>, a flexible method of UNIX authentication. Advantages of PAM:</P
><P
></P
><UL
><LI
><P
>A common authentication scheme that can be used with a wide variety of applications.
</P
></LI
><LI
><P
>PAM can be implemented with various applications without having to recompile the applications to specifically support PAM.</P
></LI
><LI
><P
>Great flexibility and control over authentication for the administrator and application developer.
</P
></LI
><LI
><P
>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.</P
></LI
></UL
><P
>The directory <TT
CLASS="filename"
>/etc/pam.d</TT
> contains the PAM configuration files (used to be <TT
CLASS="filename"
>/etc/pam.conf</TT
>). Each application or service has its own file. Each line in the file has four elements:</P
><P
></P
><UL
><LI
><P
><EM
>Module</EM
>:</P
><P
></P
><UL
><LI
><P
><TT
CLASS="option"
>auth</TT
>: provides the actual authentication (perhaps asking for and checking a password) and sets credentials, such as group membership or Kerberos tickets.</P
></LI
><LI
><P
><TT
CLASS="option"
>account</TT
>: 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).</P
></LI
><LI
><P
><TT
CLASS="option"
>password</TT
>: used to set passwords.</P
></LI
><LI
><P
><TT
CLASS="option"
>session</TT
>: 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).</P
></LI
></UL
><P
>The order in which modules are stacked, so that multiple modules can be used, is very important.</P
></LI
><LI
><P
><EM
>Control Flags</EM
>: tell PAM which actions to take upon failure or success. Values can be <TT
CLASS="option"
>required</TT
>, <TT
CLASS="option"
>requisite</TT
>, <TT
CLASS="option"
>sufficient</TT
> or <TT
CLASS="option"
>optional</TT
>.</P
></LI
><LI
><P
><EM
>Module Path</EM
>: path to the pluggable module to be used, usually in <TT
CLASS="filename"
>/lib/security</TT
>.</P
></LI
><LI
><P
><EM
>Arguments</EM
>: information for the modules</P
></LI
></UL
><P
>Shadow password files are automatically detected by PAM.</P
><P
>More information can be found in the <B
CLASS="command"
>pam</B
> man pages or at <A
HREF="http://www.kernel.org/pub/linux/libs/pam"
TARGET="_top"
>the Linux-PAM project</A
> homepage.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_04_09_03"
></A
>10.3.9.3. LDAP</H3
><P
>The Lightweight Directory Access Protocol is a client-server system for accessing global or local directory services over a network. On Linux, the <SPAN
CLASS="application"
>OpenLDAP</SPAN
> implementation is used. It includes <B
CLASS="command"
>slapd</B
>, a stand-alone server; <B
CLASS="command"
>slurpd</B
>, a stand-alone LDAP replication server; libraries implementing the LDAP protocol and a series of utilities, tools and sample clients.</P
><P
> 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.
</P
><P
>&#13;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.
</P
><P
>&#13;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.
</P
><P
> 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.</P
><P
>See your system specific information and the man pages for related commands such as <B
CLASS="command"
>ldapmodify</B
> and <B
CLASS="command"
>ldapsearch</B
> for details. More information can be found in the <A
HREF="http://www.tldp.org/HOWTO/LDAP-HOWTO.html"
TARGET="_top"
>LDAP Linux HOWTO</A
>, which discusses installation, configuration, running and maintenance of an LDAP server on Linux. The author of this Introduction to Linux document also wrote an <A
HREF="http://tille.garrels.be/training/ldap/"
TARGET="_top"
>LDAP Operations HOWTO</A
>, describing the basics everyone should know about when dealing with LDAP management, operations and integration of services.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_05"
></A
>10.4. Remote execution of applications</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_10_05_01"
></A
>10.4.1. Introduction</H2
><P
>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.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_05_02"
></A
>10.4.2. Rsh, rlogin and telnet</H2
><P
>The <B
CLASS="command"
>rlogin</B
> and <B
CLASS="command"
>rsh</B
> commands for remote login and remote execution of commands are inherited from UNIX. While seldom used because they are blatantly insecure, they still come with almost every Linux distribution for backward compatibility with UNIX programs.</P
><P
>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.</P
><P
>Because the entire connection is unencrypted, allowing <B
CLASS="command"
>telnet</B
> connections involves taking high security risks. For normal remote execution of programs, <SPAN
CLASS="application"
>Secure SHell</SPAN
> or <B
CLASS="command"
>ssh</B
> is advised. We will discuss the secure method later in this section.</P
><P
>However, <B
CLASS="command"
>telnet</B
> is still used in many cases. Below are some examples in which a mail server and a web server are tested for replies:</P
><P
>Checking that a mail server works:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[jimmy@blob ~]</TT
> <B
CLASS="command"
>telnet mailserver 25</B
>
Trying 192.168.42.1...
Connected to mailserver.
Escape character is '^]'.
220 m1.some.net ESMTP Sendmail 8.11.6/8.11.6; 200302281626
<B
CLASS="command"
>ehlo some.net</B
>
250-m1.some.net Hello blob.some.net [10.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE
250-DSN
250-ONEX
250-ETRN
250-XUSR
250 HELP
<B
CLASS="command"
>mail from: jimmy@some.net</B
>
250 2.1.0 jimmy@some.net... Sender ok
<B
CLASS="command"
>rcpt to: davy@some.net</B
>
250 2.1.5 davy@some.net... Recipient ok
<B
CLASS="command"
>data</B
>
354 Enter mail, end with "." on a line by itself
<B
CLASS="command"
>test</B
>
<B
CLASS="command"
>.</B
>
250 2.0.0 g2MA1R619237 Message accepted for delivery
<B
CLASS="command"
>quit</B
>
221 2.0.0 m1.some.net closing connection
Connection closed by foreign host.
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Checking that a web server answers to basic requests:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[jimmy@blob ~]</TT
> <B
CLASS="command"
>telnet www.some.net 80</B
>
Trying 64.39.151.23...
Connected to www.some.net.
Escape character is '^]'.
<B
CLASS="command"
>HEAD / ;HTTP/1.1</B
>
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.
<TT
CLASS="prompt"
>[jimmy@blob ~]</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>This is perfectly safe, because you never have to give a username and/or password for getting the data you want, so nobody can snoop that important information off the cable.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_05_03"
></A
>10.4.3. The X Window System</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_05_03_01"
></A
>10.4.3.1. X features</H3
><P
>As we already explained in Chapter 7 (see <A
HREF="#sect_07_03_03"
>Section 7.3.3</A
>), the <SPAN
CLASS="application"
>X Window</SPAN
> system comes with an X server which serves graphics to clients that need a display.</P
><P
>It is important to realize the distinction between the X server and the X client application(s). The X server controls the display directly and is responsible for all input and output via keyboard, mouse and display. The X client, on the other hand, does not access the input and output devices directly. It communicates with the X server which handles input and output. It is the X client which does the real work, like computing values, running applications and so forth. The X server only opens windows to handle input and output for the specified client.</P
><P
>In normal operation (graphical mode), every Linux workstation is an X server to itself, even if it only runs client applications. All the applications you are running (for example, <SPAN
CLASS="application"
>Gimp</SPAN
>, a terminal window, your browser, your office application, your CD playing tool, and so on) are clients to your X server. Server and client are running on the same machine in this case.</P
><P
>This client/server 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 <A
HREF="http://www.tldp.org/HOWTO/Remote-X-Apps.html"
TARGET="_top"
>Remote X applications mini-HOWTO</A
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_05_03_02"
></A
>10.4.3.2. Telnet and X</H3
><P
>If you would want to use <B
CLASS="command"
>telnet</B
> to display graphical applications running on a remote machine, you first need to give the remote machine access to your display (to your X server!) using the <B
CLASS="command"
>xhost</B
> command, by typing a command similar to the one below in a terminal window on your local machine:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>davy:~&#62;</TT
> <B
CLASS="command"
>xhost +remote.machine.com</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>After that, connect to the remote host and tell it to display graphics on the local machine by setting the environment variable <TT
CLASS="varname"
>DISPLAY</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[davy@remote ~]</TT
> <B
CLASS="command"
>export DISPLAY="local.host.com:0.0"</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>After completing this step, any application started in this terminal window will be displayed on your local desktop, using remote resources for computing, but your local graphical resources (your X server) for displaying the application.</P
><P
>This procedure assumes that you have some sort of X server (<SPAN
CLASS="application"
>XFree86</SPAN
>, <SPAN
CLASS="application"
>X.org</SPAN
>, <SPAN
CLASS="application"
>Exceed</SPAN
>, <SPAN
CLASS="application"
>Cygwin</SPAN
>) already set up on the machine where you want to display images. The architecture and operating system of the client machine are not important as long as they allow you to run an X server on it.</P
><P
>Mind that displaying a terminal window from the remote machine is also considered to be a display of an image.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_05_04"
></A
>10.4.4. The SSH suite</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_05_04_01"
></A
>10.4.4.1. Introduction</H3
><P
>Most UNIX and Linux systems now run <SPAN
CLASS="application"
>Secure SHell</SPAN
> in order to leave out the security risks that came with <B
CLASS="command"
>telnet</B
>. Most Linux systems will run a version of <SPAN
CLASS="application"
>OpenSSH</SPAN
>, 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.</P
><P
>The <B
CLASS="command"
>ssh</B
> client connects and logs into the specified host name. The user must provide his identity to the remote machine as specified in the <TT
CLASS="filename"
>sshd_config</TT
> file, which can usually be found in <TT
CLASS="filename"
>/etc/ssh</TT
>. The configuration file is rather self-explanatory and by defaults enables most common features. Should you need help, you can find it in the <B
CLASS="command"
>sshd</B
> man pages.</P
><P
>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.</P
><P
>The session terminates when the command or shell on the remote machine exits and all X11 and TCP/IP connections have been closed.</P
><P
>When connecting to a host for the first time, using any of the programs that are included in the SSH collection, you need to establish the authenticity of that host and acknowledge that you want to connect:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>lenny ~&#62;</TT
> <B
CLASS="command"
>ssh blob</B
>
The authenticity of host 'blob (10.0.0.1)' can't be established.
RSA fingerprint is 18:30:50:46:ac:98:3c:93:1a:56:35:09:8d:97:e3:1d.
Are you sure you want to continue connecting (yes/no)? <B
CLASS="command"
>yes</B
>
Warning: Permanently added 'blob,192.168.30.2' (RSA) to the list of
known hosts.
Last login: Sat Dec 28 13:29:19 2002 from octarine
This space for rent.
<TT
CLASS="prompt"
>lenny is in ~</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>It is important that you type <SPAN
CLASS="QUOTE"
>"yes"</SPAN
>, in three characters, not just <SPAN
CLASS="QUOTE"
>"y"</SPAN
>. This edits your <TT
CLASS="filename"
>~/.ssh/known_hosts</TT
> file, see <A
HREF="#sect_10_03_04_03"
>Section 10.4.4.3</A
>.</P
><P
>If you just want to check something on a remote machine and then get your prompt back on the local host, you can give the commands that you want to execute remotely as arguments to <B
CLASS="command"
>ssh</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>lenny ~&#62;</TT
> <B
CLASS="command"
>ssh blob who</B
>
jenny@blob's password:
root tty2 Jul 24 07:19
lena tty3 Jul 23 22:24
lena 0: Jul 25 22:03
<TT
CLASS="prompt"
>lenny ~&#62;</TT
> <B
CLASS="command"
>uname -n</B
>
magrat.example.com
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_05_04_02"
></A
>10.4.4.2. X11 and TCP forwarding</H3
><P
>If the <TT
CLASS="varname"
>X11Forwarding</TT
> entry is set to <EM
>yes</EM
> on the target machine and the user is using X applications, the <TT
CLASS="varname"
>DISPLAY</TT
> 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 <TT
CLASS="varname"
>DISPLAY</TT
>. Forwarding of X11 connections can be configured on the command line or in the <B
CLASS="command"
>sshd</B
> configuration file.</P
><P
>The value for <TT
CLASS="varname"
>DISPLAY</TT
> set by <B
CLASS="command"
>ssh</B
> will point to the server machine, but with a display number greater than zero. This is normal, and happens because <B
CLASS="command"
>ssh</B
> creates a <EM
>proxy</EM
> X server on the server machine (that runs the X client application) for forwarding the connections over the encrypted channel.</P
><P
>This is all done automatically, so when you type in the name of a graphical application, it is displayed on your local machine and not on the remote host. We use <B
CLASS="command"
>xclock</B
> in the example, since it is a small program which is generally installed and ideal for testing:</P
><DIV
CLASS="figure"
><A
NAME="AEN10847"
></A
><P
><B
>Figure 10-3. SSH X11 forwarding</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/ssh_X11.png"></P
></DIV
></DIV
><P
>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 <TT
CLASS="filename"
>Xauthority</TT
> 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).</P
><P
>Forwarding of arbitrary TCP/IP connections over the secure channel can be specified either on the command line or in a configuration file.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>The X server</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>This procedure assumes that you have a running X server on the client where you want to display the application from the remote host. The client may be of different architecture and operating system than the remote host, as long as it can run an X server, such as <SPAN
CLASS="application"
>Cygwin</SPAN
> (which implements an <SPAN
CLASS="application"
>X.org</SPAN
> server for MS Windows clients and others) or <SPAN
CLASS="application"
>Exceed</SPAN
>, it should be possible to set up a remote connection with any Linux or UNIX machine.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_03_04_03"
></A
>10.4.4.3. Server authentication</H3
><P
>The <B
CLASS="command"
>ssh</B
> 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 <TT
CLASS="filename"
>$HOME/.ssh/known_hosts</TT
> in the user's home directory. Additionally, the file <TT
CLASS="filename"
>/etc/ssh/ssh_known_hosts</TT
> is automatically checked for known hosts. Any new hosts are automatically added to the user's file. If a host's identification ever changes, <B
CLASS="command"
>ssh</B
> 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, <B
CLASS="command"
>sshd</B
> can even be configured to prevent logins to machines whose host keys have changed or are unknown.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_05_04_04"
></A
>10.4.4.4. Secure remote copying</H3
><P
>The SSH suite provides <B
CLASS="command"
>scp</B
> as a secure alternative to the <B
CLASS="command"
>rcp</B
> command that used to be popular when only <B
CLASS="command"
>rsh</B
> existed. <B
CLASS="command"
>scp</B
> uses <B
CLASS="command"
>ssh</B
> for data transfer, uses the same authentication and provides the same security as <B
CLASS="command"
>ssh</B
>. Unlike <B
CLASS="command"
>rcp</B
>, <B
CLASS="command"
>scp</B
> will ask for passwords or passphrases if they are needed for authentication:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>lenny /var/tmp&#62;</TT
> <B
CLASS="command"
>scp Schedule.sdc.gz blob:/var/tmp/</B
>
lenny@blob's password:
Schedule.sdc.gz 100% |*****************************| 100 KB 00:00
<TT
CLASS="prompt"
>lenny /var/tmp&#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>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.</P
><P
>If you would rather use an FTP-like interface, use <B
CLASS="command"
>sftp</B
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>lenny /var/tmp&#62;</TT
> <B
CLASS="command"
>sftp blob</B
>
Connecting to blob...
lenny@blob's password:
<TT
CLASS="prompt"
>sftp&#62;</TT
> <B
CLASS="command"
>cd /var/tmp</B
>
<TT
CLASS="prompt"
>sftp&#62;</TT
> <B
CLASS="command"
>get Sch*</B
>
Fetching /var/tmp/Schedule.sdc.gz to Schedule.sdc.gz
<TT
CLASS="prompt"
>sftp&#62;</TT
> <B
CLASS="command"
>bye</B
>
<TT
CLASS="prompt"
>lenny /var/tmp&#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Secure copy or FTP GUIs</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Don't feel comfortable with the command line yet? Try <SPAN
CLASS="application"
>Konqueror</SPAN
>'s capabilities for secure remote copy, or install <SPAN
CLASS="application"
>Putty</SPAN
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_05_04_05"
></A
>10.4.4.5. Authentication keys</H3
><P
>The <B
CLASS="command"
>ssh-keygen</B
> command generates, manages and converts authentication keys for <B
CLASS="command"
>ssh</B
>. It can create RSA keys for use by SSH protocol version 1 and RSA or DSA keys for use by SSH protocol version 2.</P
><P
>Normally each user wishing to use SSH with RSA or DSA authentication runs this once to create the authentication key in <TT
CLASS="filename"
>$HOME/.ssh/identity</TT
>, <TT
CLASS="filename"
>id_dsa</TT
> or <TT
CLASS="filename"
>id_rsa</TT
>. Additionally, the system administrator may use this to generate host keys for the system.</P
><P
>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 <EM
>.pub</EM
> 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.</P
><P
>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.</P
><P
>We will study SSH keys in the exercises. All information can be found in the man or <SPAN
CLASS="application"
>Info</SPAN
> pages.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_05_05"
></A
>10.4.5. VNC</H2
><P
>VNC or <SPAN
CLASS="application"
>Virtual Network Computing</SPAN
> 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:</P
><P
></P
><UL
><LI
><P
>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.</P
></LI
><LI
><P
>It is small and simple, no installation needed, can be run from a floppy if needed.</P
></LI
><LI
><P
>Platform independent with the Java client, runs on virtually everything that supports X.</P
></LI
><LI
><P
>Sharable: one desktop may be displayed on multiple viewers.</P
></LI
><LI
><P
>Free.</P
></LI
></UL
><P
>More information can be found in the VNC client man pages (<B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>vncviewer</I
></TT
></B
>) or on the <A
HREF="http://www.realvnc.com/"
TARGET="_top"
>VNC website</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_05_06"
></A
>10.4.6. The rdesktop protocol</H2
><P
>In order to ease management of MS Windows hosts, recent Linux distributions support the Remote Desktop Protocol (RDP), which is implemented in the <B
CLASS="command"
>rdesktop</B
> client. The protocol is used in a number of Microsoft products, including Windows NT Terminal Server, Windows 2000 Server, Windows XP and Windows 2003 Server.</P
><P
>Surprise your friends (or management) with the fullscreen mode, multiple types of keyboard layouts and single application mode, just like the real thing. The <B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>rdesktop</I
></TT
></B
> manual provides more information. The project's homepage is at <A
HREF="http://www.rdesktop.org/"
TARGET="_top"
>http://www.rdesktop.org/</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_05_07"
></A
>10.4.7. Cygwin</H2
><P
><A
HREF="http://www.cygwin.com"
TARGET="_top"
>Cygwin</A
> provides substantial UNIX functionality on MS Windows systems. Apart from providing UNIX command line tools and graphical applications, it can also be used to display a Linux desktop on an MS Windows machine, using remote X. From a <SPAN
CLASS="application"
>Cygwin Bash</SPAN
> shell, type the command</P
><P
><B
CLASS="command"
>/usr/X11R6/bin/XWin.exe <TT
CLASS="option"
>-query</TT
> <TT
CLASS="parameter"
><I
>your_linux_machine_name_or_IP</I
></TT
></B
> </P
><P
>The connection is by default denied. You need to change the <SPAN
CLASS="application"
>X Display Manager</SPAN
> (XDM) configuration and possibly the <SPAN
CLASS="application"
>X Font Server</SPAN
> (XFS) configuration to enable this type of connection, where you get a login screen on the remote machine. Depending on your desktop manager (<SPAN
CLASS="application"
>Gnome</SPAN
>, <SPAN
CLASS="application"
>KDE</SPAN
>, other), you might have to change some configurations there, too.</P
><P
>If you do not need to display the entire desktop, you can use SSH in <SPAN
CLASS="application"
>Cygwin</SPAN
>, just like explained in <A
HREF="#sect_10_05_04"
>Section 10.4.4</A
>. without all the fuss of editing configuration files.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_06"
></A
>10.5. Security</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_10_06_01"
></A
>10.5.1. Introduction</H2
><P
>As soon as a computer is connected to the network, all kinds of abuse becomes possible, be it a 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. There are, however, 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.</P
><P
>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:</P
><P
></P
><UL
><LI
><P
>Do you want to be in control of your own system?</P
></LI
><LI
><P
>Do you want to (unwittingly) participate in criminal activities?</P
></LI
><LI
><P
>Do you want your equipment to be used by someone else?</P
></LI
><LI
><P
>Do you want to take risks on losing your Internet connection?</P
></LI
><LI
><P
>Do you want to rebuild your system every time it has been hacked?</P
></LI
><LI
><P
>Do you want to risk personal or other data loss?</P
></LI
></UL
><P
>Presuming you don't, we will quickly list the steps you can take to secure your machine. Extended information can be found in the <A
HREF="http://www.tldp.org/HOWTO/Security-HOWTO.html"
TARGET="_top"
>Linux Security HOWTO</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_06_02"
></A
>10.5.2. Services</H2
><P
>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.</P
><P
>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 <EM
>should</EM
> be running, check which services are listening on what TCP ports using the <B
CLASS="command"
>netstat</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[elly@mars ~]</TT
> <B
CLASS="command"
>netstat -l | grep tcp</B
>
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
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Things to avoid:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>exec</B
>, <B
CLASS="command"
>rlogin</B
> and <B
CLASS="command"
>rsh</B
>, and <B
CLASS="command"
>telnet</B
> just to be on the safe side.</P
></LI
><LI
><P
>X11 on server machines.</P
></LI
><LI
><P
>No lp if no printer is physically attached.</P
></LI
><LI
><P
>No MS Windows hosts in the network, no Samba required.</P
></LI
><LI
><P
>Don't allow FTP unless an FTP server is required.</P
></LI
><LI
><P
>Don't allow NFS and NIS over the Internet, disable all related services on a stand-alone installation.</P
></LI
><LI
><P
>Don't run an MTA if you're not actually on a mail server.</P
></LI
><LI
><P
>...</P
></LI
></UL
><P
>Stop running services using the <B
CLASS="command"
>chkconfig</B
> command, the initscripts or by editing the <B
CLASS="command"
>(x)inetd</B
> configuration files.
</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_06_03"
></A
>10.5.3. Update regularly</H2
><P
>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 <EM
>all</EM
> the packages you use regularly.</P
><P
>Some updates may require new configuration files, and old files may be replaced. Check the documentation, and ensure that everything runs normal after updating.</P
><P
>Most Linux distributions provide mailing list services for security update announcements, and tools for applying updates to the system. General Linux only security issues are reported among others at <A
HREF="http://linuxsecurity.com"
TARGET="_top"
>Linuxsecurity.com</A
>.</P
><P
>Updating is an ongoing process, so it should be an almost daily habit.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_06_04"
></A
>10.5.4. Firewalls and access policies</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_10_06_04_01"
></A
>10.5.4.1. What is a firewall?</H3
><P
>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.</P
><P
><EM
>Firewall</EM
> 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 <SPAN
CLASS="QUOTE"
>"rules"</SPAN
> that are used to define what is allowed to enter and/or exit a given system or network.</P
><P
>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.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_06_04_02"
></A
>10.5.4.2. Packet filters</H3
><P
>The first line of defense is a <EM
>packet filter</EM
>, which can look inside IP packets and make decisions based on the content. Most common is the <SPAN
CLASS="application"
>Netfilter</SPAN
> package, providing the <B
CLASS="command"
>iptables</B
> command, a next generation packet filter for Linux.</P
><P
>One of the most noteworthy enhancements in the newer kernels is the <EM
>stateful inspection</EM
> 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.</P
><P
>The <SPAN
CLASS="application"
>Shoreline Firewall</SPAN
> or <SPAN
CLASS="application"
>Shorewall</SPAN
> for short is a front-end for the standard firewall functionality in Linux.</P
><P
>More information can be found at <A
HREF="http://www.netfilter.org/"
TARGET="_top"
>the Netfilter/iptables project page</A
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_06_04_03"
></A
>10.5.4.3. TCP wrappers</H3
><P
>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.</P
><P
>TCP wrappers are typically used with <B
CLASS="command"
>xinetd</B
> 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.</P
><P
>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.</P
><P
>The host based access is controlled in the <TT
CLASS="filename"
>hosts.allow</TT
> and <TT
CLASS="filename"
>hosts.deny</TT
> files. More information can be found in the TCP wrapper documentation files in <TT
CLASS="filename"
>/usr/share/doc/tcp_wrappers[-&#60;version&#62;/]</TT
> or <TT
CLASS="filename"
>/usr/share/doc/tcp</TT
> and in the man pages for the host based access control files, which contain examples.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_07_04_04"
></A
>10.5.4.4. Proxies</H3
><P
>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.</P
><P
>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 <A
HREF="http://www.tldp.org/HOWTO/Firewall-HOWTO.html"
TARGET="_top"
>Firewall HOWTO</A
> or on the Squid website.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_07_04_05"
></A
>10.5.4.5. Access to individual applications</H3
><P
>Some servers may have their own access control features. Common examples include <SPAN
CLASS="application"
>Samba</SPAN
>, <SPAN
CLASS="application"
>X Window</SPAN
>, <SPAN
CLASS="application"
>Bind</SPAN
>, <SPAN
CLASS="application"
>Apache</SPAN
> and CUPS. For every service you want to offer check which configuration files apply.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_10_07_04_06"
></A
>10.5.4.6. Log files</H3
><P
>If anything, the UNIX way of logging all kinds of activities into all kinds of files confirms that <SPAN
CLASS="QUOTE"
>"it is doing something."</SPAN
> 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.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_07_05"
></A
>10.5.5. Intrusion detection</H2
><P
> 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.</P
><P
> 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. Some systems come with the <B
CLASS="command"
>tripwire</B
> monitoring system, which is documented at the <A
HREF="http://www.tripwire.org"
TARGET="_top"
>Tripwire Open Source Project</A
> website.</P
><P
>Network intrusion detection is handled by a system that sees all the traffic that passes the firewall (not by portscanners, which advertise usable ports). <A
HREF="http://www.snort.org"
TARGET="_top"
>Snort</A
> is an Open Source example of such a program. Whitehats.com features an open Intrusion detection database, <A
HREF="http://www.whitehats.com"
TARGET="_top"
>arachNIDS</A
>. </P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_07_06"
></A
>10.5.6. More tips</H2
><P
>Some general things you should keep in mind:</P
><P
></P
><UL
><LI
><P
>Do not allow root logins. UNIX developers came up with the <B
CLASS="command"
>su</B
> over two decades ago for extra security.</P
></LI
><LI
><P
>Direct root access is always dangerous and susceptible to human errors, be it by allowing root login or by using the <B
CLASS="command"
>su <TT
CLASS="option"
>-</TT
></B
> command. Rather than using <B
CLASS="command"
>su</B
>, it is even better to use <B
CLASS="command"
>sudo</B
> to only execute the command that you need extra permissions for, and to return afterwards to your own environment.</P
></LI
><LI
><P
>Take passwords seriously. Use shadow passwords. Change your passwords regularly.</P
></LI
><LI
><P
>Try to always use SSH or SSL. Avoid <B
CLASS="command"
>telnet</B
>, FTP and E-mail clients and other client programs which send unencrypted passwords over the network. Security is not only about securing your computer, it is also about securing your passwords.</P
></LI
><LI
><P
>Limit resources using <B
CLASS="command"
>quota</B
> and/or <B
CLASS="command"
>ulimit</B
>.</P
></LI
><LI
><P
>The mail for root should be delivered to, or at least read by, an actual person.</P
></LI
><LI
><P
>The <A
HREF="http://www.sans.org"
TARGET="_top"
>SANS institute</A
> has more tips and tricks, sorted per distribution, with mailing list service.</P
></LI
><LI
><P
>Check the origin of new software, get it from a trusted place/site. Verify new packages before installing.</P
></LI
><LI
><P
>When using a non-permanent Internet connection, shut it down as soon as you don't need it anymore.</P
></LI
><LI
><P
>Run private services on odd ports instead of the ones expected by possible hackers.</P
></LI
><LI
><P
>Know your system. After a while, you can almost feel when something is happening.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_07_07"
></A
>10.5.7. Have I been hacked?</H2
><P
>How can you tell? This is a checklist of suspicious events:</P
><P
></P
><UL
><LI
><P
>Mysterious open ports, strange processes.</P
></LI
><LI
><P
>System utilities (common commands) behaving strange.</P
></LI
><LI
><P
>Login problems.</P
></LI
><LI
><P
>Unexplained bandwidth usage.</P
></LI
><LI
><P
>Damaged or missing log files, syslog daemon behaving strange.</P
></LI
><LI
><P
>Interfaces in unusual modes.</P
></LI
><LI
><P
>Unexpectedly modified configuration files.</P
></LI
><LI
><P
>Strange entries in shell history files.</P
></LI
><LI
><P
>Unidentified temporary files.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_07_08"
></A
>10.5.8. Recovering from intrusion</H2
><P
>In short, stay calm. Then take the following actions in this order:</P
><P
></P
><UL
><LI
><P
>Disconnect the machine from the network.</P
></LI
><LI
><P
>Try to find out as much as you can about how your security was breached.</P
></LI
><LI
><P
>Backup important non-system data. If possible, check these data against existing backups, made before the system was compromised, to ensure data integrity.</P
></LI
><LI
><P
>Re-install the system.</P
></LI
><LI
><P
>Use new passwords.</P
></LI
><LI
><P
>Restore from system and data backups.</P
></LI
><LI
><P
>Apply all available updates.</P
></LI
><LI
><P
>Re-examine the system: block off unnecessary services, check firewall rules and other access policies.</P
></LI
><LI
><P
>Reconnect.</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_08"
></A
>10.6. Summary</H1
><P
>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.</P
><P
>Linux is well known 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.</P
><P
>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.</P
><P
>Increasing network security is mainly done by applying frequent updates and common sense.</P
><P
>Here is an overview of network related commands:</P
><DIV
CLASS="table"
><A
NAME="AEN11263"
></A
><P
><B
>Table 10-2. New commands in chapter 10: Networking</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ftp</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Transfer files to another host (insecure).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>host</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Get information about networked hosts.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ifconfig</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display IP address information.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ip</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display IP address information.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>netstat</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display routing information and network statistics.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ping</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Send answer requests to other hosts.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>rdesktop</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display and MS Windows desktop on your Linux system.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>route</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show routing information.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>scp</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Secure copy files to and from other hosts.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>sftp</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Secure FTP files to and from other hosts.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ssh</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Make an encrypted connection to another host.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ssh-keygen</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Generate authentication keys for <SPAN
CLASS="application"
>Secure SHell</SPAN
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>telnet</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Make an insecure connection to another hosts.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>tracepath/traceroute</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print the route that packets follow to another host.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>whois</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Get information abotu a domain name.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>xclock</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>X Window clock application, handy for testing remote display.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>xhost</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>X Window access control tool.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_10_09"
></A
>10.7. Exercises</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_10_09_01"
></A
>10.7.1. General networking</H2
><P
></P
><UL
><LI
><P
>Display network information for your workstation: IP address, routes, name servers.</P
></LI
><LI
><P
>Suppose no DNS is available. What would you do to reach your neighbour's machine without typing the IP address all the time?</P
></LI
><LI
><P
>How would you permanently store proxy information for a text mode browser such as <B
CLASS="command"
>links</B
>?</P
></LI
><LI
><P
>Which name servers handle the redhat.com domain?</P
></LI
><LI
><P
>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?</P
></LI
><LI
><P
>Does your machine accept anonymous FTP connections? How do you use the <B
CLASS="command"
>ncftp</B
> program to authenticate with your user name and password?</P
></LI
><LI
><P
>Does your machine run a web server? If not, make it do so. Check the log files!</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_09_02"
></A
>10.7.2. Remote connections</H2
><P
></P
><UL
><LI
><P
>From your local workstation, display a graphical application, such as <B
CLASS="command"
>xclock</B
> on your neighbour's screen. The necessary accounts will have to be set up. Use a secure connection!</P
></LI
><LI
><P
>Set up SSH keys so you can connect to your neighbour's machine without having to enter a password.</P
></LI
><LI
><P
>Make a backup copy of your home directory in <TT
CLASS="filename"
>/var/tmp</TT
> on your neighbour's <SPAN
CLASS="QUOTE"
>"backup server,"</SPAN
> using <B
CLASS="command"
>scp</B
>. Archive and compress before starting the data transfer! Connect to the remote host using <B
CLASS="command"
>ssh</B
>, unpack the backup, and put one file back on the original machine using <B
CLASS="command"
>sftp</B
>.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_10_09_03"
></A
>10.7.3. Security</H2
><P
></P
><UL
><LI
><P
>Make a list of open (listening) ports on your machine.</P
></LI
><LI
><P
>Supposing you want to run a web server. Which services would you deactivate? How would you do that?</P
></LI
><LI
><P
>Install available updates.</P
></LI
><LI
><P
>How can you see who connected to your system?</P
></LI
><LI
><P
>Make a repetitive job that reminds you to change your password every month, and preferably the <EM
>root</EM
> password as well.</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="chapter"
><HR><H1
><A
NAME="chap_11"
></A
>Chapter 11. Sound and Video</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN11392"
></A
><P
></P
><P
>This chapter addresses the following tasks (briefly, as the field of sound and video is very wide):</P
><P
><P
></P
><UL
><LI
><P
>Sound card configuration</P
></LI
><LI
><P
>Playing CDs, copying CDs, </P
></LI
><LI
><P
>Playing music files</P
></LI
><LI
><P
>Volume control</P
></LI
><LI
><P
>Video and television</P
></LI
><LI
><P
>Recording sound</P
></LI
></UL
>
</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_11_01"
></A
>11.1. Audio Basics</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_11_01_01"
></A
>11.1.1. Installation</H2
><P
>Most likely, your system is already installed with audio drivers and the configuration was done at installation time. Likewise, should you ever need to replace your audio hardware, most systems provide tools that allow easy setup and configuration of the device. Most currently available
plug-and-play sound cards should be recognized automatically. If you can hear the samples that are played during configuration, just click <SPAN
CLASS="guibutton"
>OK</SPAN
>
and everything will be set up for you.</P
><P
>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 as well.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>If automatic sound card detection fails</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13;If your soundcard is not supported by default, you will need to apply other techniques. These are described in the <A
HREF="http://www.tldp.org/HOWTO/Sound-HOWTO/index.html"
TARGET="_top"
>Linux Sound HOWTO</A
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_11_01_02"
></A
>11.1.2. Drivers and Architecture</H2
><P
>There are generally two types of sound architecture: the older Open Sound System or OSS, which works with every UNIX-like system, and the newer Advanced Linux Sound Architecture or ALSA, that has better support for Linux, as the name indicates. ALSA also has more features and allows for faster driver development. We will focus here on the ALSA system.</P
><P
>Today, almost all mainstream audio chipsets are supported. Only some high-end professional solutions and some cards developed by manufacturers refusing to document their chipset specifications are unsupported. An overview of supported devices can be found on the ALSA site at <A
HREF="http://www.alsa-project.org/alsa-doc/index.php?vendor=All#matrix"
TARGET="_top"
>http://www.alsa-project.org/alsa-doc/index.php?vendor=All#matrix</A
>.</P
><P
>Configuring systems installed with ALSA is done using the <B
CLASS="command"
>alsaconf</B
> tool. Additionally, distributions usually provide their own tools for configuring the sound card; these tools might even integrate the old and the new way of handling sound devices.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_11_02"
></A
>11.2. Sound and video playing</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_11_02_01"
></A
>11.2.1. CD playing and copying</H2
><P
>The <EM
>cdp</EM
> package comes with most distributions and provides <B
CLASS="command"
>cdp</B
> or <B
CLASS="command"
>cdplay</B
>, a text-based CD player. Desktop managers usually include a graphical tool, such as the <B
CLASS="command"
>gnome-cd</B
> player in <SPAN
CLASS="application"
>Gnome</SPAN
>, that can be started from a menu.</P
><P
>Be sure to understand the difference between an audio CD and a data CD.
You do not have to mount an audio CD into the file system in order to listen to it. This is because the data on such a CD are not Linux file system data; they are accessed and sent to the audio output channel directly, using a CD player program. If your CD is a data CD containing <TT
CLASS="filename"
>.mp3</TT
> files, you will first need to mount it into the file system, and then use one of the programs that we discuss below in order to play the music. How to mount CDs into the file system is explained in <A
HREF="#sect_07_06_05"
>Section 7.5.5</A
>.</P
><P
>The <B
CLASS="command"
>cdparanoia</B
> tool from the package with the same name
reads audio directly as data from the CD, without analog conversions, and writes data to a file or pipe in different formats, of which <TT
CLASS="filename"
>.wav</TT
> is probably the most popular. Various tools for conversion to other formats, formats,
such as <TT
CLASS="filename"
>.mp3</TT
>, come with most distributions or are downloadable as separate packages. The GNU project provides several CD playing, ripping and encoding tools, database managers; see the <A
HREF="http://www.gnu.org/directory/audio/"
TARGET="_top"
>Free Software Directory, Audio section</A
> for detailed information.</P
><P
>Audio-CD creation is eased, among many others, with the <B
CLASS="command"
>kaudiocreator</B
> tool from the KDE suite. It comes with clear information from the KDE Help Center.</P
><P
>CD burning is covered in general in <A
HREF="#sect_09_02_02"
>Section 9.2.2</A
>.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_11_02_02"
></A
>11.2.2. Playing music files</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_11_02_02_01"
></A
>11.2.2.1. mp3 files</H3
><P
>The popular <TT
CLASS="filename"
>.mp3</TT
> format is widely supported on Linux
machines. Most distributions include multiple programs that can play these files. Among many other applications, <SPAN
CLASS="application"
>XMMS</SPAN
>, which is presented in the screenshot below, is one of the most wide-spread, partially because it has the same look and feel as the Windows tool.</P
><DIV
CLASS="figure"
><A
NAME="AEN11486"
></A
><P
><B
>Figure 11-1. XMMS mp3 player</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/xmms.png"></P
></DIV
></DIV
><P
>Also very popular for playing music are <SPAN
CLASS="application"
>AmaroK</SPAN
>, a KDE application that is steadily gaining popularity, and <SPAN
CLASS="application"
>MPlayer</SPAN
>, which can also play movies.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Restrictions</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Some distributions don't allow you to play MP3's without modifying your configuration, this is due to license restrictions on the MP3 tools. You might need to install extra software to be able to play your music.</P
></TD
></TR
></TABLE
></DIV
><P
>In text mode, you can use the <B
CLASS="command"
>mplayer</B
> command:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>[tille@octarine ~]$ </TT
><B
CLASS="command"
>mplayer <TT
CLASS="filename"
>/opt/mp3/oriental/*.mp3</TT
></B
>
MPlayer 1.0pre7-RPM-3.4.2 (C) 2000-2005 MPlayer Team
CPU: Advanced Micro Devices Duron Spitfire (Family: 6, Stepping: 1)
Detected cache-line size is 64 bytes
CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 0 SSE2: 0
Playing /opt/oldopt/mp3/oriental/Mazika_Diana-Krozon_Super-Star_Ensani-Ma-
Bansak.mp3.
Cache fill: 1.17% (98304 bytes) Audio file detected.
Clip info:
Title: Ensani-Ma-Bansak.mp3
Artist: Diana-Krozon
Album: Super-Star
Year:
Comment:
Genre: Unknown
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
mpg123: Can't rewind stream by 450 bits!
AUDIO: 44100 Hz, 2 ch, s16le, 160.0 kbit/11.34% (ratio: 20000-&#62;176400)
Selected audio codec: [mp3] afm:mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
Checking audio filter chain for 44100Hz/2ch/s16le -&#62; 44100Hz/2ch/s16le...
AF_pre: 44100Hz/2ch/s16le
AO: [oss] 44100Hz 2ch s16le (2 bps)
Building audio filter chain for 44100Hz/2ch/s16le -&#62; 44100Hz/2ch/s16le...
Video: no video
Starting playback...
A: 227.8 (03:23:.1) 1.8% 12%
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_11_02_02_02"
></A
>11.2.2.2. Other formats</H3
><P
>It would lead us too far to discuss all possible audio formats and ways to play them. An (incomplete) overview of other common sound playing and manipulating software:</P
><P
></P
><UL
><LI
><P
>Ogg Vorbis: Free audio format: see <A
HREF="http://www.gnu.org/directory/audio/ogg/"
TARGET="_top"
>the GNU audio directory</A
> for tools - they might be included in your distribution as well. The format was developed because MP3 is patented.</P
></LI
><LI
><P
>Real audio and video: <B
CLASS="command"
>realplay</B
> from <A
HREF="http://real.com"
TARGET="_top"
>RealNetworks</A
>.</P
></LI
><LI
><P
>SoX or Sound eXchange: actually a sound converter, comes with th
e <B
CLASS="command"
>play</B
> program. Plays <TT
CLASS="filename"
>.wav</TT
>, <TT
CLASS="filename"
>.
ogg</TT
> and various other formats, including raw binary formats.</P
></LI
><LI
><P
>Playmidi: a MIDI player, see the GNU directory.</P
></LI
><LI
><P
>AlsaPlayer: from the Advanced Linux Sound Architecture project,
see the <A
HREF="http://www.alsaplayer.org"
TARGET="_top"
>AlsaPlayer web site</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>mplayer</B
>: plays just about anything, including
mp3 files. More info on the <A
HREF="http://www.mplayerhq.hu/"
TARGET="_top"
>MPlayerHQ website</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>hxplay</B
>: supports RealAudio and RealVideo, mp3, mp4 audio, Flash, wav and more, see <A
HREF="http://www.helixdna.com"
TARGET="_top"
>HelixDNA</A
> (not all components of this software are completely free).</P
></LI
><LI
><P
><B
CLASS="command"
>rhythmbox</B
>: based on the <SPAN
CLASS="application"
>GStreamer</SPAN
> framework, can play everything supported in <SPAN
CLASS="application"
>GStreamer</SPAN
>, which claims to be able to play everything, see the <A
HREF="http://www.rhythmbox.org"
TARGET="_top"
>Rhythmbox</A
> and <A
HREF="http://gstreamer.freedesktop.org"
TARGET="_top"
>GStreamer</A
> sites.</P
></LI
></UL
><P
>Check your system documentation and man pages for particular tools and detailed explanations on how to use them.</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>I don't have these applications on my system!</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>A lot of the tools and applications discussed in the above sections are optional software. It is possible that such applications are not installed on your system by default, but that you can find them in your distribution as additional packages. It might also very well be that the application that you are looking for is not in your distribution at all. In that case, you need to download it from the application's web site.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_11_02_02_03"
></A
>11.2.2.3. Volume control</H3
><P
><B
CLASS="command"
>aumix</B
> and <B
CLASS="command"
>alsamixer</B
> are two common text tools for adjusting audio controls. Use the arrow keys to toggle settings. The <B
CLASS="command"
>alsamixer</B
> has a graphical interface when started from the <SPAN
CLASS="application"
>Gnome</SPAN
> menu or as <B
CLASS="command"
>gnome-alsamixer</B
> from the command line. The <B
CLASS="command"
>kmix</B
> tool does the same in KDE.</P
><P
>Regardless of how you choose 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. Use a quality head-set, rather than the ones with the small ear pieces. This is better for your ears and causes less distraction for your colleagues.</P
></DIV
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_11_02_03"
></A
>11.2.3. Recording</H2
><P
>Various tools are again available that allow you to record voice and music. For recording voice you can use <B
CLASS="command"
>arecord</B
> on the command line:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>alexey@russia:~&#62;</TT
> <B
CLASS="command"
>arecord <TT
CLASS="filename"
>/var/tmp/myvoice.wav</TT
></B
>
Recording WAVE '/var/tmp/myvoice.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
Aborted by signal Interrups...
</PRE
></FONT
></TD
></TR
></TABLE
><P
><SPAN
CLASS="QUOTE"
>"Interrupt"</SPAN
> means that the application has caught a <B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>C</B
>. Play the sample using the simple <B
CLASS="command"
>play</B
> command.</P
><P
>This is a good test that you can execute prior to testing applications that need voice input, like Voice over IP (VoIP). Keep in mind that the microphone input should be activated. If you don't hear your own voice, check your sound settings. It often happens that the microphone is muted or on verry low volume. This can be easily adjusted using <B
CLASS="command"
>alsamixer</B
> or your distribution-specific graphical interface to the sound system.</P
><P
>In KDE you can start the <B
CLASS="command"
>krec</B
> utility, <SPAN
CLASS="application"
>Gnome</SPAN
> provides the <B
CLASS="command"
>gnome-sound-recorder</B
>.</P
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_11_02_04"
></A
>11.3. Video playing, streams and television watching</H1
><P
>Various players are available:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>xine</B
>: a free video player</P
></LI
><LI
><P
><B
CLASS="command"
>ogle</B
>: DVD player.</P
></LI
><LI
><P
><B
CLASS="command"
>okle</B
>: KDE version of <B
CLASS="command"
>ogle</B
></P
></LI
><LI
><P
><B
CLASS="command"
>mplayer</B
>: Movie Player for Linux</P
></LI
><LI
><P
><B
CLASS="command"
>totem</B
>: plays both audio and video files, audio CDs, VCD and DVD.</P
></LI
><LI
><P
><B
CLASS="command"
>realplay</B
>: from RealNetworks.</P
></LI
><LI
><P
><B
CLASS="command"
>hxplay</B
>: a Real alternative, see <A
HREF="http://helixcommunity.org"
TARGET="_top"
>HelixDNA</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>kaffeine</B
>: media player for KDE3.</P
></LI
></UL
><P
>Most likely, you will find one of these in your graphical menus.</P
><P
>Keep in mind that all codecs necessary for viewing different types of video might not be on your system by default. You can get a long way downloading <SPAN
CLASS="application"
>W32codecs</SPAN
> and <SPAN
CLASS="application"
>libdvdcss</SPAN
>.</P
><P
>The <A
HREF="http://www.tldp.org/"
TARGET="_top"
>LDP</A
> released a document that is very appropriate for this section. It is entitled <A
HREF="http://www.tldp.org/HOWTO/DVD-Playback-HOWTO/index.html"
TARGET="_top"
>DVD Playback HOWTO</A
> and describes the different tools available for viewing movies on a system that has a DVD drive. It is a fine addition to the <A
HREF="http://www.tldp.org/HOWTO/DVD-HOWTO.html"
TARGET="_top"
>DVD HOWTO</A
> that explains installation of the drive.</P
><P
>For watching TV there is choice of the following tools, among many others for watching and capturing TV, video and other streams:</P
><P
></P
><UL
><LI
><P
><B
CLASS="command"
>tvtime</B
>: great program with station management, interaction with teletext, film mode and <A
HREF="http://tvtime.sourceforge .net/"
TARGET="_top"
>much more</A
>.</P
></LI
><LI
><P
><B
CLASS="command"
>zapping</B
>: Gnome-specific TV viewer.</P
></LI
><LI
><P
><B
CLASS="command"
>xawtv</B
>: X11 TV viewer.</P
></LI
></UL
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_11_02_05"
></A
>11.4. Internet Telephony</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_11_02_05_01"
></A
>11.4.1. What is it?</H2
><P
>Internet telephony, or more common, Voice over IP (VoIP) or digital telephony allows parties to exchange voice data flows over the network. The big difference is that the data flows over a general purpose network, the Internet, contrary to conventional telephony, that uses a dedicated network of voice transmission lines. The two networks can be connected, however, under special circumstances, but for now this is certainly not a standard. In other words: it is very likely that you will not be able to call people who are using a conventional telephone. If it is possible at all, it is likely that you will need to pay for a subscription.</P
><P
>While there are currently various applications available for free download, both free and proprietary, there are some major drawbacks to telephony over the Internet. Most noticably, the system is unreliable, it can be slow or there can be a lot of noise on the connection, and it can thus certainly not be used to replace conventional telephony - think about emergency calls. While some providers take their precautions, there is no guarantee that you can reach the party that you want to call.</P
><P
>Most applications currently do not use encryption, so be aware that it is potentially easy for someone to eavesdrop on your conversations. If security is a concern for you, read the documentation that comes with your VoIP client. Additionally, if you are using a firewall, it should be configured to allow incoming connections from anywhere, so using VoIP also includes taking risks on the level of site security.</P
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="sect_11_05_02"
></A
>11.4.2. What do you need?</H2
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="sect_11_05_02_01"
></A
>11.4.2.1. Server Side</H3
><P
>First of all, you need a provider offering the service. This service might integrate traditional telephony and it might or might not be free. Among others are <A
HREF="http://www.sipphone.com/"
TARGET="_top"
>SIPphone</A
>, <A
HREF="http://www.vonage.com/"
TARGET="_top"
>Vonage</A
>, <A
HREF="http://www.lingo.com/"
TARGET="_top"
>Lingo</A
>, <A
HREF="http://www.totaltalk.com/"
TARGET="_top"
>AOL TotalTalk</A
> and many locally accessible providers offering the so-called <SPAN
CLASS="QUOTE"
>"full phone service"</SPAN
>. Internet phone service only is offered by <A
HREF="http://www.skype.com/"
TARGET="_top"
>Skype</A
>, <A
HREF="http://www.sipbroker.com/"
TARGET="_top"
>SIP Broker</A
>, <A
HREF="http://www.google.com/talk/"
TARGET="_top"
>Google</A
> and many others.</P
><P
>If you want to set up a server of your own, you might want to look into <A
HREF="http://www.asterisk.org"
TARGET="_top"
>Asterisk</A
>.</P
></DIV
><DIV
CLASS="sect3"
><HR><H3
CLASS="sect3"
><A
NAME="sect_11_05_02_02"
></A
>11.4.2.2. Client Side</H3
><P
>On the client side, the applications that you can use depend on your network configuration. If you have a direct Internet connection, there won't be any problems, provided that you know on what server you can connect, and usually that you also have a username and password to authenticate to the service.</P
><P
>If you are behind a firewall that does Network Address Translation (NAT), however, some services might not work, as they will only see the IP address of the firewall and not the address of your computer, which might well be unroutable over the Internet, for instance when you are in a company network and your IP address starts with 10., 192.168. or another non-routable subnet prefix. This depends on the protocol that is used by the application.</P
><P
>Also, available bandwidth might be a blocking factor: some applications are optimized for low bandwidth consumption, while others might require high bandwidth connections. This depends on the codec that is used by the application.</P
><P
>Among the most common applications are the Skype client, which has an interface that reminds of instant messaging, and <A
HREF="http://www.counterpath.com/"
TARGET="_top"
>X-Lite</A
>, the free version of the <SPAN
CLASS="application"
>XTen softphone</SPAN
>, which looks like a mobile telephone. However, while these programs are available for free download and very popular, they are not free as in free speech: they use proprietary protocols and/or are only available in binary packages, not in source format.</P
><P
>Free <EM
>and open</EM
> VoIP clients are for instance <A
HREF="http://www.gizmoproject.com/"
TARGET="_top"
>Gizmo</A
>, <A
HREF="http://www.linphone.org"
TARGET="_top"
>Linphone</A
>, <A
HREF="http://www.gnomemeeting.org/"
TARGET="_top"
>GnomeMeeting</A
> and <A
HREF="http://www.wirlab.net/kphone/"
TARGET="_top"
>KPhone</A
>.</P
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Client hardware</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>While your computer, especially if it is a laptop PC, might have a built-in microphone, the result will be far better if you connect a headset. If you have the choice, opt for a USB headset, as it functions independently from existing audio hardware. Use <B
CLASS="command"
>alsamixer</B
> to configure input and output sound levels to your taste.</P
></TD
></TR
></TABLE
></DIV
><P
>VoIP applications are definitely a booming market. Volunteers try to document the current status at <A
HREF="http://www.voip-info.org/"
TARGET="_top"
>http://www.voip-info.org/</A
>.</P
></DIV
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_11_03"
></A
>11.5. Summary</H1
><P
>The GNU/Linux platform is fully multi-media enabled. A wide variety of devices like sound cards, tv-cards, headsets, microphones, CD and DVD players is supported. The list of applications is sheer endless, that is why we needed to shortenthe list of new commands below and limit ourselves to general audio commands.</P
><DIV
CLASS="table"
><A
NAME="AEN11708"
></A
><P
><B
>Table 11-1. New commands in chapter 11: Audio</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>alsaconf</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configure the ALSA sound system.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>alsamixer</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Tune output levels of ALSA driver.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>arecord</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Record a sound sample.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>aumix</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Audio mixer tool.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cdp</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Play an audio CD.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cdparanoia</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Rip an audio CD.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cdplay</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Play an audio CD.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>gnome-alsamixer</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><SPAN
CLASS="application"
>Gnome</SPAN
> ALSA front-end.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>gnome-cd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><SPAN
CLASS="application"
>Gnome</SPAN
> front-end for playing audio CDs.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>gnome-sound-recorder</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><SPAN
CLASS="application"
>Gnome</SPAN
> front-end for recording sound samples.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>kaudiocreator</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>KDE front-end for creating audio CDs.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>kmix</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>KDE front-end for sound settings.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>krec</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>KDE front-end for recording sound samples.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>mplayer</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Multi-media player.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>play</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command line tool for playing sound samples.</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="sect_11_04"
></A
>11.6. Exercises</H1
><P
></P
><OL
TYPE="1"
><LI
><P
>From the Gnome or KDE menu, open your sound configuration panel. Make sure audio boxes or headset are connected to your system and find an output level that is comfortable for you. Make sure, when your system is ALSA-compatible, that you use the appropriate panel.</P
></LI
><LI
><P
>If you have a microphone, try recording a sample of your own voice. Make sure the input volume is not too high, as this will result in high-pitched tones when you communicate with others, or in transfering background noise to the other party. On the command line, you might even try to use <B
CLASS="command"
>arecord</B
> and <B
CLASS="command"
>aplay</B
> for recording and playing sound.</P
></LI
><LI
><P
>Locate sound files on your system and try to play them.</P
></LI
><LI
><P
>Insert an audio CD and try to play it.</P
></LI
><LI
><P
>Find a chat partner and configure a VoIP program. (You might need to install one first.)</P
></LI
><LI
><P
>Can you listen to Internet radio?</P
></LI
><LI
><P
>If you have a DVD player and a movie on a DVD disk, try to play it.</P
></LI
></OL
></DIV
></DIV
><DIV
CLASS="appendix"
><HR><H1
><A
NAME="app1"
></A
>Appendix A. Where to go from here?</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN11800"
></A
><P
></P
><P
>This document gives an overview of useful books and sites.</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="AEN11802"
></A
>A.1. Useful Books</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN11804"
></A
>A.1.1. General Linux</H2
><P
></P
><UL
><LI
><P
>"Linux in a Nutshell" by Ellen Siever, Jessica P. Hackman, Stephen
Spainhour, Stephen Figgins, O'Reilly UK, ISBN 0596000251</P
></LI
><LI
><P
>"Running Linux" by Matt Welsh, Matthias Kalle Dalheimer, Lar Kaufman,
O'Reilly UK, ISBN 156592469X</P
></LI
><LI
><P
>"Linux Unleashed" by Tim Parker, Bill Ball, David Pitts, Sams, ISBN 0672316889</P
></LI
><LI
><P
>"When You Can't Find Your System Administrator" by Linda Mui, O'Reilly UK,
ISBN 1565921046</P
></LI
><LI
><P
>When you actually buy a distribution, it will contain a very decent user manual.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11817"
></A
>A.1.2. Editors</H2
><P
></P
><UL
><LI
><P
>"Learning the Vi Editor" by Linda Lamb and Arnold Robbins, O'Reilly UK,
ISBN 1565924266</P
></LI
><LI
><P
>"GNU Emacs Manual" by Richard M.Stallman, iUniverse.Com Inc., ISBN 0595100333</P
></LI
><LI
><P
>"Learning GNU Emacs" by Debra Cameron, Bill Rosenblatt and Eric Raymond,
O'Reilly UK, ISBN 1565921526</P
></LI
><LI
><P
>"Perl Cookbook" by Tom Christiansen and Nathan Torkington, O'Reilly UK,
ISBN 1565922433</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11828"
></A
>A.1.3. Shells</H2
><P
></P
><UL
><LI
><P
>"Unix Shell Programming" by Stephen G.Kochan and Patrick H.Wood, Sams
Publishing, ISBN 067248448X</P
></LI
><LI
><P
>"Learning the Bash Shell" by Cameron Newham and Bill Rosenblatt, O'Reilly
UK, ISBN 1565923472</P
></LI
><LI
><P
>"The Complete Linux Shell Programming Training Course" by Ellie Quigley
and Scott Hawkins, Prentice Hall PTR, ISBN 0130406767</P
></LI
><LI
><P
>"Linux and Unix Shell Programming" by David Tansley, Addison Wesley
Publishing Company, ISBN 0201674726</P
></LI
><LI
><P
>"Unix C Shell Field Guide" by Gail and Paul Anderson, Prentice Hall, ISBN 013937468X</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11841"
></A
>A.1.4. X Window</H2
><P
></P
><UL
><LI
><P
>"Gnome User's Guide" by the Gnome Community, iUniverse.Com Inc., ISBN 0595132251</P
></LI
><LI
><P
>"KDE Bible" by Dave Nash, Hungry Minds Inc., ISBN 0764546929</P
></LI
><LI
><P
>"The Concise Guide to XFree86 for Linux" by Aron HSiao, Que, ISBN 0789721821</P
></LI
><LI
><P
>"The New XFree86" by Bill Ball, Prima Publishing, ISBN 0761531521</P
></LI
><LI
><P
>"Beginning GTK+ and Gnome" by Peter Wright, Wrox Press, ISBN 1861003811</P
></LI
><LI
><P
>"KDE 2.0 Development" by David Sweet and Matthias Ettrich, Sams
Publishing, ISBN 0672318911</P
></LI
><LI
><P
>"GTK+/Gnome Application Development" by Havoc Pennington, New Riders
Publishing, ISBN 0735700788</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11858"
></A
>A.1.5. Networking</H2
><P
></P
><UL
><LI
><P
>"TCP/IP Illustrated, Volume I: The Protocols" by W. Richard Stevens,
Addison-Wesley Professional Computing Series, ISBN 0-201-63346-9</P
></LI
><LI
><P
>"DNS and BIND" by Paul Albitz, Cricket Liu, Mike Loukides and Deborah
Russell, O'Reilly &#38; Associates, ISBN 0596001584</P
></LI
><LI
><P
>"The Concise Guide to DNS and BIND" by Nicolai Langfeldt, Que, ISBN 0789722739</P
></LI
><LI
><P
>"Implementing LDAP" by Mark Wilcox, Wrox Press, ISBN 1861002211</P
></LI
><LI
><P
>"Understanding and deploying LDAP directory services" by Tim Howes and
co., Sams, ISBN 0672323168</P
></LI
><LI
><P
>"Sendmail" by Brian Costales and Eric Allman, O'Reilly UK, ISBN 1565922220</P
></LI
><LI
><P
>"Removing the Spam : Email Processing and Filtering" by Geoff Mulligan,
Addison Wesley Publishing Company, ISBN 0201379570</P
></LI
><LI
><P
>"Managing IMAP" by Dianna &#38; Kevin Mullet, O'Reilly UK, ISBN 059600012X</P
></LI
></UL
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="AEN11877"
></A
>A.2. Useful sites</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN11879"
></A
>A.2.1. General information</H2
><P
></P
><UL
><LI
><P
>&#13; <A
HREF="http://www.tldp.org"
TARGET="_top"
>The Linux documentation project</A
>:
all docs, manpages, HOWTOs, FAQs</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.linuxquestions.org"
TARGET="_top"
>LinuxQuestions.org</A
>: forum, downloads, docs and much more</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.google.com/linux"
TARGET="_top"
>Google for Linux</A
>: the
specialized search engine</P
></LI
><LI
><P
>&#13; <A
HREF="http://groups.google.com"
TARGET="_top"
>Google Groups</A
>: an archive of all newsgroup
postings, including the comp.os.linux hierarchy</P
></LI
><LI
><P
>&#13; <A
HREF="http://slashdot.org"
TARGET="_top"
>Slashdot</A
>: daily news</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.oreilly.com"
TARGET="_top"
>http://www.oreilly.com</A
>: books on
Linux System and Network administration, Perl, Java, ...</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.posix.com/posix.html"
TARGET="_top"
>POSIX</A
>: the standard</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.linuxhq.com"
TARGET="_top"
>Linux HQ</A
>: Maintains a complete
database of source, patches and documentation for various versions of the
Linux kernel.</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11906"
></A
>A.2.2. Architecture Specific References</H2
><P
></P
><UL
><LI
><P
>&#13; <A
HREF="http://www.alphalinux.org"
TARGET="_top"
>AlphaLinux</A
>: Linux on Alpha
architecture (e.g. Digital Workstation)</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.linux-mips.org"
TARGET="_top"
>Linux-MIPS</A
>: Linux on MIPS
(e.g. SGI Indy)</P
></LI
><LI
><P
>&#13; <A
HREF="http://tldp.org/LDP/Mobile-Guide/html/index.html"
TARGET="_top"
>Linux on the Road</A
>: Specific guidelines for installing and running Linux on
laptops, PDAs, mobile phones and so on. Configuration files for various models.</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.mklinux.org"
TARGET="_top"
>MkLinux</A
>: Linux on Apple</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11921"
></A
>A.2.3. Distributions</H2
><P
></P
><UL
><LI
><P
>&#13; <A
HREF="http://fedora.redhat.com/"
TARGET="_top"
>The Fedora Project</A
>:
RedHat-sponsored community effort OS.</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.mandriva.com"
TARGET="_top"
>Mandriva</A
>
</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.ubuntu.com"
TARGET="_top"
>Ubuntu</A
>
</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.debian.org"
TARGET="_top"
>Debian</A
>
</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.turbolinux.com"
TARGET="_top"
>TurboLinux</A
>
</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.slackware.com"
TARGET="_top"
>Slackware</A
>
</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.suse.de"
TARGET="_top"
>SuSE</A
>
</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.linuxiso.org"
TARGET="_top"
>LinuxISO.org</A
>: CD images for all distributions.</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.knoppix.org/"
TARGET="_top"
>Knoppix</A
>: distribution that runs
from a CD, you don't need to install anything for this one.</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.distrowatch.com/"
TARGET="_top"
>DistroWatch.com</A
>: find a
Linux that goes with your style.</P
></LI
><LI
><P
>...</P
></LI
></UL
></DIV
><DIV
CLASS="sect2"
><HR><H2
CLASS="sect2"
><A
NAME="AEN11956"
></A
>A.2.4. Software</H2
><P
></P
><UL
><LI
><P
>&#13; <A
HREF="http://freshmeat.net"
TARGET="_top"
>Freshmeat</A
>: new software, software archives</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.openssh.org"
TARGET="_top"
>OpenSSH</A
>: Secure SHell site</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.openoffice.org"
TARGET="_top"
>OpenOffice</A
>: MS compatible
Office Suite</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.kde.org"
TARGET="_top"
>KDE</A
>: K Desktop site</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.gnu.org"
TARGET="_top"
>GNU</A
>: GNU and GNU software</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.gnome.org"
TARGET="_top"
>Gnome</A
>: The official Gnome site</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.rpmfind.net"
TARGET="_top"
>RPM Find</A
>: all RPM packages</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.samba.org"
TARGET="_top"
>Samba</A
>: MS Windows file and print services</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.openldap.org"
TARGET="_top"
>Home of the OpenLDAP Project</A
>:
OpenLDAP server/clients/utilities, FAQ and other documentation.</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.sendmail.org"
TARGET="_top"
>Sendmail Homepage</A
>: A thorough
technical discussion of Sendmail features, includes configuration examples.</P
></LI
><LI
><P
>&#13; <A
HREF="http://netfilter.samba.org"
TARGET="_top"
>Netfilter</A
>: contains assorted
information about iptables: HOWTO, FAQ, guides, ...</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.gimp.org"
TARGET="_top"
>Official GIMP website</A
>: All
information about the GNU Image Manipulation Program.</P
></LI
><LI
><P
>&#13; <A
HREF="http://sourceforge.net/"
TARGET="_top"
>SourceForge.net</A
>: Open SOurce
software development site.</P
></LI
><LI
><P
>&#13; <A
HREF="http://www.vim.org/"
TARGET="_top"
>vIm homepage</A
>
</P
></LI
></UL
></DIV
></DIV
></DIV
><DIV
CLASS="appendix"
><HR><H1
><A
NAME="app2"
></A
>Appendix B. DOS versus Linux commands</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN12003"
></A
><P
></P
><P
>In this appendix, we matched DOS commands with their Linux equivalent.</P
><P
></P
></DIV
></BLOCKQUOTE
><P
>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.</P
><DIV
CLASS="table"
><A
NAME="AEN12006"
></A
><P
><B
>Table B-1. Overview of DOS/Linux commands</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>DOS commands</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Linux command</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#60;command&#62; /?</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>man &#60;command&#62;</B
> or <B
CLASS="command"
>command <TT
CLASS="option"
>--help</TT
></B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>cd</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>cd</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>chdir</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>pwd</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>cls</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>clear</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>copy</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>cp</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>date</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>date</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>del</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>rm</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>dir</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>ls</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>echo</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>echo</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>edit</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>vim (or other editor)</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>exit</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>exit</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>fc</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>diff</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>find</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>grep</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>format</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>mke2fs or mformat</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>mem</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>free</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>mkdir</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>mkdir</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>more</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>more or even less</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>move</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>mv</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>ren</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>mv</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>time</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>date</B
>
</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="appendix"
><HR><H1
><A
NAME="app3"
></A
>Appendix C. Shell Features</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN12118"
></A
><P
></P
><P
>This document gives an overview of common shell features (the same in every shell
flavour) and differing shell features (shell specific features).</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="AEN12120"
></A
>C.1. Common features</H1
><P
> 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.</P
><DIV
CLASS="table"
><A
NAME="AEN12123"
></A
><P
><B
>Table C-1. Common Shell Features</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#62;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Redirect output</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#62;&#62;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Append to file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#60;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Redirect input</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#60;&#60;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>"Here" document (redirect input)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>|</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Pipe output</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#38;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Run process in background.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Separate commands on same line</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>*</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Match any character(s) in filename</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>?</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Match single character in filename</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>[ ]</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Match any characters enclosed</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>( )</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Execute in subshell</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>` `</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Substitute output of enclosed command</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>" "</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Partial quote (allows variable and command expansion)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>' '</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Full quote (no expansion)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>\</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Quote following character</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$var</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Use value for variable</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$$</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Process id</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$0</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command name</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$n</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>nth argument (n from 0 to 9)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$*</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>All arguments as a simple word</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="literal"
>#</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Begin comment</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>bg</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Background execution</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>break</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Break from loop statements</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>cd</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change directories</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>continue</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Resume a program loop</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>echo</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display output</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>eval</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Evaluate arguments</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>exec</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Execute a new shell</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>fg</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Foreground execution</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>jobs</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Show active jobs</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>kill</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Terminate running jobs</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>newgrp</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Change to a new group</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>shift</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Shift positional parameters</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>stop</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Suspend a background job</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>suspend</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Suspend a foreground job</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>time</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Time a command</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>umask</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set or list file permissions</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>unset</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Erase variable or function definitions</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>wait</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Wait for a background job to finish</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect1"
><HR><H1
CLASS="sect1"
><A
NAME="AEN12249"
></A
>C.2. Differing features</H1
><P
>The table below shows major differences between the standard shell
(<B
CLASS="command"
>sh</B
>), Bourne Again SHell (<B
CLASS="command"
>bash</B
>), Korn shell
(<B
CLASS="command"
>ksh</B
>) and the C shell (<B
CLASS="command"
>csh</B
>).</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Shell compatibility</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Since the Bourne Again SHell is a superset of <B
CLASS="command"
>sh</B
>, all
<B
CLASS="command"
>sh</B
> commands will also work in <B
CLASS="command"
>bash</B
> - but not
vice versa. <B
CLASS="command"
>bash</B
> has many more features of its own, and, as the
table below demonstrates, many features incorporated from other shells.</P
><P
>Since the Turbo C shell is a superset of <B
CLASS="command"
>csh</B
>, all
<B
CLASS="command"
>csh</B
> commands will work in <B
CLASS="command"
>tcsh</B
>, but not the
other way round.</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="table"
><A
NAME="AEN12267"
></A
><P
><B
>Table C-2. Differing Shell Features</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>sh</B
>
</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>bash</B
>
</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>ksh</B
>
</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>csh</B
>
</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning/Action</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>$</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>%</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Default user prompt</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#62;|</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#62;|</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#62;!</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Force redirection</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#62; <TT
CLASS="filename"
>file</TT
> 2&#62;&#38;1</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#38;&#62; <TT
CLASS="filename"
>file</TT
>
</B
> or <B
CLASS="command"
>&#62; <TT
CLASS="filename"
>file</TT
> 2&#62;&#38;1</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#62; <TT
CLASS="filename"
>file</TT
> 2&#62;&#38;1</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#62;&#38; <TT
CLASS="filename"
>file</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Redirect stdout and stderr to <TT
CLASS="filename"
>file</TT
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>{ }</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>{ }</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Expand elements in list</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>`command`</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>`command`</B
> or <B
CLASS="command"
>$(command)</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>$(command)</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>`command`</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Substitute output of enclosed <B
CLASS="command"
>command</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$HOME</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$HOME</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$HOME</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$home</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Home directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>~</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>~</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>~</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Home directory symbol</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>~+</TT
>, <TT
CLASS="filename"
>~-</TT
>, <B
CLASS="command"
>dirs</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>~+</TT
>, <TT
CLASS="filename"
>~-</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="filename"
>=-</TT
>, <TT
CLASS="filename"
>=N</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Access directory stack</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#13; <TT
CLASS="varname"
>var</TT
>=value</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#13; <TT
CLASS="varname"
>VAR</TT
>=value</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>&#13; <TT
CLASS="varname"
>var</TT
>=value</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>set <TT
CLASS="varname"
>var</TT
>=value</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Variable assignment</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>export <TT
CLASS="varname"
>var</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>export <TT
CLASS="varname"
>VAR</TT
>=value</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>export <TT
CLASS="varname"
>var</TT
>=val</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>setenv <TT
CLASS="varname"
>var</TT
>
<TT
CLASS="parameter"
><I
>val</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set environment variable</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>${nnnn}</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>${nn}</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>More than 9 arguments can be referenced</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>"<TT
CLASS="varname"
>$@</TT
>"</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>"<TT
CLASS="varname"
>$@</TT
>"</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>"<TT
CLASS="varname"
>$@</TT
>"</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>All arguments as separate words</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$#</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$#</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$#</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$#argv</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Number of arguments</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$?</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$?</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$?</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$status</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Exit status of the most recently executed command</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$!</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$!</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$!</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PID of most recently backgrounded process</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$-</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$-</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <TT
CLASS="varname"
>$-</TT
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Current options</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>. <TT
CLASS="filename"
>file</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>source <TT
CLASS="filename"
>file</TT
>
</B
> or <B
CLASS="command"
>. <TT
CLASS="filename"
>file</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>. <TT
CLASS="filename"
>file</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>source <TT
CLASS="filename"
>file</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Read commands in file</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>alias x='y'</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>alias x=y</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>alias x y</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name <B
CLASS="command"
>x</B
> stands for command <B
CLASS="command"
>y</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>case</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>case</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>case</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>switch</B
> or <B
CLASS="command"
>case</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Choose alternatives</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>done</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>done</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>done</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>end</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>End a loop statement</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>esac</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>esac</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>esac</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>endsw</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>End <B
CLASS="command"
>case</B
> or <B
CLASS="command"
>switch</B
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>exit <TT
CLASS="parameter"
><I
>n</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>exit <TT
CLASS="parameter"
><I
>n</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>exit <TT
CLASS="parameter"
><I
>n</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>exit <TT
CLASS="parameter"
><I
>(expr)</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Exit with a status</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>for</B
>/<B
CLASS="command"
>do</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>for</B
>/<B
CLASS="command"
>do</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>for</B
>/<B
CLASS="command"
>do</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>foreach</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Loop through variables</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>set <TT
CLASS="option"
>-f</TT
>
</B
>, <B
CLASS="command"
>set <TT
CLASS="option"
>-o nullglob|dotglob|nocaseglob|noglob</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>noglob</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Ignore substitution characters for filename generation</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hash</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hash</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>alias <TT
CLASS="option"
>-t</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hashstat</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Display hashed commands (tracked aliases)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hash <TT
CLASS="parameter"
><I
>cmds</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hash <TT
CLASS="parameter"
><I
>cmds</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>alias <TT
CLASS="option"
>-t</TT
>
<TT
CLASS="parameter"
><I
>cmds</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>rehash</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Remember command locations</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hash <TT
CLASS="option"
>-r</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>hash <TT
CLASS="option"
>-r</TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>unhash</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Forget command locations</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>history</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>history</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>history</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>List previous commands</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="keycap"
>ArrowUp</B
>+<B
CLASS="keycap"
>Enter</B
> or <B
CLASS="command"
>!!</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>r</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>!!</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Redo previous command</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>!<TT
CLASS="parameter"
><I
>str</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>r <TT
CLASS="parameter"
><I
>str</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>!<TT
CLASS="parameter"
><I
>str</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Redo last command that starts with <SPAN
CLASS="QUOTE"
>"str"</SPAN
>
</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>!<TT
CLASS="parameter"
><I
>cmd</I
></TT
>:s/<TT
CLASS="parameter"
><I
>x</I
></TT
>/<TT
CLASS="parameter"
><I
>y</I
></TT
>/</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>r <TT
CLASS="parameter"
><I
>x</I
></TT
>=<TT
CLASS="parameter"
><I
>y</I
></TT
>
<TT
CLASS="parameter"
><I
>cmd</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>!<TT
CLASS="parameter"
><I
>cmd</I
></TT
>:s/<TT
CLASS="parameter"
><I
>x</I
></TT
>/<TT
CLASS="parameter"
><I
>y</I
></TT
>/</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Replace <SPAN
CLASS="QUOTE"
>"x"</SPAN
> with <SPAN
CLASS="QUOTE"
>"y"</SPAN
> in most recent command
starting with <SPAN
CLASS="QUOTE"
>"cmd"</SPAN
>, then execute.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>if [ <TT
CLASS="varname"
>$i</TT
> -eq <TT
CLASS="parameter"
><I
>5</I
></TT
> ]</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>if [ <TT
CLASS="varname"
>$i</TT
> -eq <TT
CLASS="parameter"
><I
>5</I
></TT
> ]</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>if ((<TT
CLASS="varname"
>i</TT
>==<TT
CLASS="parameter"
><I
>5</I
></TT
>))</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>if (<TT
CLASS="varname"
>$i</TT
>==<TT
CLASS="parameter"
><I
>5</I
></TT
>)</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Sample condition test</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>fi</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>fi</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>fi</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>endif</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>End <B
CLASS="command"
>if</B
> statement</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>ulimit</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>ulimit</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>ulimit</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>limit</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Set resource limits</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>pwd</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>pwd</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>pwd</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>dirs</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Print working directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>read</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>read</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>read</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>$&#60;</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Read from terminal</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>trap <TT
CLASS="parameter"
><I
>2</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>trap <TT
CLASS="parameter"
><I
>2</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>trap <TT
CLASS="parameter"
><I
>2</I
></TT
>
</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>onintr</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Ignore interrupts</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>unalias</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>unalias</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>unalias</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Remove aliases</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>until</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>until</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>until</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Begin <B
CLASS="command"
>until</B
> loop</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>while</B
>/<B
CLASS="command"
>do</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>while</B
>/<B
CLASS="command"
>do</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>while</B
>/<B
CLASS="command"
>do</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13; <B
CLASS="command"
>while</B
>
</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Begin <B
CLASS="command"
>while</B
> loop</TD
></TR
></TBODY
></TABLE
></DIV
><P
>The Bourne Again SHell has many more features not listed here. This table is just to
give you an idea of how this shell incorporates all useful ideas from other shells:
there are no blanks in the column for <B
CLASS="command"
>bash</B
>. More information on
features found only in Bash can be retrieved from the Bash info pages, in the
<SPAN
CLASS="QUOTE"
>"Bash Features"</SPAN
> section.</P
><P
>More information:</P
><P
>You should at least read one manual, being the manual of your shell. The preferred
choice would be <B
CLASS="command"
>info bash</B
>, <B
CLASS="command"
>bash</B
> being the GNU
shell and easiest for beginners. Print it out and take it home, study it whenever you
have 5 minutes.</P
><P
>See <A
HREF="#app2"
>Appendix B</A
> if you are having difficulties to assimilate shell commands.</P
></DIV
></DIV
><DIV
CLASS="GLOSSARY"
><H1
><A
NAME="glossary"
></A
>Glossary</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="abstract"
><A
NAME="AEN12751"
></A
><P
></P
><P
>This section contains an alphabetical overview of commands discussed in this document.</P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="A"
></A
>A</H1
><DL
><DT
><A
NAME="a2ps"
></A
><B
>a2ps</B
></DT
><DD
><P
>Format files for printing on a PostScript printer, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="acroread"
></A
><B
>acroread</B
></DT
><DD
><P
>PDF viewer, see <A
HREF="#sect_08_01_02_02"
>Section 8.1.2.2</A
>.</P
></DD
><DT
><A
NAME="adduser"
></A
><B
>adduser</B
></DT
><DD
><P
>Create a new user or update default new user information.</P
></DD
><DT
><A
NAME="alias"
></A
><B
>alias</B
></DT
><DD
><P
>Create a shell alias for a command.</P
></DD
><DT
><A
NAME="alsaconf"
></A
><B
>alsaconf</B
></DT
><DD
><P
>Configure sound card using the ALSA driver, see <A
HREF="#sect_11_01_02"
>Section 11.1.2</A
>.</P
></DD
><DT
><A
NAME="alsamixer"
></A
><B
>alsamixer</B
></DT
><DD
><P
>Tune ALSA sound device output, see <A
HREF="#sect_11_02_02_03"
>Section 11.2.2.3</A
>.</P
></DD
><DT
><A
NAME="anacron"
></A
><B
>anacron</B
></DT
><DD
><P
>Execute commands periodically, does not assume continuously running machine.</P
></DD
><DT
><A
NAME="apropos"
></A
><B
>apropos</B
></DT
><DD
><P
>Search the whatis database for strings, see <A
HREF="#sect_02_03_03_02"
>Section 2.3.3.2</A
>.</P
></DD
><DT
><A
NAME="apt-get"
></A
><B
>apt-get</B
></DT
><DD
><P
>APT package handling utility, see <A
HREF="#sect_07_06_03_02"
>Section 7.5.3.2</A
>.</P
></DD
><DT
><A
NAME="arecord"
></A
><B
>arecord</B
></DT
><DD
><P
>Record a sound sample, see <A
HREF="#sect_11_02_03"
>Section 11.2.3</A
>.</P
></DD
><DT
><A
NAME="aspell"
></A
><B
>aspell</B
></DT
><DD
><P
>Spell checker.</P
></DD
><DT
><A
NAME="at"
></A
><B
>at, atq, atrm</B
></DT
><DD
><P
>Queue, examine or delete jobs for later execution, see <A
HREF="#sect_04_01_02_02"
>Section 4.1.2.2</A
> and <A
HREF="#sect_04_04_03"
>Section 4.4.3</A
>.</P
></DD
><DT
><A
NAME="aumix"
></A
><B
>aumix</B
></DT
><DD
><P
>Adjust audio mixer, see <A
HREF="#sect_11_02_02_03"
>Section 11.2.2.3</A
>.</P
></DD
><DT
><A
NAME="awk"
></A
><B
>(g)awk</B
></DT
><DD
><P
>Pattern scanning and processing language.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="B"
></A
>B</H1
><DL
><DT
><A
NAME="bash"
></A
><B
>bash</B
></DT
><DD
><P
>Bourne Again SHell, see <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
> and <A
HREF="#sect_07_02_07"
>Section 7.2.5</A
>.</P
></DD
><DT
><A
NAME="batch"
></A
><B
>batch</B
></DT
><DD
><P
>Queue, examine or delete jobs for later execution, see <A
HREF="#sect_04_01_02_02"
>Section 4.1.2.2</A
>.</P
></DD
><DT
><A
NAME="bg"
></A
><B
>bg</B
></DT
><DD
><P
>Run a job in the background, see <A
HREF="#sect_04_01_02_01"
>Section 4.1.2.1</A
>.</P
></DD
><DT
><A
NAME="bitmap"
></A
><B
>bitmap</B
></DT
><DD
><P
>Bitmap editor and converter utilities for the X window System.</P
></DD
><DT
><A
NAME="bzip2"
></A
><B
>bzip2</B
></DT
><DD
><P
>A block-sorting file compressor, see <A
HREF="#sect_09_01_01_03"
>Section 9.1.1.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="C"
></A
>C</H1
><DL
><DT
><A
NAME="cardctl"
></A
><B
>cardctl</B
></DT
><DD
><P
>Manage PCMCIA cards, see <A
HREF="#sect_10_02_03_03"
>Section 10.2.3.3</A
>.</P
></DD
><DT
><A
NAME="cat"
></A
><B
>cat</B
></DT
><DD
><P
>Concatenate files and print to standard output, see <A
HREF="#sect_02_02"
>Section 2.2</A
> and <A
HREF="#sect_03_02_04"
>Section 3.2.4</A
>.</P
></DD
><DT
><A
NAME="cd"
></A
><B
>cd</B
></DT
><DD
><P
>Change directory, see <A
HREF="#sect_02_02"
>Section 2.2</A
>.</P
></DD
><DT
><A
NAME="cdp"
></A
><B
>cdp/cdplay</B
></DT
><DD
><P
>An interactive text-mode program for controlling and playing
audio CD Roms under Linux, see <A
HREF="#sect_11_02_01"
>Section 11.2.1</A
>.</P
></DD
><DT
><A
NAME="cdparanoia"
></A
><B
>cdparanoia</B
></DT
><DD
><P
>An audio CD reading utility which
includes extra data verification features, see <A
HREF="#sect_11_02_01"
>Section 11.2.1</A
>.</P
></DD
><DT
><A
NAME="cdrecord"
></A
><B
>cdrecord</B
></DT
><DD
><P
>Record a CD-R, see <A
HREF="#sect_09_02_02"
>Section 9.2.2</A
>.</P
></DD
><DT
><A
NAME="chattr"
></A
><B
>chattr</B
></DT
><DD
><P
>Change file attributes.</P
></DD
><DT
><A
NAME="chgrp"
></A
><B
>chgrp</B
></DT
><DD
><P
>Change group ownership, see <A
HREF="#sect_03_04_02_03"
>Section 3.4.2.3</A
>.</P
></DD
><DT
><A
NAME="chkconfig"
></A
><B
>chkconfig</B
></DT
><DD
><P
>Update or query run level information for system services, see <A
HREF="#sect_04_02_05_01"
>Section 4.2.5.1</A
>.</P
></DD
><DT
><A
NAME="chmod"
></A
><B
>chmod</B
></DT
><DD
><P
>Change file access permissions, see <A
HREF="#sect_03_04_01"
>Section 3.4.1</A
>, <A
HREF="#sect_03_04_02_01"
>Section 3.4.2.1</A
> and <A
HREF="#sect_03_04_02_04"
>Section 3.4.2.4</A
>.</P
></DD
><DT
><A
NAME="chown"
></A
><B
>chown</B
></DT
><DD
><P
>Change file owner and group, see <A
HREF="#sect_03_04_02_03"
>Section 3.4.2.3</A
>.</P
></DD
><DT
><A
NAME="compress"
></A
><B
>compress</B
></DT
><DD
><P
>Compress files.</P
></DD
><DT
><A
NAME="cp"
></A
><B
>cp</B
></DT
><DD
><P
>Copy files and directories, see <A
HREF="#sect_03_03_02"
>Section 3.3.2</A
>.</P
></DD
><DT
><A
NAME="crontab"
></A
><B
>crontab</B
></DT
><DD
><P
>Maintain crontab files, see <A
HREF="#sect_04_04_04"
>Section 4.4.4</A
>.</P
></DD
><DT
><A
NAME="csh"
></A
><B
>csh</B
></DT
><DD
><P
>Open a C shell, see <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
>.</P
></DD
><DT
><A
NAME="cut"
></A
><B
>cut</B
></DT
><DD
><P
>Remove sections from each line of file(s), see <A
HREF="#sect_07_02_07_02"
>Section 7.2.5.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="D"
></A
>D</H1
><DL
><DT
><A
NAME="date"
></A
><B
>date</B
></DT
><DD
><P
>Print or set system date and time.</P
></DD
><DT
><A
NAME="dd"
></A
><B
>dd</B
></DT
><DD
><P
>Convert and copy a file (disk dump), see <A
HREF="#sect_09_02_01_02"
>Section 9.2.1.2</A
>.</P
></DD
><DT
><A
NAME="df"
></A
><B
>df</B
></DT
><DD
><P
>Report file system disk usage, see <A
HREF="#sect_03_01_02_03"
>Section 3.1.2.3</A
>.</P
></DD
><DT
><A
NAME="dhcpcd"
></A
><B
>dhcpcd</B
></DT
><DD
><P
>DHCP client daemon, see <A
HREF="#sect_10_04_08"
>Section 10.3.8</A
>.</P
></DD
><DT
><A
NAME="diff"
></A
><B
>diff</B
></DT
><DD
><P
>Find differences between two files.</P
></DD
><DT
><A
NAME="dig"
></A
><B
>dig</B
></DT
><DD
><P
>Send domain name query packets to name servers, see <A
HREF="#sect_10_02_06_01"
>Section 10.2.6.1</A
>.</P
></DD
><DT
><A
NAME="dmesg"
></A
><B
>dmesg</B
></DT
><DD
><P
>Print or control the kernel ring buffer.</P
></DD
><DT
><A
NAME="du"
></A
><B
>du</B
></DT
><DD
><P
>Estimate file space usage.</P
></DD
><DT
><A
NAME="dump"
></A
><B
>dump</B
></DT
><DD
><P
>Backup file system, see <A
HREF="#sect_09_02_05"
>Section 9.2.5</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="E"
></A
>E</H1
><DL
><DT
><A
NAME="echo"
></A
><B
>echo</B
></DT
><DD
><P
>Display a line of text, see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
>.</P
></DD
><DT
><A
NAME="ediff"
></A
><B
>ediff</B
></DT
><DD
><P
>Diff to English translator.</P
></DD
><DT
><A
NAME="egrep"
></A
><B
>egrep</B
></DT
><DD
><P
>Extended grep.</P
></DD
><DT
><A
NAME="eject"
></A
><B
>eject</B
></DT
><DD
><P
>Unmount and eject removable media, see <A
HREF="#sect_07_06_05_02"
>Section 7.5.5.2</A
>.</P
></DD
><DT
><A
NAME="emacs"
></A
><B
>emacs</B
></DT
><DD
><P
>Start the Emacs editor, see <A
HREF="#sect_06_01_02_02"
>Section 6.1.2.1</A
>.</P
></DD
><DT
><A
NAME="exec"
></A
><B
>exec</B
></DT
><DD
><P
>Invoke subprocess(es), see <A
HREF="#sect_04_01_05_01"
>Section 4.1.5.1</A
>.</P
></DD
><DT
><A
NAME="exit"
></A
><B
>exit</B
></DT
><DD
><P
>Exit current shell, see <A
HREF="#sect_02_02"
>Section 2.2</A
>.</P
></DD
><DT
><A
NAME="export"
></A
><B
>export</B
></DT
><DD
><P
>Add function(s) to the shell environment, see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
>, <A
HREF="#sect_07_02_02"
>Section 7.2.1.2</A
> and <A
HREF="#sect_07_02_06_02"
>Section 7.2.4.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="F"
></A
>F</H1
><DL
><DT
><A
NAME="fax2ps"
></A
><B
>fax2ps</B
></DT
><DD
><P
>Convert a TIFF facsimile to PostScript, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="fdformat"
></A
><B
>fdformat</B
></DT
><DD
><P
>Format floppy disk, see <A
HREF="#sect_09_02_01_01"
>Section 9.2.1.1</A
>.</P
></DD
><DT
><A
NAME="fdisk"
></A
><B
>fdisk</B
></DT
><DD
><P
>Partition table manipulator for Linux, see <A
HREF="#sect_03_01_02_02"
>Section 3.1.2.2</A
>.</P
></DD
><DT
><A
NAME="fetchmail"
></A
><B
>fetchmail</B
></DT
><DD
><P
>Fetch mail from a POP, IMAP, ETRN or ODMR-capable server, see <A
HREF="#sect_10_04_02_03"
>Section 10.3.2.3</A
>.</P
></DD
><DT
><A
NAME="fg"
></A
><B
>fg</B
></DT
><DD
><P
>Bring a job in the foreground, see <A
HREF="#sect_04_01_02_01"
>Section 4.1.2.1</A
>.</P
></DD
><DT
><A
NAME="file"
></A
><B
>file</B
></DT
><DD
><P
>Determine file type, see <A
HREF="#sect_03_03_01_02"
>Section 3.3.1.2</A
>.</P
></DD
><DT
><A
NAME="find"
></A
><B
>find</B
></DT
><DD
><P
>Find files, see <A
HREF="#sect_03_03_03_03"
>Section 3.3.3.3</A
>.</P
></DD
><DT
><A
NAME="firefox"
></A
><B
>firefox</B
></DT
><DD
><P
>Web browser, see <A
HREF="#sect_10_04_03_02"
>Section 10.3.3.2</A
>.</P
></DD
><DT
><A
NAME="fork"
></A
><B
>fork</B
></DT
><DD
><P
>Create a new process, see <A
HREF="#sect_04_01_05_01"
>Section 4.1.5.1</A
>.</P
></DD
><DT
><A
NAME="formail"
></A
><B
>formail</B
></DT
><DD
><P
>Mail (re)formatter, see <A
HREF="#sect_10_04_02_03"
>Section 10.3.2.3</A
>.</P
></DD
><DT
><A
NAME="fortune"
></A
><B
>fortune</B
></DT
><DD
><P
>Print a random, hopefully interesting adage.</P
></DD
><DT
><A
NAME="ftp"
></A
><B
>ftp</B
></DT
><DD
><P
>Transfer files (unsafe unless anonymous account is used!)services, see <A
HREF="#sect_10_04_04_02"
>Section 10.3.4.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="G"
></A
>G</H1
><DL
><DT
><A
NAME="galeon"
></A
><B
>galeon</B
></DT
><DD
><P
>Graphical web browser.</P
></DD
><DT
><A
NAME="gdm"
></A
><B
>gdm</B
></DT
><DD
><P
>Gnome Display Manager, see <A
HREF="#sect_04_02_04"
>Section 4.2.4</A
>.</P
></DD
><DT
><A
NAME="gedit"
></A
><B
>gedit</B
></DT
><DD
><P
>GUI editor, see <A
HREF="#sect_06_03_03_03"
>Section 6.3.3.3</A
>.</P
></DD
><DT
><A
NAME="getty"
></A
><B
>(min/a)getty</B
></DT
><DD
><P
>Control console devices.</P
></DD
><DT
><A
NAME="gimp"
></A
><B
>gimp</B
></DT
><DD
><P
>Image manipulation program.</P
></DD
><DT
><A
NAME="gpg"
></A
><B
>gpg</B
></DT
><DD
><P
>Encrypt, check and decrypt files, see <A
HREF="#sect_09_04_01_02"
>Section 9.4.1.2</A
>.</P
></DD
><DT
><A
NAME="grep"
></A
><B
>grep</B
></DT
><DD
><P
>Print lines matching a pattern, see <A
HREF="#sect_03_03_03_04"
>Section 3.3.3.4</A
> and <A
HREF="#sect_05_03_01"
>Section 5.3.1</A
>.</P
></DD
><DT
><A
NAME="groff"
></A
><B
>groff</B
></DT
><DD
><P
>Emulate nroff command with groff, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="grub"
></A
><B
>grub</B
></DT
><DD
><P
>The grub shell, see <A
HREF="#sect_04_02_03"
>Section 4.2.3</A
> and <A
HREF="#sect_07_06_04"
>Section 7.5.4</A
>.</P
></DD
><DT
><A
NAME="gv"
></A
><B
>gv</B
></DT
><DD
><P
>A PostScript and PDF viewer, see <A
HREF="#sect_08_01_02_02"
>Section 8.1.2.2</A
>.</P
></DD
><DT
><A
NAME="gvim"
></A
><B
>gvim</B
></DT
><DD
><P
>Graphical version of the <SPAN
CLASS="application"
>vIm</SPAN
> editor, see <A
HREF="#sect_06_03_03_03"
>Section 6.3.3.3</A
>.</P
></DD
><DT
><A
NAME="gzip"
></A
><B
>gzip</B
></DT
><DD
><P
>Compress or expand files, see <A
HREF="#sect_09_01_01_03"
>Section 9.1.1.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="H"
></A
>H</H1
><DL
><DT
><A
NAME="halt"
></A
><B
>halt</B
></DT
><DD
><P
>Stop the system, see <A
HREF="#sect_04_02_06"
>Section 4.2.6</A
>.</P
></DD
><DT
><A
NAME="head"
></A
><B
>head</B
></DT
><DD
><P
>Output the first part of files, see <A
HREF="#sect_03_03_04_03"
>Section 3.3.4.3</A
>.</P
></DD
><DT
><A
NAME="help"
></A
><B
>help</B
></DT
><DD
><P
>Display help on a shell built-in command.</P
></DD
><DT
><A
NAME="host"
></A
><B
>host</B
></DT
><DD
><P
>DNS lookup utility, see <A
HREF="#sect_10_02_06_01"
>Section 10.2.6.1</A
>.</P
></DD
><DT
><A
NAME="httpd"
></A
><B
>httpd</B
></DT
><DD
><P
>Apache hypertext transfer protocol server, see <A
HREF="#sect_10_02_03_01"
>Section 10.2.3.1</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="I"
></A
>I</H1
><DL
><DT
><A
NAME="id"
></A
><B
>id</B
></DT
><DD
><P
>Print real and effective UIDs and GIDs, see <A
HREF="#sect_03_04_01"
>Section 3.4.1</A
>.</P
></DD
><DT
><A
NAME="ifconfig"
></A
><B
>ifconfig</B
></DT
><DD
><P
>Configure network interface or show configuration, see <A
HREF="#sect_10_01_02_03"
>Section 10.1.2.3</A
>.</P
></DD
><DT
><A
NAME="info"
></A
><B
>info</B
></DT
><DD
><P
>Read Info documents, see <A
HREF="#sect_02_03_03_01"
>Section 2.3.3.1</A
>.</P
></DD
><DT
><A
NAME="init"
></A
><B
>init</B
></DT
><DD
><P
>Process control initialization, see <A
HREF="#sect_04_01_05_01"
>Section 4.1.5.1</A
>, <A
HREF="#sect_04_02_04"
>Section 4.2.4</A
> and <A
HREF="#sect_04_02_05"
>Section 4.2.5</A
>.</P
></DD
><DT
><A
NAME="insserv"
></A
><B
>insserv</B
></DT
><DD
><P
>Manage init scripts, see <A
HREF="#sect_04_02_05_01"
>Section 4.2.5.1</A
>.</P
></DD
><DT
><A
NAME="iostat"
></A
><B
>iostat</B
></DT
><DD
><P
>Display I/O statistics, see <A
HREF="#sect_04_03_05_04"
>Section 4.3.5.4</A
>.</P
></DD
><DT
><A
NAME="ip"
></A
><B
>ip</B
></DT
><DD
><P
>Display/change network interface status, see <A
HREF="#sect_10_01_02_03"
>Section 10.1.2.3</A
>.</P
></DD
><DT
><A
NAME="ipchains"
></A
><B
>ipchains</B
></DT
><DD
><P
>IP firewall administration, see <A
HREF="#sect_10_05_04_02"
>Section 10.4.4.2</A
>.</P
></DD
><DT
><A
NAME="iptables"
></A
><B
>iptables</B
></DT
><DD
><P
>IP packet filter administration, see <A
HREF="#sect_10_05_04_02"
>Section 10.4.4.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="J"
></A
>J</H1
><DL
><DT
><A
NAME="jar"
></A
><B
>jar</B
></DT
><DD
><P
>Java archive tool, see <A
HREF="#sect_09_01_01_04"
>Section 9.1.1.4</A
>.</P
></DD
><DT
><A
NAME="jobs"
></A
><B
>jobs</B
></DT
><DD
><P
>List backgrounded tasks.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="K"
></A
>K</H1
><DL
><DT
><A
NAME="kdm"
></A
><B
>kdm</B
></DT
><DD
><P
>Desktop manager for KDE, see <A
HREF="#sect_04_02_04"
>Section 4.2.4</A
>.</P
></DD
><DT
><A
NAME="kedit"
></A
><B
>kedit</B
></DT
><DD
><P
>KDE graphical editor, see <A
HREF="#sect_06_03_03_03"
>Section 6.3.3.3</A
>.</P
></DD
><DT
><A
NAME="kill"
></A
><B
>kill(all)</B
></DT
><DD
><P
>Terminate process(es), see <A
HREF="#sect_04_01_02_01"
>Section 4.1.2.1</A
>.</P
></DD
><DT
><A
NAME="konqueror"
></A
><B
>konqueror</B
></DT
><DD
><P
>File manager, (help) browser, see <A
HREF="#sect_03_03_02_01"
>Section 3.3.2.1</A
>.</P
></DD
><DT
><A
NAME="ksh"
></A
><B
>ksh</B
></DT
><DD
><P
>Open a Korn shell, see <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
>.</P
></DD
><DT
><A
NAME="kwrite"
></A
><B
>kwrite</B
></DT
><DD
><P
>KDE graphical editor, see <A
HREF="#sect_06_03_03_03"
>Section 6.3.3.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="L"
></A
>L</H1
><DL
><DT
><A
NAME="less"
></A
><B
>less</B
></DT
><DD
><P
><B
CLASS="command"
>more</B
> with features, see <A
HREF="#sect_03_03_04_02"
>Section 3.3.4.2</A
>.</P
></DD
><DT
><A
NAME="lilo"
></A
><B
>lilo</B
></DT
><DD
><P
>Linux boot loader, see <A
HREF="#sect_04_02"
>Section 4.2</A
>.</P
></DD
><DT
><A
NAME="links"
></A
><B
>links</B
></DT
><DD
><P
>Text mode WWW browser, see <A
HREF="#sect_10_02_03_02"
>Section 10.2.3.2</A
>.</P
></DD
><DT
><A
NAME="ln"
></A
><B
>ln</B
></DT
><DD
><P
>Make links between files, see <A
HREF="#sect_03_03_05"
>Section 3.3.5</A
>.</P
></DD
><DT
><A
NAME="loadkeys"
></A
><B
>loadkeys</B
></DT
><DD
><P
>Load keyboard translation tables, see <A
HREF="#sect_07_05_01"
>Section 7.4.1</A
>.</P
></DD
><DT
><A
NAME="locate"
></A
><B
>locate</B
></DT
><DD
><P
>Find files, see <A
HREF="#sect_03_03_03_03"
>Section 3.3.3.3</A
> and <A
HREF="#sect_04_04_04"
>Section 4.4.4</A
>.</P
></DD
><DT
><A
NAME="logout"
></A
><B
>logout</B
></DT
><DD
><P
>Close current shell, see <A
HREF="#sect_02_01_03"
>Section 2.1.3</A
>.</P
></DD
><DT
><A
NAME="lp"
></A
><B
>lp</B
></DT
><DD
><P
>Send requests to the LP print service, see <A
HREF="#sect_08_01"
>Section 8.1</A
>.</P
></DD
><DT
><A
NAME="lpc"
></A
><B
>lpc</B
></DT
><DD
><P
>Line printer control program, see <A
HREF="#sect_08_01"
>Section 8.1</A
>.</P
></DD
><DT
><A
NAME="lpq"
></A
><B
>lpq</B
></DT
><DD
><P
>Print spool queue examination program, see <A
HREF="#sect_08_01"
>Section 8.1</A
>.</P
></DD
><DT
><A
NAME="lpr"
></A
><B
>lpr</B
></DT
><DD
><P
>Offline print, see <A
HREF="#sect_08_01"
>Section 8.1</A
>.</P
></DD
><DT
><A
NAME="lprm"
></A
><B
>lprm</B
></DT
><DD
><P
>Remove print requests, see <A
HREF="#sect_08_01"
>Section 8.1</A
>.</P
></DD
><DT
><A
NAME="ls"
></A
><B
>ls</B
></DT
><DD
><P
>List directory content, see <A
HREF="#sect_02_02"
>Section 2.2</A
>, <A
HREF="#sect_03_01_01_02"
>Section 3.1.1.2</A
> and <A
HREF="#sect_03_03_01_01"
>Section 3.3.1.1</A
>.</P
></DD
><DT
><A
NAME="lynx"
></A
><B
>lynx</B
></DT
><DD
><P
>Text mode WWW browser, see <A
HREF="#sect_10_02_03_02"
>Section 10.2.3.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="M"
></A
>M</H1
><DL
><DT
><A
NAME="mail"
></A
><B
>mail</B
></DT
><DD
><P
>Send and receive mail, see <A
HREF="#sect_10_04_02_03"
>Section 10.3.2.3</A
>.</P
></DD
><DT
><A
NAME="man"
></A
><B
>man</B
></DT
><DD
><P
>Read man pages, see <A
HREF="#sect_02_03_02"
>Section 2.3.2</A
>.</P
></DD
><DT
><A
NAME="mc"
></A
><B
>mc</B
></DT
><DD
><P
>Midnight COmmander, file manager, see <A
HREF="#sect_03_03_02_01"
>Section 3.3.2.1</A
>.</P
></DD
><DT
><A
NAME="mcopy"
></A
><B
>mcopy</B
></DT
><DD
><P
>Copy MSDOS files to/from Unix.</P
></DD
><DT
><A
NAME="mdir"
></A
><B
>mdir</B
></DT
><DD
><P
>Display an MSDOS directory.</P
></DD
><DT
><A
NAME="memusage"
></A
><B
>memusage</B
></DT
><DD
><P
>Display memory usage, see <A
HREF="#sect_04_03_05_03"
>Section 4.3.5.3</A
>.</P
></DD
><DT
><A
NAME="memusagestat"
></A
><B
>memusagestat</B
></DT
><DD
><P
>Display memory usage statistics, see <A
HREF="#sect_04_03_05_03"
>Section 4.3.5.3</A
>.</P
></DD
><DT
><A
NAME="mesg"
></A
><B
>mesg</B
></DT
><DD
><P
>Control write access to your terminal, see <A
HREF="#sect_04_01_06"
>Section 4.1.6</A
>.</P
></DD
><DT
><A
NAME="mformat"
></A
><B
>mformat</B
></DT
><DD
><P
>Add an MSDOS file system to a low-level formatted floppy disk, see <A
HREF="#sect_09_02_01_01"
>Section 9.2.1.1</A
>.</P
></DD
><DT
><A
NAME="mkbootdisk"
></A
><B
>mkbootdisk</B
></DT
><DD
><P
>Creates a stand-alone boot floppy for the running system.</P
></DD
><DT
><A
NAME="mkdir"
></A
><B
>mkdir</B
></DT
><DD
><P
>Create directory, see <A
HREF="#sect_03_03_02"
>Section 3.3.2</A
>.</P
></DD
><DT
><A
NAME="mkisofs"
></A
><B
>mkisofs</B
></DT
><DD
><P
>Create a hybrid ISO9660 filesystem, see <A
HREF="#sect_09_02_02"
>Section 9.2.2</A
>.</P
></DD
><DT
><A
NAME="mplayer"
></A
><B
>mplayer</B
></DT
><DD
><P
>Movie player/encoder for Linux, see <A
HREF="#sect_11_02_02"
>Section 11.2.2</A
> and <A
HREF="#sect_11_02_04"
>Section 11.3</A
>.</P
></DD
><DT
><A
NAME="more"
></A
><B
>more</B
></DT
><DD
><P
>Filter for displaying text one screen at the time, see <A
HREF="#sect_03_03_04_02"
>Section 3.3.4.2</A
>.</P
></DD
><DT
><A
NAME="mount"
></A
><B
>mount</B
></DT
><DD
><P
>Mount a file system or display information about mounted file systems, see <A
HREF="#sect_07_06_05_01"
>Section 7.5.5.1</A
>.</P
></DD
><DT
><A
NAME="mozilla"
></A
><B
>mozilla</B
></DT
><DD
><P
>Web browser, see <A
HREF="#sect_10_02_03_02"
>Section 10.2.3.2</A
>.</P
></DD
><DT
><A
NAME="mt"
></A
><B
>mt</B
></DT
><DD
><P
>Control magnetic tape drive operation.</P
></DD
><DT
><A
NAME="mtr"
></A
><B
>mtr</B
></DT
><DD
><P
>Network diagnostic tool.</P
></DD
><DT
><A
NAME="mv"
></A
><B
>mv</B
></DT
><DD
><P
>Rename files, <A
HREF="#sect_03_03_02"
>Section 3.3.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="N"
></A
>N</H1
><DL
><DT
><A
NAME="named"
></A
><B
>named</B
></DT
><DD
><P
>Internet domain name server, see <A
HREF="#sect_10_04_07"
>Section 10.3.7</A
>.</P
></DD
><DT
><A
NAME="nautilus"
></A
><B
>nautilus</B
></DT
><DD
><P
>File manager, see <A
HREF="#sect_03_03_02_01"
>Section 3.3.2.1</A
>.</P
></DD
><DT
><A
NAME="ncftp"
></A
><B
>ncftp</B
></DT
><DD
><P
>Browser program for ftp services (insecure!), see <A
HREF="#sect_10_04_04_02"
>Section 10.3.4.2</A
>.</P
></DD
><DT
><A
NAME="netstat"
></A
><B
>netstat</B
></DT
><DD
><P
>Print network connections, routing tables, interface statistics, masquerade connections, and multi-cast memberships, see <A
HREF="#sect_10_01_02_05"
>Section 10.1.2.5</A
> and <A
HREF="#sect_10_05_02"
>Section 10.4.2</A
>.</P
></DD
><DT
><A
NAME="newgrp"
></A
><B
>newgrp</B
></DT
><DD
><P
>Log in to another group, see <A
HREF="#sect_03_04_02_02"
>Section 3.4.2.2</A
>.</P
></DD
><DT
><A
NAME="nfsstat"
></A
><B
>nfsstat</B
></DT
><DD
><P
>Print statistics about networked file systems.</P
></DD
><DT
><A
NAME="nice"
></A
><B
>nice</B
></DT
><DD
><P
>Run a program with modified scheduling priority, see <A
HREF="#sect_04_03_05_01"
>Section 4.3.5.1</A
>.</P
></DD
><DT
><A
NAME="nmap"
></A
><B
>nmap</B
></DT
><DD
><P
>Network exploration tool and security scanner.</P
></DD
><DT
><A
NAME="ntpd"
></A
><B
>ntpd</B
></DT
><DD
><P
>Network Time Protocol Daemon, see <A
HREF="#sect_07_05_03"
>Section 7.4.3</A
>.</P
></DD
><DT
><A
NAME="ntpdate"
></A
><B
>ntpdate</B
></DT
><DD
><P
>Set the date and time via an NTP server, see <A
HREF="#sect_07_05_03"
>Section 7.4.3</A
>.</P
></DD
><DT
><A
NAME="ntsysv"
></A
><B
>ntsysv</B
></DT
><DD
><P
>Simple interface for configuring run levels, see <A
HREF="#sect_04_02_05_01"
>Section 4.2.5.1</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="O"
></A
>O</H1
><DL
><DT
><A
NAME="ogle"
></A
><B
>ogle</B
></DT
><DD
><P
>DVD player with support for DVD menus, see <A
HREF="#sect_11_02_04"
>Section 11.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="P"
></A
>P</H1
><DL
><DT
><A
NAME="passwd"
></A
><B
>passwd</B
></DT
><DD
><P
>Change password, see <A
HREF="#sect_02_02"
>Section 2.2</A
> and <A
HREF="#sect_04_01_06"
>Section 4.1.6</A
>.</P
></DD
><DT
><A
NAME="pccardctl"
></A
><B
>pccardctl</B
></DT
><DD
><P
>Manage PCMCIA cards, see <A
HREF="#sect_10_02_03_03"
>Section 10.2.3.3</A
>.</P
></DD
><DT
><A
NAME="pdf2ps"
></A
><B
>pdf2ps</B
></DT
><DD
><P
>Ghostscript PDF to PostScript translator, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="perl"
></A
><B
>perl</B
></DT
><DD
><P
>Practical Extraction and Report Language.</P
></DD
><DT
><A
NAME="pg"
></A
><B
>pg</B
></DT
><DD
><P
>Page through text output, see <A
HREF="#sect_03_03_04_02"
>Section 3.3.4.2</A
>.</P
></DD
><DT
><A
NAME="pgrep"
></A
><B
>pgrep</B
></DT
><DD
><P
>Look up processes based on name and other attributes, see <A
HREF="#sect_04_01_04"
>Section 4.1.4</A
>.</P
></DD
><DT
><A
NAME="ping"
></A
><B
>ping</B
></DT
><DD
><P
>Send echo request to a host, see <A
HREF="#sect_10_02_06_02"
>Section 10.2.6.2</A
>.</P
></DD
><DT
><A
NAME="play"
></A
><B
>play</B
></DT
><DD
><P
>Play a sound sample, see <A
HREF="#sect_11_02_03"
>Section 11.2.3</A
>.</P
></DD
><DT
><A
NAME="pr"
></A
><B
>pr</B
></DT
><DD
><P
>Convert text files for printing.</P
></DD
><DT
><A
NAME="printenv"
></A
><B
>printenv</B
></DT
><DD
><P
>Print all or part of environment, see <A
HREF="#sect_07_02_1"
>Section 7.2.1</A
>.</P
></DD
><DT
><A
NAME="procmail"
></A
><B
>procmail</B
></DT
><DD
><P
>Autonomous mail processor, see <A
HREF="#sect_10_04_02_03"
>Section 10.3.2.3</A
>.</P
></DD
><DT
><A
NAME="ps"
></A
><B
>ps</B
></DT
><DD
><P
>Report process status, see <A
HREF="#sect_04_01_04"
>Section 4.1.4</A
> and <A
HREF="#sect_04_03_05_04"
>Section 4.3.5.4</A
>.</P
></DD
><DT
><A
NAME="pstree"
></A
><B
>pstree</B
></DT
><DD
><P
>Display a tree of processes, see <A
HREF="#sect_04_01_04"
>Section 4.1.4</A
>.</P
></DD
><DT
><A
NAME="pwd"
></A
><B
>pwd</B
></DT
><DD
><P
>Print present working directory, see <A
HREF="#sect_02_02"
>Section 2.2</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="Q"
></A
>Q</H1
><DL
><DT
><A
NAME="quota"
></A
><B
>quota</B
></DT
><DD
><P
>Display disk usage and limits, see <A
HREF="#sect_03_02_03_03"
>Section 3.2.3.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="R"
></A
>R</H1
><DL
><DT
><A
NAME="rcp"
></A
><B
>rcp</B
></DT
><DD
><P
>Remote copy (unsafe!)</P
></DD
><DT
><A
NAME="rdesktop"
></A
><B
>rdesktop</B
></DT
><DD
><P
>Remote Desktop Protocol client, see <A
HREF="#sect_10_05_06"
>Section 10.4.6</A
>.</P
></DD
><DT
><A
NAME="reboot"
></A
><B
>reboot</B
></DT
><DD
><P
>Stop the system, see <A
HREF="#sect_04_02_06"
>Section 4.2.6</A
>.</P
></DD
><DT
><A
NAME="recode"
></A
><B
>recode</B
></DT
><DD
><P
>Convert files to another character set, see <A
HREF="#sect_07_05_04"
>Section 7.4.4</A
>.</P
></DD
><DT
><A
NAME="renice"
></A
><B
>renice</B
></DT
><DD
><P
>Alter priority of a running process, see <A
HREF="#sect_04_03_05_01"
>Section 4.3.5.1</A
>.</P
></DD
><DT
><A
NAME="restore"
></A
><B
>restore</B
></DT
><DD
><P
>Restore backups made with <B
CLASS="command"
>dump</B
>, see <A
HREF="#sect_09_02_05"
>Section 9.2.5</A
>.</P
></DD
><DT
><A
NAME="rlogin"
></A
><B
>rlogin</B
></DT
><DD
><P
>Remote login (telnet, insecure!), see <A
HREF="#sect_10_05_02"
>Section 10.4.2</A
> and <A
HREF="#sect_10_06_02"
>Section 10.5.2</A
>.</P
></DD
><DT
><A
NAME="rm"
></A
><B
>rm</B
></DT
><DD
><P
>Remove a file, see <A
HREF="#sect_03_03_02"
>Section 3.3.2</A
>.</P
></DD
><DT
><A
NAME="rmdir"
></A
><B
>rmdir</B
></DT
><DD
><P
>Remove a directory, see <A
HREF="#sect_03_03_02_03"
>Section 3.3.2.2</A
>.</P
></DD
><DT
><A
NAME="roff"
></A
><B
>roff</B
></DT
><DD
><P
>A survey of the roff typesetting system, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="rpm"
></A
><B
>rpm</B
></DT
><DD
><P
>RPM Package Manager, see <A
HREF="#sect_07_06_02_01"
>Section 7.5.2.1</A
>.</P
></DD
><DT
><A
NAME="rsh"
></A
><B
>rsh</B
></DT
><DD
><P
>Remote shell (insecure!), see <A
HREF="#sect_10_05_02"
>Section 10.4.2</A
>.</P
></DD
><DT
><A
NAME="rsync"
></A
><B
>rsync</B
></DT
><DD
><P
>Synchronize two directories, see <A
HREF="#sect_09_03"
>Section 9.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="S"
></A
>S</H1
><DL
><DT
><A
NAME="scp"
></A
><B
>scp</B
></DT
><DD
><P
>Secure remote copy, see <A
HREF="#sect_10_05_04_01"
>Section 10.4.4.1</A
>.</P
></DD
><DT
><A
NAME="screen"
></A
><B
>screen</B
></DT
><DD
><P
>Screen manager with VT100 emulation, see <A
HREF="#sect_04_01_02_01"
>Section 4.1.2.1</A
>.</P
></DD
><DT
><A
NAME="set"
></A
><B
>set</B
></DT
><DD
><P
>Display, set or change variable.</P
></DD
><DT
><A
NAME="setterm"
></A
><B
>setterm</B
></DT
><DD
><P
>Set terminal attributes.</P
></DD
><DT
><A
NAME="sftp"
></A
><B
>sftp</B
></DT
><DD
><P
>Secure (encrypted) ftp, see and <A
HREF="#sect_10_05_04_01"
>Section 10.4.4.1</A
>.</P
></DD
><DT
><A
NAME="sh"
></A
><B
>sh</B
></DT
><DD
><P
>Open a standard shell, see <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
>.</P
></DD
><DT
><A
NAME="shutdown"
></A
><B
>shutdown</B
></DT
><DD
><P
>Bring the system down, see <A
HREF="#sect_04_02_06"
>Section 4.2.6</A
>.</P
></DD
><DT
><A
NAME="sleep"
></A
><B
>sleep</B
></DT
><DD
><P
>Wait for a given period, see <A
HREF="#sect_04_04_01"
>Section 4.4.1</A
>.</P
></DD
><DT
><A
NAME="slocate"
></A
><B
>slocate</B
></DT
><DD
><P
>Security Enhanced version of the GNU Locate, see <A
HREF="#sect_03_03_03_03"
>Section 3.3.3.3</A
>.</P
></DD
><DT
><A
NAME="slrnn"
></A
><B
>slrnn</B
></DT
><DD
><P
>text mode Usenet client, see <A
HREF="#sect_10_02_06"
>Section 10.2.6</A
>.</P
></DD
><DT
><A
NAME="snort"
></A
><B
>snort</B
></DT
><DD
><P
>Network intrusion detection tool.</P
></DD
><DT
><A
NAME="sort"
></A
><B
>sort</B
></DT
><DD
><P
>Sort lines of text files, see <A
HREF="#sect_05_03_02"
>Section 5.3.2</A
>.</P
></DD
><DT
><A
NAME="spell"
></A
><B
>spell</B
></DT
><DD
><P
>Spell checker, see <A
HREF="#sect_05_01_02_03"
>Section 5.1.2.3</A
>.</P
></DD
><DT
><A
NAME="ssh"
></A
><B
>ssh</B
></DT
><DD
><P
>Secure shell, see <A
HREF="#sect_10_05_04_01"
>Section 10.4.4.1</A
>.</P
></DD
><DT
><A
NAME="ssh-keygen"
></A
><B
>ssh-keygen</B
></DT
><DD
><P
>Authentication key generation, management and conversion, see <A
HREF="#sect_10_05_04_05"
>Section 10.4.4.5</A
>.</P
></DD
><DT
><A
NAME="stty"
></A
><B
>stty</B
></DT
><DD
><P
>Change and print terminal line settings.</P
></DD
><DT
><A
NAME="su"
></A
><B
>su</B
></DT
><DD
><P
>Switch user, see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
>, <A
HREF="#sect_07_06_03_02"
>Section 7.5.3.2</A
> and <A
HREF="#sect_10_05_06"
>Section 10.4.6</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="T"
></A
>T</H1
><DL
><DT
><A
NAME="tac"
></A
><B
>tac</B
></DT
><DD
><P
>Concatenate and print files in reverse, see <A
HREF="#cat"
><I
CLASS="glossterm"
>cat</I
></A
>.</P
></DD
><DT
><A
NAME="tail"
></A
><B
>tail</B
></DT
><DD
><P
>Output the last part of files, see <A
HREF="#sect_03_03_04_03"
>Section 3.3.4.3</A
>.</P
></DD
><DT
><A
NAME="talk"
></A
><B
>talk</B
></DT
><DD
><P
>Talk to a user.</P
></DD
><DT
><A
NAME="tar"
></A
><B
>tar</B
></DT
><DD
><P
>Archiving utility, see <A
HREF="#sect_09_01_01_01"
>Section 9.1.1.1</A
>.</P
></DD
><DT
><A
NAME="tcsh"
></A
><B
>tcsh</B
></DT
><DD
><P
>Open a Turbo C shell, see <A
HREF="#sect_03_02_03_02"
>Section 3.2.3.2</A
>.</P
></DD
><DT
><A
NAME="telinit"
></A
><B
>telinit</B
></DT
><DD
><P
>Process control initialization, see <A
HREF="#sect_04_02_05"
>Section 4.2.5</A
>.</P
></DD
><DT
><A
NAME="telnet"
></A
><B
>telnet</B
></DT
><DD
><P
>User interface to the TELNET protocol (insecure!), see <A
HREF="#sect_10_05_02"
>Section 10.4.2</A
>.</P
></DD
><DT
><A
NAME="tex"
></A
><B
>tex</B
></DT
><DD
><P
>Text formatting and typesetting, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="time"
></A
><B
>time</B
></DT
><DD
><P
>Time a simple command or give resource usage, see <A
HREF="#sect_04_03_02"
>Section 4.3.2</A
>.</P
></DD
><DT
><A
NAME="tin"
></A
><B
>tin</B
></DT
><DD
><P
>News reading program, see <A
HREF="#sect_10_02_06"
>Section 10.2.6</A
>.</P
></DD
><DT
><A
NAME="top"
></A
><B
>top</B
></DT
><DD
><P
>Display top CPU processes, see <A
HREF="#sect_04_01_04"
>Section 4.1.4</A
>, <A
HREF="#sect_04_03_05_03"
>Section 4.3.5.3</A
> and <A
HREF="#sect_04_03_05_04"
>Section 4.3.5.4</A
>.</P
></DD
><DT
><A
NAME="touch"
></A
><B
>touch</B
></DT
><DD
><P
>Change file timestamps, see <A
HREF="#sect_07_01_02"
>Section 7.1.2</A
>.</P
></DD
><DT
><A
NAME="traceroute"
></A
><B
>traceroute</B
></DT
><DD
><P
>Print the route packets take to network host, see <A
HREF="#sect_10_02_06_03"
>Section 10.2.6.3</A
>.</P
></DD
><DT
><A
NAME="tripwire"
></A
><B
>tripwire</B
></DT
><DD
><P
>A file integrity checker for UNIX systems, see <A
HREF="#sect_10_05_05"
>Section 10.4.5</A
>.</P
></DD
><DT
><A
NAME="troff"
></A
><B
>troff</B
></DT
><DD
><P
>Format documents, see <A
HREF="#sect_08_01_02"
>Section 8.1.2</A
>.</P
></DD
><DT
><A
NAME="tvtime"
></A
><B
>tvime</B
></DT
><DD
><P
>A high quality television application.</P
></DD
><DT
><A
NAME="twm"
></A
><B
>twm</B
></DT
><DD
><P
>Tab Window Manager for the X Window System.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="U"
></A
>U</H1
><DL
><DT
><A
NAME="ulimit"
></A
><B
>ulimit</B
></DT
><DD
><P
>Controll resources, see <A
HREF="#sect_07_01_02_05"
>Section 7.1.2.5</A
>.</P
></DD
><DT
><A
NAME="umask"
></A
><B
>umask</B
></DT
><DD
><P
>Set user file creation mask, see <A
HREF="#sect_03_04_02_02"
>Section 3.4.2.2</A
>.</P
></DD
><DT
><A
NAME="umount"
></A
><B
>umount</B
></DT
><DD
><P
>Unmount a file system.</P
></DD
><DT
><A
NAME="uncompress"
></A
><B
>uncompress</B
></DT
><DD
><P
>Decompress compressed files.</P
></DD
><DT
><A
NAME="uniq"
></A
><B
>uniq</B
></DT
><DD
><P
>Remove duplicate lines from a sorted file, see <A
HREF="#sect_05_03_02"
>Section 5.3.2</A
>.</P
></DD
><DT
><A
NAME="up2date"
></A
><B
>up2date</B
></DT
><DD
><P
>Update RPM packages, see <A
HREF="#sect_07_06_03_03"
>Section 7.5.3.3</A
>.</P
></DD
><DT
><A
NAME="update"
></A
><B
>update</B
></DT
><DD
><P
>Kernel daemon to flush dirty buffers back to disk.</P
></DD
><DT
><A
NAME="update-rc.d"
></A
><B
>update-rc.d</B
></DT
><DD
><P
>Configure init scripts, see <A
HREF="#sect_04_02_05_01"
>Section 4.2.5.1</A
>.</P
></DD
><DT
><A
NAME="uptime"
></A
><B
>uptime</B
></DT
><DD
><P
>Display system uptime and average load, see <A
HREF="#sect_04_01_04"
>Section 4.1.4</A
> and <A
HREF="#sect_04_03_05_02"
>Section 4.3.5.2</A
>.</P
></DD
><DT
><A
NAME="urpmi"
></A
><B
>urpmi</B
></DT
><DD
><P
>Update RPM packages, see <A
HREF="#sect_07_06_03_03"
>Section 7.5.3.3</A
>.</P
></DD
><DT
><A
NAME="userdel"
></A
><B
>userdel</B
></DT
><DD
><P
>Delete a user account and related files.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="V"
></A
>V</H1
><DL
><DT
><A
NAME="vi"
></A
><B
>vi(m)</B
></DT
><DD
><P
>Start the vi (improved) editor, see <A
HREF="#sect_06_01_02_03"
>Section 6.1.2.2</A
>.</P
></DD
><DT
><A
NAME="vimtutor"
></A
><B
>vimtutor</B
></DT
><DD
><P
>The Vim tutor.</P
></DD
><DT
><A
NAME="vmstat"
></A
><B
>vmstat</B
></DT
><DD
><P
>Report virtual memory statistics, see <A
HREF="#sect_04_03_05_04"
>Section 4.3.5.4</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="W"
></A
>W</H1
><DL
><DT
><A
NAME="w"
></A
><B
>w</B
></DT
><DD
><P
>Show who is logged on and what they are doing.</P
></DD
><DT
><A
NAME="wall"
></A
><B
>wall</B
></DT
><DD
><P
>Send a message to everybody's terminal, see <A
HREF="#sect_04_01_06"
>Section 4.1.6</A
>.</P
></DD
><DT
><A
NAME="wc"
></A
><B
>wc</B
></DT
><DD
><P
>Print the number of bytes, words and lines in files, see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
>.</P
></DD
><DT
><A
NAME="which"
></A
><B
>which</B
></DT
><DD
><P
>Shows the full path of (shell) commands, see <A
HREF="#sect_03_02_01"
>Section 3.2.1</A
> and <A
HREF="#sect_03_03_03_02"
>Section 3.3.3.2</A
>.</P
></DD
><DT
><A
NAME="who"
></A
><B
>who</B
></DT
><DD
><P
>Show who is logged on, see <A
HREF="#sect_04_01_06"
>Section 4.1.6</A
>.</P
></DD
><DT
><A
NAME="whoami"
></A
><B
>who am i</B
></DT
><DD
><P
>Print effective user ID.</P
></DD
><DT
><A
NAME="whois"
></A
><B
>whois</B
></DT
><DD
><P
>Query a whois or nicname database, see <A
HREF="#sect_10_02_06_04"
>Section 10.2.6.4</A
>.</P
></DD
><DT
><A
NAME="write"
></A
><B
>write</B
></DT
><DD
><P
>Send a message to another user, see <A
HREF="#sect_04_01_06"
>Section 4.1.6</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="X"
></A
>X</H1
><DL
><DT
><A
NAME="xargs"
></A
><B
>xargs</B
></DT
><DD
><P
>Build and execute command lines from standard input, see <A
HREF="#sect_03_03_03_03"
>Section 3.3.3.3</A
>.</P
></DD
><DT
><A
NAME="xauth"
></A
><B
>xauth</B
></DT
><DD
><P
>X authority file utility.</P
></DD
><DT
><A
NAME="xawtv"
></A
><B
>xawtv</B
></DT
><DD
><P
>An X11 program for watching TV.</P
></DD
><DT
><A
NAME="xcdroast"
></A
><B
>xcdroast</B
></DT
><DD
><P
>Graphical front end to cdrecord, see <A
HREF="#sect_09_02_02"
>Section 9.2.2</A
>.</P
></DD
><DT
><A
NAME="xclock"
></A
><B
>xclock</B
></DT
><DD
><P
>Analog/digital clock for X.</P
></DD
><DT
><A
NAME="xconsole"
></A
><B
>xconsole</B
></DT
><DD
><P
>Monitor system console messages with X.</P
></DD
><DT
><A
NAME="xdm"
></A
><B
>xdm</B
></DT
><DD
><P
>X Display Manager with support for XDMCP, host chooser, see <A
HREF="#sect_04_02_04"
>Section 4.2.4</A
> and <A
HREF="#sect_07_03_02"
>Section 7.3.2</A
>.</P
></DD
><DT
><A
NAME="xdvi"
></A
><B
>xdvi</B
></DT
><DD
><P
>DVI viewer, see <A
HREF="#sect_08_01_02_02"
>Section 8.1.2.2</A
>.</P
></DD
><DT
><A
NAME="xedit"
></A
><B
>xedit</B
></DT
><DD
><P
>X Window graphical editor, see <A
HREF="#sect_06_03_03_03"
>Section 6.3.3.3</A
>.</P
></DD
><DT
><A
NAME="xfs"
></A
><B
>xfs</B
></DT
><DD
><P
>X font server.</P
></DD
><DT
><A
NAME="xhost"
></A
><B
>xhost</B
></DT
><DD
><P
>Server access control program for X, see <A
HREF="#sect_10_05_03_02"
>Section 10.4.3.2</A
>.</P
></DD
><DT
><A
NAME="xine"
></A
><B
>xine</B
></DT
><DD
><P
>A free video player, see <A
HREF="#sect_11_02_04"
>Section 11.3</A
>.</P
></DD
><DT
><A
NAME="xinetd"
></A
><B
>xinetd</B
></DT
><DD
><P
>The extended Internet services daemon, see <A
HREF="#sect_10_04_01_02"
>Section 10.3.1.2</A
>.</P
></DD
><DT
><A
NAME="xload"
></A
><B
>xload</B
></DT
><DD
><P
>System load average display for X, see <A
HREF="#sect_04_03_05_06"
>Section 4.3.5.6</A
>.</P
></DD
><DT
><A
NAME="xlsfonts"
></A
><B
>xlsfonts</B
></DT
><DD
><P
>Server font list displayer for X.</P
></DD
><DT
><A
NAME="xmms"
></A
><B
>xmms</B
></DT
><DD
><P
>Audio player for X, see <A
HREF="#sect_11_02_02_01"
>Section 11.2.2.1</A
>.</P
></DD
><DT
><A
NAME="xpdf"
></A
><B
>xpdf</B
></DT
><DD
><P
>PDF viewer, see <A
HREF="#sect_08_01_02_02"
>Section 8.1.2.2</A
>.</P
></DD
><DT
><A
NAME="xterm"
></A
><B
>xterm</B
></DT
><DD
><P
>Terminal emulator for X.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="Y"
></A
>Y</H1
><DL
><DT
><A
NAME="yast"
></A
><B
>yast</B
></DT
><DD
><P
>System administration tool on Novell SuSE Linux.</P
></DD
><DT
><A
NAME="yum"
></A
><B
>yum</B
></DT
><DD
><P
>Update RPM packages, see <A
HREF="#sect_07_06_03_03"
>Section 7.5.3.3</A
>.</P
></DD
></DL
></DIV
><DIV
CLASS="glossdiv"
><H1
CLASS="glossdiv"
><A
NAME="Z"
></A
>Z</H1
><DL
><DT
><A
NAME="zapping"
></A
><B
>zapping</B
></DT
><DD
><P
>A TV viewer for the Gnome environment.</P
></DD
><DT
><A
NAME="zcat"
></A
><B
>zcat</B
></DT
><DD
><P
>Compress or expand files.</P
></DD
><DT
><A
NAME="zgrep"
></A
><B
>zgrep</B
></DT
><DD
><P
>Search possibly compressed files for a regular expression.</P
></DD
><DT
><A
NAME="zmore"
></A
><B
>zmore</B
></DT
><DD
><P
>Filter for viewing compressed text.</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="index"
><HR><H1
><A
NAME="AEN14033"
></A
>Index</H1
></DIV
></DIV
></BODY
></HTML
>