added <prompt> and <command> tags in screen section

This commit is contained in:
tille 2004-01-01 20:37:30 +00:00
parent ec065ec6bf
commit 9337056bf5
10 changed files with 324 additions and 318 deletions

View File

@ -86,7 +86,7 @@ administrator, trainer and consultant. We hope these examples will help you
to get a better understanding of the Linux system and that you feel encouraged
to try out things on your own.
</para>
<para>Everybody who wants to get a CLUE, a Command Line User Experience, with
<para>Everybody who wants to get a <quote>CLUE</quote>, a Command Line User Experience, with
Linux (and UNIX in general) will find this book useful.
</para>
</section>
@ -113,7 +113,8 @@ http://tille.soti.org/training/tldp/</ulink>.
<revnumber>1.10</revnumber>
<date>2004-01-01</date>
<authorinitials>MG</authorinitials>
<revremark>Changed encoding to UTF-8, rearranged revision history.</revremark>
<revremark>Changed encoding to UTF-8, rearranged revision history.
Added a lot of markup in the screen sections to better distinguish prompts from commands.</revremark>
</revision>
<revision>
<revnumber>1.9</revnumber>
@ -232,7 +233,7 @@ that we two looked over.
</para>
<para>And thanks to all the readers who noticed me about missing topics and who
helped to pick out the last errors, unclear definitions and typos by going
through the trouble of mailing me all their remarks.
through the trouble of mailing me all their remarks. These are also the people who help me keep this guide up to date.
</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

View File

@ -679,11 +679,11 @@ address? Are there any gateway servers or other important networked machines
my box should communicate with?
</para>
<note><title>Linux expects to be networked</title>
<caution><title>Linux expects to be networked</title>
<para>Not using the network or configuring it incorrectly may result in slow
startup.
</para>
</note>
</caution>
</listitem>
<listitem><para>Is this computer a gateway/router/firewall? (If you have to

View File

@ -110,7 +110,7 @@ nameserver 193.134.20.4
</listitem>
<listitem><para><filename>/etc/nsswitch.conf</filename>: defines the order in which to contact different name services. For Internet use, it is important that <emphasis>dns</emphasis> shows up in the <quote>hosts</quote> line:</para>
<screen>
[bob@tux ~] grep hosts /etc/nsswitch.conf
<prompt>[bob@tux ~]</prompt> <command>grep hosts /etc/nsswitch.conf</command>
hosts: files dns
</screen>
<para>This instructs your computer to look up hostnames and IP addresses first in the <filename>/etc/hosts</filename> file, and to contact the DNS server if a given host does not occur in the local <filename>hosts</filename> file. Other possible name services to contact are LDAP, NIS and NIS+.</para>
@ -124,7 +124,7 @@ hosts: files dns
<para>The following commands show IP address and routing information:</para>
<screen>
benny@home benny&gt; ip addr show
<prompt>benny@home benny&gt;</prompt> <command>ip addr show</command>
1: lo: &lt;LOOPBACK,UP&gt; mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
@ -134,7 +134,7 @@ benny@home benny&gt; ip addr show
inet 192.168.42.15/24 brd 192.168.42.255 scope global eth0
inet6 fe80::250:bfff:fe7e:549a/10 scope link
benny@home benny&gt; ip route show
<prompt>benny@home benny&gt;</prompt> <command>ip route show</command>
192.168.42.0/24 dev eth0 scope link
127.0.0.0/8 dev lo scope link
default via 192.168.42.1 dev eth0
@ -157,7 +157,7 @@ default via 192.168.42.1 dev eth0
<sect3 id="sect_10_01_02_05"><title>Your host configuration</title>
<para>Apart from the <command>ip</command> command for displaying the network configuration, there's the common <command>netstat</command> command which has a lot of options and is generally useful on any UNIX system. Use the <option>-i</option> option to display information about network interfaces:</para>
<screen>
bob:~&gt;netstat -i
<prompt>bob:~&gt;</prompt> <command>netstat -i</command>
Kernel Interface table
Iface MTU Met RXOK RXERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 58459 0 0 0 63865 0 0 0 BMRU
@ -165,7 +165,7 @@ lo 16436 0 24060 0 0 0 24060 0 0 0 LRU
</screen>
<para>Routing information can be displayed with the <option>-nr</option> option to the <command>netstat</command> command:</para>
<screen>
bob:~&gt;netstat -nr
<prompt>bob:~&gt;</prompt> <command>netstat -nr</command>
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.42.0 0.0.0.0 255.255.255.0 U 40 0 0 eth0
@ -179,10 +179,10 @@ Destination Gateway Genmask Flags MSS Window irtt Iface
<para>We will only discuss some common UNIX/Linux text tools in this section.</para>
<para>To display information on hosts or domains, use the <command>host</command> command:</para>
<screen>
[emmy@pc10 emmy]$ host www.eunet.be
<prompt>[emmy@pc10 emmy]$</prompt> <command>host www.eunet.be</command>
www.eunet.be. has address 193.74.208.177
[emmy@pc10 emmy]$ host -t any eunet.be
<prompt>[emmy@pc10 emmy]$</prompt> <command>host -t any eunet.be</command>
eunet.be. SOA dns.eunet.be. hostmaster.Belgium.EU.net.
2002021300 28800 7200 604800 86400
eunet.be. mail is handled by 50 pophost.eunet.be.
@ -192,7 +192,7 @@ eunet.be. name server dns.eunet.be.
<para>Similar information can be displayed using the <command>dig</command> command, which gives additional information about how records are stored in the name server.</para>
<para>To check if a host is alive, use <command>ping</command>. If your system is configured to send more than one packet, interrupt <command>ping</command> with the <keycap>Ctrl</keycap>+<keycap>C</keycap> key combination:</para>
<screen>
[emmy@pc10 emmy]$ ping a.host.be
<prompt>[emmy@pc10 emmy]$</prompt> <command>ping a.host.be </command>
PING a.host.be (1.2.8.3) from 80.20.84.26: 56(84) bytes of data.
64 bytes from a.host.be(1.2.8.3):icmp_seq=0 ttl=244 time=99.977msec
--- a.host.be ping statistics ---
@ -201,7 +201,7 @@ round-trip min/avg/max/mdev = 99.977/99.977/99.977/0.000 ms
</screen>
<para>To check the route that packets follow to a network host, use the <command>traceroute</command> command:</para>
<screen>
[emmy@pc10 emmy]$ /usr/sbin/traceroute www.eunet.be
<prompt>[emmy@pc10 emmy]$</prompt> <command>/usr/sbin/traceroute www.eunet.be</command>
traceroute to www.eunet.be(193.74.208.177),30 hops max,38b packets
1 blob (10.0.0.1)
0.297ms 0.257ms 0.174ms
@ -223,7 +223,7 @@ traceroute to www.eunet.be(193.74.208.177),30 hops max,38b packets
</screen>
<para>Specific domain name information can be queried using the <command>whois</command> command, as is explained by many <command>whois</command> servers, like the one below:</para>
<screen>
[emmy@pc10 emmy]$ whois cnn.com
<prompt>[emmy@pc10 emmy]$</prompt> <command>whois cnn.com</command>
[whois.crsnic.net]
Whois Server Version 1.3
@ -286,22 +286,22 @@ Turner Broadcasting (CNN-DOM)
<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
<prompt>bob:~&gt;</prompt> <command>ps auxw | grep named</command>
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
<prompt>bob:~&gt;</prompt> <command>ps auxw | grep ftp</command>
bob 738 690 0 16:17 pts/6 00:00:00 grep ftp
bob:~&gt; ncftp localhost
<prompt>bob:~&gt;</prompt> <command>ncftp localhost</command>
NcFTP 3.1.3 (Mar 27, 2002) by Mike Gleason (ncftp@ncftp.com).
Connecting to localhost(127.0.0.1)...
myhost.my.org FTP server (Version wu-2.6.2-8) ready.
Logging in...
Guest login ok, access restrictions apply.
Logged in to localhost.
ncftp / >
<prompt>ncftp / &gt;</prompt>
</screen>
<para>Let's see in the next section how this is arranged.</para>
</sect3>
@ -309,14 +309,14 @@ ncftp / >
<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
<prompt>bob:~&gt;</prompt> <command>ps -ef | grep inet</command>
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 services.</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
<prompt>bob:~&gt;</prompt> <command>ps auxw | grep ftp</command>
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
@ -393,14 +393,14 @@ localhost.localdomain: anonymous/bob@his.server.com: IDLE
<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
<prompt>thomas:~&gt;</prompt> <command>ncftp blob</command>
NcFTP 3.0.3 (April 15, 2001) by Mike Gleason (ncftp@ncftp.com).
Connecting to blob...
blob.some.net FTP server (Version wu-2.6.1-20) ready.
Logging in...
Guest login ok, access restrictions apply.
Logged in to blob.
ncftp / &gt; help
<prompt>ncftp / &gt;</prompt> <command>help</command>
Commands may be abbreviated. 'help showall' shows hidden and
unsupported commands.
'help &lt;command&gt;' gives a brief description of &lt;command&gt;.
@ -412,7 +412,7 @@ bgstart close lchmod lrm pls rm version
binary debug lls lrmdir put rmdir
bookmark dir lmkdir ls pwd set
bookmarks get lookup mkdir quit show
ncftp / >
<prompt>ncftp / &gt;</prompt>
</screen>
<para>Excellent help with lot of examples can be found in the man pages. And again, a number of GUI applications are available.</para>
@ -467,7 +467,7 @@ nameserver 193.74.208.137
<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
<prompt>bob:~&gt;</prompt> <command>ls -l /etc/passwd /etc/shadow</command>
-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>
@ -527,12 +527,12 @@ On the negative side, if you want to use LDAP, you will need LDAP-enabled applic
<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>
<para>Checking that a mail server works:</para>
<screen>
[jimmy@blob ~] telnet mailserver 25
<prompt>[jimmy@blob ~]</prompt> <command>telnet mailserver 25</command>
Trying 192.168.42.1...
Connected to mailserver.
Escape character is '^]'.
220 m1.some.net ESMTP Sendmail 8.11.6/8.11.6; 200302281626
ehlo some.net
<command>ehlo some.net</command>
250-m1.some.net Hello blob.some.net [10.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-8BITMIME
@ -542,26 +542,26 @@ ehlo some.net
250-ETRN
250-XUSR
250 HELP
mail from: jimmy@some.net
<command>mail from: jimmy@some.net</command>
250 2.1.0 jimmy@some.net... Sender ok
rcpt to: davy@some.net
<command>rcpt to: davy@some.net</command>
250 2.1.5 davy@some.net... Recipient ok
data
<command>data</command>
354 Enter mail, end with "." on a line by itself
test
.
<command>test</command>
<command>.</command>
250 2.0.0 g2MA1R619237 Message accepted for delivery
quit
<command>quit</command>
221 2.0.0 m1.some.net closing connection
Connection closed by foreign host.
</screen>
<para>Checking that a web server answers to basic requests:</para>
<screen>
[jimmy@blob ~] telnet www.some.net 80
<prompt>[jimmy@blob ~]</prompt> <command>telnet www.some.net 80</command>
Trying 64.39.151.23...
Connected to www.some.net.
Escape character is '^]'.
HEAD / ;HTTP/1.1
<command>HEAD / ;HTTP/1.1</command>
HTTP/1.1 200 OK
Date: Fri, 22 Mar 2002 10:05:14 GMT
@ -577,7 +577,7 @@ Content-Type: text/html
Connection closed by foreign host.
[jimmy@blob ~]
<prompt>[jimmy@blob ~]</prompt>
</screen>
<para>This is perfectly safe, because you never have to give a username and/or password for getting the data you want, so nobody can snoop that important information off the cable.</para>
</sect2>
@ -591,11 +591,11 @@ Connection closed by foreign host.
<sect3 id="sect_10_03_03_02"><title>Telnet and X</title>
<para>If you would want to use <command>telnet</command> to display graphical applications running on a remote machine, you first need to give the remote machine access to your display (to your X server!) using the <command>xhost</command> command, by typing a command similar to the one below in a terminal window on your local machine:</para>
<screen>
davy:~&gt;xhost +remote.machine.com
<prompt>davy:~&gt;</prompt> <command>xhost +remote.machine.com</command>
</screen>
<para>After that, connect to the remote host and tell it to display graphics on the local machine by setting the environment variable <varname>DISPLAY</varname>:</para>
<screen>
[davy@remote ~] export DISPLAY="local.host.com:0.0"
<prompt>[davy@remote ~]</prompt> <command>export DISPLAY="local.host.com:0.0"</command>
</screen>
<para>After completing this step, any application started in this terminal window will be displayed on your local desktop, using remote resources for computing, but your local graphical resources (your X server) for displaying the application.</para>
<para>This procedure assumes that you have some sort of X server (XFree86, Exceed, Cygwin) already set up on the machine where you want to display images. The architecture and operating system of the client machine are not important as long as they allow you to run an X server on it.</para>
@ -610,27 +610,27 @@ davy:~&gt;xhost +remote.machine.com
<para>The session terminates when the command or shell on the remote machine exits and all X11 and TCP/IP connections have been closed.</para>
<para>When connecting to a host for the first time, using any of the programs that are included in the SSH collection, you need to establish the authenticity of that host and acknowledge that you want to connect:</para>
<screen>
lenny ~&gt; ssh blob
<prompt>lenny ~&gt;</prompt> <command>ssh blob</command>
The authenticity of host 'blob (10.0.0.1)' can't be established.
RSA fingerprint is 18:30:50:46:ac:98:3c:93:1a:56:35:09:8d:97:e3:1d.
Are you sure you want to continue connecting (yes/no)? yes
Are you sure you want to continue connecting (yes/no)? <command>yes</command>
Warning: Permanently added 'blob,192.168.30.2' (RSA) to the list of
known hosts.
Last login: Sat Dec 28 13:29:19 2002 from octarine
This space for rent.
lenny is in ~
<prompt>lenny is in ~</prompt>
</screen>
<para>It is important that you type <quote>yes</quote>, in three characters, not just <quote>y</quote>. This edits your <filename>~/.ssh/known_hosts</filename> file, see <xref linkend="sect_10_03_04_03" />.</para>
<para>If you just want to check something on a remote machine and then get your prompt back on the local host, you can give the commands that you want to execute remotely as arguments to <command>ssh</command>:</para>
<screen>
lenny ~&gt; ssh blob who
<prompt>lenny ~&gt;</prompt> <command>ssh blob who</command>
jenny@blob's password:
root tty2 Jul 24 07:19
lena tty3 Jul 23 22:24
lena 0: Jul 25 22:03
lenny ~&gt; uname -n
<prompt>lenny ~&gt;</prompt> <command>uname -n</command>
magrat.example.com
</screen>
</sect3>
@ -658,27 +658,27 @@ magrat.example.com
<sect3 id="sect_10_03_04_04"><title>Secure remote copying</title>
<para>The SSH suite provides <command>scp</command> as a secure alternative to the <command>rcp</command> command that used to be popular when only <command>rsh</command> existed. <command>scp</command> uses <command>ssh</command> for data transfer, uses the same authentication and provides the same security as <command>ssh</command>. Unlike <command>rcp</command>, <command>scp</command> will ask for passwords or passphrases if they are needed for authentication:</para>
<screen>
lenny /var/tmp&gt; scp Schedule.sdc.gz blob:/var/tmp/
<prompt>lenny /var/tmp&gt;</prompt> <command>scp Schedule.sdc.gz blob:/var/tmp/</command>
lenny@blob's password:
Schedule.sdc.gz 100% |*****************************| 100 KB 00:00
lenny /var/tmp&gt;
<prompt>lenny /var/tmp&gt;</prompt>
</screen>
<para>Any file name may contain a host and user specification to indicate that the file is to be copied to/from that host. Copies between two remote hosts are permitted. See the Info pages for more information.</para>
<para>If you would rather use an FTP-like interface, use <command>sftp</command>:</para>
<screen>
lenny /var/tmp&gt; sftp blob
<prompt>lenny /var/tmp&gt;</prompt> <command>sftp blob</command>
Connecting to blob...
lenny@blob's password:
sftp>cd /var/tmp
<prompt>sftp&gt;</prompt> <command>cd /var/tmp</command>
sftp> get Sch*
<prompt>sftp&gt;</prompt> <command>get Sch*</command>
Fetching /var/tmp/Schedule.sdc.gz to Schedule.sdc.gz
sftp>bye
<prompt>sftp&gt;</prompt> <command>bye</command>
lenny /var/tmp&gt;
<prompt>lenny /var/tmp&gt;</prompt>
</screen>
</sect3>
<sect3 id="sect_10_03_04_05"><title>Authentication keys</title>
@ -720,7 +720,7 @@ lenny /var/tmp&gt;
<para>The goal is to run as few services as possible. If the number of ports that are open for the outside world are kept to a minimum, this is all the better to keep an overview. If services can't be turned off for the local network, try to at least disable them for outside connections.</para>
<para>A rule of thumb is that if you don't recognize a particular service, you probably won't need it anyway. Also keep in mind that some services are not really meant to be used over the Internet. Don't rely on what <emphasis>should</emphasis> be running, check which services are listening on what TCP ports using the <command>netstat</command> command:</para>
<screen>
[elly@mars ~] netstat -l | grep tcp
<prompt>[elly@mars ~]</prompt> <command>netstat -l | grep tcp</command>
tcp 0 0 *:32769 *:* LISTEN
tcp 0 0 *:32771 *:* LISTEN
tcp 0 0 *:printer *:* LISTEN

View File

@ -62,7 +62,7 @@ more system resources.
</figure>
<para>Another common form for a prompt is this one:</para>
<screen>
[user@host dir]
<prompt>[user@host dir]</prompt>
</screen>
<para>In the above example, <emphasis>user</emphasis> will be your login name, <emphasis>hosts</emphasis> the name of the machine you are working on, and <emphasis>dir</emphasis> an indication of your current location in the file system.</para>
<para>Later we will discuss prompts and their behavior in detail. For now, it suffices to know that prompts can display all kinds of information, but that they are not part of the commands you are giving to your system.</para>
@ -197,19 +197,19 @@ blast login: _
<para>The last two items in the above table may need some extra explanantions. For instance, if you want to change into the directory <filename>directory_with_a_very_long_name</filename>, you are not going to type that very long name, no. You just type on the command line <command>cd dir</command>, then you press <keycap>Tab</keycap> and the shell completes the name for you, if no other files are starting with the same three characters. Of course, if there are no other items starting with <quote>d</quote>, then you might just as wel type <command>cd d</command> and then <keycap>Tab</keycap>. If more than one file starts with the same characters, the shell will signal this to you, upon which you can hit <keycap>Tab</keycap> twice with short interval, and the shell presents the choices you have:</para>
<screen>
your_prompt&gt; cd st
<prompt>your_prompt&gt;</prompt> <command>cd st</command>
starthere stuff stuffit
</screen>
<para>In the above example, if you type <quote>a</quote> after the first two characters and hit <keycap>Tab</keycap> again, no other possibilities are left, and the shell completes the directory name, without you having to type the string <quote>rthere</quote>:</para>
<screen>
your_prompt&gt; cd starthere
<prompt>your_prompt&gt;</prompt> <command>cd starthere</command>
</screen>
<para>Of course, you'll still have to hit <keycap>Enter</keycap> to accept this choice.</para>
<para>In the same example, if you type <quote>u</quote>, and then hit <keycap>Tab</keycap>, the shell will add the <quote>ff</quote> for you, but then it protests again, because multiple choices are possible. If you type <keycap>Tab</keycap> <keycap>Tab</keycap> again, you'll see the choices; if you type one or more characters that make the choice unambiguous to the system, and <keycap>Tab</keycap> again, or <keycap>Enter</keycap> when you've reach the end of the file name that you want to choose, the shell completes the file name and changes you into that directory - if indeed it is a directory name.</para>
<para>This works for all file names that are arguments to commands.</para>
<para>The same goes for command name completion. Typing <command>ls</command> and then hitting the <keycap>Tab</keycap> key twice, lists all the commands in your <varname>PATH</varname> (see <xref linkend="sect_03_02_01" />) that start with these two characters:</para>
<screen>
your_prompt&gt; ls
<prompt>your_prompt&gt;</prompt> <command>ls</command>
ls lsdev lspci lsraid lsw
lsattr lsmod lspgpot lss16toppm
lsb_release lsof lspnp lsusb
@ -224,7 +224,7 @@ lsb_release lsof lspnp lsusb
<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 <keycap>Enter</keycap>:</para>
<screen>
yourname@yourcomp ~&gt; man man
<prompt>yourname@yourcomp ~&gt;</prompt> <command>man <parameter>man</parameter></command>
</screen>
<para>The documentation for <command>man</command> will be displayed on your screen after you press <keycap>Enter</keycap>:</para>
<screen>
@ -311,13 +311,13 @@ Welcome to Info version 4.2. Type C-h for help, m for menu item.
<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
<prompt>[your_prompt]</prompt> <command>whatis ls</command>
ls (1) - list directory contents
</screen>
<para>This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.</para>
<para>If you don't know where to get started and which man page to read, <command>apropos</command> gives more information. Say that you don't know how to start a browser, then you could enter the following command:</para>
<screen>
another prompt&gt; apropos browser
<prompt>another prompt&gt;</prompt> <command>apropos browser</command>
Galeon [galeon](1) - gecko-based GNOME web browser
lynx (1) - a general purpose distributed information browser
for the World Wide Web
@ -334,7 +334,7 @@ viewres (1x) - graphical class browser for Xt
<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@host: cat --help
<prompt>userprompt@host:</prompt> <command>cat --help</command>
Usage: cat [OPTION] [FILE]...
Concatenate FILE(s), or standard input, to standard output.

View File

@ -40,7 +40,7 @@
</itemizedlist>
<para>The <option>-l</option> option to <command>ls</command> displays the file type, using the first character of each input line:</para>
<screen>
jaime:~/Documents&gt;ls -l
<prompt>jaime:~/Documents&gt;</prompt> <command>ls -l</command>
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
@ -143,7 +143,7 @@ Now, before we look at the important files and directories, we need to know more
<para>On a running system, information about the partitions can be displayed using the <command>df</command> command (which stands for <emphasis>disk full</emphasis> or <emphasis>disk free</emphasis>). In Linux, <command>df</command> is the GNU version, and supports the <option>-h</option> or <emphasis>human readable</emphasis> option which greatly improves readability. Note that commercial UNIX machines commonly have their own versions of <command>df</command> and many other commands. Their behavior is usually the same, though GNU versions of common tools often have more and better features.</para>
<para>The <command>df</command> command only displays information about active non-swap partitions. These can include partitions from other networked systems, like in the example below where the home directories are mounted from a file server on the network, a situation often encountered in corporate environments.</para>
<screen>
freddy:~&gt;df -h
<prompt>freddy:~&gt;</prompt> <command>df -h</command>
Filesystem Size Used Avail Use% Mounted on
/dev/hda8 496M 183M 288M 39% /
/dev/hda1 124M 8.4M 109M 8% /boot
@ -172,8 +172,8 @@ fs1:/home 8.9G 3.7G 4.7G 44% /.automount/fs1/root/home
<para>The tree of the file system starts at the trunk or <emphasis>slash</emphasis>, indicated by a forward slash (/). This directory, containing all underlying directories and files, is also called the <emphasis>root directory</emphasis> or <quote>the root</quote> of the file system.</para>
<para>Directories that are only one level below the root directory are often preceded by a slash, to indicate their position and prevent confusion with other directories that could have the same name. When starting with a new system, it is always a good idea to take a look in the root directory. Let's see what you could run into:</para>
<screen>
emmy:~&gt;cd /
emmy:/&gt;ls
<prompt>emmy:~&gt;</prompt> <command>cd /</command>
<prompt>emmy:/&gt;</prompt> <command>ls</command>
bin/ dev/ home/ lib/ misc/ opt/ root/ tmp/ var/
boot/ etc/ initrd/ lost+found/ mnt/ proc/ sbin/ usr/
</screen>
@ -248,7 +248,7 @@ boot/ etc/ initrd/ lost+found/ mnt/ proc/ sbin/ usr/
</table>
<para>How can you find out which partition a directory is on? Using the <command>df</command> command with a dot (.) as an option shows the partition the current directory belongs to, and informs about the amount of space used on this partition:</para>
<screen>
sandra:/lib&gt;df -h .
<prompt>sandra:/lib&gt;</prompt> <command>df -h .</command>
Filesystem Size Used Avail Use% Mounted on
/dev/hda7 980M 163M 767M 18% /
</screen>
@ -282,12 +282,12 @@ Filesystem Size Used Avail Use% Mounted on
<para>When you want the system to execute a command, you almost never have to give the full path to that command. For example, we know that the <command>ls</command> command is in the <filename>/bin</filename> directory (check with <command>which <option>-a</option> <parameter>ls</parameter></command>), yet we don't have to enter the command <command>/bin/ls</command> for the computer to list the content of the current directory.</para>
<para>The <varname>PATH</varname> environment variable takes care of this. This variable lists those directories in the system where executable files can be found, and thus saves the user a lot of typing and memorizing locations of commands. So the path naturally contains a lot of directories containing <filename>bin</filename> somewhere in their names, as the user below demonstrates. The <command>echo</command> command is used to display the content (<quote>$</quote>) of the variable <varname>PATH</varname>:</para>
<screen>
rogier:&gt;echo $PATH
<prompt>rogier:&gt;</prompt> <command>echo $PATH</command>
/opt/local/bin:/usr/X11R6/bin:/usr/bin:/usr/sbin/:/bin
</screen>
<para>In this example, the directories <filename>/opt/local/bin</filename>, <filename>/usr/X11R6/bin</filename>, <filename>/usr/bin</filename>, <filename>/usr/sbin</filename> and <filename>/bin</filename> are subsequently searched for the required program. As soon as a match is found, the search is stopped, even if not every directory in the path has been searched. This can lead to strange situations. In the first example below, the user knows there is a program called <command>sendsms</command> to send an SMS message, and another user on the same system can use it, but she can't. The difference is in the configuration of the <varname>PATH</varname> variable:</para>
<screen>
[jenny@blob jenny]$ sendsms
<prompt>[jenny@blob jenny]$</prompt> <command>sendsms</command>
bash: sendsms: command not found
[jenny@blob jenny]$ echo $PATH
/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/home/jenny/bin
@ -304,25 +304,25 @@ tony:~&gt;echo $PATH
<para>A backslash indicates the continuation of a line on the next, without an <keycap>Enter</keycap> separating one line from the other.</para>
<para>In the next example, a user wants to call on the <command>wc</command> (word count) command to check the number of lines in a file, but nothing happens and he has to break off his action using the <keycap>Ctrl</keycap>+<keycap>C</keycap> combination:</para>
<screen>
jumper:~&gt;wc -l test
<prompt>jumper:~&gt;</prompt> <command>wc -l test</command>
(Ctrl-C)
jumper:~&gt;which wc
<prompt>jumper:~&gt;</prompt> <command>which wc</command>
wc is hashed (/home/jumper/bin/wc)
jumper:~&gt;echo $PATH
<prompt>jumper:~&gt;</prompt> <command>echo $PATH</command>
/home/jumper/bin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:
/usr/bin:/usr/sbin:/bin:/sbin
</screen>
<para>The use of the <command>which</command> command shows us that this user has a <filename>bin</filename>-directory in his home directory, containing a program that is also called <command>wc</command>. Since the program in his home directory is found first when searching the paths upon a call for <command>wc</command>, this <quote>home-made</quote> program is executed, with input it probably doesn't understand, so we have to stop it. To resolve this problem there are several ways (there are always several ways to solve a problem in UNIX/Linux): one answer could be to rename the user's <command>wc</command> program, or the user can give the full path to the exact command he wants, which can be found by using the <option>-a</option> to the <command>which</command> command:</para>
<screen>
jumper:~&gt;/usr/bin/wc -l test
<prompt>jumper:~&gt;</prompt> <command>/usr/bin/wc -l test</command>
10 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
<prompt>jumper:~&gt;</prompt> <command>export PATH=/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:\
/usr/bin:/usr/sbin:/bin:/sbin:/home/jumper/bin</command>
</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="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>
@ -342,7 +342,7 @@ jumper:~&gt;export PATH=/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:\
</listitem>
<listitem><para>Notice the difference one more time:</para>
<screen>
theo:~&gt;ls /mp3
<prompt>theo:~&gt;</prompt> <command>ls /mp3</command>
ls: /mp3: No such file or directory
theo:~&gt;ls mp3/
oriental/ pop/ sixties/
@ -372,7 +372,7 @@ oriental/ pop/ sixties/
<para>The file <filename>/etc/shells</filename> gives an overview of known shells on a Linux system:</para>
<screen>
mia:~&gt;cat /etc/shells
<prompt>mia:~&gt;</prompt> <command>cat /etc/shells</command>
/bin/bash
/bin/sh
/bin/tcsh
@ -387,8 +387,8 @@ mia:L2NOfqdlPrHwE:504:504:Mia Maya:/home/mia:/bin/bash
</screen>
<para>To switch from one shell to another, just enter the name of the new shell in the active terminal. The system finds the directory where the name occurs using the <varname>PATH</varname> settings, and since a shell is an executable file (program), the current shell activates it and it gets executed. A new prompt is usually shown, because each shell has its typical appearance:</para>
<screen>
mia:~&gt;tcsh
[mia@post21 ~]$
<prompt>mia:~&gt;</prompt> <command>tcsh</command>
<prompt>[mia@post21 ~]$</prompt>
</screen>
</sect4>
<sect4><title>Which shell am I using?</title>
@ -401,20 +401,20 @@ mia:~&gt;tcsh
<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
<prompt>orlando:~&gt;</prompt> <command>echo $HOME</command>
/nethome/orlando
</screen>
<para>You can do whatever you like in your home directory. You can put as many files in as many directories as you want, although the total amount of data and files is naturally limited because of the hardware and size of the partitions, and sometimes because the system administrator has applied a quota system. Limiting disk usage was common practice when hard disk space was still expensive. Nowadays, limits are almost exclusively applied in large environments. You can see for yourself if a limit is set using the <command>quota</command> command:</para>
<screen>
pierre@lamaison:/&gt;quota -v
<prompt>pierre@lamaison:/&gt;</prompt> <command>quota -v</command>
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. Exceeding 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 <parameter>quota</parameter></command> or <command>man <parameter>quota</parameter></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
<prompt>rom:/var/music/albums/arno/2001&gt;</prompt> <command>cd ~/images</command>
rom:~/images&gt;pwd
<prompt>rom:~/images&gt;</prompt> <command>pwd</command>
/home/rom/images
</screen>
<para>Later in this chapter we will talk about the commands for managing files and directories in order to keep your home directory tidy.</para>
@ -711,22 +711,22 @@ rom:~/images&gt;pwd
<para>Besides the name of the file, <command>ls</command> can give a lot of other information, such as the file type, as we already discussed. It can also show permissions on a file, file size, inode number, creation date and time, owners and amount of links to the file. With the <option>-a</option> option to <command>ls</command>, files that are normally hidden from view can be displayed as well. These are files that have a name starting with a dot. A couple of typical examples include the configuration files in your home directory. When you've worked with a certain system for a while, you will notice that tens of files and directories have been created that are not automatically listed in a directory index. Next to that, every directory contains a file named just dot (.) and one with two dots (..), which are used in combination with their inode number to determine the directory's position in the file system's tree structure.</para>
<para>You should really read the Info pages about <command>ls</command>, since it is a very common command with a lot of useful options. Options can be combined, as is the case with most UNIX commands and their options. A common combination is <command>ls <option>-al</option></command>; it shows a long list of files and their properties as well as the destinations that any symbolic links point to. <command>ls <option>-latr</option></command> displays the same files, only now in reversed order of the last change, so that the file changed most recently occurs at the bottom of the list. Here are a couple of examples:</para>
<screen>
krissie:~/mp3&gt;ls
<prompt>krissie:~/mp3&gt;</prompt> <command>ls</command>
Albums/ Radio/ Singles/ gene/ index.html
krissie:~/mp3&gt;ls -a
<prompt>krissie:~/mp3&gt;</prompt> <command>ls -a</command>
./ .thumbs Radio gene/
../ Albums/ Singles/ index.html
krissie:~/mp3&gt;ls -l Radio/
<prompt>krissie:~/mp3&gt;</prompt> <command>ls -l Radio/</command>
total 8
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/
<prompt>krissie:~/mp3&gt;</prompt> <command>ls -ld Radio/</command>
drwxr-xr-x 4 krissie krissie 4096 Oct 30 1999 Radio/
krissie:~/mp3&gt;ls -ltr
<prompt>krissie:~/mp3&gt;</prompt> <command>ls -ltr</command>
total 20
drwxr-xr-x 4 krissie krissie 4096 Oct 30 1999 Radio/
-rw-r--r-- 1 krissie krissie 453 Jan 7 2001 index.html
@ -779,54 +779,54 @@ drwxrwxr-x 13 krissie krissie 4096 Dec 21 11:40 Albums/
<sect3 id="sect_03_03_01_02"><title>More tools</title>
<para>To find out more about the kind of data we are dealing with, we use the <command>file</command> command. By applying certain tests that check properties of a file in the file system, magic numbers and language tests, <command>file</command> tries to make an educated guess about the format of a file. Some examples:</para>
<screen>
mike:~&gt;file Documents/
<prompt>mike:~&gt;</prompt> <command>file Documents/</command>
Documents/: directory
mike:~&gt;file high-tech-stats.pdf
<prompt>mike:~&gt;</prompt> <command>file high-tech-stats.pdf</command>
high-tech-stats.pdf: PDF document, version 1.2
mike:~&gt;file Nari-288.rm
<prompt>mike:~&gt;</prompt> <command>file Nari-288.rm</command>
Nari-288.rm: RealMedia file
mike:~&gt;file bijlage10.sdw
<prompt>mike:~&gt;</prompt> <command>file bijlage10.sdw</command>
bijlage10.sdw: Microsoft Office Document
mike:~&gt;file logo.xcf
<prompt>mike:~&gt;</prompt> <command>file logo.xcf</command>
logo.xcf: GIMP XCF image data, version 0, 150 x 38, RGB Color
mike:~&gt;file cv.txt
<prompt>mike:~&gt;</prompt> <command>file cv.txt</command>
cv.txt: ISO-8859 text
mike:~&gt;file image.png
<prompt>mike:~&gt;</prompt> <command>file image.png</command>
image.png: PNG image data, 616 x 862, 8-bit grayscale, non-interlaced
mike:~&gt;file figure
<prompt>mike:~&gt;</prompt> <command>file figure</command>
figure: ASCII text
mike:~&gt;file me+tux.jpg
<prompt>mike:~&gt;</prompt> <command>file me+tux.jpg</command>
me+tux.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI),
"28 Jun 1999", 144 x 144
mike:~&gt;file 42.zip.gz
<prompt>mike:~&gt;</prompt> <command>file 42.zip.gz</command>
42.zip.gz: gzip compressed data, deflated, original filename,
`42.zip', last modified: Thu Nov 1 23:45:39 2001, os: Unix
mike:~&gt;file vi.gif
<prompt>mike:~&gt;</prompt> <command>file vi.gif</command>
vi.gif: GIF image data, version 89a, 88 x 31
mike:~&gt;file slide1
<prompt>mike:~&gt;</prompt> <command>file slide1</command>
slide1: HTML document text
mike:~&gt;file template.xls
<prompt>mike:~&gt;</prompt> <command>file template.xls</command>
template.xls: Microsoft Office Document
mike:~&gt;file abook.ps
<prompt>mike:~&gt;</prompt> <command>file abook.ps</command>
abook.ps: PostScript document text conforming at level 2.0
mike:~&gt;file /dev/log
<prompt>mike:~&gt;</prompt> <command>file /dev/log</command>
/dev/log: socket
mike:~&gt;file /dev/hda
<prompt>mike:~&gt;</prompt> <command>file /dev/hda</command>
/dev/hda: block special (3/0)
</screen>
<para>The <command>file</command> command has a series of options, among others the <option>-z</option> option to look into compressed files. See <command>info <parameter>file</parameter></command> for a detailed description. Keep in mind that the results of <command>file</command> are not absolute, it is only a guess. In other words, <command>file</command> can be tricked.</para>
@ -841,7 +841,7 @@ mike:~&gt;file /dev/hda
<sect3 id="sect_03_03_02_01"><title>Making a mess...</title>
<para>... Is not a difficult thing to do. Today almost every system is networked, so naturally files get copied from one machine to another. And especially when working in a graphical environment, creating new files is a piece of cake and is often done without the approval of the user. To illustrate the problem, here's the full content of a new user's directory, created on a standard RedHat system:</para>
<screen>
[newuser@blob user]$ ls -al
<prompt>[newuser@blob user]$</prompt> <command>ls -al</command>
total 32
drwx------ 3 user user 4096 Jan 16 13:32 .
drwxr-xr-x 6 root root 4096 Jan 16 13:32 ..
@ -854,7 +854,7 @@ drwxr-xr-x 3 user user 4096 Jan 16 13:32 .kde
</screen>
<para>On first sight, the content of a <quote>used</quote> home directory doesn't look that bad either:</para>
<screen>
olduser:~&gt;ls
<prompt>olduser:~&gt;</prompt> <command>ls</command>
app-defaults/ crossover/ Fvwm@ mp3/ OpenOffice.org638/
articles/ Desktop/ GNUstep/ Nautilus/ staroffice6.0/
bin/ Desktop1/ images/ nqc/ training/
@ -877,27 +877,27 @@ closed/ Emacs@ Mail/ office52/ Xrootenv.0
<sect4><title>Creating directories</title>
<para>A way of keeping things in place is to give certain files specific default locations by creating directories and subdirectories (or folders and sub-folders if you wish). This is done with the <command>mkdir</command> command:</para>
<screen>
richard:~&gt;mkdir archive
<prompt>richard:~&gt;</prompt> <command>mkdir archive</command>
richard:~&gt;ls -ld archive
<prompt>richard:~&gt;</prompt> <command>ls -ld archive</command>
drwxrwxrwx 2 richard richard 4096 Jan 13 14:09 archive/
</screen>
<para>Creating directories and subdirectories in one step is done using the <option>-p</option> option:</para>
<screen>
richard:~&gt;cd archive
<prompt>richard:~&gt;</prompt> <command>cd archive</command>
richard:~/archive&gt;mkdir 1999 2000 2001
<prompt>richard:~/archive&gt;</prompt> <command>mkdir 1999 2000 2001</command>
richard:~/archive&gt;ls
<prompt>richard:~/archive&gt;</prompt> <command>ls</command>
1999/ 2000/ 2001/
richard:~/archive&gt;mkdir 2001/reports/Restaurants-Michelin/
<prompt>richard:~/archive&gt;</prompt> <command>mkdir 2001/reports/Restaurants-Michelin/</command>
mkdir: cannot create directory `2001/reports/Restaurants-Michelin/':
No such file or directory
richard:~/archive&gt;mkdir -p 2001/reports/Restaurants-Michelin/
<prompt>richard:~/archive&gt;</prompt> <command>mkdir -p 2001/reports/Restaurants-Michelin/</command>
richard:~/archive&gt;ls 2001/reports/
<prompt>richard:~/archive&gt;</prompt> <command>ls 2001/reports/</command>
Restaurants-Michelin/
</screen>
<para>If the new file needs other permissions than the default file creation permissions, the new access rights can be set in one move, still using the <command>mkdir</command> command, see the Info pages for more. We are going to discuss access modes in the next section on File Security.</para>
@ -906,16 +906,16 @@ Restaurants-Michelin/
<sect4><title>Moving files</title>
<para>Now that we have properly structured our home directory, it is time to clean up unclassified files using the <command>mv</command> command:</para>
<screen>
richard:~/archive&gt;mv ../report[1-4].doc reports/Restaurants-Michelin/
<prompt>richard:~/archive&gt;</prompt> <command>mv ../report[1-4].doc reports/Restaurants-Michelin/</command>
</screen>
<para>This command is also applicable when renaming files:</para>
<screen>
richard:~&gt;ls To_Do
<prompt>richard:~&gt;</prompt> <command>ls To_Do</command>
-rw-rw-r-- 1 richard richard 2534 Jan 15 12:39 To_Do
richard:~&gt;mv To_Do done
<prompt>richard:~&gt;</prompt> <command>mv To_Do done</command>
richard:~&gt;ls -l done
<prompt>richard:~&gt;</prompt> <command>ls -l done</command>
-rw-rw-r-- 1 richard richard 2534 Jan 15 12:39 done
</screen>
<para>It is clear that only the name of the file changes. All other properties remain the same.</para>
@ -926,7 +926,7 @@ richard:~&gt;ls -l done
<cmdsynopsis><command>cp <optional><option>-R</option></optional> <filename>fromfile</filename> <filename>tofile</filename></command></cmdsynopsis>
<para>As an example the case of user <emphasis>newguy</emphasis>, who wants the same Gnome desktop settings user <emphasis>oldguy</emphasis> has. One way to solve the problem is to copy the settings of <emphasis>oldguy</emphasis> to the home directory of <emphasis>newguy</emphasis>:</para>
<screen>
victor:~&gt;cp -R ../oldguy/.gnome/ .
<prompt>victor:~&gt;</prompt> <command>cp -R ../oldguy/.gnome/ .</command>
</screen>
<para>This gives some errors involving file permissions, but all the errors have to do with private files that <emphasis>newguy</emphasis> doesn't need anyway. We will discuss in the next part how to change these permissions in case they really are a problem.</para>
@ -937,14 +937,14 @@ victor:~&gt;cp -R ../oldguy/.gnome/ .
<para>It is normal that the directories . (dot) and .. (dot-dot) can't be removed, since they are also necessary in an empty directory to determine the directories ranking in the file system hierarchy.</para></note>
<para>On Linux, just like on UNIX, there is no garbage can - at least not for the shell, although there are plenty of solutions for graphical use. So once removed, a file is really gone, and there is generally no way to get it back unless you have backups, or you are really fast and have a real good system administrator. To protect the beginning user from this malice, the interactive behavior of the <command>rm</command>, <command>cp</command> and <command>mv</command> commands can be activated using the <option>-i</option> option. In that case the system won't immediately act upon request. Instead it will ask for confirmation, so it takes an additional click on the <keycap>Enter</keycap> key to inflict the damage:</para>
<screen>
mary:~&gt;rm -ri archive/
rm: descend into directory `archive'? y
rm: descend into directory `archive/reports'? y
rm: remove directory `archive/reports'? y
rm: descend into directory `archive/backup'? y
rm: remove `archive/backup/sysbup200112.tar'? y
rm: remove directory `archive/backup'? y
rm: remove directory `archive'? y
<prompt>mary:~&gt;</prompt> <command>rm -ri archive/</command>
rm: descend into directory `archive'? <command>y</command>
rm: descend into directory `archive/reports'? <command>y</command>
rm: remove directory `archive/reports'? <command>y</command>
rm: descend into directory `archive/backup'? <command>y</command>
rm: remove `archive/backup/sysbup200112.tar'? <command>y</command>
rm: remove directory `archive/backup'? <command>y</command>
rm: remove directory `archive'? <command>y</command>
</screen>
<para>We will discuss how to make this option the default in <xref linkend="chap_07" />, which discusses customizing your shell environment.</para>
</sect4>
@ -960,27 +960,27 @@ rm: remove directory `archive'? y
<sect3 id="sect_03_03_03_02"><title>Which</title>
<para>A very simple way of looking up files is using the <command>which</command> command, to look in the directories listed in the user's search path for the required file. Of course, since the search path contains only paths to directories containing executable programs, <command>which</command> doesn't work for ordinary files. The <command>which</command> command is useful when troubleshooting <quote>Command not Found</quote> problems. In the example below, user <emphasis>tina</emphasis> can't use the <command>acroread</command> program, while her colleague has no troubles whatsoever on the same system. The problem is similar to the PATH problem in the previous part: Tina's colleague tells her that he can see the required program in <filename>/opt/acroread/bin</filename>, but this directory is not in her path:</para>
<screen>
tina:~&gt;which acroread
<prompt>tina:~&gt;</prompt> <command>which acroread</command>
/usr/bin/which: no acroread in (/bin:/usr/bin:/usr/bin/X11)
</screen>
<para>The problem can be solved by giving the full path to the command to run, or by re-exporting the content of the <varname>PATH</varname> variable:</para>
<screen>
tina:~&gt;export PATH=$PATH:/opt/acroread/bin
<prompt>tina:~&gt;</prompt> <command>export PATH=$PATH:/opt/acroread/bin</command>
tina:~&gt;echo $PATH
<prompt>tina:~&gt;</prompt> <command>echo $PATH</command>
/bin:/usr/bin:/usr/bin/X11:/opt/acroread/bin
</screen>
<para>Using the <command>which</command> command also checks to see if a command is an alias for another command:</para>
<screen>
gerrit:~&gt;which -a ls
<prompt>gerrit:~&gt;</prompt> <command>which -a ls</command>
ls is aliased to `ls -F --color=auto'
ls is /bin/ls
gerrit:~&gt;which -a which
<prompt>gerrit:~&gt;</prompt> <command>which -a which</command>
which is aliased to `type'
which is /usr/bin/which
gerrit:~&gt;which type
<prompt>gerrit:~&gt;</prompt> <command>which type</command>
type is a shell builtin
</screen>
<para>This actually means that <command>which</command> is built-in in the shell, but that there is also a <command>which</command> <quote>stand alone version</quote>. The shell built-in version precedes the <command>which</command> in <filename>/usr/bin</filename>, which is still there for compatibility with UNIX.</para>
@ -991,24 +991,28 @@ type is a shell builtin
<para>This can be interpreted as <quote>Look in all files and subdirectories contained in a given path, and print the names of the files containing the search string in their name</quote> (not in their content).</para>
<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
<prompt>peter:~&gt;</prompt> <command>find . -size +5000k</command>
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>
peter:~&gt; find . -name "*.tmp" -exec rm {} \;
<prompt>peter:~&gt; </prompt> <command>find . -name "*.tmp" -exec rm {} \;</command>
peter:~&gt;
<prompt>peter:~&gt;</prompt>
</screen>
<note><title>Optimize!</title>
<para>This command will call on <command>rm</command> as many times as a file answering the requirements is found. In the worst case, this might be thousands or millions of times. This is quite a load on your system.</para>
<para>A more realistic way of working would be the use of a pipe (|) and the <command>xargs</command> tool with <command>rm</command> as an argument. This way, the <command>rm</command> command is only called when the command line is full, instead of for every file. See <xref linkend="chap_05" /> for more on using I/O redirection to ease everyday tasks.</para>
</note>
<para>Later on (in 1999 according to the man pages, after 20 years of <command>find</command>), <command>locate</command> was developed. This program is easier to use, but more restricted than <command>find</command>, since its output is based on a file index database that is updated only once every day. On the other hand, a search in the <command>locate</command> database is less time- and CPU-consuming than a search with <command>find</command>.</para>
<para>Most Linux distributions use <command>slocate</command> these days, security enhanced locate, the modern version of <command>locate</command> that prevents users from getting output they have no right to read. The files in <emphasis>root</emphasis>'s home directory are such an example, these are not normally accessible to the public. A user who wants to find someone who knows about the C-shell may issue the command <command>locate <filename>.cshrc</filename></command>, to display all users who have a customized configuration file for the C shell. Supposing the users <emphasis>root</emphasis> and <emphasis>jenny</emphasis> are running C shell, then only the file <filename>/home/jenny/.cshrc</filename> will be displayed, and not the one in <emphasis>root</emphasis>'s home directory. On most systems, <command>locate</command> is a symbolic link to the <command>slocate</command> program:</para>
<screen>
billy:~&gt;ls -l /usr/bin/locate
<prompt>billy:~&gt;</prompt> <command>ls -l /usr/bin/locate</command>
lrwxrwxrwx 1 root slocate 7 Oct 28 14:18 /usr/bin/locate -&gt; slocate*
</screen>
<para>User <emphasis>tina</emphasis> could have used <command>locate</command> to find the application she wanted:</para>
<screen>
tina:~&gt;locate acroread
<prompt>tina:~&gt;</prompt> <command>locate acroread</command>
/usr/share/icons/hicolor/16x16/apps/acroread.png
/usr/share/icons/hicolor/32x32/apps/acroread.png
/usr/share/icons/locolor/16x16/apps/acroread.png
@ -1019,13 +1023,13 @@ tina:~&gt;locate acroread
</screen>
<para>Directories that don't contain the name <filename>bin</filename> can't contain the program - they don't contain executable files. There are three possibilities left. The file in <filename>/usr/local/bin</filename> is the one <emphasis>tina</emphasis> would have wanted: it is a link to the shell script that starts the actual program:</para>
<screen>
tina:~&gt;file /usr/local/bin/acroread
<prompt>tina:~&gt;</prompt> <command>file /usr/local/bin/acroread</command>
/usr/local/bin/acroread: symbolic link to ../Acrobat4/bin/acroread
tina:~&gt;file /usr/local/Acrobat4/bin/acroread
<prompt>tina:~&gt;</prompt> <command>file /usr/local/Acrobat4/bin/acroread</command>
/usr/local/Acrobat4/bin/acroread: Bourne shell script text executable
tina:~&gt;file /usr/local/Acrobat4/Reader/intellinux/bin/acroread
<prompt>tina:~&gt;</prompt> <command>file /usr/local/Acrobat4/Reader/intellinux/bin/acroread</command>
/usr/local/Acrobat4/Reader/intellinux/bin/acroread: ELF 32-bit LSB
executable, Intel 80386, version 1, dynamically linked (uses
shared libs), not stripped
@ -1039,7 +1043,7 @@ shared libs), not stripped
<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
<prompt>jerry:~&gt;</prompt> <command>grep -a find .bash_history</command>
find . -name userinfo
man find
find ../ -name common.cfg
@ -1047,27 +1051,27 @@ find ../ -name common.cfg
<note><title>Search history</title>
<para>Also useful in these cases is the search function in <command>bash</command>, activated by pressing <keycap>Ctrl</keycap>+<keycap>R</keycap> at once, such as in the example where we want to check how we did that last <command>find</command> again:</para>
<screen>
thomas ~&gt;
<prompt>thomas ~&gt;</prompt> <command>^R</command>
(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 occurrence of your search string is shown. If you want to see previous commands containing the same string, type <keycap>Ctrl</keycap>+<keycap>R</keycap> 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>
william:~&gt;grep pinguin /usr/share/dict/words
<prompt>william:~&gt;</prompt> <command>grep pinguin /usr/share/dict/words</command>
william:~&gt;grep penguin /usr/share/dict/words
<prompt>william:~&gt;</prompt> <command>grep penguin /usr/share/dict/words</command>
penguin
penguins
</screen>
<para>Who is the owner of that home directory next to mine? Hey, there's his telephone number!</para>
<screen>
lisa:~&gt;grep gdbruyne /etc/passwd
<prompt>lisa:~&gt;</prompt> <command>grep gdbruyne /etc/passwd</command>
gdbruyne:x:981:981:Guy Debruyne, tel 203234:/home/gdbruyne:/bin/bash
</screen>
<para>And what was the E-mail address of Arno again?</para>
<screen>
serge:~/mail&gt;grep -i arno *
<prompt>serge:~/mail&gt;</prompt> <command>grep -i arno *</command>
sent-mail: To: &lt;Arno.Hintjens@celeb.com&gt;
sent-mail: On Mon, 24 Dec 2001, Arno.Hintjens@celeb.com wrote:
</screen>
@ -1110,7 +1114,7 @@ sent-mail: On Mon, 24 Dec 2001, Arno.Hintjens@celeb.com wrote:
<sect3 id="sect_03_03_04_03"><title><command>Head</command> and <command>tail</command></title>
<para>These two commands display the n first/last lines of a file respectively. To see the last ten commands entered:</para>
<screen>
tony:~>tail -10 .bash_history
<prompt>tony:~&gt;</prompt> <command>tail -10 .bash_history </command>
locate configure | grep bin
man bash
cd
@ -1150,7 +1154,7 @@ frm
<para>Each regular file is principally a hardlink. Hardlinks can not span across partitions, since they refer to inodes, and inode numbers are only unique within a given partition.</para>
<para>It may be argued that there is a third kind of link, the <emphasis>user-space</emphasis> link, which is similar to a shortcut in MS Windows. These are files containing meta-data which can only be interpreted by the graphical file manager. To the kernel and the shell these are just normal files. They may end in a <emphasis>.desktop</emphasis> or <emphasis>.lnk</emphasis> suffix; an example can be found in <filename>~/.gnome-desktop</filename>:</para>
<screen>
[dupont@boulot .gnome-desktop]$ cat La\ Maison\ Dupont
<prompt>[dupont@boulot .gnome-desktop]$</prompt> <command>cat La\ Maison\ Dupont</command>
[Desktop Entry]
Encoding=Legacy-Mixed
Name=La Maison Dupont
@ -1160,7 +1164,7 @@ URL=file:///home/dupont
</screen>
<para>This example is from a KDE desktop:</para>
<screen>
[lena@venus Desktop]$ cat camera
<prompt>[lena@venus Desktop]$</prompt> <command>cat camera</command>
[Desktop Entry]
Dev=/dev/sda1
FSType=auto
@ -1178,9 +1182,9 @@ X-KDE-Dynamic-Device=true
<cmdsynopsis><command>ln <option>-s</option> <filename>targetfile</filename> <filename>linkname</filename></command></cmdsynopsis>
<para>In the example below, user <emphasis>freddy</emphasis> creates a link in a subdirectory of his home directory to a directory on another part of the system:</para>
<screen>
freddy:~/music&gt;ln -s /opt/mp3/Queen/ Queen
<prompt>freddy:~/music&gt;</prompt> <command>ln -s /opt/mp3/Queen/ Queen</command>
freddy:~/music&gt;ls -l
<prompt>freddy:~/music&gt;</prompt> <command>ls -l</command>
lrwxrwxrwx 1 freddy freddy 17 Jan 22 11:07 Queen -&gt; /opt/mp3/Queen
</screen>
<para>Symbolic links are always very small files, while hard links have the same size as the original file.</para>
@ -1193,9 +1197,9 @@ lrwxrwxrwx 1 freddy freddy 17 Jan 22 11:07 Queen -&gt; /opt/mp3/Queen
<para>The Linux security model is based on the one used on UNIX systems, and is as rigid, and in some cases even more, as the UNIX security model, which is already quite robust. On a Linux system, every file is owned by a user and a group user. There is also a third category of users, those that are not the user owner and don't belong to the group owning the file. For each category of users, read, write and execute permissions can be granted or denied.</para>
<para>We already used the <emphasis>long</emphasis> option to list files using the <command>ls <option>-l</option></command> command, though for other reasons. This command also displays file permissions for these three user categories; they are indicated by the nine characters that follow the first character, which is the file type indicator at the beginning of the file properties line. As seen in the examples below, the first three characters in this series of nine display access rights for the actual user that owns the file. The next three are for the group owner of the file, the last three for other users. The permissions are always in the same order: read, write, execute for the user, the group and the others. Some examples:</para>
<screen>
marise:~&gt;ls -l To_Do
<prompt>marise:~&gt;</prompt> <command>ls -l To_Do</command>
-rw-rw-r-- 1 marise users 5 Jan 15 12:39 To_Do
marise:~&gt;ls -l /bin/ls
<prompt>marise:~&gt;</prompt> <command>ls -l /bin/ls</command>
-rwxr-xr-x 1 root root 45948 Aug 9 15:01 /bin/ls*
</screen>
<para>The first file is a regular file (first dash). Users with user name <emphasis>marise</emphasis> or users belonging to the group <emphasis>users</emphasis> can read and write (change/move/delete) the file, but they can't execute it (second and third dash). All other users are only allowed to read this file, but they can't write or execute it (fourth and fifth dash).</para>
@ -1244,12 +1248,12 @@ marise:~&gt;ls -l /bin/ls
<para>This straight forward scheme is applied very strictly, which allows a high level of security even without network security. Among other functions, the security scheme takes care of user access to programs, it can serve files on a need-to-know basis and protect sensitive data such as home directories and system configuration files.</para>
<para>You should know what your user name is. If you don't, it can be displayed using the <command>id</command> command, which also displays the default group you belong to and eventually other groups of which you are a member:</para>
<screen>
tilly:~&gt;id
<prompt>tilly:~&gt;</prompt> <command>id</command>
uid=504(tilly) gid=504(tilly) groups=504(tilly),100(users),2051(org)
</screen>
<para>Your user name is also stored in the environment variable <varname>USER</varname>:</para>
<screen>
tilly:~&gt;echo $USER
<prompt>tilly:~&gt;</prompt> <command>echo $USER</command>
tilly
</screen>
@ -1261,29 +1265,29 @@ tilly
<para>A normal consequence of applying strict file permissions, and sometimes a nuisance, is that access rights will need to be changed for all kinds of reasons. We use the <command>chmod</command> command to do this, and eventually <emphasis>to chmod</emphasis> has become an almost acceptable English verb, meaning the changing of the access mode of a file. The <command>chmod</command> command can be used with alphanumeric or numeric options, whatever you like best.</para>
<para>The example below uses alphanumeric options in order to solve a problem that commonly occurs with new users:</para>
<screen>
asim:~&gt;./hello
<prompt>asim:~&gt;</prompt> <command>./hello</command>
bash: ./hello: bad interpreter: Permission denied
asim:~&gt;cat hello
<prompt>asim:~&gt;</prompt> <command>cat hello</command>
#!/bin/bash
echo "Hello, World"
asim:~&gt;ls -l hello
<prompt>asim:~&gt;</prompt> <command>ls -l hello</command>
-rw-rw-r-- 1 asim asim 32 Jan 15 16:29 hello
asim:~&gt;chmod u+x hello
<prompt>asim:~&gt;</prompt> <command>chmod u+x hello</command>
asim:~&gt;./hello
<prompt>asim:~&gt;</prompt> <command>./hello</command>
Hello, World
asim:~&gt;ls -l hello
<prompt>asim:~&gt;</prompt> <command>ls -l hello</command>
-rwx-rw-r-- 1 asim asim 32 Jan 15 16:29 hello*
</screen>
<para>The + and - operators are used to grant or deny a given right to a given group. Combinations separated by commas are allowed. The Info and man pages contain useful examples. Here's another one, which makes the file from the previous example a private file to user <emphasis>asim</emphasis>:</para>
<screen>
asim:~&gt;chmod u+rwx,go-rwx hello
<prompt>asim:~&gt;</prompt> <command>chmod u+rwx,go-rwx hello</command>
asim:~&gt;ls -l hello
<prompt>asim:~&gt;</prompt> <command>ls -l hello</command>
-rwx------ 1 asim asim 32 Jan 15 16:29 hello*
</screen>
<para>The kind of problem resulting in an error message saying that permission is denied somewhere is usually a problem with access rights in most cases. Also, comments like, <quote>It worked yesterday,</quote> and <quote>When I run this as root it works,</quote> are most likely caused by the wrong file permissions.</para>
@ -1332,21 +1336,21 @@ asim:~&gt;ls -l hello
<sect3 id="sect_03_04_02_02"><title>The file mask</title>
<para>When a new file is saved somewhere, it is first subjected to the standard security procedure. Files without permissions don't exist on Linux. The standard file permission is determined by the <emphasis>mask</emphasis> for new file creation. The value of this mask can be displayed using the <command>umask</command> command:</para>
<screen>
bert:~&gt;umask
<prompt>bert:~&gt;</prompt> <command>umask</command>
0002
</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 execute permission is granted to everybody when creating a new directory. When creating a new file, this function will grant read and write permissions for everybody, but set execute permissions to none for all user categories. This, before the mask is applied, a directory has permissions <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 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
<prompt>bert:~&gt;</prompt> <command>mkdir newdir</command>
bert:~&gt; ls -ld newdir
<prompt>bert:~&gt;</prompt> <command>ls -ld newdir</command>
drwxrwxr-x 2 bert bert 4096 Feb 28 13:45 newdir/
bert:~&gt; touch newfile
<prompt>bert:~&gt;</prompt> <command>touch newfile</command>
bert:~&gt; ls -l newfile
<prompt>bert:~&gt;</prompt> <command>ls -l newfile</command>
-rw-rw-r-- 1 bert bert 0 Feb 28 13:52 newfile
</screen>
@ -1365,29 +1369,29 @@ bert:~&gt; ls -l newfile
<cmdsynopsis><command>chown <parameter>newuser</parameter> <filename>file</filename></command></cmdsynopsis>
<para>If you use a colon after the user name (see the Info pages), group ownership will be changed as well, to the primary group of the user issuing the command. On a Linux system, each user has his own group, so this form can be used to make files private:</para>
<screen>
jacky:~&gt;id
<prompt>jacky:~&gt;</prompt> <command>id</command>
uid=1304(jacky) gid=(1304) groups=1304(jacky),2034(pproject)
jacky:~&gt;ls -l my_report
<prompt>jacky:~&gt;</prompt> <command>ls -l my_report</command>
-rw-rw-r-- 1 jacky project 29387 Jan 15 09:34 my_report
jacky:~&gt;chown jacky: my_report
<prompt>jacky:~&gt;</prompt> <command>chown jacky: my_report</command>
jacky:~&gt;chmod o-r my_report
<prompt>jacky:~&gt;</prompt> <command>chmod o-r my_report</command>
jacky:~&gt;ls -l my_report
<prompt>jacky:~&gt;</prompt> <command>ls -l my_report</command>
-rw-rw---- 1 jacky jacky 29387 Jan 15 09:34 my_report
</screen>
<para>If <emphasis>jacky</emphasis> would like to share this file, without having to give everybody permission to write it, he can use the <command>chgrp</command> command:</para>
<screen>
jacky:~&gt;ls -l report-20020115.xls
<prompt>jacky:~&gt;</prompt> <command>ls -l report-20020115.xls</command>
-rw-rw---- 1 jacky jacky 45635 Jan 15 09:35 report-20020115.xls
jacky:~&gt;chgrp project report-20020115.xls
<prompt>jacky:~&gt;</prompt> <command>chgrp project report-20020115.xls</command>
jacky:~&gt;chmod o= report-20020115.xls
<prompt>jacky:~&gt;</prompt> <command>chmod o= report-20020115.xls</command>
jacky:~&gt;ls -l report-20020115.xls
<prompt>jacky:~&gt;</prompt> <command>ls -l report-20020115.xls</command>
-rw-rw---- 1 jacky project 45635 Jan 15 09:35 report-20020115.xls
</screen>
<para>This way, users in the group <emphasis>project</emphasis> will be able to work on this file. Users not in this group have no business with it at all.</para>
@ -1400,7 +1404,7 @@ jacky:~&gt;ls -l report-20020115.xls
<itemizedlist>
<listitem><para>Sticky bit mode: After execution of a job, the command is kept in the system memory. Originally this was a feature used a lot to save memory, but these days memory is inexpensive, so it is not used anymore for its optimizing capabilities on single files. When applied to an entire directory, however, the sticky bit has a different meaning. In that case, a user can only change files in this directory when she is the user owner of the file or when the file has appropriate permissions. This feature is used on directories like <filename>/var/tmp</filename>, that have to be accessible for everyone, but where it is not appropriate for users to change or delete each other's data. The sticky bit is indicated by a <emphasis>t</emphasis> at the end of the file permission field:</para>
<screen>
mark:~&gt;ls -ld /var/tmp
<prompt>mark:~&gt;</prompt> <command>ls -ld /var/tmp</command>
drwxrwxrwt 19 root root 8192 Jan 16 10:37 /var/tmp/
</screen>
<para>The sticky bit is set using the command <command>chmod <parameter>o+t</parameter> <filename>directory</filename></command>. The historic origin of the <quote>t</quote> is in UNIX' <emphasis>save Text access</emphasis> feature.</para>
@ -1410,10 +1414,10 @@ drwxrwxrwt 19 root root 8192 Jan 16 10:37 /var/tmp/
<listitem><para>SGID (set group ID) on a directory: in this special case every file created in the directory will have the same group owner as the directory itself (while normal behavior would be that new files are owned by the users who create them). This way, users don't need to worry about file ownership when sharing directories:</para>
<screen>
mimi:~&gt;ls -ld /opt/docs
<prompt>mimi:~&gt;</prompt> <command>ls -ld /opt/docs</command>
drwxrws--- 4 root users 4096 Jul 25 2001 docs/
mimi:~&gt;ls -l /opt/docs
<prompt>mimi:~&gt;</prompt> <command>ls -l /opt/docs</command>
-rw-rw---- 1 mimi users 345672 Aug 30 2001-Council.doc
</screen>
<para>This is the standard way of sharing files in UNIX.</para>

View File

@ -35,10 +35,10 @@
<para>The shell offers a feature called <emphasis>job control</emphasis> which allows easy handling of multiple processes. This mechanism switches processes between the foreground and the background. Using this system, programs can also be started in the background immediately.</para>
<para>Running a process in the background is only useful for programs that don't need user input (via the shell). Putting a job in the background is typically done when execution of a job is expected to take a long time. In order to free the issuing terminal after entering the command, a trailing ampersand is added. In the example, using graphical mode, we open an extra terminal window from the existing one:</para>
<screen>
billy:~&gt; xterm &amp;
<prompt>billy:~&gt;</prompt> <command>xterm &amp;</command>
[1] 26558
billy:~&gt; jobs
<prompt>billy:~&gt;</prompt> <command>jobs</command>
[1]+ Running xterm &amp;
</screen>
<para>The full job control features are explained in detail in the <command>bash</command> Info pages, so only the frequently used job control applications are listed here:</para>
@ -89,13 +89,13 @@ billy:~&gt; jobs
<listitem><para>Terminal or TTY: terminal to which the process is connected.</para></listitem>
<listitem><para>User name of the real and effective user (RUID and EUID): the owner of the process. The real owner is the user issuing the command, the effective user is the one determining access to system resources. RUID and EUID are usually the same, and the process has the same access rights the issuing user would have. An example to clarify this: the browser <command>mozilla</command> in <filename>/usr/bin</filename> is owned by user <emphasis>root</emphasis>:</para>
<screen>
theo:~&gt;ls -l /usr/bin/mozilla
<prompt>theo:~&gt;</prompt> <command>ls -l /usr/bin/mozilla</command>
-rwxr-xr-x 1 root root 4996 Nov 20 18:28 /usr/bin/mozilla*
theo:~&gt;mozilla &amp;
<prompt>theo:~&gt;</prompt> <command>mozilla &amp;</command>
[1] 26595
theo:~&gt;ps -af
<prompt>theo:~&gt;</prompt> <command>ps -af</command>
UID PID PPID C STIME TTY TIME CMD
theo 26601 26599 0 15:04 pts/5 00:00:00 /usr/lib/mozilla/mozilla-bin
theo 26613 26569 0 15:04 pts/5 00:00:00 ps -af
@ -109,7 +109,7 @@ theo 26613 26569 0 15:04 pts/5 00:00:00 ps -af
<para>The <command>ps</command> command is one of the tools for visualizing processes. This command has several options which can be combined to display different process attributes.</para>
<para>With no options specified, <command>ps</command> only gives information about the current shell and eventual processes:</para>
<screen>
theo:~&gt; ps
<prompt>theo:~&gt;</prompt> <command>ps</command>
PID TTY TIME CMD
4245 pts/7 00:00:00 bash
5314 pts/7 00:00:00 ps
@ -118,7 +118,7 @@ theo:~&gt; ps
<cmdsynopsis><command>ps <option>-ef</option> | grep <parameter>username</parameter></command></cmdsynopsis>
<para>This example shows all processes with a process name of <command>bash</command>, the most common login shell on Linux systems:</para>
<screen>
theo:&gt; ps auxw | grep bash
<prompt>theo:&gt;</prompt> <command>ps auxw | grep bash</command>
brenda 31970 0.0 0.3 6080 1556 tty2 S Feb23 0:00 -bash
root 32043 0.0 0.3 6112 1600 tty4 S Feb23 0:00 -bash
theo 32581 0.0 0.3 6384 1864 pts/1 S Feb23 0:00 bash
@ -161,14 +161,14 @@ Swap: 1050176K av, 76428K used, 973748K free, 82756K cached
</screen>
<para>The first line of <command>top</command> contains the same information displayed by the <command>uptime</command> command:</para>
<screen>
jeff:~&gt;uptime
<prompt>jeff:~&gt;</prompt> <command>uptime</command>
3:30pm, up 12 days, 23:29, 6 users, load average: 0.01, 0.02, 0.00
</screen>
<para>The data for these programs is stored among others in <filename>/var/run/utmp</filename> (information about currently connected users) and in the virtual file system <filename>/proc</filename>, for example <filename>/proc/loadavg</filename> (average load information). There are all sorts of graphical applications to view this data, such as the <emphasis>Gnome System Monitor</emphasis> and <emphasis>lavaps</emphasis>. Open Source initiatives like Big Brother centralize this information along with other server data and logs from multiple servers on one web server, allowing monitoring of the entire IT infrastructure from one workstation.</para>
<para>The relations between processes can be visualized using the <command>pstree</command> command:</para>
<screen>
sophie:~&gt;pstree
<prompt>sophie:~&gt;</prompt> <command>pstree</command>
init-+-amd
|-apmd
|-2*[artsd]
@ -255,22 +255,22 @@ init-+-amd
<sect2 id="sect_04_01_06"><title>SUID and SGID</title>
<para>As promised in the previous chapter, we will now discuss the special modes SUID and SGID in more detail. These modes exist to provide normal users the ability to execute tasks they would normally not be able to do because of the tight file permission scheme used on UNIX based systems. In the ideal situation special modes are used as sparsely as possible, since they include security risks. Linux developers have generally tried to avoid them as much as possible. The Linux <command>ps</command> version, for example, uses the information stored in the <filename>/proc</filename> file system, which is accessible to everyone, thus avoiding exposition of sensitive system data and resources to the general public. Before that, and still on older UNIX systems, the <command>ps</command> program needed access to files such as <filename>/dev/mem</filename> and <filename>/dev/kmem</filename>, which had disadvantages because of the permissions and ownerships on these files:</para>
<screen>
rita:~&gt;ls -l /dev/*mem
<prompt>rita:~&gt;</prompt> <command>ls -l /dev/*mem</command>
crw-r----- 1 root kmem 1, 2 Aug 30 22:30 /dev/kmem
crw-r----- 1 root kmem 1, 1 Aug 30 22:30 /dev/mem
</screen>
<para>With older versions of <command>ps</command>, it was not possible to start the program as a common user, unless special modes were applied to it.</para>
<para>While we generally try to avoid applying any special modes, it is sometimes necessary to use an SUID. An example is the mechanism for changing passwords. Of course users will want to do this themselves instead of having their password set by the system administrator. As we know, user names and passwords are listed in the <filename>/etc/passwd</filename> file, which has these access permissions and owners:</para>
<screen>
bea:~&gt;ls -l /etc/passwd
<prompt>bea:~&gt;</prompt> <command>ls -l /etc/passwd</command>
-rw-r--r-- 1 root root 1267 Jan 16 14:43 /etc/passwd
</screen>
<para>Still, users need to be able to change their own information in this file. This is achieved by giving the <command>passwd</command> program special permissions:</para>
<screen>
mia:~&gt;which passwd
<prompt>mia:~&gt;</prompt> <command>which passwd</command>
passwd is /usr/bin/passwd
mia:~&gt;ls -l /usr/bin/passwd
<prompt>mia:~&gt;</prompt> <command>ls -l /usr/bin/passwd</command>
-r-s--x--x 1 root root 13476 Aug 7 06:03 /usr/bin/passwd*
</screen>
<para>When called, the <command>passwd</command> command will run using the access permissions of <emphasis>root</emphasis>, thus enabling a common user to edit the password file which is owned by the system admin.</para>
@ -278,23 +278,23 @@ mia:~&gt;ls -l /usr/bin/passwd
<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, except for the group owner, which can write to it.</para>
<screen>
joe:~&gt;which write
<prompt>joe:~&gt;</prompt> <command>which write</command>
write is /usr/bin/write
joe:~&gt;ls -l /usr/bin/write
<prompt>joe:~&gt;</prompt> <command>ls -l /usr/bin/write</command>
-rwxr-sr-x 1 root tty 8744 Dec 5 00:55 /usr/bin/write*
joe:~&gt;who
<prompt>joe:~&gt;</prompt> <command>who</command>
jenny tty1 Jan 23 11:41
jenny pts/1 Jan 23 12:21 (:0)
jenny pts/2 Jan 23 12:22 (:0)
jenny pts/3 Jan 23 12:22 (:0)
joe pts/0 Jan 20 10:13 (lo.callhost.org)
joe:~&gt;ls -l /dev/tty1
<prompt>joe:~&gt;</prompt> <command>ls -l /dev/tty1</command>
crw--w---- 1 jenny tty 4, 1 Jan 23 11:41 /dev/tty1
joe:~&gt;write jenny tty1
<prompt>joe:~&gt;</prompt> <command>write jenny tty1</command>
hey Jenny, shall we have lunch together?
^C
</screen>
@ -342,7 +342,7 @@ GRUB supports both boot methods, allowing you to use it with almost any operatin
<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, which lists the services started up in run level 5:</para>
<screen>
[jean@blub /etc/rc5.d] ls
<prompt>[jean@blub /etc/rc5.d]</prompt> <command>ls</command>
K15httpd@ K45named@ S08ipchains@ S25netfs@ S85gpm@
K16rarpd@ K46radvd@ S08iptables@ S26apmd@ S90crond@
K20nfs@ K61ldap@ S09isdn@ S28autofs@ S90xfs@
@ -437,7 +437,7 @@ All of these utilities must be run as root. The system administrator may also m
<screen>
billy:~/xml/src&gt;time make
<prompt>billy:~/xml/src&gt;</prompt> <command>time make</command>
Output written on abook.pdf (222 pages, 1619861 bytes).
Transcript written on abook.log.
@ -449,7 +449,7 @@ sys 0m1.880s
<para>The GNU <command>time</command> command in <filename>/usr/bin</filename> (as opposed to the shell built-in version) displays more information that can be formatted in different ways. It also shows the exit status of the command, and the total elapsed time. The same command as the above using the independent <command>time</command> gives this output:</para>
<screen>
billy:~/xml/src&gt;/usr/bin/time make
<prompt>billy:~/xml/src&gt;</prompt> <command>/usr/bin/time make</command>
Output written on abook.pdf (222 pages, 1595027 bytes).
Transcript written on abook.log.
@ -582,21 +582,22 @@ Command exited with non-zero status 2
<para>The <command>at</command> command executes commands at a given time, using your default shell unless you tell the command otherwise (see the man page).</para>
<para>The options to <command>at</command> are rather user-friendly, which is demonstrated in the examples below:</para>
<screen>
steven@home:~&gt;at tomorrow + 2 days
<prompt>steven@home:~&gt;</prompt> <command>at tomorrow + 2 days</command>
warning: commands will be executed using (in order) a) $SHELL
b) login shell c) /bin/sh
at> cat reports | mail myboss@mycompany
at> &lt;EOT&gt;
<prompt>at&gt;</prompt> <command> cat reports | mail myboss@mycompany</command>
<prompt>at&gt;</prompt> &lt;EOT&gt;
job 1 at 2001-06-16 12:36
</screen>
<para>Typing <keycap>Ctrl</keycap>+<keycap>D</keycap> quits the <command>at</command> utility and generates the <quote>EOT</quote> message.</para>
<para>User <emphasis>steven</emphasis> does a strange thing here combining two commands; we will study this sort of practice in <xref linkend="chap_05" />, Redirecting Input and Output.</para>
<screen>
steven@home:~&gt;at 0237
<prompt>steven@home:~&gt;</prompt> <command>at 0237</command>
warning: commands will be executed using (in order) a) $SHELL
b) login shell c) /bin/sh
at> cd new-programs
at> ./configure; make
at> &lt;EOT&gt;
<prompt>at&gt;</prompt> <command> cd new-programs</command>
<prompt>at&gt;</prompt> <command> ./configure; make</command>
<prompt>at&gt;</prompt> &lt;EOT&gt;
job 2 at 2001-06-14 02:00
</screen>
<para>The <option>-m</option> option sends mail to the user when the job is done, or explains when a job can't be done. The command <command>atq</command> lists jobs; perform this command before submitting jobs in order prevent them from starting at the same time as others. With the <command>atrm</command> command you can remove scheduled jobs if you change your mind.</para>
@ -610,7 +611,7 @@ job 2 at 2001-06-14 02:00
<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 Vixie crontab file:</para>
<screen>
[root@blob /etc]# more crontab
<prompt>[root@blob /etc]#</prompt> <command>more crontab</command>
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
@ -629,9 +630,9 @@ commands to execute every month
<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>run-parts</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
<prompt>billy@ahost cron.daily]$</prompt> <command>cat slocate.cron</command>
#!/bin/sh
renice +19 -p $$ &gt;/dev/null 2>&amp;1
renice +19 -p $$ &gt;/dev/null 2&gt;&amp;1
/usr/bin/updatedb -f "nfs,smbfs,ncpfs,proc,devpts" -e \
"/tmp,/var/tmp, /usr/tmp,/afs,/net"
</screen>
@ -639,7 +640,7 @@ renice +19 -p $$ &gt;/dev/null 2>&amp;1
<para>When you quit, the system will tell you that a new crontab is installed.</para>
<para>This crontab entry reminds <emphasis>billy</emphasis> to go to his sports club every Thursday night:</para>
<screen>
billy:~&gt;crontab -l
<prompt>billy:~&gt;</prompt> <command>crontab -l</command>
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.20264 installed on Sun Jul 20 22:35:14 2003)
# (Cron version -- $Id$)
@ -647,7 +648,7 @@ billy:~&gt;crontab -l
</screen>
<para>After adding a new scheduled task, the system will tell you that a new crontab is installed. You do not need to restart the <command>crond</command> daemon for the changes to take effect. In the example, <emphasis>billy</emphasis> added a new line pointing to a backup script:</para>
<screen>
billy:~&gt;crontab -e
<prompt>billy:~&gt;</prompt> <command>crontab -e</command>
45 15 * * 3 mail -s "sports evening" billy
4 4 * * 4,7 /home/billy/bin/backup.sh
@ -655,7 +656,7 @@ billy:~&gt;crontab -e
crontab: installing new crontab
billy:~&gt;
<prompt>billy:~&gt;</prompt>
</screen>
<para>The <filename>backup.sh</filename> script is executed every Thursday and Sunday. See <xref linkend="sect_07_02_07" /> for an introduction to shell scripting. Keep in mind that output of commands, if any, is mailed to the owner of the crontab file. If no mail service is configured, you might find the output of your commands in your local mailbox, <filename>/var/spool/mail/&lt;your_username&gt;</filename>, a plain text file.</para>
<note><title>Who runs my commands?</title>

View File

@ -27,37 +27,37 @@ Most Linux commands read input, such as a file or another attribute for the comm
<para>Sometimes you will want to put output of a command in a file, or you may want to issue another command on the output of one command. This is known as redirecting output. Redirection is done using either the <quote>&gt;</quote> (greater-than symbol), or using the <quote>|</quote> (pipe) operator which sends the standard output of one command to another command as standard input.</para>
<para>As we saw before, the <command>cat</command> command concatenates files and puts them all together to the standard output. By redirecting this output to a file, this file name will be created - or overwritten if it already exists, so take care.</para>
<screen>
nancy:~&gt; cat test1
<prompt>nancy:~&gt;</prompt> <command>cat test1</command>
some words
nancy:~&gt; cat test2
<prompt>nancy:~&gt;</prompt> <command>cat test2</command>
some other words
nancy:~&gt; cat test1 test2 &gt; test3
<prompt>nancy:~&gt;</prompt> <command>cat test1 test2 &gt; test3</command>
nancy:~&gt; cat test3
<prompt>nancy:~&gt;</prompt> <command>cat test3</command>
some words
some other words
</screen>
<para>Redirecting <quote>nothing</quote> to an existing file is equal to emptying the file:</para>
<screen>
nancy:~&gt; ls -l list
<prompt>nancy:~&gt;</prompt> <command>ls -l list</command>
-rw-rw-r-- 1 nancy nancy 117 Apr 2 18:09 list
nancy:~&gt; &gt; list
<prompt>nancy:~&gt;</prompt> <command>&gt; list</command>
nancy:~&gt; ls -l list
<prompt>nancy:~&gt;</prompt> <command>ls -l list</command>
-rw-rw-r-- 1 nancy nancy 0 Apr 4 12:01 list
</screen>
<para>This process is called <emphasis>truncating</emphasis>.</para>
<para>The same redirection to an nonexistent file will create a new empty file with the given name:</para>
<screen>
nancy:~&gt; ls -l newlist
<prompt>nancy:~&gt;</prompt> <command>ls -l newlist</command>
ls: newlist: No such file or directory
nancy:~&gt; &gt; newlist
<prompt>nancy:~&gt;</prompt> <command>&gt; newlist</command>
nancy:~&gt; ls -l newlist
<prompt>nancy:~&gt;</prompt> <command>ls -l newlist</command>
-rw-rw-r-- 1 nancy nancy 0 Apr 4 12:05 newlist
</screen>
<para><xref linkend="chap_07" /> gives some more examples on the use of this sort of redirection.</para>
@ -73,7 +73,7 @@ nancy:~&gt; ls -l newlist
<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
<prompt>andy:~&gt;</prompt> <command>mail mike@somewhere.org &lt; to_do</command>
</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 <parameter>someone</parameter></command>, but it is of course a much more elegant way of using the available tools.</para>
@ -86,7 +86,7 @@ andy:~&gt;mail mike@somewhere.org &lt; to_do
<para>This also uses input and output redirection.</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
<prompt>mike:~&gt;</prompt> <command>less --help | grep -i examine</command>
: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.
@ -95,9 +95,9 @@ mike:~&gt; less --help | grep -i examine
<para>The <option>-i</option> option is used for case-insensitive searches - remember that UNIX systems are very case-sensitive.</para>
<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
<prompt>mike:~&gt;</prompt> <command>less --help | grep -i examine &gt; examine-files-in-less</command>
mike:~&gt; cat examine-files-in-less
<prompt>mike:~&gt;</prompt> <command>cat examine-files-in-less</command>
: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.
@ -115,9 +115,9 @@ mike:~&gt; cat examine-files-in-less
<para>Instead of overwriting file data, you can also append text to an existing file using two subsequent greater-than signs:</para>
<para>Example:</para>
<screen>
mike:~&gt;date &gt;&gt; wishlist
<prompt>mike:~&gt;</prompt> <command>date &gt;&gt; wishlist</command>
mike:~&gt;cat wishlist
<prompt>mike:~&gt;</prompt> <command>cat wishlist</command>
more money
less work
Thu Feb 28 20:23:07 CET 2002
@ -150,14 +150,14 @@ Thu Feb 28 20:23:07 CET 2002
<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
<prompt>andy:~/newsoft&gt;</prompt> <command>make all 2&gt;&amp;1 | less</command>
--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
<prompt>andy:~/newsoft&gt;</prompt> <command>make all 2&gt; /dev/pts/7</command>
</screen>
</sect4>
</sect3>
@ -171,7 +171,7 @@ andy:~/newsoft&gt; make all 2&gt; /dev/pts/7
</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
<prompt>jenny:~&gt;</prompt> <command>ls -la | grep Feb</command>
</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. 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, options 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 <parameter>grep</parameter></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>
@ -181,7 +181,7 @@ jenny:~&gt;ls -la | grep Feb
<sect3 id="sect_05_01_03_02"><title>Filtering output</title>
<para>The command <command>sort</command> arranges lines in alphabetical order by default:</para>
<screen>
thomas:~&gt;cat people-I-like | sort
<prompt>thomas:~&gt;</prompt> <command>cat people-I-like | sort</command>
Auntie Emmy
Boyfriend
Dad
@ -221,7 +221,7 @@ root:x:0:0:root:/root:/bin/bash
system: root
</screen></listitem>
<listitem><para>See what happens upon issuing this command:</para>
<screen>&gt; time; date &gt;&gt; time; cat &lt; time</screen>
<cmdsynopsis><command>&gt; time; date &gt;&gt; time; cat &lt; time</command></cmdsynopsis>
</listitem>
</itemizedlist>

View File

@ -35,14 +35,14 @@
<sect3 id="sect_07_01_02_01"><title>Emptying files</title>
<para>Sometimes the content of a file doesn't interest you, but you need the file name as a marker (for instance, you just need the timestamp of a file, a reminder that the file was there or should be there some time in the future). Redirecting the output of a null command is how this is done in the Bourne and Bash shells:</para>
<screen>
andy:~&gt;cat wishlist &gt; placeholder
<prompt>andy:~&gt;</prompt> <command>cat wishlist &gt; placeholder</command>
andy:~&gt;ls -la placeholder
<prompt>andy:~&gt;</prompt> <command>ls -la placeholder</command>
-rw-rw-r-- 1 andy andy 200 Jun 12 13:34 placeholder
andy:~&gt; &gt; placeholder
<prompt>andy:~&gt;</prompt> <command> &gt; placeholder</command>
andy:~&gt;ls -la placeholder
<prompt>andy:~&gt;</prompt> <command>ls -la placeholder</command>
-rw-rw-r-- 1 andy andy 0 Jun 12 13:35 placeholder
</screen>
@ -50,11 +50,11 @@ andy:~&gt;ls -la placeholder
<para>For creating a new empty file, the same effect is obtained with the <command>touch</command> command. On an existing file, <command>touch</command> will only update the timestamp. See the Info pages on <command>touch</command> for more details.</para>
<para>To <quote>almost</quote> empty a file, use the <command>tail</command> command. Suppose user <emphasis>andy</emphasis>'s wishlist becomes rather long because he always adds stuff at the end but never deletes the things he actually gets. Now he only wants to keep the last five items:</para>
<screen>
andy:~&gt;tail -5 wishlist &gt; newlist
<prompt>andy:~&gt;</prompt> <command>tail -5 wishlist &gt; newlist</command>
andy:~&gt;cat newlist &gt; wishlist
<prompt>andy:~&gt;</prompt> <command>cat newlist &gt; wishlist</command>
andy:~&gt;rm newlist
<prompt>andy:~&gt;</prompt> <command>rm newlist</command>
</screen>
</sect3>
<sect3 id="sect_07_01_02_02"><title>More about log files</title>
@ -70,7 +70,7 @@ andy:~&gt;rm newlist
<para>Regularly clean out your mailbox, make sub-folders and automatic redirects using <command>procmail</command> (see the Info pages) or the filters of your favorite mail reading application. If you have a trash folder, clean it out on a regular basis.</para>
<para>To redirect mail, use the <filename>.forward</filename> file in your home directory. The Linux mail service looks for this file whenever it has to deliver local mail. The content of the file defines what the mail system should do with your mail. It can contain a single line holding a fully qualified E-mail address. In that case the system will send all your mail to this address. For instance, when renting space for a website, you might want to forward the mail destined for the webmaster to your own account in order not to waste disk space. The webmaster's <filename>.forward</filename> may look like this:</para>
<screen>
webmaster@www ~/>cat .forward
<prompt>webmaster@www ~/&gt;</prompt> <command>cat .forward</command>
mike@pandora.be
</screen>
<para>Using mail forwarding is also useful to prevent yourself from having to check several different mailboxes. You can make every address point to a central and easily accessible account.</para>
@ -85,7 +85,7 @@ mike@pandora.be
<sect3 id="sect_07_01_02_05"><title>Limit file sizes</title>
<para>The shell contains a built-in command to limit file sizes, <command>ulimit</command>, which can also be used to display limitations on system resources:</para>
<screen>
cindy:~&gt;ulimit -a
<prompt>cindy:~&gt;</prompt> <command>ulimit -a</command>
core file size (blocks) 0
data seg size (kbytes) unlimited
file size (blocks) unlimited
@ -120,36 +120,36 @@ virtual memory (kbytes) unlimited
<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
<prompt>debby:~&gt;</prompt> <command>echo $PATH</command>
/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bin
debby:~&gt; echo $MANPATH
<prompt>debby:~&gt;</prompt> <command>echo $MANPATH</command>
/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 export the new value from your environment into the environment that runs these programs. A common example is exporting the <varname>PATH</varname> variable. You may declare it as follows, in order to be able to play with the flight simulator software that is in <filename>/opt/FlightGear/bin</filename>:</para>
<screen>
debby:~&gt; PATH=$PATH:/opt/FlightGear/bin
<prompt>debby:~&gt;</prompt> <command>PATH=$PATH:/opt/FlightGear/bin</command>
</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/FlightGear/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; runfgfs
<prompt>debby:~&gt;</prompt> <command>runfgfs</command>
bash: runfgfs: command not found
</screen>
<para>Exporting variables is done using the shell built-in command <command>export</command>:</para>
<screen>
debby:~&gt; export PATH
<prompt>debby:~&gt;</prompt> <command>export PATH</command>
debby:~&gt; runfgfs
<prompt>debby:~&gt;</prompt> <command>runfgfs</command>
--flight simulator starts--
</screen>
<para>In Bash, we normally do this in one elegant step:</para>
<cmdsynopsis><command>export <varname>VARIABLE</varname>=<replaceable>value</replaceable></command></cmdsynopsis>
<para>The same technique is used for the <varname>MANPATH</varname> variable, that tells the <command>man</command> command where to look for compressed man pages. If new software is added to the system in new or unusual directories, the documentation for it will probably also be in an unusual directory. If you want to read the man pages for the new software, extend the <varname>MANPATH</varname> variable:</para>
<screen>
debby:~&gt; export MANPATH=$MANPATH:/opt/FlightGear/man
<prompt>debby:~&gt;</prompt> <command>export MANPATH=$MANPATH:/opt/FlightGear/man</command>
debby:~&gt; echo $MANPATH
<prompt>debby:~&gt;</prompt> <command>echo $MANPATH</command>
/usr/man:/usr/share/man:/usr/local/man:/usr/X11R6/man:/opt/FlightGear/man
</screen>
<para>You can avoid retyping this command in every window you open by adding it to one of your shell setup files, see <xref linkend="sect_07_02_04" />.</para>
@ -208,7 +208,7 @@ debby:~&gt; echo $MANPATH
<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
<prompt>debby:~&gt;</prompt> <command>cat /etc/profile</command>
# /etc/profile
# System wide environment and startup programs, for login setup
@ -270,7 +270,7 @@ unset i
<para>All readable shell scripts from the <filename>/etc/profile.d</filename> directory are read and executed. These do things like enabling <emphasis>color-ls</emphasis>, aliasing <command>vi</command> to <command>vim</command>, setting locales etc. The temporary variable <varname>i</varname> is unset to prevent it from disturbing shell behavior later on.</para>
<para>Then <command>bash</command> looks for a <filename>.bash_profile</filename> in the user's home directory:</para>
<screen>
debby:~&gt;cat .bash_profile
<prompt>debby:~&gt;</prompt> <command>cat .bash_profile </command>
#################################################################
# #
# .bash_profile file #
@ -285,7 +285,7 @@ source ~/.bash_login
<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
<prompt>debby:~&gt;</prompt> <command>cat /etc/bashrc</command>
# /etc/bashrc
# System wide functions and aliases
@ -339,7 +339,7 @@ fi
</screen>
<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
<prompt>debby:~&gt;</prompt> <command>cat .bash_logout</command>
# ~/.bash_logout
clear
@ -353,12 +353,12 @@ The Bash prompt can do much more than displaying such simple information as your
<para>Before we begin, however, we will save our current prompt in another environment variable:
</para>
<screen>
[jerry@nowhere jerry]$ MYPROMPT=$PS1
<prompt>[jerry@nowhere jerry]$</prompt> <command>MYPROMPT=$PS1</command>
[jerry@nowhere jerry]$ echo $MYPROMPT
<prompt>[jerry@nowhere jerry]$</prompt> <command>echo $MYPROMPT</command>
[\u@\h \W]\$
[jerry@nowhere jerry]$
<prompt>[jerry@nowhere jerry]$</prompt>
</screen>
<para>When we change the prompt now, for example by issuing the command <command><varname>PS1</varname>=<replaceable>"-&gt;"</replaceable></command>, we can always get our original prompt back with the command <command><varname>PS1</varname>=<varname>$MYPROMPT</varname></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>
@ -396,7 +396,7 @@ The Bash prompt can do much more than displaying such simple information as your
<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>
[jerry@nowhere ~] cat hello.sh
<prompt>[jerry@nowhere ~]</prompt> <command>cat hello.sh</command>
#!/bin/bash
echo "Hello $USER"
</screen>
@ -408,7 +408,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:~&gt; cat /usr/local/bin/wav2mp3
<prompt>tille:~&gt;</prompt> <command>cat /usr/local/bin/wav2mp3 </command>
#!/bin/bash
# convert *.wav into *.mp3
LIST=$(ls *.wav)
@ -588,7 +588,7 @@ If your soundcard is not supported by default, you will need to apply other tech
<para>Both Gnome and KDE incorporate other graphical mp3 players, look in your menus.</para>
<para>Start <command>xmms</command> from a menu, or from the command line like this:</para>
<screen>
debby:~/mp3&gt; xmms music.mp3
<prompt>debby:~/mp3&gt;</prompt> <command>xmms music.mp3</command>
</screen>
<para>Alternatively, enter the command <command>xmms <filename>*.mp3</filename></command> for playing all <filename>.mp3</filename> files in a directory.</para>
</sect4>
@ -655,7 +655,7 @@ export INPUTRC="/etc/inputrc"
<sect2 id="sect_07_05_03"><title>Time zone</title>
<para>Setting time information is usually done at installation time. After that, it can be kept up to date using an <emphasis>NTP</emphasis> (Network Time Protocol) client. Most Linux systems run <command>ntpd</command> by default:</para>
<screen>
debby:~&gt; ps -ef | grep ntpd
<prompt>debby:~&gt;</prompt> <command>ps -ef | grep ntpd</command>
ntp 24678 1 0 2002 ? 00:00:33 ntpd -U ntp
</screen>
<para>See your system manual and the documentation that comes with the NTP package. Most desktop managers include tools to set the system time, providing that you have access to the system administrator's account.</para>
@ -666,16 +666,16 @@ ntp 24678 1 0 2002 ? 00:00:33 ntpd -U ntp
<para>Note that on most systems, the default tends to be <emphasis>en_US.UTF-8</emphasis> these days. This is not a problem, because systems where this is the default, will also come with all the programs supporting this encoding. Thus, <command>vi</command> can edit all the files on your system, <command>cat</command> won't behave strange and so on.</para>
<para>Trouble starts when you connect to an older system not supporting this font encoding, or when you open a <emphasis>UTF-8</emphasis> encoded file on a system supporting only 1-byte character fonts. The <command>recode</command> utility might come in handy to convert files from one character set to another. Read the man pages for an overview of features and usage. Another solution might be to temporarily work with another encoding definition, by setting the <varname>LANG</varname> environment variable:</para>
<screen>
debby:~&gt; acroread /var/tmp/51434s.pdf
<prompt>debby:~&gt;</prompt> <command>acroread /var/tmp/51434s.pdf</command>
Warning: charset "UTF-8" not supported, using "ISO8859-1".
Aborted
debby:~&gt; set | grep UTF
<prompt>debby:~&gt;</prompt> <command>set | grep UTF</command>
LANG=en_US.UTF-8
debby:~&gt; export LANG=en_US
<prompt>debby:~&gt;</prompt> <command>export LANG=en_US</command>
debby:~&gt; acroread /var/tmp/51434s.pdf
<prompt>debby:~&gt;</prompt> <command>acroread /var/tmp/51434s.pdf</command>
&lt;--new window opens--&gt;
</screen>
</sect2>
@ -703,15 +703,15 @@ debby:~&gt; acroread /var/tmp/51434s.pdf
<cmdsynopsis><command>rpm <option>-Uvh</option> <filename>/path/to/rpm-package(s)</filename></command></cmdsynopsis>
<para>The <option>-v</option> option generates more verbose output, and <option>-h</option> makes <command>rpm</command> print a progress bar:</para>
<screen>
[root@jupiter tmp]# rpm -Uvh totem-0.99.5-1.fr.i386.rpm
<prompt>[root@jupiter tmp]#</prompt> <command>rpm -Uvh totem-0.99.5-1.fr.i386.rpm</command>
Preparing... ########################################### [100%]
1:totem ########################################### [100%]
[root@jupiter tmp]#
<prompt>[root@jupiter tmp]#</prompt>
</screen>
<para>New kernel packages, however, are installed with the install option <option>-i</option>, which does not overwrite existing version(s) of the package, least to be able to boot your system with the old kernel if the new one does not work.</para>
<para>You can also use <command>rpm</command> to check whether a package is installed on your system:</para>
<screen>
[david@jupiter ~] rpm -qa | grep vim
<prompt>[david@jupiter ~]</prompt> <command>rpm -qa | grep vim</command>
vim-minimal-6.1-29
vim-X11-6.1-29
vim-enhanced-6.1-29
@ -719,20 +719,20 @@ vim-common-6.1-29
</screen>
<para>Or you can find out which package contains a certain file or executable:</para>
<screen>
[david@jupiter ~] rpm -qf /etc/profile
<prompt>[david@jupiter ~]</prompt> <command>rpm -qf /etc/profile</command>
setup-2.5.25-1
[david@jupiter ~] which cat
<prompt>[david@jupiter ~]</prompt> <command>which cat</command>
cat is /bin/cat
[david@jupiter ~] rpm -qf /bin/cat
<prompt>[david@jupiter ~]</prompt> <command>rpm -qf /bin/cat</command>
coreutils-4.5.3-19
</screen>
<para>Note that you need not have access to administrative privileges in order to use <command>rpm</command> to query the RPM database. You only need to be <emphasis>root</emphasis> when adding, modifying or deleting packages.</para>
<para>Below is one last example, demonstrating how to uninstall a package using <command>rpm</command>:</para>
<screen>
[root@jupiter root]# rpm -e totem
[root@jupiter root]#
<prompt>[root@jupiter root]#</prompt> <command>rpm -e totem</command>
<prompt>[root@jupiter root]#</prompt>
</screen>
<para>Note that uninstalling is not that verbose by default, it is normal that you don't see much happening. When in doubt, use <command>rpm <option>-qa</option></command> again to verify that the package has been removed.</para>
<para>RPM can do much more than the couple of basic functions we discussed in this introduction; the <ulink url="http://www.ibiblio.org/mdw/HOWTO/RPM-HOWTO/index.html">RPM HOWTO</ulink> contains further references.</para>
@ -763,7 +763,7 @@ this applies to all operating systems and Linux is not different.</para>
<para>Do this often, it's an easy way to keep your system up-to-date and thus safe.</para>
<para>Apart from this general usage, <command>apt-get</command> is also very fast for installing individual packages. This is how it works:</para>
<screen>
[david@jupiter ~] su - -c "apt-get install xsnow"
<prompt>[david@jupiter ~]</prompt> <command>su - -c "apt-get install xsnow"</command>
Password:
Reading Package Lists... Done
Building Dependency Tree... Done
@ -828,13 +828,13 @@ title old-kernel
<para>On some systems, only <emphasis>root</emphasis> can mount removable media; this depends on the configuration.</para>
<para>For automation purposes, the CD drive usually has an entry in <filename>/etc/fstab</filename>, which lists the file systems and their mount points, that make up your file system tree. This is such a line:</para>
<screen>
[david@jupiter ~] grep cdrom /etc/fstab
<prompt>[david@jupiter ~]</prompt> <command>grep cdrom /etc/fstab</command>
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0
</screen>
<para>This indicates that the system will understand the command <command>mount <filename>/mnt/cdrom</filename></command>. The <option>noauto</option> means that on this system, CDs are not mounted automatically.</para>
<para>You may even try to right click on the CD icon on your desktop to mount the CD if your file manager doesn't do it for you. You can check whether it worked issuing the <command>mount</command> command with no arguments:</para>
<screen>
[david@jupiter ~] mount | grep cdrom
<prompt>[david@jupiter ~]</prompt> <command>mount | grep cdrom</command>
/dev/cdrom on /mnt/cdrom type iso9660 (ro,nosuid,nodev)
</screen>
</sect3>

View File

@ -20,25 +20,25 @@
<para><command>Lpr</command> uses a spooling daemon, <command>lpd</command> to print the named files when facilities become available. If no names appear, standard input is assumed (such as when the output of a command is piped into <command>lpr</command>). The <command>lpr</command> command has a lot of options, which can be displayed using the <option>--help</option> option. Full information is in the Info pages. You will also find the <command>lp</command> command on your Linux system, for compatibility reasons with other (UNIX) programs. You will find that <command>lp</command> is in fact a symbolic link to <command>lpr</command>:</para>
<screen>
davy:~&gt;ls -l /usr/bin/lp*
<prompt>davy:~&gt;</prompt> <command>ls -l /usr/bin/lp*</command>
lrwxrwxrwx 1 root root 3 Oct 28 14:21 /usr/bin/lp -> lpr
-rwxr-xr-x 1 lp lp 395192 Aug 11 2001 /usr/bin/lpq
-rwxr-xr-x 1 lp lp 408536 Aug 11 2001 /usr/bin/lpr
-rwxr-xr-x 1 lp lp 392984 Aug 11 2001 /usr/bin/lprm
-rwxr-xr-x 1 root root 4651 Oct 19 22:17 /usr/bin/lprsetup.sh
-rwxr-xr-x 1 lp lp 398488 Aug 11 2001 /usr/bin/lpstat
davy:~&gt;ps -ef | grep lpd
<prompt>davy:~&gt;</prompt> <command>ps -ef | grep lpd</command>
lp 1003 1 0 Feb22 ? 00:00:00 lpd Waiting
</screen>
<para>Once the file is accepted in the print queue, an identification number for the print job is assigned:</para>
<screen>
davy:~&gt;lp /etc/profile
<prompt>davy:~&gt;</prompt> <command>lp /etc/profile</command>
request id is davy@blob+253
</screen>
<para>To view (query) the print queue, use the <command>lpq</command> command. When entered without arguments, it displays the contents of the default print queue.</para>
<screen>
davy:~&gt;lpq
<prompt>davy:~&gt;</prompt> <command>lpq</command>
Printer: lp@blob
Queue: no printable jobs in queue
Status: job 'cfA284blob.somewhere.org' removed at 11:02:47.098
@ -108,7 +108,7 @@ More information can be found at <ulink url="http://www.cups.org">the CUPS homep
<title>My print hasn't come out</title>
<para>Use the <command>lpq</command> command and see if you can spot your job:</para>
<screen>
elly:~&gt;lpq
<prompt>elly:~&gt;</prompt> <command>lpq</command>
Printer: lp@blob
Queue: 2 printable jobs
Server: pid 29998 active

View File

@ -35,42 +35,42 @@
<para>The archives made with a proprietary <command>tar</command> version on one system, may be incompatible with <command>tar</command> on another proprietary system. This may cause much headaches, such as if the archive needs to be recovered on a system that doesn't exist anymore. Use the GNU <command>tar</command> version on all systems to prevent your system admin from bursting into tears. Linux always uses GNU tar. When working on other UNIX machines, enter <command>tar <option>--help</option></command> to find out which version you are using. Contact your system admin if you don't see the word GNU somewhere.</para></note>
<para>In the example below, an archive is created and unpacked.</para>
<screen>
gaby:~&gt;ls images/
<prompt>gaby:~&gt;</prompt> <command>ls images/</command>
me+tux.jpg nimf.jpg
gaby:~&gt;tar cvf images-in-a-dir.tar images/
<prompt>gaby:~&gt;</prompt> <command>tar cvf images-in-a-dir.tar images/</command>
images/
images/nimf.jpg
images/me+tux.jpg
gaby:~&gt;cd images
<prompt>gaby:~&gt;</prompt> <command>cd images</command>
gaby:~/images&gt;tar cvf images-without-a-dir.tar *.jpg
<prompt>gaby:~/images&gt;</prompt> <command>tar cvf images-without-a-dir.tar *.jpg</command>
me+tux.jpg
nimf.jpg
gaby:~/images&gt;cd
<prompt>gaby:~/images&gt;</prompt> <command>cd</command>
gaby:~&gt;ls */*.tar
<prompt>gaby:~&gt;</prompt> <command>ls */*.tar</command>
images/images-without-a-dir.tar
gaby:~&gt;ls *.tar
<prompt>gaby:~&gt;</prompt> <command>ls *.tar</command>
images-in-a-dir.tar
gaby:~&gt;tar xvf images-in-a-dir.tar
<prompt>gaby:~&gt;</prompt> <command>tar xvf images-in-a-dir.tar </command>
images/
images/nimf.jpg
images/me+tux.jpg
gaby:~&gt;tar tvf images/images-without-dir.tar
<prompt>gaby:~&gt;</prompt> <command>tar tvf images/images-without-dir.tar </command>
-rw-r--r-- gaby/gaby 42888 1999-06-30 20:52:25 me+tux.jpg
-rw-r--r-- gaby/gaby 7578 2000-01-26 12:58:46 nimf.jpg
gaby:~&gt;tar xvf images/images-without-a-dir.tar
<prompt>gaby:~&gt;</prompt> <command>tar xvf images/images-without-a-dir.tar </command>
me+tux.jpg
nimf.jpg
gaby:~&gt;ls *.jpg
<prompt>gaby:~&gt;</prompt> <command>ls *.jpg</command>
me+tux.jpg nimf.jpg
</screen>
<para>This example also illustrates the difference between a tarred directory and a bunch of tarred files. It is advisable to only compress directories, so files don't get spread all over when unpacking the tarball (which may be on another system, where you may not know which files where already there and which are the ones from the archive).</para>
@ -81,7 +81,7 @@ me+tux.jpg nimf.jpg
<sect3 id="sect_09_01_01_02"><title>Incremental backups with tar</title>
<para>The <command>tar</command> tool supports the creation of incremental backups, using the <option>-N</option> option. With this option, you can specify a date, and <command>tar</command> will check modification time of all specified files against this date. If files are changed more recent than date, they will be included in the backup. The example below uses the timestamp on a previous archive as the date value. First, the initial archive is created and the timestamp on the initial backup file is shown. Then a new file is created, upon which we take a new backup, containing only this new file:</para>
<screen>
jimmy:~&gt; tar cvpf /var/tmp/javaproggies.tar java/*.java
<prompt>jimmy:~&gt;</prompt> <command>tar cvpf /var/tmp/javaproggies.tar java/*.java</command>
java/btw.java
java/error.java
java/hello.java
@ -98,36 +98,36 @@ java/TestOne.java
java/TestTwo.java
java/Vehicle.java
jimmy:~&gt; ls -l /var/tmp/javaproggies.tar
<prompt>jimmy:~&gt;</prompt> <command>ls -l /var/tmp/javaproggies.tar</command>
-rw-rw-r-- 1 jimmy jimmy 10240 Jan 21 11:58 /var/tmp/javaproggies.tar
jimmy:~&gt; touch java/newprog.java
<prompt>jimmy:~&gt;</prompt> <command>touch java/newprog.java</command>
jimmy:~&gt; tar -N /var/tmp/javaproggies.tar \
-cvp /var/tmp/incremental1-javaproggies.tar java/*.java 2&gt; /dev/null
<prompt>jimmy:~&gt;</prompt> <command>tar -N /var/tmp/javaproggies.tar \
-cvp /var/tmp/incremental1-javaproggies.tar java/*.java 2&gt; /dev/null</command>
java/newprog.java
jimmy:~&gt; cd /var/tmp/
<prompt>jimmy:~&gt;</prompt> <command>cd /var/tmp/</command>
jimmy:~&gt; tar xvf incremental1-javaproggies.tar
<prompt>jimmy:~&gt;</prompt> <command>tar xvf incremental1-javaproggies.tar</command>
java/newprog.java
</screen>
<para>Standard errors are redirected to <filename>/dev/null</filename>. If you don't do this, <command>tar</command> will print a message for each unchanged file, telling you it won't be dumped.</para>
<para>This way of working has the disadvantage that it looks at timestamps on files. Say that you download an archive into the directory containing your backups, and the archive contains files that have been created two years ago. When checking the timestamps of those files against the timestamp on the initial archive, the new files will actually seem old to <command>tar</command>, and will not be included in an incremental backup made using the <option>-N</option> option.</para>
<para>A better choice would be the <option>-g</option> option, which will create a list of files to backup. When making incremental backups, files are checked against this list. This is how it works:</para>
<screen>
jimmy:~&gt; tar cvpf work-20030121.tar -g snapshot-20030121 work/
<prompt>jimmy:~&gt;</prompt> <command>tar cvpf work-20030121.tar -g snapshot-20030121 work/</command>
work/
work/file1
work/file2
work/file3
jimmy:~&gt; file snapshot-20030121
<prompt>jimmy:~&gt;</prompt> <command>file snapshot-20030121</command>
snapshot-20030121: ASCII text
</screen>
<para>The next day, user <emphasis>jimmy</emphasis> works on <filename>file3</filename> a bit more, and creates <filename>file4</filename>. At the end of the day, he makes a new backup:</para>
<screen>
jimmy:~&gt; tar cvpf work-20030122.tar -g snapshot-20030121 work/
<prompt>jimmy:~&gt;</prompt> <command>tar cvpf work-20030122.tar -g snapshot-20030121 work/</command>
work/
work/file3
work/file4
@ -140,12 +140,12 @@ work/file4
Data, including tarballs, can be compressed using zip tools. The <command>gzip</command> command will add the suffix .gz to the file name and remove the original file.
</para>
<screen>
jimmy:~&gt;ls -la | grep tar
<prompt>jimmy:~&gt;</prompt> <command>ls -la | grep tar</command>
-rw-rw-r-- 1 jimmy jimmy 61440 Jun 6 14:08 images-without-dir.tar
jimmy:~&gt;gzip images-without-dir.tar
<prompt>jimmy:~&gt;</prompt> <command>gzip images-without-dir.tar</command>
jimmy:~&gt;ls -la images-without-dir.tar.gz
<prompt>jimmy:~&gt;</prompt> <command>ls -la images-without-dir.tar.gz </command>
-rw-rw-r-- 1 jimmy jimmy 50562 Jun 6 14:08 images-without-dir.tar.gz
</screen>
<para>Uncompress gzipped files with the <option>-d</option> option.</para>
@ -182,11 +182,11 @@ jimmy:~&gt;ls -la images-without-dir.tar.gz
<command>fdformat</command> is the low-level floppy disk formatting tool. It has the device name of the floppy disk as an option. <command>fdformat</command> will display an error when the floppy is write-protected.
</para>
<screen>
emma:~&gt;fdformat /dev/fd0H1440
<prompt>emma:~&gt;</prompt> <command>fdformat /dev/fd0H1440</command>
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done
Verifying ... done
emma:~&gt;
<prompt>emma:~&gt;</prompt>
</screen>
<para>The <command>mformat</command> command (from the mtools package) is used to create DOS-compatible floppies which can then be accessed using the <command>mcopy</command>, <command>mdir</command> and other m-commands.</para>
<para>Graphical tools are also available.</para>
@ -204,15 +204,15 @@ emma:~&gt;
<sect3 id="sect_09_02_01_02"><title>Using the <command>dd</command> command to dump data</title>
<para>The <command>dd</command> command can be used to put data on a disk, or get it off again, depending on the given input and output devices. An example:</para>
<screen>
gaby:~&gt;dd if=images-without-dir.tar.gz of=/dev/fd0H1440
<prompt>gaby:~&gt;</prompt> <command>dd if=images-without-dir.tar.gz of=/dev/fd0H1440</command>
98+1 records in
98+1 records out
gaby~&gt;dd if=/dev/fd0H1440 of=/var/tmp/images.tar.gz
<prompt>gaby~&gt;</prompt> <command>dd if=/dev/fd0H1440 of=/var/tmp/images.tar.gz</command>
2880+0 records in
2880+0 records out
gaby:~&gt;ls /var/tmp/images*
<prompt>gaby:~&gt;</prompt> <command>ls /var/tmp/images*</command>
/var/tmp/images.tar.gz
</screen>
@ -225,14 +225,14 @@ gaby:~&gt;ls /var/tmp/images*
<sect2 id="sect_09_02_02"><title>Making a copy with a CD-writer</title>
<para>On some systems users are allowed to use the CD-writer device. Your data will need to be formatted first. Use the <command>mkisofs</command> command to do this in the directory containing the files you want to backup. Check with <command>df</command> that enough disk space is available, because a new file about the same size as the entire current directory will be created:</para>
<screen>
[rose@blob recordables] df -h .
<prompt>[rose@blob recordables]</prompt> <command>df -h .</command>
Filesystem Size Used Avail Use% Mounted on
/dev/hde5 19G 15G 3.2G 82% /home
[rose@blob recordables] du -h -s .
<prompt>[rose@blob recordables]</prompt> <command>du -h -s .</command>
325M .
[rose@blob recordables] mkisofs -J -r -o cd.iso .
<prompt>[rose@blob recordables]</prompt> <command>mkisofs -J -r -o cd.iso .</command>
&lt;--snap--&gt;
making a lot of conversions
&lt;--/snap--&gt;
@ -246,7 +246,7 @@ Max brk space used 37e84
</screen>
<para>The <option>-J</option> and <option>-r</option> options are used to make the CD-ROM mountable on different systems, see the man pages for more. After that, the CD can be created using the <command>cdrecord</command> tool with appropriate options:</para>
<screen>
[rose@blob recordables] cdrecord -dev 0,0,0 -speed=8 cd.iso
<prompt>[rose@blob recordables]</prompt> <command>cdrecord -dev 0,0,0 -speed=8 cd.iso</command>
Cdrecord 1.10 (i686-pc-linux-gnu) (C) 1995-2001 Joerg Schilling
scsidev: '0,0,0'
scsibus: 0 target: 0 lun: 0
@ -288,14 +288,14 @@ Track 01: Total bytes read/written: 341540864/341540864
<para>These devices are usually mounted into the file system. After the mount procedure, they are accessed as normal directories, so you can use the standard commands for manipulating files.</para>
<para>In the example below, images are copied from a USB camera to the hard disk:</para>
<screen>
robin:~&gt;mount /mnt/camera
<prompt>robin:~&gt;</prompt> <command>mount /mnt/camera</command>
robin:~&gt;mount | grep camera
<prompt>robin:~&gt;</prompt> <command>mount | grep camera</command>
/dev/sda1 on /mnt/camera type vfat (rw,nosuid,nodev)
robin:~&gt;cp -R /mnt/camera/* images/
<prompt>robin:~&gt;</prompt> <command>cp -R /mnt/camera/* images/</command>
robin:~&gt;umount /mnt/camera
<prompt>robin:~&gt;</prompt> <command>umount /mnt/camera</command>
</screen>
<para>Likewise, a jazz drive may be mounted on <filename>/mnt/jazz</filename>.</para>
<para>Appropriate lines should be added in <filename>/etc/modules.conf</filename> and <filename>/etc/fstab</filename> to make this work. Refer to specific hardware HOWTOs for more information.</para>