This commit is contained in:
gferg 2003-03-26 21:58:11 +00:00
parent 532160b205
commit 7b10111202
10 changed files with 399 additions and 199 deletions

View File

@ -38,7 +38,7 @@
</author>
</authorgroup>
<edition>Version 3.0.2 Last updated 20030228</edition>
<edition>Version 3.0.3 Last updated 20030325</edition>
<keywordset>
<keyword>Linux</keyword>
<keyword>Beginners</keyword>
@ -90,7 +90,7 @@ This guide was created as an overview of the Linux Operating System, geared towa
<date>2003-01-22</date>
<authorinitials>MG</authorinitials>
<revremark>Bug fixes;
removed some more too RedHat specifix stuff;
removed some more too RedHat specific stuff;
corrected minor errors;
moved most recent version to decent URL;
improved tar section, added something about jar.</revremark>
@ -107,6 +107,23 @@ resized images that were too large to be printed;
resized oversized text boxes for better print quality;
updated glossary.</revremark>
</revision>
<revision>
<revnumber>1.3</revnumber>
<date>2003-03-26</date>
<authorinitials>MG</authorinitials>
<revremark>grep and escape characters;
exporting variables;
more consequent about security issues;
init and cron revised;
window and desktop managers explanation;
removed some more too RedHat specific stuff;
added piece about (x)inetd;
local authentication;
text conversions and encoding;
graphical help, graphical file managers, note on internet connections;
spellcheck.
</revremark>
</revision>
</revhistory>
</para>
</section>
@ -118,6 +135,7 @@ updated glossary.</revremark>
Many thanks to all the people who shared their experiences. And especially to the Belgian Linux users, among them my husband, for hearing me out every day and always being generous in their comments.</para>
<para>Also a special thought for Tabatha Persad for doing a really thorough revision, spell check and styling, and to Eugene Crosser for marking the errors that we two looked over.</para>
<para>And thanks to all the readers who helped to pick out the last errors, unclear definitions and typos by going through the trouble of mailing me all their remarks.</para>
<para>Finally, a big thank you for the volunteers who are currently translating this document in French, Swedish, German and more. It is a big work that should not be underestimated; I admire your braveness.</para>
</section>
<section id="intro_06">

View File

@ -67,7 +67,7 @@ nice.
<title>Current application of Linux systems</title>
<para>Today Linux has joined the desktop market. Linux developers concentrated on networking and services in the beginning, and office applications have been the last barrier to be taken down. We don't like to admit that Microsoft is ruling this market, so plenty of alternatives have been started over the last couple of years to make Linux an acceptable choice as a workstation, providing an easy user interface and MS compatible office applications like word processors, spreadsheets, presentations and the like.</para>
<para>On the server side, Linux is well-known as a stable and reliable platform, providing database and trading services for companies like Amazon, the well-known online bookshop, US Post Office, the German army and such. Especially Internet providers and Internet service providers have grown fond of Linux as firewall, proxy- and web server, and you will find a Linux box within reach of every UNIX system administrator who appreciates a comfortable management station. Clusters of Linux machines are used in the creation of movies such as <quote>Titanic</quote>, <quote>Shrek</quote> 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.</para>
<para>It is also worth to note that modern Linux not only runs on workstations, mid- and high-end servers, but also on <quote>gadgets</quote> like PDA's, cellphones, 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.</para>
<para>It is also worth to note that modern Linux not only runs on workstations, mid- and high-end servers, but also on <quote>gadgets</quote> 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.</para>
</sect2>
</sect1>
@ -111,7 +111,7 @@ nice.
<sect2 id="sect_01_03_02"><title>Ten years of experience at your service</title>
<para>While Linux is probably the most well-known Open Source initiative, there is another project that contributed enormously to the popularity of the Linux operating system. This project is called SAMBA, and its achievement is the reverse engineering of the Server Message Block (SMB)/Common Internet File System (CIFS) protocol used for file- and print-serving on PC-related machines, natively supported by MS Windows NT and OS/2, and Linux. Packages are now available for almost every system and provide interconnection solutions in mixed environments using MS Windows protocols: Windows-compatible (up to and including Win2K) file- and print-servers.</para>
<para>Maybe even more successful than the SAMBA project is the Apache HTTP server project. The server runs on UNIX, Windows NT and many other operating systems. Originally known as <quote>A PAtCHy server</quote>, based on existing code and a series of <quote>patch files</quote>, the name for the matured code deserves to be connotated with the native American tribe of the Apache, well-known for their superior skills in warfare strategy and inexhaustible endurance. Apache has been shown to be substantially faster, more stable and more feature-full than many other web servers. Apache is run on sites that get millions of visitors per day, and while no official support is provided by the developers, the Apache user community provides answers to all your questions. Commercial support is now being provided by a number of third parties.</para>
<para>Maybe even more successful than the SAMBA project is the Apache HTTP server project. The server runs on UNIX, Windows NT and many other operating systems. Originally known as <quote>A PAtCHy server</quote>, based on existing code and a series of <quote>patch files</quote>, the name for the matured code deserves to be 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.</para>
<para>In the category of office applications, a choice of MS Office suite clones is available, ranging from partial to full implementations of the applications available on MS Windows workstations. These initiatives helped a great deal to make Linux acceptable for the desktop market, because the users don't need extra training to learn how to work with new systems. With the desktop comes the praise of the common users, and not only their praise, but also their specific requirements, which are growing more intricate and demanding by the day.</para>
<para>The Open Source community, consisting largely of people who have been contributing for over half a decade, assures Linux' position as an important player on the desktop market as well as in general IT application. Paid employees and volunteers alike are working diligently so that Linux can maintain a position in the market. The more users, the more questions. The Open Source community makes sure answers keep coming, and watches the quality of the answers with a suspicious eye, resulting in ever more stability and accessibility.</para>
<para>Listing all the available Linux software is beyond the scope of this guide, as there are tens of thousands of packages. Throughout this course we will present you with the most common packages, which are almost all freely available. In order to take away some of the fear of the beginning user, here's a screenshot of one of your most-wanted programs. You can see for yourself that no effort has been spared to make users who are switching from Windows feel at home:</para>
@ -193,7 +193,7 @@ In light of its popularity, considerable effort has been made to make Linux even
<para>
Although there are a large number of Linux implementations, you will find a lot of similarities in the different distributions, if only because every Linux machine is a box with building blocks that you may put together following your own needs and views. Installing the system is only the beginning of a longterm relationship. Just when you think you have a nice running system, Linux will stimulate your imagination and creativeness, and the more you realize what power the system can give you, the more you will try to redefine its limits.
</para>
<para>Linux may appear different depending on the distribution, your hardware and personal taste, but the fundamentals on which all 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 dpkg packages 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-packages form suitable for your system.</para>
<para>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 dpkg packages 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.</para>
<para>A list of common GNU software:</para>
<itemizedlist>
<listitem><para>Bash: The GNU shell</para></listitem>
@ -219,11 +219,11 @@ Although there are a large number of Linux implementations, you will find a lot
<para>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.</para>
</sect2>
<sect2 id="sect_01_05_03"><title>Which distribution should I install?</title>
<para>Prior to installation, the most important factor is your hardware. Since every Linux distribution contains the basic packages and can be built to meet most any requirement (because they all use the Linux kernel), you only need to consider if the distribution will run on your hardware. LinuxPPC for example has been made to run on MacIntosh and other PowerPCs and does not run on an ordinary x86 based PC. LinuxPPC does run on the new Macs, but you can't use it for some of the older ones with ancient bus technology. Another tricky case is Sun hardware, which could be an old SPARC CPU or a newer UltraSparc, both requiring different versions of Linux.</para>
<para>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 MacIntosh and other PowerPCs and does not run on an ordinary x86 based PC. LinuxPPC does run on the new Macs, but you can't use it for some of the older ones with ancient bus technology. Another tricky case is Sun hardware, which could be an old SPARC CPU or a newer UltraSparc, both requiring different versions of Linux.</para>
<para>Some Linux distributions are optimized for certain processors, such as Athlon CPUs, while they will at the same time run decent enough on the standard 486, 586 and 686 Intel processors. Sometimes distributions for special CPUs are not as reliable, since they are tested by fewer people.</para>
<para>Most Linux distributions 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. Examles are RedHat, SuSE and Mandrake, 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 RedHat system.</para>
<para>While the standard desktop might be Gnome on one system, another might offer KDE by default. Generally, both Gnome and KDE are available for all Linux distributions. Other window and desktop managers are available for more advanced users.</para>
<para>The standard installation process will allows 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.</para>
<para>The standard installation process allows 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.</para>
</sect2>
</sect1>

View File

@ -37,7 +37,7 @@
</sect3>
<sect3 id="sect_10_01_01_04"><title>ISDN</title>
<para>The Linux kernel has built-in ISDN capabilities. Isdn4linux controls ISDN PC cards and can emulate a modem with the Hayes command set (<quote>AT</quote> commands). The possibilities range from simply using a terminal program to full connection to the Internet.</para>
<para>The <command>internet-druid</command> tool may be used to set ISDN connections as well.</para>
<para>Check your system documentation.</para>
</sect3>
<sect3 id="sect_10_01_01_05"><title>AppleTalk</title>
<para>Appletalk is the name of Apple's internetworking stack. It allows a peer-to-peer network model which provides basic functionality such as file and printer sharing. Each machine can simultaneously act as a client and a server, and the software and hardware necessary are included with every Apple computer.</para>
@ -256,13 +256,61 @@ Turner Broadcasting (CNN-DOM)
</sect1>
<sect1 id="sect_10_02"><title>Internet/Intranet applications</title>
<para>The Linux system is a great platform for offering networking services. In this section, we will try to give an overview of most common network servers and applications.</para>
<sect2 id="sect_10_02_01"><title>Mail</title>
<sect3 id="sect_10_02_01_01"><title>Servers</title>
<note><title>Connecting to the Internet</title>
<para>Internet connections can be arranged in many different ways; we can not decribe them all in this document, all the more because the connection type is often country or region specific. Check your system documentation and contact your local Internet provider, a local fellow Linux user or your local Linux User Group, see <ulink url="http://www.ssc.com:8080/glue/groups/">GLUE</ulink> (<emphasis>Groups of Linux Users Everywhere</emphasis>).</para>
</note>
<sect2 id="sect_10_02_01"><title>Server types</title>
<sect3 id="sect_10_02_01_01"><title>Standalone server</title>
<para>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.</para>
<para>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 <ulink url="http://sourceforge.net">Sourceforge</ulink> or <ulink url="http://tucows.com">your Tucows mirror</ulink>, which must handle thousands of FTP requests per day.</para>
<para>An example of a standalone network service on your home computer might be the <command>named</command>, a caching name server. Standalone services have there own processes running, you can check any time using <command>ps</command>:</para>
<screen>
bob:~&gt; ps auxw | grep named
named 908 0.0 1.0 14876 5108 ? S Mar14 0:07 named -u named
</screen>
<para>Most services on your home PC, such as the FTP service, don't have a running daemon, yet you can use them:</para>
<screen>
bob:~&gt; ps auxw | grep ftp
bob 738 690 0 16:17 pts/6 00:00:00 grep ftp
bob:~&gt; ncftp localhost
NcFTP 3.1.3 (Mar 27, 2002) by Mike Gleason (ncftp@ncftp.com).
Connecting to localhost(127.0.0.1)...
octarine.hq.soti.org FTP server (Version wu-2.6.2-8) ready.
Logging in...
Guest login ok, access restrictions apply.
Logged in to localhost.
ncftp / >
</screen>
<para>Let's see in the next section how this is arranged.</para>
</sect3>
<sect3 id="sect_10_02_01_02"><title>(x)inetd</title>
<para>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.</para>
<para>This super-server, the Internet services daemon, is started up at system initialization time. There are two common implementations: <command>inetd</command> and <command>xinetd</command> (the extended Internet services daemon). One or the other is usually running on every Linux system:</para>
<screen>
bob:~&gt; ps -ef | grep inet
root 926 1 0 Mar14 ? 00:00:00 xinetd-ipv6 -stayalive -reuse \
-pidfile /var/run/xinetd.pid
</screen>
<para>The services for which the Internet daemon is responsible, are listed in its configuration file, <filename>/etc/inetd.conf</filename>, for <command>inetd</command>, and in the directory <filename>/etc/xinetd.d</filename> for <command>xinetd</command>. Commonly managed services include file share and print services, SSH, FTP, telnet, the Samba configuration daemon, talk and time servcies.</para>
<para>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 <emphasis>bob</emphasis> starts an FTP session to the local host, an FTP daemon is running as long as the session is active:</para>
<screen>
bob:~&gt; ps auxw | grep ftp
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
</screen>
<para>Of course, the same happens when you open connections to remote hosts: either a daemon answers directly, or a remote <command>(x)inetd</command> starts the service you need and stops it when you quit.</para>
</sect3>
</sect2>
<sect2 id="sect_10_02_02"><title>Mail</title>
<sect3 id="sect_10_02_02_01"><title>Servers</title>
<para><emphasis>Sendmail</emphasis> is the standard mail server program or Mail Transport Agent for UNIX platforms. It is robust, scalable, and when properly configured with appropriate hardware, handles thousands of users without blinking. More information about how to configure Sendmail is included with the sendmail and sendmail-cf packages, you may want to read the <filename>README</filename> and <filename>README.cf</filename> files in <filename>/usr/share/doc/sendmail</filename>. The <command>man sendmail</command> and <command>man aliases</command> are also useful.</para>
<para>Qmail is another mail server, gaining popularity because it claims to be more secure than Sendmail. While Sendmail is a monolithic program, Qmail consists of smaller interacting program parts that can be better secured.</para>
<para>These servers handle mailing lists, filtering, virus scanning and much more. Free and commercial scanners are available for use with Linux. Examples of mailing list software are Mailman, Listserv, Majordomo and EZmlm. See the web page of your favorite virus scanner for information on Linux client and server support.</para>
</sect3>
<sect3 id="sect_10_02_01_02"><title>Remote mail servers</title>
<sect3 id="sect_10_02_02_02"><title>Remote mail servers</title>
<para>The most popular protocols to access mail remotely are <emphasis>POP3</emphasis> and <emphasis>IMAP4</emphasis>. IMAP and POP both allow offline operation, remote access to new mail and they both rely on an SMTP server to send mail.</para>
<para>While POP is a simple protocol, easy to implement and supported by almost any mail client, IMAP is to be preferred because:</para>
<itemizedlist>
@ -276,7 +324,7 @@ Turner Broadcasting (CNN-DOM)
</itemizedlist>
</sect3>
<sect3 id="sect_10_02_01_03"><title>Mail user-agents</title>
<sect3 id="sect_10_02_02_03"><title>Mail user-agents</title>
<para>There are plenty of both text and graphical E-mail clients, we'll just name a few of the common ones. Pick your favorite.</para>
<para>The UNIX <command>mail</command> command has been around for years, even before networking existed. It is a simple interface to send messages and small files to other users, who can then save the message, redirect it, reply to it and such.</para>
<para>While it is not commonly used as a client anymore, the <command>mail</command> program is still useful, for example to mail the output of a command to somebody:</para>
@ -292,14 +340,14 @@ Turner Broadcasting (CNN-DOM)
</sect3>
</sect2>
<sect2 id="sect_10_02_02"><title>Web</title>
<sect3 id="sect_10_02_02_01"><title>The Apache Web Server</title>
<sect2 id="sect_10_02_03"><title>Web</title>
<sect3 id="sect_10_02_03_01"><title>The Apache Web Server</title>
<para>Apache is by far the most popular web server, used on more than half of all Internet web servers. Most Linux distributions include Apache. Apache's advantages include its modular design, SSL support, stability and speed. Given the appropriate hardware and configuration it can support the highest loads.</para>
<para>On Linux systems, the server configuration is usually done in the <filename>/etc/httpd</filename> directory. The most important configuration file is <filename>httpd.conf</filename>; it is rather self-explanatory. Should you need help, you can find it in the <command>httpd</command> man page or on the <ulink url="http://www.apache.org">Apache website</ulink>.</para>
</sect3>
<sect3 id="sect_10_02_02_02"><title>Web browsers</title>
<sect3 id="sect_10_02_03_02"><title>Web browsers</title>
<para>A number of web browsers, both free and commercial, exist for the Linux platform. Netscape Navigator has long been the only decent option, but with Mozilla a competitive alternative is available.</para>
<para>Amaya is the W3C browser. Opera is a commercial browser, compact and fast. Many desktop managers offer web browsing features in their file manager, like <command>galeon</command> or <command>nautilus</command>.</para>
<para>Amaya is the W3C browser. Opera is a commercial browser, compact and fast. Many desktop managers offer web browsing features in their file manager, like <command>nautilus</command>.</para>
<para>Among the popular text based browsers are <command>lynx</command> and <command>links</command>. You may need to define proxy servers in your shell, by setting the appropriate variables.</para>
<para>Text browsers are fast and handy when no graphical environment is available, such as when used in scripts. Below is an excerpt from a shell script that acts as a network worm probing available services:</para>
<screen>
@ -320,13 +368,13 @@ Apache/1.3.14
</screen>
</sect3>
</sect2>
<sect2 id="sect_10_02_03"><title>File Transfer Protocol</title>
<sect3 id="sect_10_02_03_01"><title>FTP servers</title>
<sect2 id="sect_10_02_04"><title>File Transfer Protocol</title>
<sect3 id="sect_10_02_04_01"><title>FTP servers</title>
<para>On a Linux system, an FTP server is typically run from <command>xinetd</command>, using the <emphasis>WU-ftpd</emphasis> server, although the FTP server may be configured as a stand-alone server on systems with heavy FTP traffic. See the exercises.</para>
<para>Other FTP servers include among others <emphasis>Ncftpd</emphasis> and <emphasis>Proftpd</emphasis>.</para>
<para>Most Linux distributions contain the <emphasis>anonftp</emphasis> package, which sets up an anonymous FTP server tree and accompanying configuration files.</para>
</sect3>
<sect3 id="sect_10_02_03_02"><title>FTP clients</title>
<sect3 id="sect_10_02_04_02"><title>FTP clients</title>
<para>Most Linux distributions include <command>ncftp</command>, an improved version of the common UNIX <command>ftp</command> command, which you may also know from the Windows command line. The <command>ncftp</command> program offers extra features such as a nicer and more comprehensible user interface, file name completion, append and resume functions, bookmarking, session management and more:</para>
<screen>
thomas:~&gt;ncftp blob
@ -356,11 +404,11 @@ ncftp / >
<para>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 <command>sftp</command> program comes with the Secure SHell suite, see <xref linkend="sect_10_03_04" />.</para></note>
</sect3>
</sect2>
<sect2 id="sect_10_02_04"><title>News services</title>
<sect2 id="sect_10_02_05"><title>News services</title>
<para>Running a Usenet server involves a lot of expertise and fine-tuning, so refer to the <ulink url="http://www.isc.org">INN homepage</ulink> for more information.</para>
<para>There are a couple of interesting newsgroups in the <emphasis>comp.*</emphasis> hierarchy, which can be accessed using a variety of text and graphical clients. A lot of mail clients support newsgroup browsing as well, check your program or see your local Open Source software mirror for text clients such as <command>tin</command>, <command>slrnn</command> and <command>mutt</command>, or download Mozilla or one of a number of other graphical clients.</para>
</sect2>
<sect2 id="sect_10_02_05"><title>The Domain Name System</title>
<sect2 id="sect_10_02_06"><title>The Domain Name System</title>
<para>All these applications need DNS services to match IP addresses to host names and vice versa. A DNS server does not know all the IP addresses in the world, but networks with other DNS servers which it can query to find an unknown address. Most UNIX systems can run <command>named</command>, which is part of the bind (Berkeley Internet Name Domain) package distributed by the Internet Software Consortium. It can run as a stand-alone caching <emphasis>nameserver</emphasis>, which is often done on Linux systems in order to speed up network access.</para>
<para>Your main client configuration file is <filename>/etc/resolv.conf</filename>, which determines the order in which Domain Name Servers are contacted:</para>
<screen>
@ -370,7 +418,7 @@ nameserver 193.74.208.137
</screen>
<para>More information can be found in the Info pages on <command>named</command>, in the <filename>/usr/share/doc/bind-&lt;version&gt;</filename> files and on the <ulink url="http://www.isc.org/products/BIND">Bind project</ulink> homepage. The <ulink url="http://www.ibiblio.org/mdw/HOWTO/DNS-HOWTO.html">DNS HOWTO</ulink> covers the use of BIND as a DNS server.</para>
</sect2>
<sect2 id="sect_10_02_06"><title>DHCP</title>
<sect2 id="sect_10_02_07"><title>DHCP</title>
<para>DHCP is the Dynamic Host Configuration Protocol, which is gradually replacing good old <command>bootp</command> in larger environments. It is used to control vital networking parameters such as IP addresses and name servers of hosts. DHCP is backward compatible with <command>bootp</command>. For configuring the server, you will need to read the HOWTO.</para>
<para>RedHat DHCP client machines will usually be configured using the GUI, <command>redhat-config-network</command>, which will set <varname>BOOTPROTO</varname> to <emphasis>dhcp</emphasis> in <filename>/etc/sysconfig/network-scripts/ifcfg-eth0</filename>. The <command>netconfig</command> command does the same in text mode. DHCP clients need to run the DHCP client daemon, <command>dhcpcd</command> to obtain network information from a remote server.</para>
<figure><title>Network Configuration Tool</title>
@ -385,8 +433,17 @@ nameserver 193.74.208.137
</figure>
</sect2>
<sect2 id="sect_10_02_07"><title>Authentication</title>
<sect3 id="sect_10_02_07_01"><title>PAM</title>
<sect2 id="sect_10_02_08"><title>Authenticationi services</title>
<sect3 id="sect_10_02_08_01"><title>Traditional</title>
<para>Traditionally, users are authenticated locally, using the information stored in <filename>/etc/passwd</filename> and <filename>/etc/shadow</filename> 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.</para>
<para>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:</para>
<screen>
bob:~&gt; ls -l /etc/passwd /etc/shadow
-rw-r--r-- 1 root root 1803 Mar 10 13:08 /etc/passwd
-r-------- 1 root root 1116 Mar 10 13:08 /etc/shadow
</screen>
</sect3>
<sect3 id="sect_10_02_08_02"><title>PAM</title>
<para>Linux can use PAM, the Pluggable Authentication Module, a flexible method of UNIX authentication. Advantages of PAM:</para>
<itemizedlist>
<listitem><para>A common authentication scheme that can be used with a wide variety of applications.
@ -417,7 +474,7 @@ nameserver 193.74.208.137
<para>Shadow password files are automatically detected by PAM.</para>
<para>More information can be found in the <command>pam</command> man pages or at <ulink url="http://www.kernel.org/pub/linux/libs/pam">the Linux-PAM project</ulink> homepage.</para>
</sect3>
<sect3 id="sect_10_02_07_02"><title>LDAP</title>
<sect3 id="sect_10_02_09_03"><title>LDAP</title>
<para>The Lightweight Directory Access Protocol is a client-server system for accessing global or local directory services over a network. On Linux, the OpenLDAP implementation is used. It includes <command>slapd</command>, a stand-alone server; <command>slurpd</command>, a stand-alone LDAP replication server; libraries implementing the LDAP protocol and a series of utilities, tools and sample clients.</para>
<para> The main benefit of using LDAP is the consolidation of certain types of information within your organization. For example, all of the different lists of users within your organization can be merged into one LDAP directory. This directory can be queried by any LDAP-enabled applications that need this information. It can also be accessed by users who need directory information.
</para><para>
@ -435,7 +492,7 @@ On the negative side, if you want to use LDAP, you will need LDAP-enabled applic
<para>There are a couple of different ways to execute commands or run programs on a remote machine and have the output, be it text or graphics, sent to your workstation. The connections can be secure or insecure. While it is of course advised to use secure connections instead of transporting your password over the network unencrypted, we will discuss some practical applications of the older (unsafe) mechanisms, as they are still useful in a modern networked environment, such as for troubleshooting or running exotic programs.</para>
</sect2>
<sect2 id="sect_10_03_02"><title>Rsh, rlogin and telnet</title>
<para>The <command>rlogin</command> and <command>rsh</command> commands for remote login and remote execution of commands are a heritance from UNIX. While seldom used because they are blatantly insecure, they still come with almost every Linux distribution for backward compatibility with UNIX programs.</para>
<para>The <command>rlogin</command> and <command>rsh</command> 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.</para>
<para>Telnet, on the other hand, is still commonly used, often by system and network administrators. Telnet is one of the most powerful tools for remote access to files and remote administration, allowing connections from anywhere on the Internet. Combined with an X server, remote graphical applications can be displayed locally. There is no difference between working on the local machine and using the remote machine.</para>
<para>Because the entire connection is unencrypted, allowing <command>telnet</command> connections involves taking high security risks. For normal remote execution of programs, Secure SHell or <command>ssh</command> is advised. We will discuss the secure method later in this section.</para>
<para>However, <command>telnet</command> is still used in many cases. Below are some examples in which a mail server and a web server are tested for replies:</para>

View File

@ -61,6 +61,10 @@ blast login: _
</screen>
<para>The login is different from a graphical login, in that you have to hit the [ENTER] key after providing your user name. Then you should enter your password, followed by another [ENTER]. You won't see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security reasons.</para>
<para>When the system has accepted you as a valid user, you may get some more information, called the <emphasis>message of the day</emphasis>, which can be anything and is not displayed when opening a graphical terminal. But after that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.</para>
<note><title>Don't log in as root</title>
<para>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.</para>
</note>
<para>Logging out is done by entering the <command>logout</command> command, followed by [ENTER]. You are successfully disconnected from the system when you see the login screen again.</para>
<note><title>Don't hit the power button!</title>
<para>Don't power-off the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!</para></note>
@ -131,14 +135,18 @@ blast login: _
</table>
</sect2>
<sect2 id="sect_02_02_02"><title>General remarks</title>
<para>In Linux, like in UNIX, directories are separated using forward slashes, like the ones used in web addresses (URLs). We will discuss directory structure indepth later.</para>
<para>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.</para>
<para>The symbols . and .. have special meaning when directories are concerned. We will try to find out about those during the exercises, and more in the next chapter.</para>
<para>Try to avoid logging in with or using the system administrator's account, <emphasis>root</emphasis>. Besides doing your normal work, most tasks, including checking the system, collecting information etc., can be executed using a normal user account with no special permissions at all. If needed, for instance when creating a new user or installing new software, the preferred way of obtaining root access is by switching user IDs, see <xref linkend="sect_03_02_01" /> for an example.</para>
<para>Almost all commands in this book can be executed without system administrator priviledges. 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've done, leave the application or session that gives you root privileges immediately.</para>
<para>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've done, leave the application or session that gives you root privileges immediately.</para>
<para>Reading documentation should become your second nature. Especially in the beginning, it is important to read system documentation, manuals for basic commands, HOWTOs and so on. Since the amount of documentation is so enormous, it is impossible to include all related documentation. This book will try to guide you to the most appropriate documentation on every subject discussed, in order to stimulate the habit of reading the man pages.</para>
</sect2>
<sect2 id="sect_02_02_03"><title>The man pages</title>
</sect1>
<sect1 id="sect_02_03"><title>Getting help</title>
<sect2 id="sect_02_03_01"><title>Be warned</title>
<para>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.</para>
</sect2>
<sect2 id="sect_02_03_02"><title>The man pages</title>
<para>A lot of beginning users fear the man (manual) pages, because they are an overwhelming source of documentation. They are, however, very structured, as you will see from the example below on: <command>man <option>man</option></command>.</para>
<para>Reading man pages is usually done in a terminal window when in graphical mode, or just in text mode if you prefer it. Type the command like this at the prompt, followed by enter:</para>
<screen>
@ -194,12 +202,12 @@ lines 1-27
<cmdsynopsis><command>man <option>-a</option> passwd</command></cmdsynopsis>
<para>This way, when you reach the end of the first man page and press <keycap>SPACE</keycap> again, the man page from the next section will be displayed.</para>
</sect2>
<sect2 id="sect_02_02_04"><title>More info</title>
<sect3 id="sect_02_02_04_01"><title>The Info pages</title>
<sect2 id="sect_02_03_03"><title>More info</title>
<sect3 id="sect_02_03_03_01"><title>The Info pages</title>
<para>In addition to the man pages, you can read the info pages about a command, using the <command>info</command> command. These usually contain more recent information and are somewhat easier to use. The man pages for some commands refer to the info pages.</para>
<para>Get started with <command>info <option>info</option></command>. Use the arrow keys to browse trough the text and move the cursor on a line starting with an asterisk, containing the keyword about which you want info. Use the p- and n-keys to go to the previous or next subject. The space bar will move you one page further, no matter whether this starts a new subject or an info page for another command. Use <keycap>q</keycap> to quit. The <command>info</command> program has more information.</para>
</sect3>
<sect3 id="sect_02_02_04_02"><title>The whatis and apropos commands</title>
<sect3 id="sect_02_03_03_02"><title>The whatis and apropos commands</title>
<para>A short index of explanations for commands is available using the <command>whatis</command> command, like in the examples below:</para>
<screen>
[your_prompt] whatis ls
@ -222,10 +230,10 @@ viewres (1x) - graphical class browser for Xt
</screen>
<para>After pressing enter 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 <quote>(1)</quote>, is suitable for trying out as a user. The user who issued the above <command>apropos</command> might consequently try to start the commands <command>galeon</command>, <command>lynx</command> or <command>opera</command>, since these clearly have to do with browsing the world wide web.</para>
</sect3>
<sect3 id="sect_02_02_04_03"><title>The --help option</title>
<sect3 id="sect_02_03_03_03"><title>The --help option</title>
<para>Most GNU commands support the <option>--help</option>, 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 <command>cat</command>:</para>
<screen>
userprompt: cat --help
userprompt@host: cat --help
Usage: cat [OPTION] [FILE]...
Concatenate FILE(s), or standard input, to standard output.
@ -248,14 +256,23 @@ With no FILE, or when FILE is -, read standard input.
Report bugs to &lt;bug-textutils@gnu.org&gt;.
</screen>
</sect3>
<sect3 id="sect_02_02_04_04"><title>Exceptions</title>
<para>Some commands don't have separate documentation, because they are part of another command. <command>cd</command>, <command>exit</command>, <command>logout</command> and <command>pwd</command> are such exceptions. They are part of your shell program and are called <emphasis>shell builtin</emphasis> commands. For information about these, refer to the man or info page of your shell. Most beginning Linux users have a Bash shell. See <xref linkend="sect_03_02_03_02" /> for more about shells.</para>
<sect3 id="sect_02_03_04"><title>Graphical help</title>
<para>Don't despair if you prefer a graphical user interface. Konqueror, the default KDE file manager, provides painless and colourful access to the man and Info pages. You may want to try <quote>info:info</quote> in the <emphasis>Location</emphasis> address bar, and you will get a browsable Info page about the <command>info</command> command. Similarly, <quote>man:ls</quote> will present you with the man page for the <command>ls</command> command. You even get command name completion: you will see the man pages for all the commands starting with <quote>ls</quote> in a scroll-down menu. Entering <quote>info:/dir</quote> in the address location toolbar displays all the Info pages, arranged in utility categories. Excellent <quote>Help</quote> content, including the Konqueror Handbook.</para>
<para>The Gnome Help Browser is very user friendly as well. You can start it selecting <quote>Help</quote> in the Gnome <quote>Applications</quote> menu, by clicking the lifeguard icon on your desktop or by entering the command <command>gnome-help</command> in a terminal window. The system documentation and man pages are easily browsable with a plain interface.</para>
<para>The <command>nautilus</command> file manager provides a searchable index of the man and Info pages, they are easily browsable and interlinked. Nautilus is started from the command line, or clicking your home directory icon, or from the Gnome menu.</para>
<para>The big advantage of GUIs for system documentation is that all information is completely interlinked, so you can click through in the <quote>SEE ALSO</quote> sections and wherever links to other man pages appear, and thus browse and acquire knowledge without interruption for hours at the time.</para>
</sect3>
<sect3 id="sect_02_03_05"><title>Exceptions</title>
<para>Some commands don't have separate documentation, because they are part of another command. <command>cd</command>, <command>exit</command>, <command>logout</command> and <command>pwd</command> are such exceptions. They are part of your shell program and are called <emphasis>shell built-in</emphasis> commands. For information about these, refer to the man or info page of your shell. Most beginning Linux users have a Bash shell. See <xref linkend="sect_03_02_03_02" /> for more about shells.</para>
<para>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 <varname>MANPATH</varname> variable. How to do this is explained in <xref linkend="sect_07_02_02" />.</para>
<para>Some programs or packages only have a set of instructions or references in the directory <filename>/usr/share/doc</filename>. See <xref linkend="sect_03_03_04" /> to display.</para>
<para>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 willingly remove man pages or other documentation). In that case, first try to make sure that there is really nothing appropriate left using a search tool, read on in <xref linkend="sect_03_03_03" />. If so, you may have to re-install the package that contains the command to which the documentation applied, see <xref linkend="sect_07_06" />.</para>
</sect3>
</sect2>
</sect1>
<sect1 id="sect_02_03"><title>Exercises</title>
<sect1 id="sect_02_04"><title>Exercises</title>
<para>Most of what we learn is by making mistakes and by seeing how things can go wrong. These exercises are made to get you to read some error messages. The order in which you do these exercises, is important.</para>
<sect2 id="sect_02_03_01"><title>Connecting and disconnecting</title>
<sect2 id="sect_02_04_01"><title>Connecting and disconnecting</title>
<para>
<itemizedlist>
<listitem><para>Determine whether you are working in text or in graphical mode.</para>
@ -271,7 +288,7 @@ Report bugs to &lt;bug-textutils@gnu.org&gt;.
</para>
</sect2>
<sect2 id="sect_02_03_02"><title>Passwords</title>
<sect2 id="sect_02_04_02"><title>Passwords</title>
<para>Log in again with your user name and password.</para>
<itemizedlist>
<listitem><para>Change your password into <emphasis>P6p3.aa!</emphasis> and hit the [ENTER] key.</para>
@ -289,7 +306,7 @@ Report bugs to &lt;bug-textutils@gnu.org&gt;.
</itemizedlist>
</sect2>
<sect2 id="sect_02_03_03"><title>Directories</title>
<sect2 id="sect_02_04_03"><title>Directories</title>
<para>These are some exercises to help you get the feel.</para>
<itemizedlist>
<listitem><para>Enter the command <command>cd <filename>blah</filename></command></para>
@ -320,7 +337,7 @@ Report bugs to &lt;bug-textutils@gnu.org&gt;.
</listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_02_03_04"><title>Files</title>
<sect2 id="sect_02_04_04"><title>Files</title>
<itemizedlist>
<listitem><para>Change directory to <filename>/</filename> and then to <filename>etc</filename>. Type <command>ls</command>; if the output is longer than your screen, make the window longer, or try [SHIFT]+[Page Up] and [SHIFT]+[Page Down].</para>
<para>The file <filename>inittab</filename> contains the answer to the first question in this list. Try the <command>file</command> command on it.</para>
@ -340,7 +357,7 @@ Report bugs to &lt;bug-textutils@gnu.org&gt;.
</listitem>
</itemizedlist>
</sect2>
<sect2 id="sect_02_03_05"><title>Getting help</title>
<sect2 id="sect_02_04_05"><title>Getting help</title>
<itemizedlist>
<listitem><para>Read <command>man <option>intro</option></command></para></listitem>
<listitem><para>Read <command>man <option>ls</option></command></para></listitem>

View File

@ -44,7 +44,7 @@ jaime:~/Documents&gt;ls -l
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 cours/
drwxrwxr-x 2 jaime jaime 4096 Feb 25 11:50 course/
</screen>
<para>This table gives an overview of the characters determining the file type:</para>
<table frame="all">
@ -96,7 +96,7 @@ Before we look at the important files and directories, we need to know more abou
<listitem><para><emphasis>swap partition</emphasis>: expansion of the computer's physical memory, extra memory on hard disk.</para></listitem>
</itemizedlist>
<para>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.</para>
<para>Most Linux systems use <command>fdisk</command> at installation time to set the partition type. As you may have noticed during the exercise from Chapter 1, this usually happens automatically. At 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 <command>fdisk</command> utility has built-in help, should you forget these values.</para>
<para>Most Linux systems use <command>fdisk</command> 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 <command>fdisk</command> utility has built-in help, should you forget these values.</para>
<para>The standard root partition 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.</para>
<para>Swap space 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 never see irritating messages like <emphasis>Out of memory, please close some applications first and try again</emphasis>, because of this extra memory. 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 <xref linkend="chap_04" />.</para>
<para>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:</para>
@ -147,7 +147,7 @@ fs1:/home 8.9G 3.7G 4.7G 44% /.automount/fs1/root/home
</sect2>
<sect2 id="sect_03_01_03"><title>More file system layout</title>
<sect3 id="sect_03_01_03_01"><title>Visual</title>
<para>For convenience, the Linux file system is usually thought of in a tree structure. On a standard Linux system, including RedHat, you will find the layout generally follows the scheme as presented below.</para>
<para>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.</para>
<figure><title>Linux file system layout</title>
<mediaobject>
<imageobject>
@ -280,7 +280,7 @@ rogier:&gt;echo $PATH
[jenny@blob jenny]$ sendsms
bash: sendsms: command not found
[jenny@blob jenny]$ echo $PATH
/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/home/clo/bin
/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/home/jenny/bin
[jenny@blob jenny]$ su - tony
Password:
tony:~&gt;which sendsms
@ -311,11 +311,11 @@ jumper:~&gt;/usr/bin/wc -l test
</screen>
<para>If the user uses programs in the other directories more frequently, he can change his path to look in his own directories last:</para>
<screen>
jumper:~&gt;export $PATH=/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:
/usr/bin:/usr/sbin:/bin:/sbin:.:/home/jumper/bin
jumper:~&gt;export PATH=/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:\
/usr/bin:/usr/sbin:/bin:/sbin:/home/jumper/bin
</screen>
<note><title>Changes are not permanent!</title>
<para>Note that when using the <command>export</command> 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 <xref linkend="chap_06" /> how we can make these kinds of changes to the environment permanent.</para></note>
<para>Note that when using the <command>export</command> 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 <xref linkend="sect_07_02" /> how we can make these kinds of changes to the environment permanent, adding these lines to the shell configuration files.</para></note>
</sect2>
<sect2 id="sect_03_02_02"><title>Absolute and relative paths</title>
@ -327,7 +327,7 @@ jumper:~&gt;export $PATH=/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:
<para>When you want to compile source code, the installation documentation often instructs you to run the command <command>./configure</command>, which runs the <emphasis>configure</emphasis> program located in the current directory (that came with the new code), as opposed to running another configure program elsewhere on the system.</para></listitem>
<listitem><para>In HTML files, relative paths are often used to make a set of pages easily movable to another place:</para>
<screen>
&lt;img alt="Een beeld" src="../images/beeld.jpg"&gt;
&lt;img alt="Garden with trees" src="../images/garden.jpg"&gt;
</screen>
</listitem>
<listitem><para>Notice the difference one more time:</para>
@ -368,6 +368,9 @@ mia:~&gt;cat /etc/shells
/bin/tcsh
/bin/csh
</screen>
<note><title>Fake Bourne shell</title>
<para>Note that <filename>/bin/sh</filename> is usually a link to Bash, which will execute in Bourne shell compatible mode when called on this way.</para>
</note>
<para>Your default shell is set in the <filename>/etc/passwd</filename> file, like this line for user <emphasis>mia</emphasis>:</para>
<screen>
mia:L2NOfqdlPrHwE:504:504:Mia Maya:/home/mia:/bin/bash
@ -385,7 +388,7 @@ mia:~&gt;tcsh
</sect3>
<sect3 id="sect_03_02_03_03"><title>Your home directory</title>
<para>Your home directory is your default destination when connecting to the system. In most cases it is a subdirectory of <filename>/home</filename>, 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 <filename>/nethome/your_user_name</filename>. In another case the system administrator may have opted for a less comprehensible layout and your home directory may be on <filename>/disk6/HU/07/dgillard</filename>.</para>
<para>Your home directory is your default destination when connecting to the system. In most cases it is a subdirectory of <filename>/home</filename>, 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 <filename>/nethome/your_user_name</filename>. In another case the system administrator may have opted for a less comprehensible layout and your home directory may be on <filename>/disk6/HU/07/jgillard</filename>.</para>
<para>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 <varname>HOME</varname> environment variable, in case some program needs it. With the <command>echo</command> command you can display the content of this variable:</para>
<screen>
orlando:~&gt;echo $HOME
@ -396,7 +399,7 @@ orlando:~&gt;echo $HOME
pierre@lamaison:/&gt;quota -v
Diskquotas for user pierre (uid 501): none
</screen>
<para>In case quotas have been set, you get a list of the limited partitions and their specific limitations. Excessing the limits may be tolerated during a grace period with porer or no restrictions at all. Detailed information can be found using the <command>info quota</command> or <command>man quota</command> commands.</para>
<para>In case quotas have been set, you get a list of the limited partitions and their specific limitations. Exceding the limits may be tolerated during a grace period with fewer or no restrictions at all. Detailed information can be found using the <command>info quota</command> or <command>man quota</command> commands.</para>
<para>Your home directory is indicated by a tilde (~), shorthand for <filename>/path_to_home/user_name</filename>. This same path is stored in the <varname>HOME</varname> variable, so you don't have to do anything to activate it. A simple application: switch from <filename>/var/music/albums/arno/2001</filename> to <filename>images</filename> in your home directory using one elegant command:</para>
<screen>
rom:/var/music/albums/arno/2001&gt;cd ~/images
@ -634,7 +637,7 @@ rom:~/images&gt;pwd
</sect2>
<sect2 id="sect_03_02_05"><title>The most common devices</title>
<para>Devices, generally every peripheral attachment of a PC that is not the CPU itself, is presented to the system as an entry in the <filename>/dev</filename> directory. On 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.</para>
<para>Devices, generally every peripheral attachment of a PC that is not the CPU itself, is presented to the system as an entry in the <filename>/dev</filename> 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.</para>
<para>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.</para>
<table frame="all"><title>Common devices</title>
<tgroup cols="2" align="left" colsep="1" rowsep="1">
@ -704,7 +707,7 @@ krissie:~/mp3&gt;ls -a
krissie:~/mp3&gt;ls -l Radio/
total 8
drwxr-xr-x 2 krissie krissie 4096 Oct 30 1999 Leugenpaleis/
drwxr-xr-x 2 krissie krissie 4096 Oct 30 1999 Carolina/
drwxr-xr-x 2 krissie krissie 4096 Sep 24 1999 Slashdot/
krissie:~/mp3&gt;ls -ld Radio/
@ -824,14 +827,14 @@ mike:~&gt;file /dev/hda
<screen>
[newuser@blob user]$ ls -al
total 32
drwx------ 3 gebruike gebruike 4096 Jan 16 13: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 gebruike gebruike 24 Jan 16 13:32 .bash_logout
-rw-r--r-- 1 gebruike gebruike 191 Jan 16 13:32 .bash_profile
-rw-r--r-- 1 gebruike gebruike 124 Jan 16 13:32 .bashrc
drwxr-xr-x 3 gebruike gebruike 4096 Jan 16 13:32 .kde
-rw-r--r-- 1 gebruike gebruike 3511 Jan 16 13:32 .screenrc
-rw------- 1 gebruike gebruike 61 Jan 16 13:32 .xauthDqztLr
-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
</screen>
<para>On first sight, the content of a <quote>used</quote> home directory doesn't look that bad either:</para>
<screen>
@ -841,11 +844,18 @@ articles/ Desktop/ GNUstep/ Nautilus/ staroffice6.0/
bin/ Desktop1/ images/ nqc/ training/
brol/ desktoptest/ Machines@ ns_imap/ webstart/
C/ Documents/ mail/ nsmail/ xml/
clo/ Emacs@ Mail/ office52/ Xrootenv.0
closed/ Emacs@ Mail/ office52/ Xrootenv.0
</screen>
<para>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.</para>
<para>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.</para>
<para>In the next section, we will discuss our means of keeping order. We only discuss text tools available to the shell, since graphical tools, such as the Nautilus file manager that comes with most distributions, 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.</para>
<para>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:</para>
<itemizedlist>
<listitem><para><command>nautilus</command>: The default file manager in Gnome, the GNU desktop. Excellent documentation about working with this tool can be found at <ulink url="http://www.gnome.org/learn/users-guide/latest/gosnautilus-1.html">http://www.gnome.org</ulink>.</para></listitem>
<listitem><para><command>konqueror</command>: The file manager typically used on a KDE desktop. The handbook is at <ulink url="http://docs.kde.org/en/3.1/kdebase/konqueror/">http://docs.kde.org</ulink>.</para></listitem>
<listitem><para><command>mc</command>: Midnight Commander, the Unix file manager after the fashion of Norton Commander. All documentation available from <ulink url="http://www.gnu.org/directory/midnightcommander.html">http://gnu.org/directory/</ulink>.</para></listitem>
</itemizedlist>
<para>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.</para>
</sect3>
<sect3 id="sect_03_03_02_03"><title>The tools</title>
<sect4><title>Creating directories</title>
@ -966,7 +976,7 @@ type is a shell builtin
<para>Another application of <command>find</command> is for searching files of a certain size, as in the example below, where user <emphasis>peter</emphasis> wants to find all files in the current directory or one of its subdirectories, that are bigger than 5 MB:</para>
<screen>
peter:~&gt;find . -size +5000k
Samson_En_Gert_8.12_Samson_is_de_liefste_hond.mp3
psychotic_chaos.mp3
</screen>
<para>If you dig in the man pages, you will see that <command>find</command> can also perform operations on the found files. A common example is removing files. It is best to first test without the <option>-exec</option> 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 <filename>.tmp</filename>:</para>
<screen>
@ -1010,6 +1020,7 @@ shared libs), not stripped
</sect3>
<sect3 id="sect_03_03_03_04"><title>The grep command</title>
<sect4 id="sect_03_03_03_04_01"><title>General line filtering</title>
<para>A simple but powerful program, <command>grep</command> is used for filtering input lines and returning certain patterns to the output. There are literally thousands of applications for the <command>grep</command> program. In the example below, <emphasis>jerry</emphasis> uses <command>grep</command> to see how he did the thing with <command>find</command>:</para>
<screen>
jerry:~&gt;grep -a find .bash_history
@ -1023,7 +1034,7 @@ find ../ -name common.cfg
thomas ~&gt;
(reverse-i-search)`find': find `/home/thomas` -name *.xml
</screen>
<para>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 <filename>.bash_history</filename> in your home directory when you quit that session). The most recent occurance of your search string is shown. If you want to see previous commands containing the same string, type [CTRL] + [R] again.</para>
<para>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 <filename>.bash_history</filename> 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 [CTRL] + [R] again.</para>
<para>See the Info pages on <command>bash</command> for more.</para></note>
<para>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 <filename>words</filename>, located in <filename>/usr/share/dict</filename>. To quickly check the correct spelling of a word, no graphical application is needed:</para>
<screen>
@ -1045,7 +1056,14 @@ sent-mail: To: &lt;Arno.Hintjens@celeb.com&gt;
sent-mail: On Mon, 24 Dec 2001, Arno.Hintjens@celeb.com wrote:
</screen>
<para><command>find</command> and <command>locate</command> are often used in combination with <command>grep</command> to define some serious queries. For more information, see <xref linkend="chap_05" /> on I/O redirection.</para>
</sect4>
<sect4 id="sect_03_03_03_04_02"><title>Special characters</title>
<para>Characters that have a special meaning to the shell have to be <emphasis>escaped</emphasis>. The escape character in Bash 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. For instance, say that you want to display the lines containing <quote>searchstring*</quote> (where * matches the asterisk character) instead of any lines containing the string <quote>searchstring</quote>* (where * matches any amount of any character), you issue the command</para>
<cmdsynopsis><command>grep <option>"searchstring\*"</option> <filename>file(s)</filename></command></cmdsynopsis>
<para>Finding the string <quote>e.g.</quote> in a file will report all lines containing any character in the second and forth position of the search string. If you escape the dots, you will find the occurrences of the string representing the abbreviation for <quote>example given</quote>:</para>
<cmdsynopsis><command>grep <option>"e\.g\."</option> <filename>file</filename></command></cmdsynopsis>
<para>More in the <command>grep</command> Info pages.</para>
</sect4>
</sect3>
</sect2>
@ -1055,10 +1073,13 @@ sent-mail: On Mon, 24 Dec 2001, Arno.Hintjens@celeb.com wrote:
<para>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, OpenOffice. Other examples are the GIMP (start up with <command>gimp</command> from the command line), the GNU Image Manipulation Program; <command>xpdf</command> to view Portable Document Format files (PDF); GhostView (<command>gv</command>) for viewing PostScript files; the Mozilla Project, <command>links</command> (a text mode browser), Konqueror, Opera and many others for web content; XMMS, CDplay and others for multi-media file content; AbiWord, Gnumeric, KOffice etc. for all kinds of office applications and so on. There are thousands of Linux applications; to list them all would take days.</para>
<para>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 <command>file</command> command.</para>
<para>So let's see what text tools we have that are useful to look inside files.</para>
<note><title>Font problems</title>
<para>Plain text tools such as the ones we will now be discussing, often have problems with <quote>plain</quote> 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 <emphasis>en_US</emphasis> encoding and so on, are then displayed the wrong way or replaced by unreadable rubbish. These problems are discussed in <xref linkend="sect_07_05" />.</para>
</note>
</sect3>
<sect3 id="sect_03_03_04_02"><title><quote><command>Less</command> is <command>more</command></quote></title>
<para>Undoubtedly you will here someone say this phrase sooner or later when working in a UNIX environment. A little bit of UNIX history explains this:</para>
<para>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:</para>
<itemizedlist>
<listitem><para>First there was <command>cat</command>. Output was streamed in an uncontrollable way.</para>
</listitem>
@ -1078,7 +1099,7 @@ locate configure | grep bin
man bash
cd
xawtv &amp;
grep useable /usr/share/dict/words
grep usable /usr/share/dict/words
grep advisable /usr/share/dict/words
info quota
man quota
@ -1300,7 +1321,7 @@ bert:~&gt;umask
</screen>
<para>Instead of adding the symbolic values to each other, as with <command>chmod</command>, 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: <emphasis>user</emphasis>, <emphasis>group</emphasis> and <emphasis>other</emphasis>. The first zero is part of the special file attributes settings, which we will discuss in <xref linkend="sect_03_04_02_04" /> and <xref linkend="sect_04_01_06" />. It might just as well be that this first zero is not displayed on your system when entering the <command>umask</command> command, and that you only see 3 numbers representing the default file creation mask.</para>
<para>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 excute 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 <emphasis>777</emphasis> or <emphasis>rwxrwxrwx</emphasis>, a plain file <emphasis>666</emphasis> or <emphasis>rw-rw-rw-</emphasis>.</para>
<para>The <emphasis>umask</emphasis> value is substracted from these default permissions after the function has created the new file or directory. Thus, a directory will have permissions of <emphasis>775</emphasis> by default, a file <emphasis>664</emphasis>, if the mask value is <emphasis>(0)002</emphasis>. This is demonstrated in the example below:</para>
<para>The <emphasis>umask</emphasis> value is subtracted from these default permissions after the function has created the new file or directory. Thus, a directory will have permissions of <emphasis>775</emphasis> by default, a file <emphasis>664</emphasis>, if the mask value is <emphasis>(0)002</emphasis>. This is demonstrated in the example below:</para>
<screen>
bert:~&gt; mkdir newdir

View File

@ -189,7 +189,7 @@ init-+-amd
| |-bash---pstree
| |-bash---ssh
| |-bash---mozilla-bin---mozilla-bin---3*[mozilla-bin]
| `-gnome-pty-helpe
| `-gnome-pty-helper
|-gpm
|-gweather
|-kapm-idled
@ -247,7 +247,7 @@ init-+-amd
<para>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 <emphasis>zombie</emphasis> process.</para>
</sect3>
<sect3 id="sect_04_01_05_02"><title>Ending processes</title>
<para>When a process ends normally (it is not killed or otherwise unexpectedly interupted), the program returns its <emphasis>exit status</emphasis> to the parent. This exit status is a number returned by the program providing the results of the program's execution. The system of returning information upon executing a job has its origin in the C programming language in which UNIX has been written.</para>
<para>When a process ends normally (it is not killed or otherwise unexpectedly interrupted), the program returns its <emphasis>exit status</emphasis> to the parent. This exit status is a number returned by the program providing the results of the program's execution. The system of returning information upon executing a job has its origin in the C programming language in which UNIX has been written.</para>
<para>The return codes can then be interpreted by the parent, or in scripts. The values of the return codes are program-specific. This information can usually be found in the man pages of the specified program, for example the <command>grep</command> command returns <computeroutput>-1</computeroutput> if no matches are found, upon which a message on the lines of "No files found" can be printed. Another example is the Bash Builtin command <command>true</command>, which does nothing except return an exit status of 0, meaning success.</para>
</sect3>
@ -276,7 +276,7 @@ mia:~&gt;ls -l /usr/bin/passwd
<para>When called, the <command>passwd</command> command will run using the access permissions of <emphasis>root</emphasis>, thus enabling a common user to edit the password file which is owned by the system admin.</para>
<para>SGID modes on a file don't occur nearly as frequently as SUID, because SGID often involves the creation of extra groups. In some cases, however, we have to go through this trouble in order to build an elegant solution (don't worry about this too much - the necessary groups are usually created upon installation). This is the case for the <command>write</command> and <command>wall</command> programs, which are used to send messages to other users' terminals (ttys). The <command>write</command> command writes a message to a single user, while <command>wall</command> writes to all connected users.</para>
<para>Sending text to another user's terminal or graphical display is normally not allowed. In order to bypass this problem, a group has been created, which owns all terminal devices. When the <command>write</command> and <command>wall</command> commands are granted SGID permissions, the commands will run using the access rights as applicable to this group, <emphasis>tty</emphasis> in the example. Since this group has write access to the destination terminal, also a user having no permissions to use that terminal in any way can send messages to it.</para>
<para>In the example below, user <emphasis>joe</emphasis> first finds out on which terminal his correspondent is connected, using the <command>who</command> command. Then he sends her a message using the <command>write</command> command. Also illustrated are the access rights on the <command>write</command> program and on the terminals occupied by the receiving user: it is clear that others than the user owner have no permissions on the device, exept for the group owner, which can write to it.</para>
<para>In the example below, user <emphasis>joe</emphasis> first finds out on which terminal his correspondent is connected, using the <command>who</command> command. Then he sends her a message using the <command>write</command> command. Also illustrated are the access rights on the <command>write</command> program and on the terminals occupied by the receiving user: it is clear that others than the user owner have no permissions on the device, except for the group owner, which can write to it.</para>
<screen>
joe:~&gt;which write
write is /usr/bin/write
@ -335,12 +335,12 @@ GRUB supports both boot methods, allowing you to use it with almost any operatin
</sect2>
<sect2 id="sect_04_02_04"><title>Init</title>
<para>The kernel, once it is loaded, finds <command>init</command> in <filename>sbin</filename> and executes it.</para>
<para>When <command>init</command> starts, it becomes the parent or grandparent of all of the processes that start up automatically on your Linux system. First, it runs the <filename>/etc/rc.d/rc.sysinit</filename> script, which sets your path, starts swapping, checks the file systems, and so on. Basically, <filename>rc.sysinit</filename> takes care of everything that your system needs to have done at system initialization: setting the clock, initializing serial ports and so forth.</para>
<para> Then <command>init</command> runs the <filename>/etc/inittab</filename> script, which describes how the system should be set up in each run level and sets the default run level. This file states, among other things, that <command>/sbin/update</command> should be run whenever a run level starts. The <command>update</command> program is used to flush dirty buffers back to disk.</para>
<para> Whenever the run level changes, <command>init</command> uses the scripts in <filename>/etc/rc.d/init.d</filename> to start and stop various services, such as your web server, DNS server, and so on. First, <command>init</command> sets the source function library for the system (commonly <filename>/etc/rc.d/init.d/functions</filename>), which spells out how to start or kill a program and how to find out the PID of a program. Then <command>init</command> determines the current and the previous run level.</para>
<para>Next, <command>init</command> starts all of the background processes necessary for the system to run by looking in the appropriate <filename>rc</filename> directory for that run level. <command>init</command> runs each of the kill scripts (their file names start with a K) with a stop parameter. It then runs all of the start scripts (their file names start with an S) in the appropriate run level directory so that all services and applications are started correctly. In fact, you can execute these same scripts manually after the system is finished booting with a command like <command>/etc/rc.d/init.d/httpd stop</command> or <command>service httpd stop</command> logged in as <emphasis>root</emphasis>, in this case stopping the web server.</para>
<para>When <command>init</command> starts, it becomes the parent or grandparent of all of the processes that start up automatically on your Linux system. The first thing <command>init</command> does, is reading its initialization file, <filename>/etc/inittab</filename>. This instructs <command>init</command> 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.</para>
<para> Then <command>init</command> continues to read the <filename>/etc/inittab</filename> file, which describes how the system should be set up in each run level and sets the default <emphasis>run level</emphasis>. 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.</para>
<para>Commonly, run level 3 is configured to be text mode on a Linux machine, and run level 5 initializes the graphical login and environment. More about run levels in the next section, see <xref linkend="sect_04_02_05" />.</para>
<para>After having determined the default run level for your system, <command>init</command> starts all of the background processes necessary for the system to run by looking in the appropriate <filename>rc</filename> directory for that run level. <command>init</command> runs each of the kill scripts (their file names start with a K) with a stop parameter. It then runs all of the start scripts (their file names start with an S) in the appropriate run level directory so that all services and applications are started correctly. In fact, you can execute these same scripts manually after the system is finished booting with a command like <command>/etc/rc.d/init.d/httpd stop</command> or <command>service httpd stop</command> logged in as <emphasis>root</emphasis>, in this case stopping the web server.</para>
<para> None of the scripts that actually start and stop the services are located in <filename>/etc/rc.d/rc&lt;x&gt;.d</filename>. Rather, all of the files in <filename>/etc/rc.d/rc&lt;x&gt;.d</filename> are symbolic links that point to the actual scripts located in <filename>/etc/rc.d/init.d</filename>. A symbolic link is nothing more than a file that points to another file, and is used in this case because it can be created and deleted without affecting the actual scripts that kill or start the services. The symbolic links to the various scripts are numbered in a particular order so that they start in that order. You can change the order in which the services start up or are killed by changing the name of the symbolic link that refers to the script that actually controls the service. You can use the same number multiple times if you want a particular service started or stopped right before or after another service.</para>
<para>Below a sample of <filename>/etc/rc5.d</filename> content:</para>
<para>Below a sample of <filename>/etc/rc5.d</filename> content, which lists the services started up in run level 5:</para>
<screen>
[jean@blub /etc/rc5.d] ls
K15httpd@ K45named@ S08ipchains@ S25netfs@ S85gpm@
@ -355,13 +355,13 @@ K34yppasswdd@ S05kudzu@ S20random@ S80sendmail@
</screen>
<para>After <command>init</command> has progressed through the run levels to get to the default run level, the <filename>/etc/inittab</filename> script forks a <command>getty</command> process for each virtual console (login prompt) for each run level (run levels 2-5 get all six consoles; run level 1, which is single user mode, only gets one console; run levels 0 and 6 get no virtual consoles). <command>getty</command> opens tty lines, sets their modes, prints the login prompt, gets the user's name, and then initiates a login process for that user. This allows users to authenticate themselves to the system and use it.</para>
<para>
<filename>/etc/inittab</filename> also tells <command>init</command> how it should handle a user pressing [CTRL]-[ALT]-[DEL] at the console. As the system should be properly shut down and restarted rather than immediately power-cycled, <command>init</command> is told to execute the command <command>/sbin/shutdown <option>-t3 -r now</option></command> when a user hits those keys. In addition, <filename>/etc/inittab</filename> states what <command>init</command> should do in case of power failures, if your system has a UPS unit attached to it.</para>
<filename>/etc/inittab</filename> can also tell <command>init</command> how it should handle a user pressing [CTRL]-[ALT]-[DEL] at the console. As the system should be properly shut down and restarted rather than immediately power-cycled, <command>init</command> is told to execute the command <command>/sbin/shutdown <option>-t3 -r now</option></command>, for instance, when a user hits those keys. In addition, <filename>/etc/inittab</filename> states what <command>init</command> should do in case of power failures, if your system has a UPS unit attached to it.</para>
<para>
In run level 5, <filename>/etc/inittab</filename> runs a script called <filename>/etc/X11/prefdm</filename>. The <filename>prefdm</filename> script runs the preferred X display manager (<command>gdm</command> if you run GNOME or <command>kdm</command> if you run KDE) based on the contents of the <filename>/etc/sysconfig/desktop</filename> directory. The <filename>/etc/sysconfig</filename> directory contains entries for a range of functions and services, these are all read at boot time. This last part, however, might be somewhat different depending on your Linux distribution.</para>
<para>Besides the graphical user environment, a lot of other services may be started as well. But if all goes well, you should be looking at a login prompt or login screen when the boot process has finished.</para>
<note><title>Other procedures</title>
<para>We explained how SysV <command>init</command> works on x86 based machines. Startup procedures may vary on other architectures. Other UNIX systems may use BSD <command>init</command>.</para></note>
<para>We explained how SysV <command>init</command> works on x86 based machines. Startup procedures may vary on other architectures and distributions. Other systems may use the BSD-style <command>init</command>, where startup files are not split up into multiple <filename>/etc/rc.d/rc&lt;LEVEL&gt;.d</filename> directories.</para></note>
</sect2>
<sect2 id="sect_04_02_05"><title>Init run levels</title>
<para> The idea behind operating different services at different run levels essentially revolves around the fact that different systems can be used in different ways. Some services cannot be used until the system is in a particular state, or <emphasis>mode</emphasis>, such as being ready for more than one user or having networking available.</para>
@ -373,12 +373,8 @@ There are times in which you may want to operate the system in a lower mode. Ex
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, &lt;miquels@drinkel.nl.mugnet.org&gt;
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# Default runlevel. The runlevels are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS
@ -389,18 +385,24 @@ There are times in which you may want to operate the system in a lower mode. Ex
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
&lt;--cut--&gt;
</screen>
<para> Feel free to configure runlevels 2 and 4 as you see fit. Many users configure those runlevels in a way that makes the most sense for them while leaving the standard runlevels 3 and 5 alone. This allows them to quickly move in and out of their custom configuration without disturbing the normal set of features at the standard runlevels.</para>
<para> If your machine gets into a state where it will not boot due to a bad <filename>/etc/inittab</filename> or will not let you log in because you have a corrupted <filename>/etc/passwd</filename> file (or if you have simply forgotten your password), boot into single-user mode.</para>
<note><title>No graphics?</title>
<para>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 <command>who -r</command>. If it is set to something else than 5, chances are that the system does not start up in graphical mode by default. Contact your system administrator or read <command>man init</command> in that case. Note that switching run levels is done using the <command>init</command> command; switching from a text to a graphical console or vice versa does not involve a run level switch.</para>
</note>
<sect3 id="sect_04_02_05_01"><title>Tools</title>
<para>The <command>chkconfig</command> utility in <filename>/sbin</filename> provides a simple command-line tool for maintaining the <filename>/etc/rc.d/init.d</filename> directory hierarchy. It relieves system administrators from having to directly manipulate the numerous symbolic links in the directories under <filename>/etc/rc.d</filename>.</para>
<para>
In addition, there is <command>ntsysv</command>, which provides a text-based interface; you may find this easier to use than <command>chkconfig</command>'s command-line interface.</para>
In addition, some systems offer the <command>ntsysv</command> tool, which provides a text-based interface; you may find this easier to use than <command>chkconfig</command>'s command-line interface. On SuSE Linux, you will find the <command>yast</command> and <command>insserv</command> tools. For Mandrake easy configuration, you may want to try <emphasis>DrakConf</emphasis>, which allows among other features switching between run levels 3 and 5.</para>
<para>
If you prefer a graphical interface, use the <command>serviceconf</command> program.</para>
Most distributions provide a graphical user interface for configuring processes, check with your system documentation.</para>
<para>
All of these utilities must be run as root.</para>
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.</para>
</sect3>
</sect2>
<sect2 id="sect_04_02_06"><title>Shutdown</title>
@ -494,7 +496,7 @@ Command exited with non-zero status 2
<para>If none of these solutions are an option in your particular situation, you may want to upgrade your CPU. On a UNIX machine this is a job for the system admin.</para>
</sect3>
<sect3 id="sect_04_03_05_03"><title>Memory resources</title>
<para>When the currently running processes expect more memory than the system has physically available, a Linux system will not crash; it will start paging, or <emphasis>swapping</emphasis>, meaning the process uses the memory on disk or in swap space, moving contents of the physical memory (pieces of running programs or entire programs in the case of swapping) to disk, thus reclaiming the physical memory to handle more processes. This slows the system down enormously since access to disk is much slower than access to memory. The <command>top</command> command can be used to display memory and swap use. Systems using glibc, such as RedHat, offer the <command>memusage</command> and <command>memusagestat</command> commands to visualize memory usage.</para>
<para>When the currently running processes expect more memory than the system has physically available, a Linux system will not crash; it will start paging, or <emphasis>swapping</emphasis>, meaning the process uses the memory on disk or in swap space, moving contents of the physical memory (pieces of running programs or entire programs in the case of swapping) to disk, thus reclaiming the physical memory to handle more processes. This slows the system down enormously since access to disk is much slower than access to memory. The <command>top</command> command can be used to display memory and swap use. Systems using glibc offer the <command>memusage</command> and <command>memusagestat</command> commands to visualize memory usage.</para>
<para>If you find that a lot of memory and swap space are being used, you can try:</para>
<itemizedlist>
<listitem><para>Killing, stopping or renicing those programs that use a big chunk of memory</para></listitem>
@ -602,9 +604,9 @@ job 2 at 2001-06-14 02:00
</sect2>
<sect2 id="sect_04_04_04"><title>Cron and crontab</title>
<para>The cron system is managed by the cron daemon. It gets information about which programs and when they should run from the system's and users' crontab entries. Only the root user has access to the system crontabs, while each user should only have access to his own crontabs. On some systems (some) users may not have access to the cron facility.</para>
<para>At system startup the daemon searches <filename>/var/spool/cron/</filename> for crontab entries which are named after accounts in <filename>/etc/passwd</filename>, it searches <filename>/etc/cron.d/</filename> and it searches <filename>/etc/crontab</filename>, then uses this information every minute to check if there is something to be done. It executes commands as the user who owns the crontab file and mails any output of commands to the owner.</para>
<para>At system startup the cron daemon searches <filename>/var/spool/cron/</filename> for crontab entries which are named after accounts in <filename>/etc/passwd</filename>, it searches <filename>/etc/cron.d/</filename> and it searches <filename>/etc/crontab</filename>, then uses this information every minute to check if there is something to be done. It executes commands as the user who owns the crontab file and mails any output of commands to the owner.</para>
<para>On systems using Vixie cron, jobs that occur hourly, daily, weekly and monthly are kept in separate directories in <filename>/etc</filename> to keep an overview, as opposed to the standard UNIX cron function, where all tasks are entered into one big file.</para>
<para>Example of a crontab file:</para>
<para>Example of a Vixie crontab file:</para>
<screen>
[root@blob /etc]# more crontab
SHELL=/bin/bash
@ -622,7 +624,7 @@ HOME=/
commands to execute every month
42 4 1 * * root run-parts /etc/cron.monthly
</screen>
<para>Some variables are set, and after that there's the actual scheduling, one line per job, starting with 5 time and date fields. The first field contains the minutes (from 0 to 59), the second defines the hour of execution (0-23), the third is day of the month (1-31), then the day of the month (1-12), the last is day of the week (0-7, both 0 and 7 are Sunday). An asterisk in these fields represents the total acceptable range for the field. Lists are allowed; to execute a job from Monday to Friday enter 1-5 in the last field, to execute a job on Monday, Wednesday and Friday enter 1,3,5.</para>
<para>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.</para>
<para>Then comes the user who should run the processes which are listed in the last column. The example above is from a Vixie cron configuration where root runs the program <command>runparts</command> on regular intervals, with the appropriate directories as options. In these directories, the actual jobs to be executed at the scheduled time are stored as shell scripts, like this little script that is run daily to update the database used by the <command>locate</command> command:</para>
<screen>
billy@ahost cron.daily]$ cat slocate.cron
@ -774,7 +776,7 @@ billy:~>crontab -l
<listitem><para>Create an <command>at</command> job that copies all files in your home directory to <filename>/var/tmp</filename> within half an hour. You may want to create a sub-directory in <filename>/var/tmp</filename>.</para></listitem>
<listitem><para>Make a cronjob that does this task every Monday to Friday during lunch.</para></listitem>
<listitem><para>Check that it works.</para></listitem>
<listitem><para>Make a mistake in the crontab entry, like issuing the unexisting command <command>coppy</command> instead of <command>cp</command>. What happens upon execution of the task?</para></listitem>
<listitem><para>Make a mistake in the crontab entry, like issuing the nonexistent command <command>coppy</command> instead of <command>cp</command>. What happens upon execution of the task?</para></listitem>
</itemizedlist>
</sect2>
</sect1>

View File

@ -1,8 +1,8 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<chapter id="chap_05">
<title>Input and output redirection</title>
<title>I/O redirection</title>
<abstract>
<para>This chapter describes more about the powerful UNIX mechanism of redirecting input and output. Topics include:</para>
<para>This chapter describes more about the powerful UNIX mechanism of redirecting input, output and errors. Topics include:</para>
<para>
<itemizedlist>
<listitem><para>Standard input, output and errors</para></listitem>
@ -49,7 +49,7 @@ some other words
[jean@saturnus ~/Documents] ls -l list
-rw-rw-r-- 1 jean jean 0 Apr 4 12:01 list
</screen>
<para>This process is called <emphasis>truncating</emphasis>. The same redirection to an unexisting file will create a new empty file with the given name:</para>
<para>This process is called <emphasis>truncating</emphasis>. The same redirection to an nonexistent file will create a new empty file with the given name:</para>
<screen>
[jean@saturnus ~] ls -l newlist
ls: newlist: No such file or directory
@ -62,9 +62,6 @@ ls: newlist: No such file or directory
<para><xref linkend="chap_07" /> gives some more examples on the use of this sort of redirection.</para>
<para>Some examples using piping of commands:</para>
<itemizedlist>
<listitem><para>To mail a text file to somebody:</para>
<para><command>cat <filename>file</filename> | mail somebody@somewhere.com</command></para>
</listitem>
<listitem><para>To find a word within some text, display all lines matching pattern1, or exclude lines also matching pattern2 from being displayed:</para>
<para><command>grep pattern1 <filename>file</filename> | grep -v pattern2</command></para>
</listitem>
@ -74,44 +71,64 @@ ls: newlist: No such file or directory
<listitem><para>To find an entry in a directory:</para>
<para><command>ls -l | grep <filename>entry</filename></command></para></listitem>
</itemizedlist>
</sect3>
<sect3 id="sect_05_01_01_02"><title>Input redirection</title>
<para>In another case, you may want a file to be the input for a command that normally wouldn't accept a file as an option. This redirecting of input is done using the <quote>&lt;</quote> (less-than symbol) operator.</para>
<para>Below is an example of sending a file to somebody, using input redirection.</para>
<screen>
andy:~&gt;mail mike@somewhere.org &lt; to_do
</screen>
<para>If the user <emphasis>mike</emphasis> exists on the system, you don't need to type the full address. If you want to reach somebody on the Internet, enter the fully qualified address as an argument to <command>mail</command>.</para>
<para>This reads a bit more difficult than the beginner's <command>cat <filename>file</filename> | mail <option>someone</option></command>, but it is of course a much more elegant way of using the available tools.</para>
</sect3>
<sect3 id="sect_05_01_01_03"><title>Combining redirections</title>
<para>The following example combines input and output redirection. The file <filename>text.txt</filename> is first checked for spelling mistakes, and the output is redirected to an error log file:</para>
<para><command>aspell &lt; <filename>text.txt</filename> &gt; error.log</command></para>
<para>The following command lists all commands that you can issue to examine another file when using <command>less</command>:</para>
<screen>
mike:~&gt; less --help | grep -i examine
: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.
</screen>
<para>If you want to save output of this command for future reference, redirect the output to a file:</para>
<screen>
mike:~&gt; less --help | grep -i examine &gt; examine-files-in-less
mike:~&gt; cat examine-files-in-less
: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.
</screen>
<para>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 info pages) of the commands you use if you should encounter errors.</para>
<note><title>Don't overwrite!</title>
<para>Be careful not to overwrite existing (important) files when redirecting output. Many shells, including Bash, have a built-in feature to protect you from that risk: <command>noclobber</command>. See the Info pages for more information. In Bash, you would want to add the <command>set -o noclobber</command> command to your <filename>.bashrc</filename> configuration file in order to prevent accidental overwriting of files.</para></note>
<para>The pipe command (<command>|</command>) will feed output of one program as input to another. This is a way of sending mail using redirection of output instead of redirection of input:</para>
<screen>
andy:~&gt;cat to_do | mail mike
</screen>
<para>The output of the piped command can then be piped into another command, just as long as these commands would normally read input from the standard input and put output to the standard output.</para>
</sect3>
<sect3 id="sect_05_01_01_02"><title>The &gt; &gt; operator</title>
<sect3 id="sect_05_01_01_04"><title>The &gt; &gt; operator</title>
<para>Instead of overwriting file data, you can also append text to an existing file.</para>
<para>Example:</para>
<screen>
mike:~&gt;date &gt; &gt; today's_wishlist
mike:~&gt;date &gt; &gt; wishlist
mike:~&gt;cat today's_wishlist
mike:~&gt;cat wishlist
more money
less work
Thu Feb 28 20:23:07 CET 2002
</screen>
<para>The <command>date</command> command would normally put the last line on the screen; now it is appended to the file <filename>test3</filename>.
<para>The <command>date</command> command would normally put the last line on the screen; now it is appended to the file <filename>wishlist</filename>.
</para>
</sect3>
</sect2>
<sect2 id="sect_05_01_02"><title>Advanced redirection features</title>
<para>There are three types of output, which each have their own identifier, called a file descriptor:</para>
<sect3 id="sect_05_01_02_01"><title>Use of file descriptors</title>
<para>There are three types of I/O, which each have their own identifier, called a file descriptor:</para>
<itemizedlist>
<listitem><para>standard input: 0</para></listitem>
<listitem><para>standard output: 1</para></listitem>
@ -125,18 +142,39 @@ Thu Feb 28 20:23:07 CET 2002
<cmdsynopsis><command>ls 2&gt;&amp;1 &gt; <filename>dirlist</filename></command></cmdsynopsis>
<para>will only direct standard output to <filename>dirlist</filename>. This can be a useful option for programmers.</para>
<para>All this is explained in detail in the Bash Info pages.</para>
</sect3>
<sect3 id="sect_05_01_02_02"><title>Examples</title>
<sect4><title>Analyzing errors</title>
<para>If your process generates a lot of errors, this is a way to thoroughly examine them:</para>
<cmdsynopsis><command>command 2&gt;&amp;1 | less</command></cmdsynopsis>
<para>This is often used when creating new software using the <command>make</command>, such as in:</para>
<screen>
andy:~/newsoft&gt; make all 2&gt;&amp;1 | less
--output ommitted--
</screen>
</sect4>
<sect4><title>Separating standard output from standard error</title>
<para>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 <command>tty</command> command first:</para>
<screen>
andy:~/newsoft&gt; make all 2&gt; /dev/pts/7
</screen>
</sect4>
</sect3>
</sect2>
<sect2 id="sect_05_01_03">
<title>Filters</title>
<para>When a program performs operations on input and writes the result to the standard output, it is called a filter. One of the most common uses of filters is to restructure output. We'll discuss a couple of the most important filters below.</para>
<sect3 id="sect_05_01_03_01"><title><command>grep</command></title>
<para><command>grep</command> scans the output line per line, searching for matching patterns. All lines containing the pattern will be printed to standard output. This behavior can be reversed using the <command>-v</command> option.
<sect3 id="sect_05_01_03_01"><title>More about grep</title>
<para>As we saw in <xref linkend="sect_03_03_03_04" />, <command>grep</command> scans the output line per line, searching for matching patterns. All lines containing the pattern will be printed to standard output. This behavior can be reversed using the <command>-v</command> option.
</para>
<para>Some examples: suppose we want to know which files in a certain directory have been modified in February:</para>
<screen>
jenny:~&gt;ls -la | grep Feb
</screen>
<para>The <command>grep</command> command, like most commands, is case sensitive. Use the <option>-i</option> option to make no difference between upper and lower case. Again, all the information is contained in the Info pages.</para>
<para>The <command>grep</command> command, like most commands, is case sensitive. Use the <option>-i</option> option to make no difference between upper and lower case. A lot of GNU extensions are available as well, such as <option>--colour</option>, which is helpful to highlight searchterms in long lines, and <option>--after-context</option>, which prints the number of lines after the last matching line. You can issue a recursive <command>grep</command> that searches all subdirectories of encountered directories using the <option>-r</option> option. As usual, option can be combined.</para>
<para>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 <command>grep</command> documentation. An excellent chapter is included in the <command>info grep</command> 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.</para>
<para>Play around a bit with <command>grep</command>, 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 started, see <xref linkend="sect_05_03" />.</para>
</sect3>
<sect3 id="sect_05_01_03_02"><title>Filtering output</title>

View File

@ -60,8 +60,8 @@ andy:~&gt;rm newlist
<para>Some Linux programs insist on writing all sorts of output in a log file. Usually there are options to only log errors, or to log a minimal amount of information, for example setting the debugging level of the program. But even then, you might not care about the log file. Here are some ways to get rid of them or at least set some limits to their size:</para>
<itemizedlist>
<listitem><para>Try removing the log file when the program is not running, if you are sure that you won't need it again. Some programs may even see, when restarted, that there is no log file and will therefore not log.</para></listitem>
<listitem><para>If you remove the log file and the program recreates it, read the documentation for this particular program in search for command options that avoid making logfiles.</para></listitem>
<listitem><para>Try making smaller logfiles by logging only the information that is relevant to you, or by logging only significant information.</para></listitem>
<listitem><para>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.</para></listitem>
<listitem><para>Try making smaller log files by logging only the information that is relevant to you, or by logging only significant information.</para></listitem>
<listitem><para>Try replacing the log file with a symbolic link to <filename>/dev/null</filename>; if you're lucky the program won't complain. Don't do this with the log files of programs that run at system boot or programs that run from cron (see <xref linkend="chap_04" />). These programs might replace the symbolic link with a small file that starts growing again.</para></listitem>
</itemizedlist>
</sect3>
@ -109,11 +109,55 @@ virtual memory (kbytes) unlimited
</sect1>
<sect1 id="sect_07_02"><title>Your text environment</title>
<sect2 id="sect_07_02_1"><title>Environment variables</title>
<sect3 id="sect_07_02_01"><title>General</title>
<para>We already mentioned a couple of environment variables, such as <varname>PATH</varname> and <varname>HOME</varname>. Until now, we only saw examples in which they serve a certain purpose to the shell. But there are many other Linux utilities that need information about you in order to do a good job.</para>
<para>What other information do programs need apart from paths and home directories?</para>
<para>A lot of programs want to know about the kind of terminal you are using; this information is stored in the <varname>TERM</varname> variable. In text mode, this will be the <emphasis>linux</emphasis> terminal emulation, in graphical mode you are likely to use <emphasis>xterm</emphasis>. Lots of programs want to know what your favorite editor is, in case they have to start an editor in a subprocess. The shell you are using is stored in the <varname>SHELL</varname> variable, the operating system type in <varname>OS</varname> and so on. A list of all variables currently defined for your session can be viewed entering the <command>printenv</command> command.</para>
<para>The environment variables are managed by the shell. As opposed to regular shell variables, environment variables are inherited by any program you start, including another shell. New processes are assigned a copy of these variables, which they can read, modify and pass on in turn to their own child processes.</para>
<para>There is nothing special about variable names, except that the common ones are in upper case characters by convention. You may come up with any name you want, although there are standard variables that are important enough to be the same on every Linux system, such as <varname>PATH</varname> and <varname>HOME</varname>.</para>
</sect3>
<sect3 id="sect_07_02_02"><title>Exporting variables</title>
<para>An individual variable's content is usually displayed using the <command>echo</command> command, as in these examples:</para>
<screen>
debby:~&gt; echo $PATH
/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bin
debby:~&gt; echo $MANPATH
/usr/man:/usr/share/man/:/usr/local/man:/usr/X11R6/man
</screen>
<para>If you want to change the content of a variable in a way that is useful to other programs, you have to exported the new value from your environment into the environment that runs these programs. A common example is exporting the <varname>PATH</varname>. You may very well declare it as follows, in order to be able to use that Acrobat Reader software that is in <filename>/opt/acrobat/bin</filename>:</para>
<screen>
debby:~&gt; PATH=$PATH:/opt/acrobat/bin
</screen>
<para>This instructs the shell to not only search programs in the current path, <varname>$PATH</varname>, but also in the additional directory <filename>/opt/acrobat/bin</filename>.</para>
<para>However, as long as the new value of the <varname>PATH</varname> variable is not known to the environment, things will still not work:</para>
<screen>
debby:~&gt; acroread file.pdf
bash: acroread: command not found
</screen>
<para>Exporting variables is done using the shell built-in command <command>export</command>:</para>
<screen>
debby:~&gt; export PATH
debby:~&gt; acroread file.pdf
--new window opens--
</screen>
<para>In Bash, we normally do this in one elegant step:</para>
<cmdsynopsis><command>export <varname>VARIABLE</varname>=value</command></cmdsynopsis>
<para>A more advanced example for users who install software in their home directory:</para>
<screen>
debby:~&gt; export MANPATH=$MANPATH:$HOME/man
debby:~&gt; echo $MANPATH
/usr/man:/usr/share/man/:/usr/local/man:/usr/X11R6/man:/home/debby/man
</screen>
<para>Or other unusual locations, for instance to read man pages for the <command>stuffit</command> program, that may be installed in <filename>/opt</filename>:</para>
<screen>
debby:~&gt; export MANPATH=/usr/man:/usr/share/man/:/usr/local/man\
:/usr/X11R6/man:/opt/stuffit/man
</screen>
</sect3>
<sect3 id="sect_07_02_03"><title>Reserved variables</title>
<para>The following table gives an overview of the most common predefined variables:</para>
<table frame="all">
@ -138,7 +182,7 @@ virtual memory (kbytes) unlimited
<row><entry><varname>OS</varname></entry><entry>string describing the operating system</entry></row>
<row><entry><varname>OSTYPE</varname></entry><entry>more information about version etc.</entry></row>
<row><entry><varname>PAGER</varname></entry><entry>used by programs like <command>man</command> which need to know what to do in case output is more than one terminal window.</entry></row>
<row><entry><varname>PATH</varname></entry><entry>serach paths for commands</entry></row>
<row><entry><varname>PATH</varname></entry><entry>search paths for commands</entry></row>
<row><entry><varname>PS1</varname></entry><entry>primary prompt</entry></row>
<row><entry><varname>PS2</varname></entry><entry>secundary prompt</entry></row>
<row><entry><varname>PWD</varname></entry><entry>present working directory</entry></row>
@ -152,11 +196,11 @@ virtual memory (kbytes) unlimited
</tbody>
</tgroup>
</table>
<para>A lot of variables are not only predefined but also preset, using configuration files. We discuss these in the next section.</para>
</sect3>
</sect2>
<sect2 id="sect_07_02_02"><title>Shell setup files</title>
<sect2 id="sect_07_02_04"><title>Shell setup files</title>
<para>When entering the <command>ls -al</command> command to get a long listing of all files, including the ones starting with a dot, in your home directory, you will see one or more files starting with a . and ending in <emphasis>rc</emphasis>. For the case of <command>bash</command>, this is <filename>.bashrc</filename>. This is the counterpart of the system-wide configuration file <filename>/etc/bashrc</filename>.</para>
<para>When logging into an interactive login shell, <command>login</command> will do the authentication, set the environment and start your shell. In the case of <command>bash</command>, the next step is reading the general <filename>profile</filename> from <filename>/etc</filename>, if that file exists. <command>bash</command> then looks for <filename>~/.bash_profile</filename>, <filename>~/.bash_login</filename> and <filename>~/.profile</filename>, in that order, and reads and executes commands from the first one that exists and is readable. If none exists, <filename>/etc/bashrc</filename> is applied.</para>
<para>When a login shell exits, <command>bash</command> reads and executes commands from the file <filename>~/.bash_logout</filename>, if it exists.
@ -164,7 +208,7 @@ virtual memory (kbytes) unlimited
<para>This procedure is explained in detail in the <command>login</command> and <command>bash</command> man pages.</para>
</sect2>
<sect2 id="sect_07_02_03"><title>A typical set of setup files</title>
<sect2 id="sect_07_02_05"><title>A typical set of setup files</title>
<para>Let's look at some of these config files. First <filename>/etc/profile</filename> is read, in which important variables such as <varname>PATH</varname>, <varname>USER</varname> and <varname>HOSTNAME</varname> are set:</para>
<screen>
debby:~&gt;cat /etc/profile
@ -213,11 +257,11 @@ if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
</screen>
<para>If the variable <varname>INPUTRC</varname> is not set, and there is no <filename>.inputrc</filename> in the user's home directory, then the default input control file is loaded.</para>
<para>If the variable <varname>INPUTRC</varname> is not set, and there is no <filename>.inputrc</filename> in the user's home directory, then the default input control file is loaded. </para>
<screen>
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
</screen>
<para>All variables are exported together.</para>
<para>All variables are exported, so that they are available to other programs requesting information about your environment.</para>
<screen>
for i in /etc/profile.d/*.sh ; do
if [ -r $i ]; then
@ -238,27 +282,11 @@ debby:~&gt;cat .bash_profile
# #
#################################################################
DO_FORTUNE=1
source ~/.bashrc
source ~/.bash_login
case "$OS" in
IRIX)
stty sane dec
stty erase
;;
# SunOS)
# stty erase
# ;;
*)
stty sane
;;
esac
if test "$DO_FORTUNE" -a ! -f "$HOME/.hushlogin"; then
"$DO_FORTUNE"
fi
</screen>
<para>First, a variable is set that is used in the end to determine whether or not to display a fortune cookie. If the user has a <filename>~/.hushlogin</filename> file, which silences the login process (see <command>man login</command>), nothing is done. Then (this is a general config file for use on multiple architectures) terminal line settings are defined for operating systems that might make a fuss about them.</para>
<para>The <filename>~/.bash_login</filename> file defines default file protection by setting the <command>umask</command> value. The <filename>~/.bashrc</filename> is used to define a bunch of user-specific aliases and functions and personal environment variables. It first reads <filename>/etc/bashrc</filename>, which describes the default prompt (<varname>PS1</varname>) and the default umask value. After that, you can add your own settings. If no <filename>~/.bashrc</filename> exists, <filename>/etc/bashrc</filename> is read by default:</para>
<para>This very straight forward file instructs your shell to first read <filename>~/.bashrc</filename> and then <filename>~/.bash_login</filename>. You will encounter the <command>source</command> built-in shell command regularly when working in a shell environment: it is used to apply configuration changes to the current environment.</para>
<para>The <filename>~/.bash_login</filename> file defines default file protection by setting the <command>umask</command> value, see <xref linkend="sect_03_04_02_02" />. The <filename>~/.bashrc</filename> file is used to define a bunch of user-specific aliases and functions and personal environment variables. It first reads <filename>/etc/bashrc</filename>, which describes the default prompt (<varname>PS1</varname>) and the default umask value. After that, you can add your own settings. If no <filename>~/.bashrc</filename> exists, <filename>/etc/bashrc</filename> is read by default:</para>
<screen>
debby:~&gt;cat /etc/bashrc
# /etc/bashrc
@ -312,11 +340,17 @@ ${PWD/$HOME/~}\007"'
fi
fi
</screen>
<para>Upon logout, the commands in <filename>~/.bash_logout</filename> are executed, which can e.g. clear the terminal.</para>
<para>Let's take a closer look at how these scripts work in the next section. Keep <command>man bash</command> close at hand.</para>
<para>Upon logout, the commands in <filename>~/.bash_logout</filename> 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:</para>
<screen>
debby:~&gt; cat .bash_logout
# ~/.bash_logout
clear
</screen>
<para>Let's take a closer look at how these scripts work in the next section. Keep <command>info bash</command> close at hand.</para>
</sect2>
<sect2 id="sect_07_02_04"><title>The Bash prompt</title>
<sect3 id="sect_07_02_04_01"><title>Introduction</title>
<sect2 id="sect_07_02_06"><title>The Bash prompt</title>
<sect3 id="sect_07_02_06_01"><title>Introduction</title>
<para>
The Bash prompt can do much more than displaying such simple information as your user name, the name of your machine and some indication about the present working directory. We can add other information such as the current date and time, number of connected users etc.</para>
<para>Before we begin, however, we will save our current prompt in another environment variable:
@ -331,7 +365,7 @@ The Bash prompt can do much more than displaying such simple information as your
</screen>
<para>When we change the prompt now, e.g. issuing the command <command>PS1="-&gt;"</command>, we can always get our original prompt back with the command <command>PS1=$MYPROMPT</command>. You will, of course, also get it back when you reconnect, as long as you just fiddle with the prompt on the command line and avoid putting it in a shell configuration file.</para>
</sect3>
<sect3 id="sect_07_02_04_02"><title>Some examples</title>
<sect3 id="sect_07_02_06_02"><title>Some examples</title>
<para>In order to understand these prompts and the escape sequences used, we refer to the Bash Info or man pages.</para>
<itemizedlist>
<listitem><para><command>export PS1="[\t \j] "</command></para><para>Displays time of day and number of running jobs</para>
@ -340,25 +374,26 @@ The Bash prompt can do much more than displaying such simple information as your
<listitem><para><command>export PS1="{\!} "</command></para><para>Displays history number for each command.</para></listitem>
<listitem><para><command>export PS1="\[\033[1;35m\]\u@\h\[\033[0m\] "</command></para><para>Displays user@host in pink.</para></listitem>
<listitem><para><command>export PS1="\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] "</command></para><para>Sets the user name in pink and the present working directory in blue.</para></listitem>
<listitem><para><command>export PS1="\[\033[1;44m\]$USER is in \w\[\033[0m\] "</command></para></listitem>
<listitem><para><command>export PS1="\[\033[1;44m\]$USER is in \w\[\033[0m\] "</command></para><para>Prompt for people who have difficulties seeing the difference between the prompt and what they type.</para></listitem>
<listitem><para><command>export PS1=...</command></para></listitem>
</itemizedlist>
<para>Variables are exported so the subsequently executed commands will also know about the environment. The prompt configuration line that you want is best put in your shell configuration file, <filename>~/.bashrc</filename>.</para>
<para>If you want, prompts can execute shell scripts and behave different under different conditions. You can even have the prompt play a tune every time you issue a command, although this way it gets boring pretty soon. More information can be found in the <ulink url="http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/">Bash-Prompt HOWTO</ulink>.</para>
</sect3>
</sect2>
<sect2 id="sect_07_02_05"><title>Shell scripts</title>
<sect2 id="sect_07_02_07"><title>Shell scripts</title>
<sect3 id="sect_07_02_07_01"><title>What are scripts?</title>
<para>A shell script is, as we saw in the shell configuration examples, a text file containing shell commands. When such a file is used as the first non-option argument when invoking Bash, and neither the `-c' nor `-s' option is supplied, Bash reads and executes commands from the file, then exits. This mode of operation creates a non-interactive shell. When Bash runs a shell script, it sets the special parameter `0' to the name of the file, rather than the name of the shell, and the positional parameters are set to the remaining arguments, if any are given. If no additional arguments are supplied, the positional parameters are unset.</para>
<para>A shell script may be made executable by using the <command>chmod</command> command to turn on the execute bit. When Bash finds such a file while searching the <varname>PATH</varname> for a command, it spawns a sub-shell to execute it. In other words, executing</para>
<cmdsynopsis><command>filename <option>ARGUMENTS</option></command></cmdsynopsis>
<para>is equivalent to executing</para>
<cmdsynopsis><command>bash file_name <option>ARGUMENTS</option></command></cmdsynopsis>
<cmdsynopsis><command>bash filename <option>ARGUMENTS</option></command></cmdsynopsis>
<para>if `filename' is an executable shell script. This sub-shell reinitializes itself, so that the effect is as if a new shell had been invoked to interpret the script, with the exception that the locations of commands remembered by the parent (see <command>hash</command> in the Info pages) are retained by the child.</para>
<para>Most versions of UNIX make this a part of the operating system's command execution mechanism. If the first line of a script begins with the two characters `#!', the remainder of the line specifies an interpreter for the program. Thus, you can specify <command>bash</command>, <command>awk</command>, <command>perl</command> or some other interpreter or shell and write the rest of the script file in that language.</para>
<para>The arguments to the interpreter consist of a single optional argument following the interpreter name on the first line of the script file, followed by the name of the script file, followed by the rest of the arguments. Bash will perform this action on operating systems that do not handle it themselves.</para>
<para>Bash scripts often begin with `#! /bin/bash' (assuming that Bash has been installed in `/bin'), since this ensures that Bash will be used to interpret the script, even if it is executed under another shell.</para>
<sect3 id="sect_07_02_05_01"><title>Some simple examples</title>
</sect3>
<sect3 id="sect_07_02_07_02"><title>Some simple examples</title>
<para>A very simple script consisting of only one command, that says hello to the user executing it:</para>
<screen>
#!/bin/bash
@ -372,7 +407,7 @@ who | cut -d " " -f 1 | sort -u
</screen>
<para>Here is a script consisting of some more lines, that I use to convert wav-files to mp3-format using the <command>lame</command> command. The script first makes a list of all wav-files in the current directory and puts it in the variable <varname>LIST</varname>. Then it sets the new name for each file, and converts the file format. After that, it cleans up the wav-files which are replaced by their mp3 counterparts:</para>
<screen>
tille:~>cat /usr/local/bin/wav2mp3
tille:~&gt; cat /usr/local/bin/wav2mp3
#!/bin/bash
# convert *.wav into *.mp3
LIST=$(ls *.wav)
@ -385,42 +420,35 @@ for i in $LIST; do
done
</screen>
<para>The <command>cut</command> command is used in this example to separate the actual file name from the file name suffix. Just entering a line like <command>mv *.wav *.mp3</command> won't work. An <command>echo</command> command was added in order to display some activity. <command>echo</command>'s are generally useful when a script won't work: insert one after each doubted step and you will find the error in no time.</para>
<para>The <filename>/etc/rc.d/init.d</filename> directory contains loads of examples. Let's look at this script that controls the RedHat Interchange server (E-commerce server), which uses somewhat more advanced techniques:</para>
<para>The <filename>/etc/rc.d/init.d</filename> directory contains loads of examples. Let's look at this script that controls the fictive ICanSeeYou server:</para>
<screen>
#!/bin/sh
#
# Run control script for Interchange
# http://interchange.redhat.com/
#
# chkconfig: 345 96 4
# description: Interchange is a database access and
# HTML templating system
# focused on ecommerce
# processname: interchange
# pidfile: /var/run/interchange/interchange.pid
# config: /etc/interchange.cfg
# config: /var/lib/interchange/*/catalog.cfg
# 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 we were called.
# See how (with which arguments) we were called.
case "$1" in
start)
echo -n "Starting Interchange: "
daemon interchange -q
echo -n "Starting ICanSeeYou: "
daemon ICanSeeYou
echo
touch /var/lock/subsys/interchange
touch /var/lock/subsys/ICanSeeYou
;;
stop)
echo -n "Shutting down Interchange: "
killproc interchange
echo -n "Shutting down ICanSeeYou: "
killproc ICanSeeYou
echo
rm -f /var/lock/subsys/interchange
rm -f /var/run/interchange/interchange.pid
rm -f /var/lock/subsys/ICanSeeYou
rm -f /var/run/ICanSeeYou/ICanSeeYou.pid
;;
status)
status interchange
status ICanSeeYou
;;
restart)
$0 stop