SEESenv/web/html/ch8ult_module_plan.html
changeset 6 1ce9b33fb6ff
parent 2 52d12eb31c30
child 15 f2383fee6584
equal deleted inserted replaced
5:c9c9819cd5e5 6:1ce9b33fb6ff
     1 <html>
     1 <html>
     2 <head>
     2  <head>
     3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     4 <title>ULT Module Plan </title>
     4   <title>
     5 <link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png">
     5    Chapter. ult_module_plan
     6 <link rel="stylesheet" href="/review/support/styles.css" type="text/css">
     6   </title>
     7 <script type="text/javascript" src="/review/support/jquery-min.js"></script>
     7   <link rel="stylesheet" href="hgbook.css" type="text/css" />
     8 <script type="text/javascript" src="/review/support/form.js"></script>
     8   <meta name="generator" content="DocBook XSL Stylesheets V1.75.1" />
     9 <script type="text/javascript" src="/review/support/hsbook.js"></script>
     9  </head>
    10 <meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
    10  <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
    11 </head>
    11   <div class="chapter" id="ult_module_plan">
    12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter" id="ch8ult_module_plan">
    12    <div class="titlepage">
    13 <div class="titlepage"></div>
    13    </div>
    14 <div class="toc">
    14    <div class="toc">
    15 <p><b>Table of Contents</b></p>
    15     <p>
    16 <dl>
    16      <b>
    17 <dt><span class="article"><a href="#id2718075"></a></span></dt>
    17       Table of Contents
    18 <dd><dl>
    18      </b>
    19 <dt><span class="section"><a href="#id2528200">1. Introducing Linux</a></span></dt>
    19     </p>
    20 <dd><dl>
    20     <dl>
    21 <dt><span class="section"><a href="#id2717879">1.1. Historical Background</a></span></dt>
    21      <dt>
    22 <dt><span class="section"><a href="#id2769136">1.2. Design and Implications</a></span></dt>
    22       <span class="article">
    23 <dt><span class="section"><a href="#id2769410">1.3. Reasons for Using Linux</a></span></dt>
    23        <a href="#id2611170">
    24 </dl></dd>
    24        </a>
    25 <dt><span class="section"><a href="#id2769551">2. Getting Started</a></span></dt>
    25       </span>
    26 <dd><dl><dt><span class="section"><a href="#id2769560">2.1. Logging in, activating the user interface and logging out</a></span></dt></dl></dd>
    26      </dt>
    27 <dt><span class="section"><a href="#id2769839">3. Basic Commands</a></span></dt>
    27      <dd>
    28 <dd><dl>
    28       <dl>
    29 <dt><span class="section"><a href="#id2769848">3.1. ls</a></span></dt>
    29        <dt>
    30 <dt><span class="section"><a href="#id2770012">3.2. date</a></span></dt>
    30         <span class="section">
    31 <dt><span class="section"><a href="#id2770073">3.3. cd</a></span></dt>
    31          <a href="#id2421294">
    32 <dt><span class="section"><a href="#id2770176">3.4. who</a></span></dt>
    32           1. Introducing Linux
    33 <dt><span class="section"><a href="#id2770259">3.5. mkdir</a></span></dt>
    33          </a>
    34 </dl></dd>
    34         </span>
    35 <dt><span class="section"><a href="#id2770440">4. Getting Help</a></span></dt>
    35        </dt>
    36 <dd><dl>
    36        <dd>
    37 <dt><span class="section"><a href="#id2770448">4.1. apropos and whatis</a></span></dt>
    37         <dl>
    38 <dt><span class="section"><a href="#id2770542">4.2. man</a></span></dt>
    38          <dt>
    39 <dt><span class="section"><a href="#id2770752">4.3. info</a></span></dt>
    39           <span class="section">
    40 <dt><span class="section"><a href="#id2770844">4.4. --help</a></span></dt>
    40            <a href="#id2610974">
    41 </dl></dd>
    41             1.1. Historical Background
    42 <dt><span class="section"><a href="#id2770897">5. Basic file handling</a></span></dt>
    42            </a>
    43 <dd><dl>
    43           </span>
    44 <dt><span class="section"><a href="#id2770906">5.1. cp</a></span></dt>
    44          </dt>
    45 <dt><span class="section"><a href="#id2771220">5.2. mv</a></span></dt>
    45          <dt>
    46 <dt><span class="section"><a href="#id2771353">5.3. rm</a></span></dt>
    46           <span class="section">
    47 </dl></dd>
    47            <a href="#id2662231">
    48 <dt><span class="section"><a href="#id2771662">6. Command Line Arguments</a></span></dt>
    48             1.2. Design and Implications
    49 <dt><span class="section"><a href="#id2771755">7. Basic Text Processing</a></span></dt>
    49            </a>
    50 <dd><dl>
    50           </span>
    51 <dt><span class="section"><a href="#id2771764">7.1. head</a></span></dt>
    51          </dt>
    52 <dt><span class="section"><a href="#id2771851">7.2. tail</a></span></dt>
    52          <dt>
    53 <dt><span class="section"><a href="#id2771978">7.3. cut</a></span></dt>
    53           <span class="section">
    54 <dt><span class="section"><a href="#id2772065">7.4. paste</a></span></dt>
    54            <a href="#id2662505">
    55 </dl></dd>
    55             1.3. Reasons for Using Linux
    56 <dt><span class="section"><a href="#id2772200">8. Shell Meta Characters</a></span></dt>
    56            </a>
    57 <dt><span class="section"><a href="#id2772308">9. Looking At Files</a></span></dt>
    57           </span>
    58 <dd><dl>
    58          </dt>
    59 <dt><span class="section"><a href="#id2772317">9.1. cat</a></span></dt>
    59         </dl>
    60 <dt><span class="section"><a href="#id2772505">9.2. more</a></span></dt>
    60        </dd>
    61 <dt><span class="section"><a href="#id2772616">9.3. less</a></span></dt>
    61        <dt>
    62 </dl></dd>
    62         <span class="section">
    63 <dt><span class="section"><a href="#id2772859">10. Directory Structure</a></span></dt>
    63          <a href="#id2662646">
    64 <dd><dl>
    64           2. Getting Started
    65 <dt><span class="section"><a href="#id2773133">10.1. man hier</a></span></dt>
    65          </a>
    66 <dt><span class="section"><a href="#id2773150">10.2. ls -l</a></span></dt>
    66         </span>
    67 </dl></dd>
    67        </dt>
    68 <dt><span class="section"><a href="#id2773173">11. Permissions and Ownership</a></span></dt>
    68        <dd>
    69 <dd><dl><dt><span class="section"><a href="#id2773182">11.1. chmod</a></span></dt></dl></dd>
    69         <dl>
    70 <dt><span class="section"><a href="#id2773959">12. Redirection and Piping</a></span></dt>
    70          <dt>
    71 <dd><dl>
    71           <span class="section">
    72 <dt><span class="section"><a href="#id2773995">12.1. Redirecting standard input and standard output</a></span></dt>
    72            <a href="#id2662654">
    73 <dt><span class="section"><a href="#id2774063">12.2. Piping</a></span></dt>
    73             2.1. Logging in, activating the user interface and logging out
    74 <dt><span class="section"><a href="#id2774125">12.3. Redirecting to and from the standard file handles</a></span></dt>
    74            </a>
    75 <dt><span class="section"><a href="#id2774332">12.4. Chained pipelines</a></span></dt>
    75           </span>
    76 <dt><span class="section"><a href="#id2774367">12.5. Redirect to multiple outputs</a></span></dt>
    76          </dt>
    77 </dl></dd>
    77         </dl>
    78 <dt><span class="section"><a href="#id2774397">13. More Text Processing</a></span></dt>
    78        </dd>
    79 <dd><dl>
    79        <dt>
    80 <dt><span class="section"><a href="#id2774406">13.1. grep</a></span></dt>
    80         <span class="section">
    81 <dt><span class="section"><a href="#id2774596">13.2. tr</a></span></dt>
    81          <a href="#id2662934">
    82 </dl></dd>
    82           3. Basic Commands
    83 <dt><span class="section"><a href="#id2774748">14. Elementary Regex</a></span></dt>
    83          </a>
    84 <dd><dl><dt><span class="section"><a href="#id2774972">14.1. Lazy quantification</a></span></dt></dl></dd>
    84         </span>
    85 <dt><span class="section"><a href="#id2775048">15. One Liners</a></span></dt>
    85        </dt>
    86 </dl></dd>
    86        <dd>
    87 </dl>
    87         <dl>
    88 </div>
    88          <dt>
    89 <div class="article">
    89           <span class="section">
    90 <div class="titlepage">
    90            <a href="#id2662942">
    91 <div><div><h2 class="title" id="id2718075"></a></h2></div></div>
    91             3.1. ls
    92 <hr>
    92            </a>
    93 </div>
    93           </span>
    94 <div class="toc">
    94          </dt>
    95 <p><b>Table of Contents</b></p>
    95          <dt>
    96 <dl>
    96           <span class="section">
    97 <dt><span class="section"><a href="#id2528200">1. Introducing Linux</a></span></dt>
    97            <a href="#id2663106">
    98 <dd><dl>
    98             3.2. date
    99 <dt><span class="section"><a href="#id2717879">1.1. Historical Background</a></span></dt>
    99            </a>
   100 <dt><span class="section"><a href="#id2769136">1.2. Design and Implications</a></span></dt>
   100           </span>
   101 <dt><span class="section"><a href="#id2769410">1.3. Reasons for Using Linux</a></span></dt>
   101          </dt>
   102 </dl></dd>
   102          <dt>
   103 <dt><span class="section"><a href="#id2769551">2. Getting Started</a></span></dt>
   103           <span class="section">
   104 <dd><dl><dt><span class="section"><a href="#id2769560">2.1. Logging in, activating the user interface and logging out</a></span></dt></dl></dd>
   104            <a href="#id2663167">
   105 <dt><span class="section"><a href="#id2769839">3. Basic Commands</a></span></dt>
   105             3.3. cd
   106 <dd><dl>
   106            </a>
   107 <dt><span class="section"><a href="#id2769848">3.1. ls</a></span></dt>
   107           </span>
   108 <dt><span class="section"><a href="#id2770012">3.2. date</a></span></dt>
   108          </dt>
   109 <dt><span class="section"><a href="#id2770073">3.3. cd</a></span></dt>
   109          <dt>
   110 <dt><span class="section"><a href="#id2770176">3.4. who</a></span></dt>
   110           <span class="section">
   111 <dt><span class="section"><a href="#id2770259">3.5. mkdir</a></span></dt>
   111            <a href="#id2663271">
   112 </dl></dd>
   112             3.4. who
   113 <dt><span class="section"><a href="#id2770440">4. Getting Help</a></span></dt>
   113            </a>
   114 <dd><dl>
   114           </span>
   115 <dt><span class="section"><a href="#id2770448">4.1. apropos and whatis</a></span></dt>
   115          </dt>
   116 <dt><span class="section"><a href="#id2770542">4.2. man</a></span></dt>
   116          <dt>
   117 <dt><span class="section"><a href="#id2770752">4.3. info</a></span></dt>
   117           <span class="section">
   118 <dt><span class="section"><a href="#id2770844">4.4. --help</a></span></dt>
   118            <a href="#id2663353">
   119 </dl></dd>
   119             3.5. mkdir
   120 <dt><span class="section"><a href="#id2770897">5. Basic file handling</a></span></dt>
   120            </a>
   121 <dd><dl>
   121           </span>
   122 <dt><span class="section"><a href="#id2770906">5.1. cp</a></span></dt>
   122          </dt>
   123 <dt><span class="section"><a href="#id2771220">5.2. mv</a></span></dt>
   123         </dl>
   124 <dt><span class="section"><a href="#id2771353">5.3. rm</a></span></dt>
   124        </dd>
   125 </dl></dd>
   125        <dt>
   126 <dt><span class="section"><a href="#id2771662">6. Command Line Arguments</a></span></dt>
   126         <span class="section">
   127 <dt><span class="section"><a href="#id2771755">7. Basic Text Processing</a></span></dt>
   127          <a href="#id2663534">
   128 <dd><dl>
   128           4. Getting Help
   129 <dt><span class="section"><a href="#id2771764">7.1. head</a></span></dt>
   129          </a>
   130 <dt><span class="section"><a href="#id2771851">7.2. tail</a></span></dt>
   130         </span>
   131 <dt><span class="section"><a href="#id2771978">7.3. cut</a></span></dt>
   131        </dt>
   132 <dt><span class="section"><a href="#id2772065">7.4. paste</a></span></dt>
   132        <dd>
   133 </dl></dd>
   133         <dl>
   134 <dt><span class="section"><a href="#id2772200">8. Shell Meta Characters</a></span></dt>
   134          <dt>
   135 <dt><span class="section"><a href="#id2772308">9. Looking At Files</a></span></dt>
   135           <span class="section">
   136 <dd><dl>
   136            <a href="#id2663542">
   137 <dt><span class="section"><a href="#id2772317">9.1. cat</a></span></dt>
   137             4.1. apropos and whatis
   138 <dt><span class="section"><a href="#id2772505">9.2. more</a></span></dt>
   138            </a>
   139 <dt><span class="section"><a href="#id2772616">9.3. less</a></span></dt>
   139           </span>
   140 </dl></dd>
   140          </dt>
   141 <dt><span class="section"><a href="#id2772859">10. Directory Structure</a></span></dt>
   141          <dt>
   142 <dd><dl>
   142           <span class="section">
   143 <dt><span class="section"><a href="#id2773133">10.1. man hier</a></span></dt>
   143            <a href="#id2663636">
   144 <dt><span class="section"><a href="#id2773150">10.2. ls -l</a></span></dt>
   144             4.2. man
   145 </dl></dd>
   145            </a>
   146 <dt><span class="section"><a href="#id2773173">11. Permissions and Ownership</a></span></dt>
   146           </span>
   147 <dd><dl><dt><span class="section"><a href="#id2773182">11.1. chmod</a></span></dt></dl></dd>
   147          </dt>
   148 <dt><span class="section"><a href="#id2773959">12. Redirection and Piping</a></span></dt>
   148          <dt>
   149 <dd><dl>
   149           <span class="section">
   150 <dt><span class="section"><a href="#id2773995">12.1. Redirecting standard input and standard output</a></span></dt>
   150            <a href="#id2663847">
   151 <dt><span class="section"><a href="#id2774063">12.2. Piping</a></span></dt>
   151             4.3. info
   152 <dt><span class="section"><a href="#id2774125">12.3. Redirecting to and from the standard file handles</a></span></dt>
   152            </a>
   153 <dt><span class="section"><a href="#id2774332">12.4. Chained pipelines</a></span></dt>
   153           </span>
   154 <dt><span class="section"><a href="#id2774367">12.5. Redirect to multiple outputs</a></span></dt>
   154          </dt>
   155 </dl></dd>
   155          <dt>
   156 <dt><span class="section"><a href="#id2774397">13. More Text Processing</a></span></dt>
   156           <span class="section">
   157 <dd><dl>
   157            <a href="#id2663939">
   158 <dt><span class="section"><a href="#id2774406">13.1. grep</a></span></dt>
   158             4.4. --help
   159 <dt><span class="section"><a href="#id2774596">13.2. tr</a></span></dt>
   159            </a>
   160 </dl></dd>
   160           </span>
   161 <dt><span class="section"><a href="#id2774748">14. Elementary Regex</a></span></dt>
   161          </dt>
   162 <dd><dl><dt><span class="section"><a href="#id2774972">14.1. Lazy quantification</a></span></dt></dl></dd>
   162         </dl>
   163 <dt><span class="section"><a href="#id2775048">15. One Liners</a></span></dt>
   163        </dd>
   164 </dl>
   164        <dt>
   165 </div>
   165         <span class="section">
   166 <div class="section" title="1. Introducing Linux">
   166          <a href="#id2663992">
   167 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
   167           5. Basic file handling
   168 <a name="id2528200"></a>1. Introducing Linux</h2></div></div></div>
   168          </a>
   169 <p id="ch8ult_module_plan_1"></a>(Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)</p>
   169         </span>
   170 <p id="ch8ult_module_plan_2"></a>Linux (usually pronounced ˈlɪnəks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.</p>
   170        </dt>
   171 <p id="ch8ult_module_plan_3"></a>Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.</p>
   171        <dd>
   172 <p id="ch8ult_module_plan_4"></a>The name "Linux"  comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.</p>
   172         <dl>
   173 <div class="section" title="1.1. Historical Background">
   173          <dt>
   174 <div class="titlepage"><div><div><h3 class="title">
   174           <span class="section">
   175 <a name="id2717879"></a>1.1. Historical Background</h3></div></div></div>
   175            <a href="#id2664000">
   176 <div class="section" title="1.1.1. Events leading to the creation">
   176             5.1. cp
   177 <div class="titlepage"><div><div><h4 class="title">
   177            </a>
   178 <a name="id2715861"></a>1.1.1. Events leading to the creation</h4></div></div></div>
   178           </span>
   179 <div class="itemizedlist"><ul class="itemizedlist" type="*">
   179          </dt>
   180 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_5"></a>The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.</p></li>
   180          <dt>
   181 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_6"></a>In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.</p></li>
   181           <span class="section">
   182 </ul></div>
   182            <a href="#id2664315">
   183 </div>
   183             5.2. mv
   184 <div class="section" title="1.1.2. The Creation of Linux">
   184            </a>
   185 <div class="titlepage"><div><div><h4 class="title">
   185           </span>
   186 <a name="id2769092"></a>1.1.2. The Creation of Linux</h4></div></div></div>
   186          </dt>
   187 <p id="ch8ult_module_plan_7"></a>In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).</p>
   187          <dt>
   188 <p id="ch8ult_module_plan_8"></a>Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.</p>
   188           <span class="section">
   189 </div>
   189            <a href="#id2664447">
   190 </div>
   190             5.3. rm
   191 <div class="section" title="1.2. Design and Implications">
   191            </a>
   192 <div class="titlepage"><div><div><h3 class="title">
   192           </span>
   193 <a name="id2769136"></a>1.2. Design and Implications</h3></div></div></div>
   193          </dt>
   194 <p id="ch8ult_module_plan_9"></a>A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".</p>
   194         </dl>
   195 <div class="section" title="1.2.1. User Interface">
   195        </dd>
   196 <div class="titlepage"><div><div><h4 class="title">
   196        <dt>
   197 <a name="id2769161"></a>1.2.1. User Interface</h4></div></div></div>
   197         <span class="section">
   198 <p id="ch8ult_module_plan_a"></a>Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.</p>
   198          <a href="#id2664756">
   199 <p id="ch8ult_module_plan_b"></a>A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A “headless system” (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.</p>
   199           6. Command Line Arguments
   200 </div>
   200          </a>
   201 <div class="section" title="1.2.2. Development">
   201         </span>
   202 <div class="titlepage"><div><div><h4 class="title">
   202        </dt>
   203 <a name="id2769215"></a>1.2.2. Development</h4></div></div></div>
   203        <dt>
   204 <p id="ch8ult_module_plan_c"></a>The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.</p>
   204         <span class="section">
   205 <p id="ch8ult_module_plan_d"></a>Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.</p>
   205          <a href="#id2664849">
   206 <p id="ch8ult_module_plan_e"></a>A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.</p>
   206           7. Basic Text Processing
   207 </div>
   207          </a>
   208 <div class="section" title="1.2.3. Community">
   208         </span>
   209 <div class="titlepage"><div><div><h4 class="title">
   209        </dt>
   210 <a name="id2769272"></a>1.2.3. Community</h4></div></div></div>
   210        <dd>
   211 <p id="ch8ult_module_plan_f"></a>A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.</p>
   211         <dl>
   212 <p id="ch8ult_module_plan_10"></a>In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.</p>
   212          <dt>
   213 <p id="ch8ult_module_plan_11"></a>Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.</p>
   213           <span class="section">
   214 </div>
   214            <a href="#id2664858">
   215 <div class="section" title="1.2.4. Can I make a profit out of running a business involving Linux?">
   215             7.1. head
   216 <div class="titlepage"><div><div><h4 class="title">
   216            </a>
   217 <a name="id2769317"></a>1.2.4. Can I make a profit out of running a business involving Linux?</h4></div></div></div>
   217           </span>
   218 <p id="ch8ult_module_plan_12"></a>The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.</p>
   218          </dt>
   219 </div>
   219          <dt>
   220 <div class="section" title="1.2.5. Programming on Linux">
   220           <span class="section">
   221 <div class="titlepage"><div><div><h4 class="title">
   221            <a href="#id2664945">
   222 <a name="id2769363"></a>1.2.5. Programming on Linux</h4></div></div></div>
   222             7.2. tail
   223 <p id="ch8ult_module_plan_13"></a>Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.</p>
   223            </a>
   224 <p id="ch8ult_module_plan_14"></a>Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.</p>
   224           </span>
   225 <p id="ch8ult_module_plan_15"></a>The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.</p>
   225          </dt>
   226 </div>
   226          <dt>
   227 </div>
   227           <span class="section">
   228 <div class="section" title="1.3. Reasons for Using Linux">
   228            <a href="#id2665073">
   229 <div class="titlepage"><div><div><h3 class="title">
   229             7.3. cut
   230 <a name="id2769410"></a>1.3. Reasons for Using Linux</h3></div></div></div>
   230            </a>
   231 <div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_16"></a>Linux is free:</p></li></ul></div>
   231           </span>
   232 <p id="ch8ult_module_plan_17"></a>As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
   232          </dt>
       
   233          <dt>
       
   234           <span class="section">
       
   235            <a href="#id2665160">
       
   236             7.4. paste
       
   237            </a>
       
   238           </span>
       
   239          </dt>
       
   240         </dl>
       
   241        </dd>
       
   242        <dt>
       
   243         <span class="section">
       
   244          <a href="#id2665294">
       
   245           8. Shell Meta Characters
       
   246          </a>
       
   247         </span>
       
   248        </dt>
       
   249        <dt>
       
   250         <span class="section">
       
   251          <a href="#id2665403">
       
   252           9. Looking At Files
       
   253          </a>
       
   254         </span>
       
   255        </dt>
       
   256        <dd>
       
   257         <dl>
       
   258          <dt>
       
   259           <span class="section">
       
   260            <a href="#id2665411">
       
   261             9.1. cat
       
   262            </a>
       
   263           </span>
       
   264          </dt>
       
   265          <dt>
       
   266           <span class="section">
       
   267            <a href="#id2665599">
       
   268             9.2. more
       
   269            </a>
       
   270           </span>
       
   271          </dt>
       
   272          <dt>
       
   273           <span class="section">
       
   274            <a href="#id2665710">
       
   275             9.3. less
       
   276            </a>
       
   277           </span>
       
   278          </dt>
       
   279         </dl>
       
   280        </dd>
       
   281        <dt>
       
   282         <span class="section">
       
   283          <a href="#id2665953">
       
   284           10. Directory Structure
       
   285          </a>
       
   286         </span>
       
   287        </dt>
       
   288        <dd>
       
   289         <dl>
       
   290          <dt>
       
   291           <span class="section">
       
   292            <a href="#id2666228">
       
   293             10.1. man hier
       
   294            </a>
       
   295           </span>
       
   296          </dt>
       
   297          <dt>
       
   298           <span class="section">
       
   299            <a href="#id2666244">
       
   300             10.2. ls -l
       
   301            </a>
       
   302           </span>
       
   303          </dt>
       
   304         </dl>
       
   305        </dd>
       
   306        <dt>
       
   307         <span class="section">
       
   308          <a href="#id2666267">
       
   309           11. Permissions and Ownership
       
   310          </a>
       
   311         </span>
       
   312        </dt>
       
   313        <dd>
       
   314         <dl>
       
   315          <dt>
       
   316           <span class="section">
       
   317            <a href="#id2666276">
       
   318             11.1. chmod
       
   319            </a>
       
   320           </span>
       
   321          </dt>
       
   322         </dl>
       
   323        </dd>
       
   324        <dt>
       
   325         <span class="section">
       
   326          <a href="#id2667054">
       
   327           12. Redirection and Piping
       
   328          </a>
       
   329         </span>
       
   330        </dt>
       
   331        <dd>
       
   332         <dl>
       
   333          <dt>
       
   334           <span class="section">
       
   335            <a href="#id2667089">
       
   336             12.1. Redirecting standard input and standard output
       
   337            </a>
       
   338           </span>
       
   339          </dt>
       
   340          <dt>
       
   341           <span class="section">
       
   342            <a href="#id2667158">
       
   343             12.2. Piping
       
   344            </a>
       
   345           </span>
       
   346          </dt>
       
   347          <dt>
       
   348           <span class="section">
       
   349            <a href="#id2667219">
       
   350             12.3. Redirecting to and from the standard file handles
       
   351            </a>
       
   352           </span>
       
   353          </dt>
       
   354          <dt>
       
   355           <span class="section">
       
   356            <a href="#id2667427">
       
   357             12.4. Chained pipelines
       
   358            </a>
       
   359           </span>
       
   360          </dt>
       
   361          <dt>
       
   362           <span class="section">
       
   363            <a href="#id2667461">
       
   364             12.5. Redirect to multiple outputs
       
   365            </a>
       
   366           </span>
       
   367          </dt>
       
   368         </dl>
       
   369        </dd>
       
   370        <dt>
       
   371         <span class="section">
       
   372          <a href="#id2667492">
       
   373           13. More Text Processing
       
   374          </a>
       
   375         </span>
       
   376        </dt>
       
   377        <dd>
       
   378         <dl>
       
   379          <dt>
       
   380           <span class="section">
       
   381            <a href="#id2667501">
       
   382             13.1. grep
       
   383            </a>
       
   384           </span>
       
   385          </dt>
       
   386          <dt>
       
   387           <span class="section">
       
   388            <a href="#id2667691">
       
   389             13.2. tr
       
   390            </a>
       
   391           </span>
       
   392          </dt>
       
   393         </dl>
       
   394        </dd>
       
   395        <dt>
       
   396         <span class="section">
       
   397          <a href="#id2667842">
       
   398           14. Elementary Regex
       
   399          </a>
       
   400         </span>
       
   401        </dt>
       
   402        <dd>
       
   403         <dl>
       
   404          <dt>
       
   405           <span class="section">
       
   406            <a href="#id2668066">
       
   407             14.1. Lazy quantification
       
   408            </a>
       
   409           </span>
       
   410          </dt>
       
   411         </dl>
       
   412        </dd>
       
   413        <dt>
       
   414         <span class="section">
       
   415          <a href="#id2668143">
       
   416           15. One Liners
       
   417          </a>
       
   418         </span>
       
   419        </dt>
       
   420       </dl>
       
   421      </dd>
       
   422     </dl>
       
   423    </div>
       
   424    <div class="article">
       
   425     <div class="titlepage">
       
   426      <div>
       
   427       <div>
       
   428        <h2 class="title" id="id2611170">
       
   429        </h2>
       
   430       </div>
       
   431      </div>
       
   432      <hr />
       
   433     </div>
       
   434     <div class="toc">
       
   435      <p>
       
   436       <b>
       
   437        Table of Contents
       
   438       </b>
       
   439      </p>
       
   440      <dl>
       
   441       <dt>
       
   442        <span class="section">
       
   443         <a href="#id2421294">
       
   444          1. Introducing Linux
       
   445         </a>
       
   446        </span>
       
   447       </dt>
       
   448       <dd>
       
   449        <dl>
       
   450         <dt>
       
   451          <span class="section">
       
   452           <a href="#id2610974">
       
   453            1.1. Historical Background
       
   454           </a>
       
   455          </span>
       
   456         </dt>
       
   457         <dt>
       
   458          <span class="section">
       
   459           <a href="#id2662231">
       
   460            1.2. Design and Implications
       
   461           </a>
       
   462          </span>
       
   463         </dt>
       
   464         <dt>
       
   465          <span class="section">
       
   466           <a href="#id2662505">
       
   467            1.3. Reasons for Using Linux
       
   468           </a>
       
   469          </span>
       
   470         </dt>
       
   471        </dl>
       
   472       </dd>
       
   473       <dt>
       
   474        <span class="section">
       
   475         <a href="#id2662646">
       
   476          2. Getting Started
       
   477         </a>
       
   478        </span>
       
   479       </dt>
       
   480       <dd>
       
   481        <dl>
       
   482         <dt>
       
   483          <span class="section">
       
   484           <a href="#id2662654">
       
   485            2.1. Logging in, activating the user interface and logging out
       
   486           </a>
       
   487          </span>
       
   488         </dt>
       
   489        </dl>
       
   490       </dd>
       
   491       <dt>
       
   492        <span class="section">
       
   493         <a href="#id2662934">
       
   494          3. Basic Commands
       
   495         </a>
       
   496        </span>
       
   497       </dt>
       
   498       <dd>
       
   499        <dl>
       
   500         <dt>
       
   501          <span class="section">
       
   502           <a href="#id2662942">
       
   503            3.1. ls
       
   504           </a>
       
   505          </span>
       
   506         </dt>
       
   507         <dt>
       
   508          <span class="section">
       
   509           <a href="#id2663106">
       
   510            3.2. date
       
   511           </a>
       
   512          </span>
       
   513         </dt>
       
   514         <dt>
       
   515          <span class="section">
       
   516           <a href="#id2663167">
       
   517            3.3. cd
       
   518           </a>
       
   519          </span>
       
   520         </dt>
       
   521         <dt>
       
   522          <span class="section">
       
   523           <a href="#id2663271">
       
   524            3.4. who
       
   525           </a>
       
   526          </span>
       
   527         </dt>
       
   528         <dt>
       
   529          <span class="section">
       
   530           <a href="#id2663353">
       
   531            3.5. mkdir
       
   532           </a>
       
   533          </span>
       
   534         </dt>
       
   535        </dl>
       
   536       </dd>
       
   537       <dt>
       
   538        <span class="section">
       
   539         <a href="#id2663534">
       
   540          4. Getting Help
       
   541         </a>
       
   542        </span>
       
   543       </dt>
       
   544       <dd>
       
   545        <dl>
       
   546         <dt>
       
   547          <span class="section">
       
   548           <a href="#id2663542">
       
   549            4.1. apropos and whatis
       
   550           </a>
       
   551          </span>
       
   552         </dt>
       
   553         <dt>
       
   554          <span class="section">
       
   555           <a href="#id2663636">
       
   556            4.2. man
       
   557           </a>
       
   558          </span>
       
   559         </dt>
       
   560         <dt>
       
   561          <span class="section">
       
   562           <a href="#id2663847">
       
   563            4.3. info
       
   564           </a>
       
   565          </span>
       
   566         </dt>
       
   567         <dt>
       
   568          <span class="section">
       
   569           <a href="#id2663939">
       
   570            4.4. --help
       
   571           </a>
       
   572          </span>
       
   573         </dt>
       
   574        </dl>
       
   575       </dd>
       
   576       <dt>
       
   577        <span class="section">
       
   578         <a href="#id2663992">
       
   579          5. Basic file handling
       
   580         </a>
       
   581        </span>
       
   582       </dt>
       
   583       <dd>
       
   584        <dl>
       
   585         <dt>
       
   586          <span class="section">
       
   587           <a href="#id2664000">
       
   588            5.1. cp
       
   589           </a>
       
   590          </span>
       
   591         </dt>
       
   592         <dt>
       
   593          <span class="section">
       
   594           <a href="#id2664315">
       
   595            5.2. mv
       
   596           </a>
       
   597          </span>
       
   598         </dt>
       
   599         <dt>
       
   600          <span class="section">
       
   601           <a href="#id2664447">
       
   602            5.3. rm
       
   603           </a>
       
   604          </span>
       
   605         </dt>
       
   606        </dl>
       
   607       </dd>
       
   608       <dt>
       
   609        <span class="section">
       
   610         <a href="#id2664756">
       
   611          6. Command Line Arguments
       
   612         </a>
       
   613        </span>
       
   614       </dt>
       
   615       <dt>
       
   616        <span class="section">
       
   617         <a href="#id2664849">
       
   618          7. Basic Text Processing
       
   619         </a>
       
   620        </span>
       
   621       </dt>
       
   622       <dd>
       
   623        <dl>
       
   624         <dt>
       
   625          <span class="section">
       
   626           <a href="#id2664858">
       
   627            7.1. head
       
   628           </a>
       
   629          </span>
       
   630         </dt>
       
   631         <dt>
       
   632          <span class="section">
       
   633           <a href="#id2664945">
       
   634            7.2. tail
       
   635           </a>
       
   636          </span>
       
   637         </dt>
       
   638         <dt>
       
   639          <span class="section">
       
   640           <a href="#id2665073">
       
   641            7.3. cut
       
   642           </a>
       
   643          </span>
       
   644         </dt>
       
   645         <dt>
       
   646          <span class="section">
       
   647           <a href="#id2665160">
       
   648            7.4. paste
       
   649           </a>
       
   650          </span>
       
   651         </dt>
       
   652        </dl>
       
   653       </dd>
       
   654       <dt>
       
   655        <span class="section">
       
   656         <a href="#id2665294">
       
   657          8. Shell Meta Characters
       
   658         </a>
       
   659        </span>
       
   660       </dt>
       
   661       <dt>
       
   662        <span class="section">
       
   663         <a href="#id2665403">
       
   664          9. Looking At Files
       
   665         </a>
       
   666        </span>
       
   667       </dt>
       
   668       <dd>
       
   669        <dl>
       
   670         <dt>
       
   671          <span class="section">
       
   672           <a href="#id2665411">
       
   673            9.1. cat
       
   674           </a>
       
   675          </span>
       
   676         </dt>
       
   677         <dt>
       
   678          <span class="section">
       
   679           <a href="#id2665599">
       
   680            9.2. more
       
   681           </a>
       
   682          </span>
       
   683         </dt>
       
   684         <dt>
       
   685          <span class="section">
       
   686           <a href="#id2665710">
       
   687            9.3. less
       
   688           </a>
       
   689          </span>
       
   690         </dt>
       
   691        </dl>
       
   692       </dd>
       
   693       <dt>
       
   694        <span class="section">
       
   695         <a href="#id2665953">
       
   696          10. Directory Structure
       
   697         </a>
       
   698        </span>
       
   699       </dt>
       
   700       <dd>
       
   701        <dl>
       
   702         <dt>
       
   703          <span class="section">
       
   704           <a href="#id2666228">
       
   705            10.1. man hier
       
   706           </a>
       
   707          </span>
       
   708         </dt>
       
   709         <dt>
       
   710          <span class="section">
       
   711           <a href="#id2666244">
       
   712            10.2. ls -l
       
   713           </a>
       
   714          </span>
       
   715         </dt>
       
   716        </dl>
       
   717       </dd>
       
   718       <dt>
       
   719        <span class="section">
       
   720         <a href="#id2666267">
       
   721          11. Permissions and Ownership
       
   722         </a>
       
   723        </span>
       
   724       </dt>
       
   725       <dd>
       
   726        <dl>
       
   727         <dt>
       
   728          <span class="section">
       
   729           <a href="#id2666276">
       
   730            11.1. chmod
       
   731           </a>
       
   732          </span>
       
   733         </dt>
       
   734        </dl>
       
   735       </dd>
       
   736       <dt>
       
   737        <span class="section">
       
   738         <a href="#id2667054">
       
   739          12. Redirection and Piping
       
   740         </a>
       
   741        </span>
       
   742       </dt>
       
   743       <dd>
       
   744        <dl>
       
   745         <dt>
       
   746          <span class="section">
       
   747           <a href="#id2667089">
       
   748            12.1. Redirecting standard input and standard output
       
   749           </a>
       
   750          </span>
       
   751         </dt>
       
   752         <dt>
       
   753          <span class="section">
       
   754           <a href="#id2667158">
       
   755            12.2. Piping
       
   756           </a>
       
   757          </span>
       
   758         </dt>
       
   759         <dt>
       
   760          <span class="section">
       
   761           <a href="#id2667219">
       
   762            12.3. Redirecting to and from the standard file handles
       
   763           </a>
       
   764          </span>
       
   765         </dt>
       
   766         <dt>
       
   767          <span class="section">
       
   768           <a href="#id2667427">
       
   769            12.4. Chained pipelines
       
   770           </a>
       
   771          </span>
       
   772         </dt>
       
   773         <dt>
       
   774          <span class="section">
       
   775           <a href="#id2667461">
       
   776            12.5. Redirect to multiple outputs
       
   777           </a>
       
   778          </span>
       
   779         </dt>
       
   780        </dl>
       
   781       </dd>
       
   782       <dt>
       
   783        <span class="section">
       
   784         <a href="#id2667492">
       
   785          13. More Text Processing
       
   786         </a>
       
   787        </span>
       
   788       </dt>
       
   789       <dd>
       
   790        <dl>
       
   791         <dt>
       
   792          <span class="section">
       
   793           <a href="#id2667501">
       
   794            13.1. grep
       
   795           </a>
       
   796          </span>
       
   797         </dt>
       
   798         <dt>
       
   799          <span class="section">
       
   800           <a href="#id2667691">
       
   801            13.2. tr
       
   802           </a>
       
   803          </span>
       
   804         </dt>
       
   805        </dl>
       
   806       </dd>
       
   807       <dt>
       
   808        <span class="section">
       
   809         <a href="#id2667842">
       
   810          14. Elementary Regex
       
   811         </a>
       
   812        </span>
       
   813       </dt>
       
   814       <dd>
       
   815        <dl>
       
   816         <dt>
       
   817          <span class="section">
       
   818           <a href="#id2668066">
       
   819            14.1. Lazy quantification
       
   820           </a>
       
   821          </span>
       
   822         </dt>
       
   823        </dl>
       
   824       </dd>
       
   825       <dt>
       
   826        <span class="section">
       
   827         <a href="#id2668143">
       
   828          15. One Liners
       
   829         </a>
       
   830        </span>
       
   831       </dt>
       
   832      </dl>
       
   833     </div>
       
   834     <div class="section" title="1.Introducing Linux">
       
   835      <div class="titlepage">
       
   836       <div>
       
   837        <div>
       
   838         <h2 class="title" style="clear: both">
       
   839          <a name="id2421294">
       
   840          </a>
       
   841          1.Introducing Linux
       
   842         </h2>
       
   843        </div>
       
   844       </div>
       
   845      </div>
       
   846      <p id="ch8ult_module_plan_1">
       
   847       (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
       
   848      </p>
       
   849      <p id="ch8ult_module_plan_2">
       
   850       Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
       
   851      </p>
       
   852      <p id="ch8ult_module_plan_3">
       
   853       Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
       
   854      </p>
       
   855      <p id="ch8ult_module_plan_4">
       
   856       The name "Linux"  comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
       
   857      </p>
       
   858      <div class="section" title="1.1.Historical Background">
       
   859       <div class="titlepage">
       
   860        <div>
       
   861         <div>
       
   862          <h3 class="title">
       
   863           <a name="id2610974">
       
   864           </a>
       
   865           1.1.Historical Background
       
   866          </h3>
       
   867         </div>
       
   868        </div>
       
   869       </div>
       
   870       <div class="section" title="1.1.1.Events leading to the creation">
       
   871        <div class="titlepage">
       
   872         <div>
       
   873          <div>
       
   874           <h4 class="title">
       
   875            <a name="id2608955">
       
   876            </a>
       
   877            1.1.1.Events leading to the creation
       
   878           </h4>
       
   879          </div>
       
   880         </div>
       
   881        </div>
       
   882        <div class="itemizedlist">
       
   883         <ul class="itemizedlist" type="*">
       
   884          <li class="listitem" style="list-style-type: *">
       
   885           <p id="ch8ult_module_plan_5">
       
   886            The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
       
   887           </p>
       
   888          </li>
       
   889          <li class="listitem" style="list-style-type: *">
       
   890           <p id="ch8ult_module_plan_6">
       
   891            In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
       
   892           </p>
       
   893          </li>
       
   894         </ul>
       
   895        </div>
       
   896       </div>
       
   897       <div class="section" title="1.1.2.The Creation of Linux">
       
   898        <div class="titlepage">
       
   899         <div>
       
   900          <div>
       
   901           <h4 class="title">
       
   902            <a name="id2662186">
       
   903            </a>
       
   904            1.1.2.The Creation of Linux
       
   905           </h4>
       
   906          </div>
       
   907         </div>
       
   908        </div>
       
   909        <p id="ch8ult_module_plan_7">
       
   910         In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
       
   911        </p>
       
   912        <p id="ch8ult_module_plan_8">
       
   913         Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
       
   914        </p>
       
   915       </div>
       
   916      </div>
       
   917      <div class="section" title="1.2.Design and Implications">
       
   918       <div class="titlepage">
       
   919        <div>
       
   920         <div>
       
   921          <h3 class="title">
       
   922           <a name="id2662231">
       
   923           </a>
       
   924           1.2.Design and Implications
       
   925          </h3>
       
   926         </div>
       
   927        </div>
       
   928       </div>
       
   929       <p id="ch8ult_module_plan_9">
       
   930        A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
       
   931       </p>
       
   932       <div class="section" title="1.2.1.User Interface">
       
   933        <div class="titlepage">
       
   934         <div>
       
   935          <div>
       
   936           <h4 class="title">
       
   937            <a name="id2662256">
       
   938            </a>
       
   939            1.2.1.User Interface
       
   940           </h4>
       
   941          </div>
       
   942         </div>
       
   943        </div>
       
   944        <p id="ch8ult_module_plan_a">
       
   945         Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
       
   946        </p>
       
   947        <p id="ch8ult_module_plan_b">
       
   948         A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
       
   949        </p>
       
   950       </div>
       
   951       <div class="section" title="1.2.2.Development">
       
   952        <div class="titlepage">
       
   953         <div>
       
   954          <div>
       
   955           <h4 class="title">
       
   956            <a name="id2662310">
       
   957            </a>
       
   958            1.2.2.Development
       
   959           </h4>
       
   960          </div>
       
   961         </div>
       
   962        </div>
       
   963        <p id="ch8ult_module_plan_c">
       
   964         The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
       
   965        </p>
       
   966        <p id="ch8ult_module_plan_d">
       
   967         Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
       
   968        </p>
       
   969        <p id="ch8ult_module_plan_e">
       
   970         A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
       
   971        </p>
       
   972       </div>
       
   973       <div class="section" title="1.2.3.Community">
       
   974        <div class="titlepage">
       
   975         <div>
       
   976          <div>
       
   977           <h4 class="title">
       
   978            <a name="id2662367">
       
   979            </a>
       
   980            1.2.3.Community
       
   981           </h4>
       
   982          </div>
       
   983         </div>
       
   984        </div>
       
   985        <p id="ch8ult_module_plan_f">
       
   986         A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
       
   987        </p>
       
   988        <p id="ch8ult_module_plan_10">
       
   989         In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
       
   990        </p>
       
   991        <p id="ch8ult_module_plan_11">
       
   992         Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
       
   993        </p>
       
   994       </div>
       
   995       <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
       
   996        <div class="titlepage">
       
   997         <div>
       
   998          <div>
       
   999           <h4 class="title">
       
  1000            <a name="id2662412">
       
  1001            </a>
       
  1002            1.2.4.Can I make a profit out of running a business involving Linux?
       
  1003           </h4>
       
  1004          </div>
       
  1005         </div>
       
  1006        </div>
       
  1007        <p id="ch8ult_module_plan_12">
       
  1008         The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
       
  1009        </p>
       
  1010       </div>
       
  1011       <div class="section" title="1.2.5.Programming on Linux">
       
  1012        <div class="titlepage">
       
  1013         <div>
       
  1014          <div>
       
  1015           <h4 class="title">
       
  1016            <a name="id2662458">
       
  1017            </a>
       
  1018            1.2.5.Programming on Linux
       
  1019           </h4>
       
  1020          </div>
       
  1021         </div>
       
  1022        </div>
       
  1023        <p id="ch8ult_module_plan_13">
       
  1024         Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
       
  1025        </p>
       
  1026        <p id="ch8ult_module_plan_14">
       
  1027         Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
       
  1028        </p>
       
  1029        <p id="ch8ult_module_plan_15">
       
  1030         The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
       
  1031        </p>
       
  1032       </div>
       
  1033      </div>
       
  1034      <div class="section" title="1.3.Reasons for Using Linux">
       
  1035       <div class="titlepage">
       
  1036        <div>
       
  1037         <div>
       
  1038          <h3 class="title">
       
  1039           <a name="id2662505">
       
  1040           </a>
       
  1041           1.3.Reasons for Using Linux
       
  1042          </h3>
       
  1043         </div>
       
  1044        </div>
       
  1045       </div>
       
  1046       <div class="itemizedlist">
       
  1047        <ul class="itemizedlist" type="*">
       
  1048         <li class="listitem" style="list-style-type: *">
       
  1049          <p id="ch8ult_module_plan_16">
       
  1050           Linux is free:
       
  1051          </p>
       
  1052         </li>
       
  1053        </ul>
       
  1054       </div>
       
  1055       <p id="ch8ult_module_plan_17">
       
  1056        As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
   233 Most of all, Linux is free as in "free speech":
  1057 Most of all, Linux is free as in "free speech":
   234 The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.</p>
  1058 The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
   235 <div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_18"></a>Linux is portable to any hardware platform:</p></li></ul></div>
  1059       </p>
   236 <p id="ch8ult_module_plan_19"></a>A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.</p>
  1060       <div class="itemizedlist">
   237 <div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_1a"></a>Linux was made to keep on running:</p></li></ul></div>
  1061        <ul class="itemizedlist" type="*">
   238 <p id="ch8ult_module_plan_1b"></a>As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.</p>
  1062         <li class="listitem" style="list-style-type: *">
   239 <div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_1c"></a>Linux is secure and versatile:</p></li></ul></div>
  1063          <p id="ch8ult_module_plan_18">
   240 <p id="ch8ult_module_plan_1d"></a>The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.</p>
  1064           Linux is portable to any hardware platform:
   241 <div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_1e"></a>Linux is scalable:</p></li></ul></div>
  1065          </p>
   242 <p id="ch8ult_module_plan_1f"></a>From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.</p>
  1066         </li>
   243 <div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_20"></a>The Linux OS and Linux applications have very short debug−times:</p></li></ul></div>
  1067        </ul>
   244 <p id="ch8ult_module_plan_21"></a>Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.</p>
  1068       </div>
   245 </div>
  1069       <p id="ch8ult_module_plan_19">
   246 </div>
  1070        A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
   247 <div class="section" title="2. Getting Started">
  1071       </p>
   248 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  1072       <div class="itemizedlist">
   249 <a name="id2769551"></a>2. Getting Started</h2></div></div></div>
  1073        <ul class="itemizedlist" type="*">
   250 <div class="section" title="2.1. Logging in, activating the user interface and logging out">
  1074         <li class="listitem" style="list-style-type: *">
   251 <div class="titlepage"><div><div><h3 class="title">
  1075          <p id="ch8ult_module_plan_1a">
   252 <a name="id2769560"></a>2.1. Logging in, activating the user interface and logging out</h3></div></div></div>
  1076           Linux was made to keep on running:
   253 <p id="ch8ult_module_plan_22"></a>In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PC−based Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multi−user features, or in graphical console mode, which looks better but eats more system resources.</p>
  1077          </p>
   254 <div class="section" title="2.1.1. Graphical Mode">
  1078         </li>
   255 <div class="titlepage"><div><div><h4 class="title">
  1079        </ul>
   256 <a name="id2769590"></a>2.1.1. Graphical Mode</h4></div></div></div>
  1080       </div>
   257 <p id="ch8ult_module_plan_23"></a>This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.</p>
  1081       <p id="ch8ult_module_plan_1b">
   258 <p id="ch8ult_module_plan_24"></a>To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click <span class="emphasis"><em>OK</em></span> or press <span class="emphasis"><em>Enter</em></span>.
  1082        As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
   259 It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.</p>
  1083       </p>
   260 <p id="ch8ult_module_plan_25"></a>After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.</p>
  1084       <div class="itemizedlist">
   261 <p id="ch8ult_module_plan_26"></a>To continue, you will need to open a <span class="emphasis"><em>terminal window</em></span> or <span class="emphasis"><em>xterm</em></span> for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the <span class="emphasis"><em>Applications−&gt;Utilities-&gt;System Tools</em></span> or <span class="emphasis"><em>Internet menu</em></span>, depending on what window manager you are using. There might be icons that you can use as a shortcut to get an <span class="emphasis"><em>xterm</em></span> window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.</p>
  1085        <ul class="itemizedlist" type="*">
   262 <p id="ch8ult_module_plan_27"></a>While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old point−n−click method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.</p>
  1086         <li class="listitem" style="list-style-type: *">
   263 <p id="ch8ult_module_plan_28"></a>A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)</p>
  1087          <p id="ch8ult_module_plan_1c">
   264 <p id="ch8ult_module_plan_29"></a>Another common form for a prompt is this one:
  1088           Linux is secure and versatile:
   265 [</p>
  1089          </p>
   266 <div class="reference">
  1090         </li>
   267 <div class="titlepage"><hr></div>user@host</div>
  1091        </ul>
   268 <p> dir]</p>
  1092       </div>
   269 <p id="ch8ult_module_plan_2a"></a>In the above example, <span class="emphasis"><em>user</em></span> will be your login name, <span class="emphasis"><em>hosts</em></span> the name of the machine you are working on, and <span class="emphasis"><em>dir</em></span> an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the <span class="emphasis"><em>logout</em></span> icon or find <span class="emphasis"><em>Log Out</em></span> in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.</p>
  1093       <p id="ch8ult_module_plan_1d">
   270 <p id="ch8ult_module_plan_2b"></a>When you see the login screen again, asking to enter user name and password, logout was successful.</p>
  1094        The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
   271 </div>
  1095       </p>
   272 <div class="section" title="2.1.2. Text Mode">
  1096       <div class="itemizedlist">
   273 <div class="titlepage"><div><div><h4 class="title">
  1097        <ul class="itemizedlist" type="*">
   274 <a name="id2769750"></a>2.1.2. Text Mode</h4></div></div></div>
  1098         <li class="listitem" style="list-style-type: *">
   275 <p id="ch8ult_module_plan_2c"></a>One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.</p>
  1099          <p id="ch8ult_module_plan_1e">
   276 <p id="ch8ult_module_plan_2d"></a>The login is different from a graphical login, in that you have to hit the <span class="emphasis"><em>Enter</em></span> key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another <span class="emphasis"><em>Enter</em></span>. You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
  1100           Linux is scalable:
   277 reasons.</p>
  1101          </p>
   278 <p id="ch8ult_module_plan_2e"></a>When the system has accepted you as a valid user, you may get some more information, called the <span class="emphasis"><em>message of the day</em></span>, which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.</p>
  1102         </li>
   279 <p id="ch8ult_module_plan_2f"></a>Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a non−privileged user.</p>
  1103        </ul>
   280 <p id="ch8ult_module_plan_30"></a>Logging out is done by entering the <span class="emphasis"><em>logout</em></span> command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't power−off the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!</p>
  1104       </div>
   281 </div>
  1105       <p id="ch8ult_module_plan_1f">
   282 </div>
  1106        From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
   283 </div>
  1107       </p>
   284 <div class="section" title="3. Basic Commands">
  1108       <div class="itemizedlist">
   285 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  1109        <ul class="itemizedlist" type="*">
   286 <a name="id2769839"></a>3. Basic Commands</h2></div></div></div>
  1110         <li class="listitem" style="list-style-type: *">
   287 <div class="section" title="3.1. ls">
  1111          <p id="ch8ult_module_plan_20">
   288 <div class="titlepage"><div><div><h3 class="title">
  1112           The Linux OS and Linux applications have very short debugtimes:
   289 <a name="id2769848"></a>3.1. ls</h3></div></div></div>
  1113          </p>
   290 <p id="ch8ult_module_plan_31"></a>When invoked without any arguments, <span class="emphasis"><em>ls</em></span> lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name <span class="emphasis"><em>ls</em></span> is derived from <span class="emphasis"><em>list segments</em></span> which was used in earlier systems.</p>
  1114         </li>
   291 <p id="ch8ult_module_plan_32"></a>Files whose names start with "." are not listed, unless the <span class="emphasis"><em>-a</em></span> flag is specified or the files are specified explicitly.</p>
  1115        </ul>
   292 <p id="ch8ult_module_plan_33"></a>Without options, <span class="emphasis"><em>ls</em></span> displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:</p>
  1116       </div>
   293 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  1117       <p id="ch8ult_module_plan_21">
   294 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_34"></a><span class="emphasis"><em>-l</em></span> long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename</p></li>
  1118        Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
   295 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_35"></a><span class="emphasis"><em>-F</em></span> appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.</p></li>
  1119       </p>
   296 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_36"></a><span class="emphasis"><em>-a</em></span> lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.</p></li>
  1120      </div>
   297 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_37"></a><span class="emphasis"><em>-R</em></span> recursively lists subdirectories. The command ls -R / would therefore list all files.</p></li>
  1121     </div>
   298 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_38"></a><span class="emphasis"><em>-d</em></span> shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.</p></li>
  1122     <div class="section" title="2.Getting Started">
   299 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_39"></a><span class="emphasis"><em>-t</em></span> sort the list of files by modification time.</p></li>
  1123      <div class="titlepage">
   300 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_3a"></a><span class="emphasis"><em>-h</em></span> print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)</p></li>
  1124       <div>
   301 </ul></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_3b"></a>In some environments, providing the option <span class="emphasis"><em>--color</em></span> (for GNU ls) or <span class="emphasis"><em>-G</em></span> (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as <span class="emphasis"><em>-F</em></span> would. To determine what color to use for a file, GNU <span class="emphasis"><em>ls</em></span> checks the Unix file type, the file permissions, and the file extension, while FreeBSD <span class="emphasis"><em>ls</em></span> checks only the Unix file type and file permissions.:</p>
  1125        <div>
   302 <pre class="programlisting">$ ls
  1126         <h2 class="title" style="clear: both">
       
  1127          <a name="id2662646">
       
  1128          </a>
       
  1129          2.Getting Started
       
  1130         </h2>
       
  1131        </div>
       
  1132       </div>
       
  1133      </div>
       
  1134      <div class="section" title="2.1.Logging in, activating the user interface and logging out">
       
  1135       <div class="titlepage">
       
  1136        <div>
       
  1137         <div>
       
  1138          <h3 class="title">
       
  1139           <a name="id2662654">
       
  1140           </a>
       
  1141           2.1.Logging in, activating the user interface and logging out
       
  1142          </h3>
       
  1143         </div>
       
  1144        </div>
       
  1145       </div>
       
  1146       <p id="ch8ult_module_plan_22">
       
  1147        In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
       
  1148       </p>
       
  1149       <div class="section" title="2.1.1.Graphical Mode">
       
  1150        <div class="titlepage">
       
  1151         <div>
       
  1152          <div>
       
  1153           <h4 class="title">
       
  1154            <a name="id2662685">
       
  1155            </a>
       
  1156            2.1.1.Graphical Mode
       
  1157           </h4>
       
  1158          </div>
       
  1159         </div>
       
  1160        </div>
       
  1161        <p id="ch8ult_module_plan_23">
       
  1162         This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
       
  1163        </p>
       
  1164        <p id="ch8ult_module_plan_24">
       
  1165         To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
       
  1166         <span class="emphasis">
       
  1167          <em>
       
  1168           OK
       
  1169          </em>
       
  1170         </span>
       
  1171         or press
       
  1172         <span class="emphasis">
       
  1173          <em>
       
  1174           Enter
       
  1175          </em>
       
  1176         </span>
       
  1177         .
       
  1178 It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
       
  1179        </p>
       
  1180        <p id="ch8ult_module_plan_25">
       
  1181         After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
       
  1182        </p>
       
  1183        <p id="ch8ult_module_plan_26">
       
  1184         To continue, you will need to open a
       
  1185         <span class="emphasis">
       
  1186          <em>
       
  1187           terminal window
       
  1188          </em>
       
  1189         </span>
       
  1190         or
       
  1191         <span class="emphasis">
       
  1192          <em>
       
  1193           xterm
       
  1194          </em>
       
  1195         </span>
       
  1196         for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
       
  1197         <span class="emphasis">
       
  1198          <em>
       
  1199           Applications&gt;Utilities-&gt;System Tools
       
  1200          </em>
       
  1201         </span>
       
  1202         or
       
  1203         <span class="emphasis">
       
  1204          <em>
       
  1205           Internet menu
       
  1206          </em>
       
  1207         </span>
       
  1208         , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
       
  1209         <span class="emphasis">
       
  1210          <em>
       
  1211           xterm
       
  1212          </em>
       
  1213         </span>
       
  1214         window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
       
  1215        </p>
       
  1216        <p id="ch8ult_module_plan_27">
       
  1217         While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
       
  1218        </p>
       
  1219        <p id="ch8ult_module_plan_28">
       
  1220         A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
       
  1221        </p>
       
  1222        <p id="ch8ult_module_plan_29">
       
  1223         Another common form for a prompt is this one:
       
  1224 [
       
  1225        </p>
       
  1226        <div class="reference">
       
  1227         <div class="titlepage">
       
  1228          <hr />
       
  1229         </div>
       
  1230         user@host
       
  1231        </div>
       
  1232        <p>
       
  1233         dir]
       
  1234        </p>
       
  1235        <p id="ch8ult_module_plan_2a">
       
  1236         In the above example,
       
  1237         <span class="emphasis">
       
  1238          <em>
       
  1239           user
       
  1240          </em>
       
  1241         </span>
       
  1242         will be your login name,
       
  1243         <span class="emphasis">
       
  1244          <em>
       
  1245           hosts
       
  1246          </em>
       
  1247         </span>
       
  1248         the name of the machine you are working on, and
       
  1249         <span class="emphasis">
       
  1250          <em>
       
  1251           dir
       
  1252          </em>
       
  1253         </span>
       
  1254         an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
       
  1255         <span class="emphasis">
       
  1256          <em>
       
  1257           logout
       
  1258          </em>
       
  1259         </span>
       
  1260         icon or find
       
  1261         <span class="emphasis">
       
  1262          <em>
       
  1263           Log Out
       
  1264          </em>
       
  1265         </span>
       
  1266         in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
       
  1267        </p>
       
  1268        <p id="ch8ult_module_plan_2b">
       
  1269         When you see the login screen again, asking to enter user name and password, logout was successful.
       
  1270        </p>
       
  1271       </div>
       
  1272       <div class="section" title="2.1.2.Text Mode">
       
  1273        <div class="titlepage">
       
  1274         <div>
       
  1275          <div>
       
  1276           <h4 class="title">
       
  1277            <a name="id2662844">
       
  1278            </a>
       
  1279            2.1.2.Text Mode
       
  1280           </h4>
       
  1281          </div>
       
  1282         </div>
       
  1283        </div>
       
  1284        <p id="ch8ult_module_plan_2c">
       
  1285         One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
       
  1286        </p>
       
  1287        <p id="ch8ult_module_plan_2d">
       
  1288         The login is different from a graphical login, in that you have to hit the
       
  1289         <span class="emphasis">
       
  1290          <em>
       
  1291           Enter
       
  1292          </em>
       
  1293         </span>
       
  1294         key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
       
  1295         <span class="emphasis">
       
  1296          <em>
       
  1297           Enter
       
  1298          </em>
       
  1299         </span>
       
  1300         . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
       
  1301 reasons.
       
  1302        </p>
       
  1303        <p id="ch8ult_module_plan_2e">
       
  1304         When the system has accepted you as a valid user, you may get some more information, called the
       
  1305         <span class="emphasis">
       
  1306          <em>
       
  1307           message of the day
       
  1308          </em>
       
  1309         </span>
       
  1310         , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
       
  1311        </p>
       
  1312        <p id="ch8ult_module_plan_2f">
       
  1313         Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
       
  1314        </p>
       
  1315        <p id="ch8ult_module_plan_30">
       
  1316         Logging out is done by entering the
       
  1317         <span class="emphasis">
       
  1318          <em>
       
  1319           logout
       
  1320          </em>
       
  1321         </span>
       
  1322         command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
       
  1323        </p>
       
  1324       </div>
       
  1325      </div>
       
  1326     </div>
       
  1327     <div class="section" title="3.Basic Commands">
       
  1328      <div class="titlepage">
       
  1329       <div>
       
  1330        <div>
       
  1331         <h2 class="title" style="clear: both">
       
  1332          <a name="id2662934">
       
  1333          </a>
       
  1334          3.Basic Commands
       
  1335         </h2>
       
  1336        </div>
       
  1337       </div>
       
  1338      </div>
       
  1339      <div class="section" title="3.1.ls">
       
  1340       <div class="titlepage">
       
  1341        <div>
       
  1342         <div>
       
  1343          <h3 class="title">
       
  1344           <a name="id2662942">
       
  1345           </a>
       
  1346           3.1.ls
       
  1347          </h3>
       
  1348         </div>
       
  1349        </div>
       
  1350       </div>
       
  1351       <p id="ch8ult_module_plan_31">
       
  1352        When invoked without any arguments,
       
  1353        <span class="emphasis">
       
  1354         <em>
       
  1355          ls
       
  1356         </em>
       
  1357        </span>
       
  1358        lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
       
  1359        <span class="emphasis">
       
  1360         <em>
       
  1361          ls
       
  1362         </em>
       
  1363        </span>
       
  1364        is derived from
       
  1365        <span class="emphasis">
       
  1366         <em>
       
  1367          list segments
       
  1368         </em>
       
  1369        </span>
       
  1370        which was used in earlier systems.
       
  1371       </p>
       
  1372       <p id="ch8ult_module_plan_32">
       
  1373        Files whose names start with "." are not listed, unless the
       
  1374        <span class="emphasis">
       
  1375         <em>
       
  1376          -a
       
  1377         </em>
       
  1378        </span>
       
  1379        flag is specified or the files are specified explicitly.
       
  1380       </p>
       
  1381       <p id="ch8ult_module_plan_33">
       
  1382        Without options,
       
  1383        <span class="emphasis">
       
  1384         <em>
       
  1385          ls
       
  1386         </em>
       
  1387        </span>
       
  1388        displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
       
  1389       </p>
       
  1390       <span style="color: red">
       
  1391        &lt;block_quote&gt;
       
  1392        <div class="itemizedlist">
       
  1393         <ul class="itemizedlist" type="*">
       
  1394          <li class="listitem" style="list-style-type: *">
       
  1395           <p id="ch8ult_module_plan_34">
       
  1396            <span class="emphasis">
       
  1397             <em>
       
  1398              -l
       
  1399             </em>
       
  1400            </span>
       
  1401            long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
       
  1402           </p>
       
  1403          </li>
       
  1404          <li class="listitem" style="list-style-type: *">
       
  1405           <p id="ch8ult_module_plan_35">
       
  1406            <span class="emphasis">
       
  1407             <em>
       
  1408              -F
       
  1409             </em>
       
  1410            </span>
       
  1411            appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
       
  1412           </p>
       
  1413          </li>
       
  1414          <li class="listitem" style="list-style-type: *">
       
  1415           <p id="ch8ult_module_plan_36">
       
  1416            <span class="emphasis">
       
  1417             <em>
       
  1418              -a
       
  1419             </em>
       
  1420            </span>
       
  1421            lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
       
  1422           </p>
       
  1423          </li>
       
  1424          <li class="listitem" style="list-style-type: *">
       
  1425           <p id="ch8ult_module_plan_37">
       
  1426            <span class="emphasis">
       
  1427             <em>
       
  1428              -R
       
  1429             </em>
       
  1430            </span>
       
  1431            recursively lists subdirectories. The command ls -R / would therefore list all files.
       
  1432           </p>
       
  1433          </li>
       
  1434          <li class="listitem" style="list-style-type: *">
       
  1435           <p id="ch8ult_module_plan_38">
       
  1436            <span class="emphasis">
       
  1437             <em>
       
  1438              -d
       
  1439             </em>
       
  1440            </span>
       
  1441            shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
       
  1442           </p>
       
  1443          </li>
       
  1444          <li class="listitem" style="list-style-type: *">
       
  1445           <p id="ch8ult_module_plan_39">
       
  1446            <span class="emphasis">
       
  1447             <em>
       
  1448              -t
       
  1449             </em>
       
  1450            </span>
       
  1451            sort the list of files by modification time.
       
  1452           </p>
       
  1453          </li>
       
  1454          <li class="listitem" style="list-style-type: *">
       
  1455           <p id="ch8ult_module_plan_3a">
       
  1456            <span class="emphasis">
       
  1457             <em>
       
  1458              -h
       
  1459             </em>
       
  1460            </span>
       
  1461            print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
       
  1462           </p>
       
  1463          </li>
       
  1464         </ul>
       
  1465        </div>
       
  1466        &lt;/block_quote&gt;
       
  1467       </span>
       
  1468       <p id="ch8ult_module_plan_3b">
       
  1469        In some environments, providing the option
       
  1470        <span class="emphasis">
       
  1471         <em>
       
  1472          --color
       
  1473         </em>
       
  1474        </span>
       
  1475        (for GNU ls) or
       
  1476        <span class="emphasis">
       
  1477         <em>
       
  1478          -G
       
  1479         </em>
       
  1480        </span>
       
  1481        (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
       
  1482        <span class="emphasis">
       
  1483         <em>
       
  1484          -F
       
  1485         </em>
       
  1486        </span>
       
  1487        would. To determine what color to use for a file, GNU
       
  1488        <span class="emphasis">
       
  1489         <em>
       
  1490          ls
       
  1491         </em>
       
  1492        </span>
       
  1493        checks the Unix file type, the file permissions, and the file extension, while FreeBSD
       
  1494        <span class="emphasis">
       
  1495         <em>
       
  1496          ls
       
  1497         </em>
       
  1498        </span>
       
  1499        checks only the Unix file type and file permissions.:
       
  1500       </p>
       
  1501       <pre class="programlisting">
       
  1502        $ ls
   303 jeeves.rst psmith.html blandings.html
  1503 jeeves.rst psmith.html blandings.html
   304 $ ls -l
  1504 $ ls -l
   305 drwxr--r--   1 plum  editors   4096  jeeves
  1505 drwxr--r--   1 plum  editors   4096  jeeves
   306 -rw-r--r--   1 plum  editors  30405  psmith
  1506 -rw-r--r--   1 plum  editors  30405  psmith
   307 -r-xr-xr-x   1 plum  plum      8460  blandings</pre>
  1507 -r-xr-xr-x   1 plum  plum      8460  blandings
   308 <p id="ch8ult_module_plan_3c"></a>Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.</p>
  1508       </pre>
   309 </div>
  1509       <p id="ch8ult_module_plan_3c">
   310 <div class="section" title="3.2. date">
  1510        Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
   311 <div class="titlepage"><div><div><h3 class="title">
  1511       </p>
   312 <a name="id2770012"></a>3.2. date</h3></div></div></div>
  1512      </div>
   313 <p id="ch8ult_module_plan_3d"></a>The Unix date command displays the time and date. The super-user can use it to set the system clock.</p>
  1513      <div class="section" title="3.2.date">
   314 <p id="ch8ult_module_plan_3e"></a>With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:</p>
  1514       <div class="titlepage">
   315 <pre class="programlisting">$date
  1515        <div>
   316 Tue Sep  8 12:01:45 IST 2009</pre>
  1516         <div>
   317 <p id="ch8ult_module_plan_3f"></a>On some systems to set the current date and time to September 8, 2004 01:22 you type:</p>
  1517          <h3 class="title">
   318 <pre class="programlisting">$date --set="20040908 01:22"</pre>
  1518           <a name="id2663106">
   319 <p id="ch8ult_module_plan_40"></a>In order to view the various options for the <span class="emphasis"><em>date</em></span> command, type:</p>
  1519           </a>
   320 <pre class="programlisting">$man date</pre>
  1520           3.2.date
   321 <p id="ch8ult_module_plan_41"></a>This will take you to the "Manual" page comprising of all the details on the <span class="emphasis"><em>date</em></span> command. You can return to the terminal from the "man" page by pressing the <span class="emphasis"><em>Esc</em></span> key in the keyboard and typing ":q" in that order.</p>
  1521          </h3>
   322 </div>
  1522         </div>
   323 <div class="section" title="3.3. cd">
  1523        </div>
   324 <div class="titlepage"><div><div><h3 class="title">
  1524       </div>
   325 <a name="id2770073"></a>3.3. cd</h3></div></div></div>
  1525       <p id="ch8ult_module_plan_3d">
   326 <p id="ch8ult_module_plan_42"></a>This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, “ cd ..” can be used.</p>
  1526        The Unix date command displays the time and date. The super-user can use it to set the system clock.
   327 <p id="ch8ult_module_plan_43"></a>One dot '.' represents the current directory while two dots '..' represent the parent directory.</p>
  1527       </p>
   328 <p id="ch8ult_module_plan_44"></a>“ cd -” will return you to the previous directory (a bit like an “undo”).</p>
  1528       <p id="ch8ult_module_plan_3e">
   329 <p id="ch8ult_module_plan_45"></a>You can also use cd absolute path or cd relative path (see below):</p>
  1529        With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
   330 <p id="ch8ult_module_plan_46"></a>Absolute paths:</p>
  1530       </p>
   331 <span style="color: red">&lt;block_quote&gt;<p id="ch8ult_module_plan_47"></a>An “ absolute path” is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.</p>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_48"></a>For example to get to /boot/grub you would type:</p>
  1531       <pre class="programlisting">
   332 <pre class="programlisting">$cd /boot/grub</pre>
  1532        $date
   333 <p id="ch8ult_module_plan_49"></a>This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).</p>
  1533 Tue Sep  8 12:01:45 IST 2009
   334 <p id="ch8ult_module_plan_4a"></a>Relative paths:</p>
  1534       </pre>
   335 <span style="color: red">&lt;block_quote&gt;<p id="ch8ult_module_plan_4b"></a>A “ relative path” doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.</p>
  1535       <p id="ch8ult_module_plan_3f">
   336 <p id="ch8ult_module_plan_4c"></a>For example if you are in root's home directory and want to get to /root/music, you type:</p>
  1536        On some systems to set the current date and time to September 8, 2004 01:22 you type:
   337 <pre class="programlisting">$ cd music</pre>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_4d"></a>Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.</p>
  1537       </p>
   338 </div>
  1538       <pre class="programlisting">
   339 <div class="section" title="3.4. who">
  1539        $date --set="20040908 01:22"
   340 <div class="titlepage"><div><div><h3 class="title">
  1540       </pre>
   341 <a name="id2770176"></a>3.4. who</h3></div></div></div>
  1541       <p id="ch8ult_module_plan_40">
   342 <p id="ch8ult_module_plan_4e"></a>The standard Unix command <span class="emphasis"><em>who</em></span> displays a list of users who are currently logged into a computer.</p>
  1542        In order to view the various options for the
   343 <p id="ch8ult_module_plan_4f"></a>The <span class="emphasis"><em>who</em></span> command is related to the command <span class="emphasis"><em>w</em></span>, which provides the same information but also displays additional data and statistics.:</p>
  1543        <span class="emphasis">
   344 <pre class="programlisting">$who
  1544         <em>
       
  1545          date
       
  1546         </em>
       
  1547        </span>
       
  1548        command, type:
       
  1549       </p>
       
  1550       <pre class="programlisting">
       
  1551        $man date
       
  1552       </pre>
       
  1553       <p id="ch8ult_module_plan_41">
       
  1554        This will take you to the "Manual" page comprising of all the details on the
       
  1555        <span class="emphasis">
       
  1556         <em>
       
  1557          date
       
  1558         </em>
       
  1559        </span>
       
  1560        command. You can return to the terminal from the "man" page by pressing the
       
  1561        <span class="emphasis">
       
  1562         <em>
       
  1563          Esc
       
  1564         </em>
       
  1565        </span>
       
  1566        key in the keyboard and typing ":q" in that order.
       
  1567       </p>
       
  1568      </div>
       
  1569      <div class="section" title="3.3.cd">
       
  1570       <div class="titlepage">
       
  1571        <div>
       
  1572         <div>
       
  1573          <h3 class="title">
       
  1574           <a name="id2663167">
       
  1575           </a>
       
  1576           3.3.cd
       
  1577          </h3>
       
  1578         </div>
       
  1579        </div>
       
  1580       </div>
       
  1581       <p id="ch8ult_module_plan_42">
       
  1582        This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered,  cd .. can be used.
       
  1583       </p>
       
  1584       <p id="ch8ult_module_plan_43">
       
  1585        One dot '.' represents the current directory while two dots '..' represent the parent directory.
       
  1586       </p>
       
  1587       <p id="ch8ult_module_plan_44">
       
  1588        cd - will return you to the previous directory (a bit like an undo).
       
  1589       </p>
       
  1590       <p id="ch8ult_module_plan_45">
       
  1591        You can also use cd absolute path or cd relative path (see below):
       
  1592       </p>
       
  1593       <p id="ch8ult_module_plan_46">
       
  1594        Absolute paths:
       
  1595       </p>
       
  1596       <span style="color: red">
       
  1597        &lt;block_quote&gt;
       
  1598       </span>
       
  1599       <p id="ch8ult_module_plan_47">
       
  1600        An  absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
       
  1601       </p>
       
  1602       &lt;/block_quote&gt;
       
  1603       <p id="ch8ult_module_plan_48">
       
  1604        For example to get to /boot/grub you would type:
       
  1605       </p>
       
  1606       <pre class="programlisting">
       
  1607        $cd /boot/grub
       
  1608       </pre>
       
  1609       <p id="ch8ult_module_plan_49">
       
  1610        This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
       
  1611       </p>
       
  1612       <p id="ch8ult_module_plan_4a">
       
  1613        Relative paths:
       
  1614       </p>
       
  1615       <span style="color: red">
       
  1616        &lt;block_quote&gt;
       
  1617       </span>
       
  1618       <p id="ch8ult_module_plan_4b">
       
  1619        A  relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
       
  1620       </p>
       
  1621       <p id="ch8ult_module_plan_4c">
       
  1622        For example if you are in root's home directory and want to get to /root/music, you type:
       
  1623       </p>
       
  1624       <pre class="programlisting">
       
  1625        $ cd music
       
  1626       </pre>
       
  1627       &lt;/block_quote&gt;
       
  1628       <p id="ch8ult_module_plan_4d">
       
  1629        Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
       
  1630       </p>
       
  1631      </div>
       
  1632      <div class="section" title="3.4.who">
       
  1633       <div class="titlepage">
       
  1634        <div>
       
  1635         <div>
       
  1636          <h3 class="title">
       
  1637           <a name="id2663271">
       
  1638           </a>
       
  1639           3.4.who
       
  1640          </h3>
       
  1641         </div>
       
  1642        </div>
       
  1643       </div>
       
  1644       <p id="ch8ult_module_plan_4e">
       
  1645        The standard Unix command
       
  1646        <span class="emphasis">
       
  1647         <em>
       
  1648          who
       
  1649         </em>
       
  1650        </span>
       
  1651        displays a list of users who are currently logged into a computer.
       
  1652       </p>
       
  1653       <p id="ch8ult_module_plan_4f">
       
  1654        The
       
  1655        <span class="emphasis">
       
  1656         <em>
       
  1657          who
       
  1658         </em>
       
  1659        </span>
       
  1660        command is related to the command
       
  1661        <span class="emphasis">
       
  1662         <em>
       
  1663          w
       
  1664         </em>
       
  1665        </span>
       
  1666        , which provides the same information but also displays additional data and statistics.:
       
  1667       </p>
       
  1668       <pre class="programlisting">
       
  1669        $who
   345 beeblebrox tty7         2009-09-08 10:50 (:0)
  1670 beeblebrox tty7         2009-09-08 10:50 (:0)
   346 beeblebrox pts/0        2009-09-08 11:25 (:0.0)
  1671 beeblebrox pts/0        2009-09-08 11:25 (:0.0)
   347 dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
  1672 dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
   348 beeblebrox pts/2        2009-09-08 18:53 (:0.0)</pre>
  1673 beeblebrox pts/2        2009-09-08 18:53 (:0.0)
   349 <p id="ch8ult_module_plan_50"></a>The command can be invoked with the arguments <span class="emphasis"><em>am i</em></span> or <span class="emphasis"><em>am I</em></span> (so it is invoked as <span class="emphasis"><em>who am i</em></span> or * who am I*), showing information about the current terminal only (see the <span class="emphasis"><em>-m</em></span> option below, of which this invocation is equivalent).</p>
  1674       </pre>
   350 <p id="ch8ult_module_plan_51"></a>In order to find out the various options that can be appended to the <span class="emphasis"><em>who</em></span> command, check the <span class="emphasis"><em>man</em></span> page by typing out the following in the terminal:</p>
  1675       <p id="ch8ult_module_plan_50">
   351 <pre class="programlisting">$man who</pre>
  1676        The command can be invoked with the arguments
   352 <p id="ch8ult_module_plan_52"></a>This will take you to the "Manual" page containing details about the <span class="emphasis"><em>who</em></span> command</p>
  1677        <span class="emphasis">
   353 </div>
  1678         <em>
   354 <div class="section" title="3.5. mkdir">
  1679          am i
   355 <div class="titlepage"><div><div><h3 class="title">
  1680         </em>
   356 <a name="id2770259"></a>3.5. mkdir</h3></div></div></div>
  1681        </span>
   357 <p id="ch8ult_module_plan_53"></a>This command is used to make a new directory. Normal usage is as straightforward as follows:</p>
  1682        or
   358 <pre class="programlisting">$mkdir name_of_directory</pre>
  1683        <span class="emphasis">
   359 <p id="ch8ult_module_plan_54"></a>Where <span class="emphasis"><em>name_of_directory</em></span> is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and <span class="emphasis"><em>mkdir</em></span> will try to create all of them.</p>
  1684         <em>
   360 <div class="section" title="3.5.1. Options">
  1685          am I
   361 <div class="titlepage"><div><div><h4 class="title">
  1686         </em>
   362 <a name="id2770291"></a>3.5.1. Options</h4></div></div></div>
  1687        </span>
   363 <p id="ch8ult_module_plan_55"></a>On Unix-like operating systems, <span class="emphasis"><em>mkdir</em></span> takes options. Three of the most common options are:</p>
  1688        (so it is invoked as
   364 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  1689        <span class="emphasis">
   365 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_56"></a><span class="emphasis"><em>-p</em></span>: will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.</p></li>
  1690         <em>
   366 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_57"></a><span class="emphasis"><em>-v</em></span>: display each directory that mkdir creates. Most often used with -p.</p></li>
  1691          who am i
   367 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_58"></a><span class="emphasis"><em>-m</em></span>: specify the octal permissions of directories created by mkdir.</p></li>
  1692         </em>
   368 </ul></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_59"></a><span class="emphasis"><em>-p</em></span> is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.</p>
  1693        </span>
   369 </div>
  1694        or * who am I*), showing information about the current terminal only (see the
   370 <div class="section" title="3.5.2. Examples">
  1695        <span class="emphasis">
   371 <div class="titlepage"><div><div><h4 class="title">
  1696         <em>
   372 <a name="id2770353"></a>3.5.2. Examples</h4></div></div></div>
  1697          -m
   373 <p id="ch8ult_module_plan_5a"></a>An example of <span class="emphasis"><em>-p</em></span> in action is:</p>
  1698         </em>
   374 <pre class="programlisting">$mkdir -p /tmp/a/b/c</pre>
  1699        </span>
   375 <p id="ch8ult_module_plan_5b"></a>If <span class="emphasis"><em>/tmp/a</em></span> exists but <span class="emphasis"><em>/tmp/a/b</em></span> does not, mkdir will create <span class="emphasis"><em>/tmp/a/b</em></span> before creating <span class="emphasis"><em>/tmp/a/b/c</em></span>.</p>
  1700        option below, of which this invocation is equivalent).
   376 <p id="ch8ult_module_plan_5c"></a>And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):</p>
  1701       </p>
   377 <pre class="programlisting">$mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}</pre>
  1702       <p id="ch8ult_module_plan_51">
   378 <p id="ch8ult_module_plan_5d"></a>This will create:</p>
  1703        In order to find out the various options that can be appended to the
   379 <span style="color: red">&lt;definition_list&gt;<span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;tmpdir  - branches&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  1704        <span class="emphasis">
   380 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_5e"></a>tag</p></li>
  1705         <em>
   381 <li class="listitem" style="list-style-type: *"><span style="color: red">&lt;definition_list&gt;<span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;trunk - sources - includes&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_5f"></a>docs</p></li></ul></div>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span>&lt;/definition_list&gt;</span></li>
  1706          who
   382 </ul></div>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span>&lt;/definition_list&gt;</span>
  1707         </em>
   383 </div>
  1708        </span>
   384 </div>
  1709        command, check the
   385 </div>
  1710        <span class="emphasis">
   386 <div class="section" title="4. Getting Help">
  1711         <em>
   387 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  1712          man
   388 <a name="id2770440"></a>4. Getting Help</h2></div></div></div>
  1713         </em>
   389 <div class="section" title="4.1. apropos and whatis">
  1714        </span>
   390 <div class="titlepage"><div><div><h3 class="title">
  1715        page by typing out the following in the terminal:
   391 <a name="id2770448"></a>4.1. apropos and whatis</h3></div></div></div>
  1716       </p>
   392 <p id="ch8ult_module_plan_60"></a>This is a command to search the manual pages files in Unix and Unix-like operating systems.</p>
  1717       <pre class="programlisting">
   393 <pre class="programlisting">$ apropos grep
  1718        $man who
       
  1719       </pre>
       
  1720       <p id="ch8ult_module_plan_52">
       
  1721        This will take you to the "Manual" page containing details about the
       
  1722        <span class="emphasis">
       
  1723         <em>
       
  1724          who
       
  1725         </em>
       
  1726        </span>
       
  1727        command
       
  1728       </p>
       
  1729      </div>
       
  1730      <div class="section" title="3.5.mkdir">
       
  1731       <div class="titlepage">
       
  1732        <div>
       
  1733         <div>
       
  1734          <h3 class="title">
       
  1735           <a name="id2663353">
       
  1736           </a>
       
  1737           3.5.mkdir
       
  1738          </h3>
       
  1739         </div>
       
  1740        </div>
       
  1741       </div>
       
  1742       <p id="ch8ult_module_plan_53">
       
  1743        This command is used to make a new directory. Normal usage is as straightforward as follows:
       
  1744       </p>
       
  1745       <pre class="programlisting">
       
  1746        $mkdir name_of_directory
       
  1747       </pre>
       
  1748       <p id="ch8ult_module_plan_54">
       
  1749        Where
       
  1750        <span class="emphasis">
       
  1751         <em>
       
  1752          name_of_directory
       
  1753         </em>
       
  1754        </span>
       
  1755        is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
       
  1756        <span class="emphasis">
       
  1757         <em>
       
  1758          mkdir
       
  1759         </em>
       
  1760        </span>
       
  1761        will try to create all of them.
       
  1762       </p>
       
  1763       <div class="section" title="3.5.1.Options">
       
  1764        <div class="titlepage">
       
  1765         <div>
       
  1766          <div>
       
  1767           <h4 class="title">
       
  1768            <a name="id2663385">
       
  1769            </a>
       
  1770            3.5.1.Options
       
  1771           </h4>
       
  1772          </div>
       
  1773         </div>
       
  1774        </div>
       
  1775        <p id="ch8ult_module_plan_55">
       
  1776         On Unix-like operating systems,
       
  1777         <span class="emphasis">
       
  1778          <em>
       
  1779           mkdir
       
  1780          </em>
       
  1781         </span>
       
  1782         takes options. Three of the most common options are:
       
  1783        </p>
       
  1784        <span style="color: red">
       
  1785         &lt;block_quote&gt;
       
  1786         <div class="itemizedlist">
       
  1787          <ul class="itemizedlist" type="*">
       
  1788           <li class="listitem" style="list-style-type: *">
       
  1789            <p id="ch8ult_module_plan_56">
       
  1790             <span class="emphasis">
       
  1791              <em>
       
  1792               -p
       
  1793              </em>
       
  1794             </span>
       
  1795             : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
       
  1796            </p>
       
  1797           </li>
       
  1798           <li class="listitem" style="list-style-type: *">
       
  1799            <p id="ch8ult_module_plan_57">
       
  1800             <span class="emphasis">
       
  1801              <em>
       
  1802               -v
       
  1803              </em>
       
  1804             </span>
       
  1805             : display each directory that mkdir creates. Most often used with -p.
       
  1806            </p>
       
  1807           </li>
       
  1808           <li class="listitem" style="list-style-type: *">
       
  1809            <p id="ch8ult_module_plan_58">
       
  1810             <span class="emphasis">
       
  1811              <em>
       
  1812               -m
       
  1813              </em>
       
  1814             </span>
       
  1815             : specify the octal permissions of directories created by mkdir.
       
  1816            </p>
       
  1817           </li>
       
  1818          </ul>
       
  1819         </div>
       
  1820         &lt;/block_quote&gt;
       
  1821        </span>
       
  1822        <p id="ch8ult_module_plan_59">
       
  1823         <span class="emphasis">
       
  1824          <em>
       
  1825           -p
       
  1826          </em>
       
  1827         </span>
       
  1828         is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
       
  1829        </p>
       
  1830       </div>
       
  1831       <div class="section" title="3.5.2.Examples">
       
  1832        <div class="titlepage">
       
  1833         <div>
       
  1834          <div>
       
  1835           <h4 class="title">
       
  1836            <a name="id2663447">
       
  1837            </a>
       
  1838            3.5.2.Examples
       
  1839           </h4>
       
  1840          </div>
       
  1841         </div>
       
  1842        </div>
       
  1843        <p id="ch8ult_module_plan_5a">
       
  1844         An example of
       
  1845         <span class="emphasis">
       
  1846          <em>
       
  1847           -p
       
  1848          </em>
       
  1849         </span>
       
  1850         in action is:
       
  1851        </p>
       
  1852        <pre class="programlisting">
       
  1853         $mkdir -p /tmp/a/b/c
       
  1854        </pre>
       
  1855        <p id="ch8ult_module_plan_5b">
       
  1856         If
       
  1857         <span class="emphasis">
       
  1858          <em>
       
  1859           /tmp/a
       
  1860          </em>
       
  1861         </span>
       
  1862         exists but
       
  1863         <span class="emphasis">
       
  1864          <em>
       
  1865           /tmp/a/b
       
  1866          </em>
       
  1867         </span>
       
  1868         does not, mkdir will create
       
  1869         <span class="emphasis">
       
  1870          <em>
       
  1871           /tmp/a/b
       
  1872          </em>
       
  1873         </span>
       
  1874         before creating
       
  1875         <span class="emphasis">
       
  1876          <em>
       
  1877           /tmp/a/b/c
       
  1878          </em>
       
  1879         </span>
       
  1880         .
       
  1881        </p>
       
  1882        <p id="ch8ult_module_plan_5c">
       
  1883         And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
       
  1884        </p>
       
  1885        <pre class="programlisting">
       
  1886         $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
       
  1887        </pre>
       
  1888        <p id="ch8ult_module_plan_5d">
       
  1889         This will create:
       
  1890        </p>
       
  1891        <span style="color: red">
       
  1892         &lt;definition_list&gt;
       
  1893         <span style="color: red">
       
  1894          &lt;definition_list_item&gt;
       
  1895          <span style="color: red">
       
  1896           &lt;term&gt;tmpdir  - branches&lt;/term&gt;
       
  1897          </span>
       
  1898          <span style="color: red">
       
  1899           &lt;definition&gt;
       
  1900           <div class="itemizedlist">
       
  1901            <ul class="itemizedlist" type="*">
       
  1902             <li class="listitem" style="list-style-type: *">
       
  1903              <p id="ch8ult_module_plan_5e">
       
  1904               tag
       
  1905              </p>
       
  1906             </li>
       
  1907             <li class="listitem" style="list-style-type: *">
       
  1908              <span style="color: red">
       
  1909               &lt;definition_list&gt;
       
  1910               <span style="color: red">
       
  1911                &lt;definition_list_item&gt;
       
  1912                <span style="color: red">
       
  1913                 &lt;term&gt;trunk - sources - includes&lt;/term&gt;
       
  1914                </span>
       
  1915                <span style="color: red">
       
  1916                 &lt;definition&gt;
       
  1917                 <div class="itemizedlist">
       
  1918                  <ul class="itemizedlist" type="*">
       
  1919                   <li class="listitem" style="list-style-type: *">
       
  1920                    <p id="ch8ult_module_plan_5f">
       
  1921                     docs
       
  1922                    </p>
       
  1923                   </li>
       
  1924                  </ul>
       
  1925                 </div>
       
  1926                 &lt;/definition&gt;
       
  1927                </span>
       
  1928                &lt;/definition_list_item&gt;
       
  1929               </span>
       
  1930               &lt;/definition_list&gt;
       
  1931              </span>
       
  1932             </li>
       
  1933            </ul>
       
  1934           </div>
       
  1935           &lt;/definition&gt;
       
  1936          </span>
       
  1937          &lt;/definition_list_item&gt;
       
  1938         </span>
       
  1939         &lt;/definition_list&gt;
       
  1940        </span>
       
  1941       </div>
       
  1942      </div>
       
  1943     </div>
       
  1944     <div class="section" title="4.Getting Help">
       
  1945      <div class="titlepage">
       
  1946       <div>
       
  1947        <div>
       
  1948         <h2 class="title" style="clear: both">
       
  1949          <a name="id2663534">
       
  1950          </a>
       
  1951          4.Getting Help
       
  1952         </h2>
       
  1953        </div>
       
  1954       </div>
       
  1955      </div>
       
  1956      <div class="section" title="4.1.apropos and whatis">
       
  1957       <div class="titlepage">
       
  1958        <div>
       
  1959         <div>
       
  1960          <h3 class="title">
       
  1961           <a name="id2663542">
       
  1962           </a>
       
  1963           4.1.apropos and whatis
       
  1964          </h3>
       
  1965         </div>
       
  1966        </div>
       
  1967       </div>
       
  1968       <p id="ch8ult_module_plan_60">
       
  1969        This is a command to search the manual pages files in Unix and Unix-like operating systems.
       
  1970       </p>
       
  1971       <pre class="programlisting">
       
  1972        $ apropos grep
   394 egrep       egrep (1)       Search a file for a pattern using full regular expressions
  1973 egrep       egrep (1)       Search a file for a pattern using full regular expressions
   395 fgrep       fgrep (1)       Search a file for a fixed-character string
  1974 fgrep       fgrep (1)       Search a file for a fixed-character string
   396 fmlgrep     fmlgrep (1)     Search a file for a pattern
  1975 fmlgrep     fmlgrep (1)     Search a file for a pattern
   397 grep        grep (1)        Search a file for a pattern
  1976 grep        grep (1)        Search a file for a pattern
   398 gzgrep      gzgrep (1)      Search a possibly compressed file for a regular expression
  1977 gzgrep      gzgrep (1)      Search a possibly compressed file for a regular expression
   399 nisgrep     nismatch (1)    Utilities for searching NIS+ tables
  1978 nisgrep     nismatch (1)    Utilities for searching NIS+ tables
   400 pgrep       pgrep (1)       Find or signal a process by name or other attribute
  1979 pgrep       pgrep (1)       Find or signal a process by name or other attribute
   401 zgrep       zgrep (1)       Search a possibly compressed file for a regular expression
  1980 zgrep       zgrep (1)       Search a possibly compressed file for a regular expression
   402 ...</pre>
  1981 ...
   403 <p id="ch8ult_module_plan_61"></a>In this example, the user uses <span class="emphasis"><em>apropos</em></span> to search for the string "grep", and apropos returns the indicated <span class="emphasis"><em>man</em></span> pages that include the term "grep".</p>
  1982       </pre>
   404 <p id="ch8ult_module_plan_62"></a>A short index of explanations for commands is available using the <span class="emphasis"><em>whatis</em></span> command, like in the examples below:</p>
  1983       <p id="ch8ult_module_plan_61">
   405 <pre class="programlisting">$whatis ls
  1984        In this example, the user uses
   406 ls (1)           - list directory contents</pre>
  1985        <span class="emphasis">
   407 <p id="ch8ult_module_plan_63"></a>This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.</p>
  1986         <em>
   408 <p id="ch8ult_module_plan_64"></a>If you don't know where to get started and which man page to read, <span class="emphasis"><em>apropos</em></span> gives more information. Say that you do not know how to start a browser, then you could enter the following command:</p>
  1987          apropos
   409 <pre class="programlisting">$apropos browser
  1988         </em>
       
  1989        </span>
       
  1990        to search for the string "grep", and apropos returns the indicated
       
  1991        <span class="emphasis">
       
  1992         <em>
       
  1993          man
       
  1994         </em>
       
  1995        </span>
       
  1996        pages that include the term "grep".
       
  1997       </p>
       
  1998       <p id="ch8ult_module_plan_62">
       
  1999        A short index of explanations for commands is available using the
       
  2000        <span class="emphasis">
       
  2001         <em>
       
  2002          whatis
       
  2003         </em>
       
  2004        </span>
       
  2005        command, like in the examples below:
       
  2006       </p>
       
  2007       <pre class="programlisting">
       
  2008        $whatis ls
       
  2009 ls (1)           - list directory contents
       
  2010       </pre>
       
  2011       <p id="ch8ult_module_plan_63">
       
  2012        This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
       
  2013       </p>
       
  2014       <p id="ch8ult_module_plan_64">
       
  2015        If you don't know where to get started and which man page to read,
       
  2016        <span class="emphasis">
       
  2017         <em>
       
  2018          apropos
       
  2019         </em>
       
  2020        </span>
       
  2021        gives more information. Say that you do not know how to start a browser, then you could enter the following command:
       
  2022       </p>
       
  2023       <pre class="programlisting">
       
  2024        $apropos browser
   410 gmusicbrowser (1)    - Jukebox for large collections of audio files
  2025 gmusicbrowser (1)    - Jukebox for large collections of audio files
   411 infobrowser (1)      - read Info documents
  2026 infobrowser (1)      - read Info documents
   412 libsmbclient (7)     - An extension library for browsers and that               can be used...
  2027 libsmbclient (7)     - An extension library for browsers and that               can be used...
   413 opera (1)            - a standards-compliant graphical Web browser
  2028 opera (1)            - a standards-compliant graphical Web browser
   414 sensible-browser (1) - sensible editing, paging, and web browsing
  2029 sensible-browser (1) - sensible editing, paging, and web browsing
   415 smbtree (1)          - A text based smb network browser
  2030 smbtree (1)          - A text based smb network browser
   416 tvtk_doc (1)         - A GUI based TVTK documentation search browser.
  2031 tvtk_doc (1)         - A GUI based TVTK documentation search browser.
   417 viewres (1)          - graphical class browser for Xt
  2032 viewres (1)          - graphical class browser for Xt
   418 w3m (1)              - a text based Web browser and pager
  2033 w3m (1)              - a text based Web browser and pager
   419 www-browser (1)      - a text based Web browser and pager
  2034 www-browser (1)      - a text based Web browser and pager
   420 ...</pre>
  2035 ...
   421 </div>
  2036       </pre>
   422 <div class="section" title="4.2. man">
  2037      </div>
   423 <div class="titlepage"><div><div><h3 class="title">
  2038      <div class="section" title="4.2.man">
   424 <a name="id2770542"></a>4.2. man</h3></div></div></div>
  2039       <div class="titlepage">
   425 <p id="ch8ult_module_plan_65"></a>Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is <span class="emphasis"><em>man</em></span>. Each page is a self-contained document.</p>
  2040        <div>
   426 <p id="ch8ult_module_plan_66"></a>To read a manual page for a Unix command, one can use:</p>
  2041         <div>
   427 <pre class="programlisting">$ man &lt;command_name&gt;</pre>
  2042          <h3 class="title">
   428 <p id="ch8ult_module_plan_67"></a>at a shell prompt; for example, "man ftp". In order to simplify navigation through the output, <span class="emphasis"><em>man</em></span> generally uses the less terminal pager.</p>
  2043           <a name="id2663636">
   429 <p id="ch8ult_module_plan_68"></a>Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are <span class="emphasis"><em>man(1)</em></span> and <span class="emphasis"><em>man(7)</em></span>, or <span class="emphasis"><em>exit(2)</em></span> and <span class="emphasis"><em>exit(3)</em></span>. The syntax for accessing the non-default manual section varies between different man implementations. On Linux and <span class="emphasis"><em>BSD, for example, the syntax for reading *printf(3)</em></span> is:</p>
  2044           </a>
   430 <pre class="programlisting">$man 3 printf</pre>
  2045           4.2.man
   431 <p id="ch8ult_module_plan_69"></a>Another example:</p>
  2046          </h3>
   432 <pre class="programlisting">$man man</pre>
  2047         </div>
   433 <p id="ch8ult_module_plan_6a"></a>The previous example will take you to the "Manual" page entry about manual pages!</p>
  2048        </div>
   434 <div class="section" title="4.2.1. Layout">
  2049       </div>
   435 <div class="titlepage"><div><div><h4 class="title">
  2050       <p id="ch8ult_module_plan_65">
   436 <a name="id2770624"></a>4.2.1. Layout</h4></div></div></div>
  2051        Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
   437 <p id="ch8ult_module_plan_6b"></a>All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:</p>
  2052        <span class="emphasis">
   438 <span style="color: red">&lt;definition_list&gt;<span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;NAME&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<p id="ch8ult_module_plan_6c"></a>The name of the command or function, followed by a one-line description of what it does.</p>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span><span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;SYNOPSIS&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<p id="ch8ult_module_plan_6d"></a>In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.</p>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span><span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;DESCRIPTION&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<p id="ch8ult_module_plan_6e"></a>A textual description of the functioning of the command or function.</p>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span><span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;EXAMPLES&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<p id="ch8ult_module_plan_6f"></a>Some examples of common usage.</p>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span><span style="color: red">&lt;definition_list_item&gt;<span style="color: red">&lt;term&gt;SEE ALSO&lt;/term&gt;</span><span style="color: red">&lt;definition&gt;<p id="ch8ult_module_plan_70"></a>A list of related commands or functions.</p>&lt;/definition&gt;</span>&lt;/definition_list_item&gt;</span>&lt;/definition_list&gt;</span><p id="ch8ult_module_plan_71"></a>Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.</p>
  2053         <em>
   439 <p id="ch8ult_module_plan_72"></a>These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to <span class="emphasis"><em>man</em></span> have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.</p>
  2054          man
   440 <p id="ch8ult_module_plan_73"></a>However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.</p>
  2055         </em>
   441 <p id="ch8ult_module_plan_74"></a>Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.</p>
  2056        </span>
   442 <p id="ch8ult_module_plan_75"></a>Usually the man pages are written in English. Translations into other languages can be also available on the system.</p>
  2057        . Each page is a self-contained document.
   443 <p id="ch8ult_module_plan_76"></a>The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.</p>
  2058       </p>
   444 </div>
  2059       <p id="ch8ult_module_plan_66">
   445 </div>
  2060        To read a manual page for a Unix command, one can use:
   446 <div class="section" title="4.3. info">
  2061       </p>
   447 <div class="titlepage"><div><div><h3 class="title">
  2062       <pre class="programlisting">
   448 <a name="id2770752"></a>4.3. info</h3></div></div></div>
  2063        $ man &lt;command_name&gt;
   449 <p id="ch8ult_module_plan_77"></a><span class="emphasis"><em>info</em></span> is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.</p>
  2064       </pre>
   450 <p id="ch8ult_module_plan_78"></a>The syntax is</p>
  2065       <p id="ch8ult_module_plan_67">
   451 <pre class="programlisting">$ info &lt;command_name&gt;</pre>
  2066        at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
   452 <p id="ch8ult_module_plan_79"></a><span class="emphasis"><em>info</em></span> processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance</p>
  2067        <span class="emphasis">
   453 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  2068         <em>
   454 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_7a"></a><span class="emphasis"><em>n</em></span> goes to the next page.</p></li>
  2069          man
   455 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_7b"></a><span class="emphasis"><em>p</em></span> goes to the previous page.</p></li>
  2070         </em>
   456 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_7c"></a><span class="emphasis"><em>u</em></span> goes to the upper page.</p></li>
  2071        </span>
   457 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_7d"></a><span class="emphasis"><em>l</em></span> goes to the last(visited) node</p></li>
  2072        generally uses the less terminal pager.
   458 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_7e"></a>To follow a cross reference, the cursor can be moved over a link (a word preceded by a <span style="color: red">&lt;title_reference&gt;*&lt;/title_reference&gt;</span>) and enter pressed.</p></li>
  2073       </p>
   459 </ul></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_7f"></a>info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.</p>
  2074       <p id="ch8ult_module_plan_68">
   460 </div>
  2075        Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
   461 <div class="section" title="4.4. --help">
  2076        <span class="emphasis">
   462 <div class="titlepage"><div><div><h3 class="title">
  2077         <em>
   463 <a name="id2770844"></a>4.4. --help</h3></div></div></div>
  2078          man(1)
   464 <p id="ch8ult_module_plan_80"></a>Most GNU commands support the --help, 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 <span class="emphasis"><em>cat</em></span> command:</p>
  2079         </em>
   465 <pre class="programlisting">$ userprompt@host: cat --help
  2080        </span>
       
  2081        and
       
  2082        <span class="emphasis">
       
  2083         <em>
       
  2084          man(7)
       
  2085         </em>
       
  2086        </span>
       
  2087        , or
       
  2088        <span class="emphasis">
       
  2089         <em>
       
  2090          exit(2)
       
  2091         </em>
       
  2092        </span>
       
  2093        and
       
  2094        <span class="emphasis">
       
  2095         <em>
       
  2096          exit(3)
       
  2097         </em>
       
  2098        </span>
       
  2099        . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
       
  2100        <span class="emphasis">
       
  2101         <em>
       
  2102          BSD, for example, the syntax for reading *printf(3)
       
  2103         </em>
       
  2104        </span>
       
  2105        is:
       
  2106       </p>
       
  2107       <pre class="programlisting">
       
  2108        $man 3 printf
       
  2109       </pre>
       
  2110       <p id="ch8ult_module_plan_69">
       
  2111        Another example:
       
  2112       </p>
       
  2113       <pre class="programlisting">
       
  2114        $man man
       
  2115       </pre>
       
  2116       <p id="ch8ult_module_plan_6a">
       
  2117        The previous example will take you to the "Manual" page entry about manual pages!
       
  2118       </p>
       
  2119       <div class="section" title="4.2.1.Layout">
       
  2120        <div class="titlepage">
       
  2121         <div>
       
  2122          <div>
       
  2123           <h4 class="title">
       
  2124            <a name="id2663719">
       
  2125            </a>
       
  2126            4.2.1.Layout
       
  2127           </h4>
       
  2128          </div>
       
  2129         </div>
       
  2130        </div>
       
  2131        <p id="ch8ult_module_plan_6b">
       
  2132         All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
       
  2133        </p>
       
  2134        <span style="color: red">
       
  2135         &lt;definition_list&gt;
       
  2136         <span style="color: red">
       
  2137          &lt;definition_list_item&gt;
       
  2138          <span style="color: red">
       
  2139           &lt;term&gt;NAME&lt;/term&gt;
       
  2140          </span>
       
  2141          <span style="color: red">
       
  2142           &lt;definition&gt;
       
  2143          </span>
       
  2144         </span>
       
  2145        </span>
       
  2146        <p id="ch8ult_module_plan_6c">
       
  2147         The name of the command or function, followed by a one-line description of what it does.
       
  2148        </p>
       
  2149        &lt;/definition&gt;
       
  2150        &lt;/definition_list_item&gt;
       
  2151        <span style="color: red">
       
  2152         &lt;definition_list_item&gt;
       
  2153         <span style="color: red">
       
  2154          &lt;term&gt;SYNOPSIS&lt;/term&gt;
       
  2155         </span>
       
  2156         <span style="color: red">
       
  2157          &lt;definition&gt;
       
  2158         </span>
       
  2159        </span>
       
  2160        <p id="ch8ult_module_plan_6d">
       
  2161         In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
       
  2162        </p>
       
  2163        &lt;/definition&gt;
       
  2164        &lt;/definition_list_item&gt;
       
  2165        <span style="color: red">
       
  2166         &lt;definition_list_item&gt;
       
  2167         <span style="color: red">
       
  2168          &lt;term&gt;DESCRIPTION&lt;/term&gt;
       
  2169         </span>
       
  2170         <span style="color: red">
       
  2171          &lt;definition&gt;
       
  2172         </span>
       
  2173        </span>
       
  2174        <p id="ch8ult_module_plan_6e">
       
  2175         A textual description of the functioning of the command or function.
       
  2176        </p>
       
  2177        &lt;/definition&gt;
       
  2178        &lt;/definition_list_item&gt;
       
  2179        <span style="color: red">
       
  2180         &lt;definition_list_item&gt;
       
  2181         <span style="color: red">
       
  2182          &lt;term&gt;EXAMPLES&lt;/term&gt;
       
  2183         </span>
       
  2184         <span style="color: red">
       
  2185          &lt;definition&gt;
       
  2186         </span>
       
  2187        </span>
       
  2188        <p id="ch8ult_module_plan_6f">
       
  2189         Some examples of common usage.
       
  2190        </p>
       
  2191        &lt;/definition&gt;
       
  2192        &lt;/definition_list_item&gt;
       
  2193        <span style="color: red">
       
  2194         &lt;definition_list_item&gt;
       
  2195         <span style="color: red">
       
  2196          &lt;term&gt;SEE ALSO&lt;/term&gt;
       
  2197         </span>
       
  2198         <span style="color: red">
       
  2199          &lt;definition&gt;
       
  2200         </span>
       
  2201        </span>
       
  2202        <p id="ch8ult_module_plan_70">
       
  2203         A list of related commands or functions.
       
  2204        </p>
       
  2205        &lt;/definition&gt;
       
  2206        &lt;/definition_list_item&gt;
       
  2207        &lt;/definition_list&gt;
       
  2208        <p id="ch8ult_module_plan_71">
       
  2209         Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
       
  2210        </p>
       
  2211        <p id="ch8ult_module_plan_72">
       
  2212         These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
       
  2213         <span class="emphasis">
       
  2214          <em>
       
  2215           man
       
  2216          </em>
       
  2217         </span>
       
  2218         have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
       
  2219        </p>
       
  2220        <p id="ch8ult_module_plan_73">
       
  2221         However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
       
  2222        </p>
       
  2223        <p id="ch8ult_module_plan_74">
       
  2224         Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
       
  2225        </p>
       
  2226        <p id="ch8ult_module_plan_75">
       
  2227         Usually the man pages are written in English. Translations into other languages can be also available on the system.
       
  2228        </p>
       
  2229        <p id="ch8ult_module_plan_76">
       
  2230         The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
       
  2231        </p>
       
  2232       </div>
       
  2233      </div>
       
  2234      <div class="section" title="4.3.info">
       
  2235       <div class="titlepage">
       
  2236        <div>
       
  2237         <div>
       
  2238          <h3 class="title">
       
  2239           <a name="id2663847">
       
  2240           </a>
       
  2241           4.3.info
       
  2242          </h3>
       
  2243         </div>
       
  2244        </div>
       
  2245       </div>
       
  2246       <p id="ch8ult_module_plan_77">
       
  2247        <span class="emphasis">
       
  2248         <em>
       
  2249          info
       
  2250         </em>
       
  2251        </span>
       
  2252        is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
       
  2253       </p>
       
  2254       <p id="ch8ult_module_plan_78">
       
  2255        The syntax is
       
  2256       </p>
       
  2257       <pre class="programlisting">
       
  2258        $ info &lt;command_name&gt;
       
  2259       </pre>
       
  2260       <p id="ch8ult_module_plan_79">
       
  2261        <span class="emphasis">
       
  2262         <em>
       
  2263          info
       
  2264         </em>
       
  2265        </span>
       
  2266        processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
       
  2267       </p>
       
  2268       <span style="color: red">
       
  2269        &lt;block_quote&gt;
       
  2270        <div class="itemizedlist">
       
  2271         <ul class="itemizedlist" type="*">
       
  2272          <li class="listitem" style="list-style-type: *">
       
  2273           <p id="ch8ult_module_plan_7a">
       
  2274            <span class="emphasis">
       
  2275             <em>
       
  2276              n
       
  2277             </em>
       
  2278            </span>
       
  2279            goes to the next page.
       
  2280           </p>
       
  2281          </li>
       
  2282          <li class="listitem" style="list-style-type: *">
       
  2283           <p id="ch8ult_module_plan_7b">
       
  2284            <span class="emphasis">
       
  2285             <em>
       
  2286              p
       
  2287             </em>
       
  2288            </span>
       
  2289            goes to the previous page.
       
  2290           </p>
       
  2291          </li>
       
  2292          <li class="listitem" style="list-style-type: *">
       
  2293           <p id="ch8ult_module_plan_7c">
       
  2294            <span class="emphasis">
       
  2295             <em>
       
  2296              u
       
  2297             </em>
       
  2298            </span>
       
  2299            goes to the upper page.
       
  2300           </p>
       
  2301          </li>
       
  2302          <li class="listitem" style="list-style-type: *">
       
  2303           <p id="ch8ult_module_plan_7d">
       
  2304            <span class="emphasis">
       
  2305             <em>
       
  2306              l
       
  2307             </em>
       
  2308            </span>
       
  2309            goes to the last(visited) node
       
  2310           </p>
       
  2311          </li>
       
  2312          <li class="listitem" style="list-style-type: *">
       
  2313           <p id="ch8ult_module_plan_7e">
       
  2314            To follow a cross reference, the cursor can be moved over a link (a word preceded by a
       
  2315            <span style="color: red">
       
  2316             &lt;title_reference&gt;*&lt;/title_reference&gt;
       
  2317            </span>
       
  2318            ) and enter pressed.
       
  2319           </p>
       
  2320          </li>
       
  2321         </ul>
       
  2322        </div>
       
  2323        &lt;/block_quote&gt;
       
  2324       </span>
       
  2325       <p id="ch8ult_module_plan_7f">
       
  2326        info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
       
  2327       </p>
       
  2328      </div>
       
  2329      <div class="section" title="4.4.--help">
       
  2330       <div class="titlepage">
       
  2331        <div>
       
  2332         <div>
       
  2333          <h3 class="title">
       
  2334           <a name="id2663939">
       
  2335           </a>
       
  2336           4.4.--help
       
  2337          </h3>
       
  2338         </div>
       
  2339        </div>
       
  2340       </div>
       
  2341       <p id="ch8ult_module_plan_80">
       
  2342        Most GNU commands support the --help, 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
       
  2343        <span class="emphasis">
       
  2344         <em>
       
  2345          cat
       
  2346         </em>
       
  2347        </span>
       
  2348        command:
       
  2349       </p>
       
  2350       <pre class="programlisting">
       
  2351        $ userprompt@host: cat --help
   466 Usage: cat [OPTION] [FILE]...
  2352 Usage: cat [OPTION] [FILE]...
   467 Concatenate FILE(s), or standard input, to standard output.
  2353 Concatenate FILE(s), or standard input, to standard output.
   468 
  2354 
   469   -A, --show-all           equivalent to -vET
  2355   -A, --show-all           equivalent to -vET
   470   -b, --number-nonblank    number nonempty output lines
  2356   -b, --number-nonblank    number nonempty output lines
   483 
  2369 
   484 Examples:
  2370 Examples:
   485   cat f - g  Output f's contents, then standard input, then g's           contents.
  2371   cat f - g  Output f's contents, then standard input, then g's           contents.
   486   cat        Copy standard input to standard output.
  2372   cat        Copy standard input to standard output.
   487 
  2373 
   488 Report bugs to &lt;bug-coreutils@gnu.org&gt;.</pre>
  2374 Report bugs to &lt;bug-coreutils@gnu.org&gt;.
   489 </div>
  2375       </pre>
   490 </div>
  2376      </div>
   491 <div class="section" title="5. Basic file handling">
  2377     </div>
   492 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  2378     <div class="section" title="5.Basic file handling">
   493 <a name="id2770897"></a>5. Basic file handling</h2></div></div></div>
  2379      <div class="titlepage">
   494 <div class="section" title="5.1. cp">
  2380       <div>
   495 <div class="titlepage"><div><div><h3 class="title">
  2381        <div>
   496 <a name="id2770906"></a>5.1. cp</h3></div></div></div>
  2382         <h2 class="title" style="clear: both">
   497 <p id="ch8ult_module_plan_81"></a><span class="emphasis"><em>cp</em></span> is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.</p>
  2383          <a name="id2663992">
   498 <div class="section" title="5.1.1. Usage">
  2384          </a>
   499 <div class="titlepage"><div><div><h4 class="title">
  2385          5.Basic file handling
   500 <a name="id2770923"></a>5.1.1. Usage</h4></div></div></div>
  2386         </h2>
   501 <p id="ch8ult_module_plan_82"></a>To copy a file to another file:</p>
  2387        </div>
   502 <pre class="programlisting">$ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile</pre>
  2388       </div>
   503 <p id="ch8ult_module_plan_83"></a>To copy a file to a directory:</p>
  2389      </div>
   504 <pre class="programlisting">$ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ...              TargetDirectory</pre>
  2390      <div class="section" title="5.1.cp">
   505 <p id="ch8ult_module_plan_84"></a>To copy a directory to a directory:</p>
  2391       <div class="titlepage">
   506 <pre class="programlisting">$ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
  2392        <div>
   507 SourceDirectory ... TargetDirectory</pre>
  2393         <div>
   508 </div>
  2394          <h3 class="title">
   509 <div class="section" title="5.1.2. Flags">
  2395           <a name="id2664000">
   510 <div class="titlepage"><div><div><h4 class="title">
  2396           </a>
   511 <a name="id2770957"></a>5.1.2. Flags</h4></div></div></div>
  2397           5.1.cp
   512 <p id="ch8ult_module_plan_85"></a><span class="emphasis"><em>-f</em></span> (force) – specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.</p>
  2398          </h3>
   513 <p id="ch8ult_module_plan_86"></a><span class="emphasis"><em>-P</em></span> – makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.</p>
  2399         </div>
   514 <p id="ch8ult_module_plan_87"></a><span class="emphasis"><em>-i</em></span> (interactive) – prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.</p>
  2400        </div>
   515 <p id="ch8ult_module_plan_88"></a><span class="emphasis"><em>-p</em></span> (preserve) – duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:</p>
  2401       </div>
   516 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  2402       <p id="ch8ult_module_plan_81">
   517 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_89"></a>The time of the last data modification and the time of the last access.</p></li>
  2403        <span class="emphasis">
   518 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_8a"></a>The user ID and group ID (only if it has permissions to do this)</p></li>
  2404         <em>
   519 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_8b"></a>The file permission bits and the SUID and SGID bits.</p></li>
  2405          cp
   520 </ul></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_8c"></a><span class="emphasis"><em>-R</em></span> (recursive) – copy directories (recursively copying all the contents)</p>
  2406         </em>
   521 </div>
  2407        </span>
   522 <div class="section" title="5.1.3. Examples">
  2408        is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
   523 <div class="titlepage"><div><div><h4 class="title">
  2409       </p>
   524 <a name="id2771056"></a>5.1.3. Examples</h4></div></div></div>
  2410       <div class="section" title="5.1.1.Usage">
   525 <p id="ch8ult_module_plan_8d"></a>To make a copy of a file in the current directory, enter:</p>
  2411        <div class="titlepage">
   526 <pre class="programlisting">$ cp prog.c prog.bak</pre>
  2412         <div>
   527 <p id="ch8ult_module_plan_8e"></a>This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.</p>
  2413          <div>
   528 <p id="ch8ult_module_plan_8f"></a>To copy a file in your current directory into another directory, enter:</p>
  2414           <h4 class="title">
   529 <pre class="programlisting">$ cp zaphod /home/books/hhgg</pre>
  2415            <a name="id2664018">
   530 <p id="ch8ult_module_plan_90"></a>This copies the jones file to /home/books/hhgg/zaphod.</p>
  2416            </a>
   531 <p id="ch8ult_module_plan_91"></a>To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:</p>
  2417            5.1.1.Usage
   532 <pre class="programlisting">$ cp -p martin_luther_king martin_luther_king.jr</pre>
  2418           </h4>
   533 <p id="ch8ult_module_plan_92"></a>This copies the <span class="emphasis"><em>martin_luther_king</em></span> file to the <span class="emphasis"><em>martin_luther_king.jr</em></span> file. Instead of creating the file with the current date and time stamp, the system gives the <span class="emphasis"><em>martin_luther_king.jr</em></span> file the same date and time as the <span class="emphasis"><em>martin_luther_king</em></span> file. The <span class="emphasis"><em>martin_luther_king.jr</em></span> file also inherits the <span class="emphasis"><em>martin_luther_king</em></span> file's access control protection.</p>
  2419          </div>
   534 <p id="ch8ult_module_plan_93"></a>To copy all the files in a directory to a new directory, enter:</p>
  2420         </div>
   535 <pre class="programlisting">$ cp /home/galactica/clients/* /home/hhgg/customers</pre>
  2421        </div>
   536 <p id="ch8ult_module_plan_94"></a>This copies only the files in the clients directory to the customers directory.</p>
  2422        <p id="ch8ult_module_plan_82">
   537 <p id="ch8ult_module_plan_95"></a>To copy a directory, including all its files and subdirectories, to another directory, enter:</p>
  2423         To copy a file to another file:
   538 <span style="color: red">&lt;block_quote&gt;<p id="ch8ult_module_plan_96"></a>$ cp -R /home/hhgg/clients /home/hhgg/customers</p>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_97"></a>This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.</p>
  2424        </p>
   539 <p id="ch8ult_module_plan_98"></a>To copy a specific set of files of any extension to another directory, enter:</p>
  2425        <pre class="programlisting">
   540 <pre class="programlisting">$ cp zaphod arthur ford /home/hhgg/clients</pre>
  2426         $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
   541 <p id="ch8ult_module_plan_99"></a>This copies the <span class="emphasis"><em>zaphod</em></span>, <span class="emphasis"><em>arthur</em></span>, and <span class="emphasis"><em>ford</em></span> files in your current working directory to the /home/hhgg/clients directory.</p>
  2427        </pre>
   542 <p id="ch8ult_module_plan_9a"></a>To use pattern-matching characters to copy files, enter:</p>
  2428        <p id="ch8ult_module_plan_83">
   543 <pre class="programlisting">$ cp programs/*.py .</pre>
  2429         To copy a file to a directory:
   544 <p id="ch8ult_module_plan_9b"></a>This copies the files in the programs directory that end with <span class="emphasis"><em>.py</em></span> to the current directory, signified by the single "." (dot). You must type a space between the <span class="emphasis"><em>py</em></span> and the final dot.</p>
  2430        </p>
   545 </div>
  2431        <pre class="programlisting">
   546 </div>
  2432         $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ...              TargetDirectory
   547 <div class="section" title="5.2. mv">
  2433        </pre>
   548 <div class="titlepage"><div><div><h3 class="title">
  2434        <p id="ch8ult_module_plan_84">
   549 <a name="id2771220"></a>5.2. mv</h3></div></div></div>
  2435         To copy a directory to a directory:
   550 <p id="ch8ult_module_plan_9c"></a><span class="emphasis"><em>mv</em></span> (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system), <span class="emphasis"><em>mv</em></span> will rename the file instead. Write permission is required on all directories being modified.</p>
  2436        </p>
   551 <div class="section" title="5.2.1. Conflicting existing file">
  2437        <pre class="programlisting">
   552 <div class="titlepage"><div><div><h4 class="title">
  2438         $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
   553 <a name="id2771244"></a>5.2.1. Conflicting existing file</h4></div></div></div>
  2439 SourceDirectory ... TargetDirectory
   554 <p id="ch8ult_module_plan_9d"></a>In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.</p>
  2440        </pre>
   555 </div>
  2441       </div>
   556 <div class="section" title="5.2.2. Differences with copy and delete">
  2442       <div class="section" title="5.1.2.Flags">
   557 <div class="titlepage"><div><div><h4 class="title">
  2443        <div class="titlepage">
   558 <a name="id2771264"></a>5.2.2. Differences with copy and delete</h4></div></div></div>
  2444         <div>
   559 <p id="ch8ult_module_plan_9e"></a>Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.</p>
  2445          <div>
   560 </div>
  2446           <h4 class="title">
   561 <div class="section" title="5.2.3. Examples">
  2447            <a name="id2664052">
   562 <div class="titlepage"><div><div><h4 class="title">
  2448            </a>
   563 <a name="id2771294"></a>5.2.3. Examples</h4></div></div></div>
  2449            5.1.2.Flags
   564 <pre class="programlisting">$ mv myfile mynewfilename    renames a file
  2450           </h4>
       
  2451          </div>
       
  2452         </div>
       
  2453        </div>
       
  2454        <p id="ch8ult_module_plan_85">
       
  2455         <span class="emphasis">
       
  2456          <em>
       
  2457           -f
       
  2458          </em>
       
  2459         </span>
       
  2460         (force)  specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
       
  2461        </p>
       
  2462        <p id="ch8ult_module_plan_86">
       
  2463         <span class="emphasis">
       
  2464          <em>
       
  2465           -P
       
  2466          </em>
       
  2467         </span>
       
  2468         makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
       
  2469        </p>
       
  2470        <p id="ch8ult_module_plan_87">
       
  2471         <span class="emphasis">
       
  2472          <em>
       
  2473           -i
       
  2474          </em>
       
  2475         </span>
       
  2476         (interactive)  prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
       
  2477        </p>
       
  2478        <p id="ch8ult_module_plan_88">
       
  2479         <span class="emphasis">
       
  2480          <em>
       
  2481           -p
       
  2482          </em>
       
  2483         </span>
       
  2484         (preserve)  duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
       
  2485        </p>
       
  2486        <span style="color: red">
       
  2487         &lt;block_quote&gt;
       
  2488         <div class="itemizedlist">
       
  2489          <ul class="itemizedlist" type="*">
       
  2490           <li class="listitem" style="list-style-type: *">
       
  2491            <p id="ch8ult_module_plan_89">
       
  2492             The time of the last data modification and the time of the last access.
       
  2493            </p>
       
  2494           </li>
       
  2495           <li class="listitem" style="list-style-type: *">
       
  2496            <p id="ch8ult_module_plan_8a">
       
  2497             The user ID and group ID (only if it has permissions to do this)
       
  2498            </p>
       
  2499           </li>
       
  2500           <li class="listitem" style="list-style-type: *">
       
  2501            <p id="ch8ult_module_plan_8b">
       
  2502             The file permission bits and the SUID and SGID bits.
       
  2503            </p>
       
  2504           </li>
       
  2505          </ul>
       
  2506         </div>
       
  2507         &lt;/block_quote&gt;
       
  2508        </span>
       
  2509        <p id="ch8ult_module_plan_8c">
       
  2510         <span class="emphasis">
       
  2511          <em>
       
  2512           -R
       
  2513          </em>
       
  2514         </span>
       
  2515         (recursive)  copy directories (recursively copying all the contents)
       
  2516        </p>
       
  2517       </div>
       
  2518       <div class="section" title="5.1.3.Examples">
       
  2519        <div class="titlepage">
       
  2520         <div>
       
  2521          <div>
       
  2522           <h4 class="title">
       
  2523            <a name="id2664151">
       
  2524            </a>
       
  2525            5.1.3.Examples
       
  2526           </h4>
       
  2527          </div>
       
  2528         </div>
       
  2529        </div>
       
  2530        <p id="ch8ult_module_plan_8d">
       
  2531         To make a copy of a file in the current directory, enter:
       
  2532        </p>
       
  2533        <pre class="programlisting">
       
  2534         $ cp prog.c prog.bak
       
  2535        </pre>
       
  2536        <p id="ch8ult_module_plan_8e">
       
  2537         This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
       
  2538        </p>
       
  2539        <p id="ch8ult_module_plan_8f">
       
  2540         To copy a file in your current directory into another directory, enter:
       
  2541        </p>
       
  2542        <pre class="programlisting">
       
  2543         $ cp zaphod /home/books/hhgg
       
  2544        </pre>
       
  2545        <p id="ch8ult_module_plan_90">
       
  2546         This copies the jones file to /home/books/hhgg/zaphod.
       
  2547        </p>
       
  2548        <p id="ch8ult_module_plan_91">
       
  2549         To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
       
  2550        </p>
       
  2551        <pre class="programlisting">
       
  2552         $ cp -p martin_luther_king martin_luther_king.jr
       
  2553        </pre>
       
  2554        <p id="ch8ult_module_plan_92">
       
  2555         This copies the
       
  2556         <span class="emphasis">
       
  2557          <em>
       
  2558           martin_luther_king
       
  2559          </em>
       
  2560         </span>
       
  2561         file to the
       
  2562         <span class="emphasis">
       
  2563          <em>
       
  2564           martin_luther_king.jr
       
  2565          </em>
       
  2566         </span>
       
  2567         file. Instead of creating the file with the current date and time stamp, the system gives the
       
  2568         <span class="emphasis">
       
  2569          <em>
       
  2570           martin_luther_king.jr
       
  2571          </em>
       
  2572         </span>
       
  2573         file the same date and time as the
       
  2574         <span class="emphasis">
       
  2575          <em>
       
  2576           martin_luther_king
       
  2577          </em>
       
  2578         </span>
       
  2579         file. The
       
  2580         <span class="emphasis">
       
  2581          <em>
       
  2582           martin_luther_king.jr
       
  2583          </em>
       
  2584         </span>
       
  2585         file also inherits the
       
  2586         <span class="emphasis">
       
  2587          <em>
       
  2588           martin_luther_king
       
  2589          </em>
       
  2590         </span>
       
  2591         file's access control protection.
       
  2592        </p>
       
  2593        <p id="ch8ult_module_plan_93">
       
  2594         To copy all the files in a directory to a new directory, enter:
       
  2595        </p>
       
  2596        <pre class="programlisting">
       
  2597         $ cp /home/galactica/clients/* /home/hhgg/customers
       
  2598        </pre>
       
  2599        <p id="ch8ult_module_plan_94">
       
  2600         This copies only the files in the clients directory to the customers directory.
       
  2601        </p>
       
  2602        <p id="ch8ult_module_plan_95">
       
  2603         To copy a directory, including all its files and subdirectories, to another directory, enter:
       
  2604        </p>
       
  2605        <span style="color: red">
       
  2606         &lt;block_quote&gt;
       
  2607        </span>
       
  2608        <p id="ch8ult_module_plan_96">
       
  2609         $ cp -R /home/hhgg/clients /home/hhgg/customers
       
  2610        </p>
       
  2611        &lt;/block_quote&gt;
       
  2612        <p id="ch8ult_module_plan_97">
       
  2613         This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
       
  2614        </p>
       
  2615        <p id="ch8ult_module_plan_98">
       
  2616         To copy a specific set of files of any extension to another directory, enter:
       
  2617        </p>
       
  2618        <pre class="programlisting">
       
  2619         $ cp zaphod arthur ford /home/hhgg/clients
       
  2620        </pre>
       
  2621        <p id="ch8ult_module_plan_99">
       
  2622         This copies the
       
  2623         <span class="emphasis">
       
  2624          <em>
       
  2625           zaphod
       
  2626          </em>
       
  2627         </span>
       
  2628         ,
       
  2629         <span class="emphasis">
       
  2630          <em>
       
  2631           arthur
       
  2632          </em>
       
  2633         </span>
       
  2634         , and
       
  2635         <span class="emphasis">
       
  2636          <em>
       
  2637           ford
       
  2638          </em>
       
  2639         </span>
       
  2640         files in your current working directory to the /home/hhgg/clients directory.
       
  2641        </p>
       
  2642        <p id="ch8ult_module_plan_9a">
       
  2643         To use pattern-matching characters to copy files, enter:
       
  2644        </p>
       
  2645        <pre class="programlisting">
       
  2646         $ cp programs/*.py .
       
  2647        </pre>
       
  2648        <p id="ch8ult_module_plan_9b">
       
  2649         This copies the files in the programs directory that end with
       
  2650         <span class="emphasis">
       
  2651          <em>
       
  2652           .py
       
  2653          </em>
       
  2654         </span>
       
  2655         to the current directory, signified by the single "." (dot). You must type a space between the
       
  2656         <span class="emphasis">
       
  2657          <em>
       
  2658           py
       
  2659          </em>
       
  2660         </span>
       
  2661         and the final dot.
       
  2662        </p>
       
  2663       </div>
       
  2664      </div>
       
  2665      <div class="section" title="5.2.mv">
       
  2666       <div class="titlepage">
       
  2667        <div>
       
  2668         <div>
       
  2669          <h3 class="title">
       
  2670           <a name="id2664315">
       
  2671           </a>
       
  2672           5.2.mv
       
  2673          </h3>
       
  2674         </div>
       
  2675        </div>
       
  2676       </div>
       
  2677       <p id="ch8ult_module_plan_9c">
       
  2678        <span class="emphasis">
       
  2679         <em>
       
  2680          mv
       
  2681         </em>
       
  2682        </span>
       
  2683        (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
       
  2684        <span class="emphasis">
       
  2685         <em>
       
  2686          mv
       
  2687         </em>
       
  2688        </span>
       
  2689        will rename the file instead. Write permission is required on all directories being modified.
       
  2690       </p>
       
  2691       <div class="section" title="5.2.1.Conflicting existing file">
       
  2692        <div class="titlepage">
       
  2693         <div>
       
  2694          <div>
       
  2695           <h4 class="title">
       
  2696            <a name="id2664339">
       
  2697            </a>
       
  2698            5.2.1.Conflicting existing file
       
  2699           </h4>
       
  2700          </div>
       
  2701         </div>
       
  2702        </div>
       
  2703        <p id="ch8ult_module_plan_9d">
       
  2704         In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
       
  2705        </p>
       
  2706       </div>
       
  2707       <div class="section" title="5.2.2.Differences with copy and delete">
       
  2708        <div class="titlepage">
       
  2709         <div>
       
  2710          <div>
       
  2711           <h4 class="title">
       
  2712            <a name="id2664358">
       
  2713            </a>
       
  2714            5.2.2.Differences with copy and delete
       
  2715           </h4>
       
  2716          </div>
       
  2717         </div>
       
  2718        </div>
       
  2719        <p id="ch8ult_module_plan_9e">
       
  2720         Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
       
  2721        </p>
       
  2722       </div>
       
  2723       <div class="section" title="5.2.3.Examples">
       
  2724        <div class="titlepage">
       
  2725         <div>
       
  2726          <div>
       
  2727           <h4 class="title">
       
  2728            <a name="id2664389">
       
  2729            </a>
       
  2730            5.2.3.Examples
       
  2731           </h4>
       
  2732          </div>
       
  2733         </div>
       
  2734        </div>
       
  2735        <pre class="programlisting">
       
  2736         $ mv myfile mynewfilename    renames a file
   565 $ mv myfile otherfilename    renames a file and deletes the existing            file "myfile"
  2737 $ mv myfile otherfilename    renames a file and deletes the existing            file "myfile"
   566 $ mv myfile /myfile          moves 'myfile' from the current            directory to the root directory
  2738 $ mv myfile /myfile          moves 'myfile' from the current            directory to the root directory
   567 $ mv myfile dir/myfile       moves 'myfile' to 'dir/myfile' relative            to the current directory
  2739 $ mv myfile dir/myfile       moves 'myfile' to 'dir/myfile' relative            to the current directory
   568 $ mv myfile dir              same as the previous command (the          filename is implied to be the same)
  2740 $ mv myfile dir              same as the previous command (the          filename is implied to be the same)
   569 $ mv myfile dir/myfile2      moves 'myfile' to dir and renames it to            'myfile2'
  2741 $ mv myfile dir/myfile2      moves 'myfile' to dir and renames it to            'myfile2'
   570 $ mv foo bar baz dir         moves multiple files to directory dir
  2742 $ mv foo bar baz dir         moves multiple files to directory dir
   571 $ mv --help                  shows a very concise help about the                syntax of the command
  2743 $ mv --help                  shows a very concise help about the                syntax of the command
   572 $ man mv                     prints an extensive user manual for                'mv' in the terminal</pre>
  2744 $ man mv                     prints an extensive user manual for                'mv' in the terminal
   573 <p id="ch8ult_module_plan_9f"></a>In all cases, the file or files being moved or renamed can be a directory.</p>
  2745        </pre>
   574 <p id="ch8ult_module_plan_a0"></a>Note that when the command is called with two arguments (as <span class="emphasis"><em>mv name1 name2</em></span> or <span class="emphasis"><em>mv name1 /dir/name2</em></span>), it can have three different effects, depending on whether <span class="emphasis"><em>name2</em></span> does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory, <span class="emphasis"><em>/.</em></span> (or in some Unix versions <span class="emphasis"><em>/</em></span> is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.</p>
  2746        <p id="ch8ult_module_plan_9f">
   575 </div>
  2747         In all cases, the file or files being moved or renamed can be a directory.
   576 </div>
  2748        </p>
   577 <div class="section" title="5.3. rm">
  2749        <p id="ch8ult_module_plan_a0">
   578 <div class="titlepage"><div><div><h3 class="title">
  2750         Note that when the command is called with two arguments (as
   579 <a name="id2771353"></a>5.3. rm</h3></div></div></div>
  2751         <span class="emphasis">
   580 <p id="ch8ult_module_plan_a1"></a><span class="emphasis"><em>rm</em></span> (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.</p>
  2752          <em>
   581 <p id="ch8ult_module_plan_a2"></a>Here's example to remove a file named "foo" from a directory, here shown with the -i option:</p>
  2753           mv name1 name2
   582 <pre class="programlisting">$ rm -i foo
  2754          </em>
   583 remove foo? y</pre>
  2755         </span>
   584 <div class="section" title="5.3.1. Options">
  2756         or
   585 <div class="titlepage"><div><div><h4 class="title">
  2757         <span class="emphasis">
   586 <a name="id2768880"></a>5.3.1. Options</h4></div></div></div>
  2758          <em>
   587 <p id="ch8ult_module_plan_a3"></a>Common options that rm accepts include:</p>
  2759           mv name1 /dir/name2
   588 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  2760          </em>
   589 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_a4"></a><span class="emphasis"><em>-r</em></span>, which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")</p></li>
  2761         </span>
   590 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_a5"></a><span class="emphasis"><em>-i</em></span>, which asks for every deletion to be confirmed ("interactive")</p></li>
  2762         ), it can have three different effects, depending on whether
   591 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_a6"></a><span class="emphasis"><em>-f</em></span>, which ignores non-existent files and overrides any confirmation prompts ("force")</p></li>
  2763         <span class="emphasis">
   592 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_a7"></a><span class="emphasis"><em>-v</em></span>, which shows what is being removed as it happens ("verbose")</p></li>
  2764          <em>
   593 </ul></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_a8"></a><span class="emphasis"><em>rm</em></span> is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).</p>
  2765           name2
   594 <p id="ch8ult_module_plan_a9"></a><span class="emphasis"><em>rm -rf</em></span> (variously, rm -rf /, rm -rf <span style="color: red">&lt;title_reference&gt;*&lt;/title_reference&gt;</span>, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.</p>
  2766          </em>
   595 <p id="ch8ult_module_plan_aa"></a><span class="emphasis"><em>rm</em></span> is often used in conjunction with xargs to supply a list of files to delete:</p>
  2767         </span>
   596 <pre class="programlisting">xargs rm &lt; filelist</pre>
  2768         does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
   597 <p id="ch8ult_module_plan_ab"></a>When <span class="emphasis"><em>rm</em></span> is used on a symbolic link, it deletes the link, but does not affect the target of the link.</p>
  2769         <span class="emphasis">
   598 </div>
  2770          <em>
   599 <div class="section" title="5.3.2. Permissions">
  2771           /.
   600 <div class="titlepage"><div><div><h4 class="title">
  2772          </em>
   601 <a name="id2768983"></a>5.3.2. Permissions</h4></div></div></div>
  2773         </span>
   602 <p id="ch8ult_module_plan_ac"></a>Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)</p>
  2774         (or in some Unix versions
   603 <p id="ch8ult_module_plan_ad"></a>To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.</p>
  2775         <span class="emphasis">
   604 <p id="ch8ult_module_plan_ae"></a>If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.</p>
  2776          <em>
   605 </div>
  2777           /
   606 </div>
  2778          </em>
   607 </div>
  2779         </span>
   608 <div class="section" title="6. Command Line Arguments">
  2780         is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
   609 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  2781        </p>
   610 <a name="id2771662"></a>6. Command Line Arguments</h2></div></div></div>
  2782       </div>
   611 <p id="ch8ult_module_plan_af"></a>In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.</p>
  2783      </div>
   612 <p id="ch8ult_module_plan_b0"></a>For example, in Unix and Unix-like environments, an example of a command-line argument is:</p>
  2784      <div class="section" title="5.3.rm">
   613 <pre class="programlisting">rm file.s</pre>
  2785       <div class="titlepage">
   614 <p id="ch8ult_module_plan_b1"></a>"file.s" is a command line argument which tells the program rm to remove the file "file.s".</p>
  2786        <div>
   615 <p id="ch8ult_module_plan_b2"></a>Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.</p>
  2787         <div>
   616 <p id="ch8ult_module_plan_b3"></a>A command line option or simply <span class="emphasis"><em>option</em></span> (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.</p>
  2788          <h3 class="title">
   617 <p id="ch8ult_module_plan_b4"></a>Long options are introduced via "--", and are typically whole words. For example, <span class="emphasis"><em>ls --long --classify --all</em></span>. Arguments to long options are provided with "=", as <span class="emphasis"><em>ls --block-size=1024</em></span>. Some Unix programs use long options with single dashes, for example MPlayer as in <span class="emphasis"><em>mplayer -nosound</em></span>.</p>
  2789           <a name="id2664447">
   618 <p id="ch8ult_module_plan_b5"></a>Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called <span class="emphasis"><em>-file1</em></span> by using <span class="emphasis"><em>rm -file1</em></span> may produce an error, since rm may interpret <span class="emphasis"><em>-file1</em></span> as a command line switch. Using <span class="emphasis"><em>rm -- -file1</em></span> removes ambiguity.</p>
  2790           </a>
   619 </div>
  2791           5.3.rm
   620 <div class="section" title="7. Basic Text Processing">
  2792          </h3>
   621 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  2793         </div>
   622 <a name="id2771755"></a>7. Basic Text Processing</h2></div></div></div>
  2794        </div>
   623 <div class="section" title="7.1. head">
  2795       </div>
   624 <div class="titlepage"><div><div><h3 class="title">
  2796       <p id="ch8ult_module_plan_a1">
   625 <a name="id2771764"></a>7.1. head</h3></div></div></div>
  2797        <span class="emphasis">
   626 <p id="ch8ult_module_plan_b6"></a><span class="emphasis"><em>head</em></span> is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:</p>
  2798         <em>
   627 <pre class="programlisting">$ head [options] &lt;file_name&gt;</pre>
  2799          rm
   628 <p id="ch8ult_module_plan_b7"></a>By default, <span class="emphasis"><em>head</em></span> will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:</p>
  2800         </em>
   629 <pre class="programlisting">$ head -n 20 filename</pre>
  2801        </span>
   630 <p id="ch8ult_module_plan_b8"></a>This displays the first 5 lines of all files starting with <span class="emphasis"><em>foo</em></span>:</p>
  2802        (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
   631 <pre class="programlisting">$ head -n 5 foo*</pre>
  2803       </p>
   632 <p id="ch8ult_module_plan_b9"></a>Some versions omit the n and just let you say -5.</p>
  2804       <p id="ch8ult_module_plan_a2">
   633 <div class="section" title="7.1.1. Flags">
  2805        Here's example to remove a file named "foo" from a directory, here shown with the -i option:
   634 <div class="titlepage"><div><div><h4 class="title">
  2806       </p>
   635 <a name="id2771815"></a>7.1.1. Flags</h4></div></div></div>
  2807       <pre class="programlisting">
   636 <pre class="programlisting">-c &lt;x number of bytes&gt; Copy first x number of bytes.</pre>
  2808        $ rm -i foo
   637 <p id="ch8ult_module_plan_ba"></a>Other options: <span class="emphasis"><em>sed</em></span></p>
  2809 remove foo? y
   638 <p id="ch8ult_module_plan_bb"></a>Many early versions of Unix did not have this command, and so documentation and books had <span class="emphasis"><em>sed</em></span> do this job:</p>
  2810       </pre>
   639 <pre class="programlisting">sed 5q foo</pre>
  2811       <div class="section" title="5.3.1.Options">
   640 <p id="ch8ult_module_plan_bc"></a>This says to print every line (implicit), and quit after the fifth.</p>
  2812        <div class="titlepage">
   641 </div>
  2813         <div>
   642 </div>
  2814          <div>
   643 <div class="section" title="7.2. tail">
  2815           <h4 class="title">
   644 <div class="titlepage"><div><div><h3 class="title">
  2816            <a name="id2661975">
   645 <a name="id2771851"></a>7.2. tail</h3></div></div></div>
  2817            </a>
   646 <p id="ch8ult_module_plan_bd"></a><span class="emphasis"><em>tail</em></span> is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.</p>
  2818            5.3.1.Options
   647 <p id="ch8ult_module_plan_be"></a>The command-syntax is:</p>
  2819           </h4>
   648 <pre class="programlisting">$ tail [options] &lt;file_name&gt;</pre>
  2820          </div>
   649 <p id="ch8ult_module_plan_bf"></a>By default, <span class="emphasis"><em>tail</em></span> will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:</p>
  2821         </div>
   650 <pre class="programlisting">$ tail -n 20 filename</pre>
  2822        </div>
   651 <p id="ch8ult_module_plan_c0"></a>This example shows the last 15 bytes of all files starting with <span class="emphasis"><em>foo</em></span>:</p>
  2823        <p id="ch8ult_module_plan_a3">
   652 <pre class="programlisting">$ tail -c 15 foo*</pre>
  2824         Common options that rm accepts include:
   653 <p id="ch8ult_module_plan_c1"></a>This example shows all lines of filename from the second line onwards:</p>
  2825        </p>
   654 <pre class="programlisting">$ tail -n +2 filename</pre>
  2826        <span style="color: red">
   655 <p id="ch8ult_module_plan_c2"></a>Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:</p>
  2827         &lt;block_quote&gt;
   656 <pre class="programlisting">$ tail -20 filename
  2828         <div class="itemizedlist">
   657 $ tail -50c filename</pre>
  2829          <ul class="itemizedlist" type="*">
   658 <p id="ch8ult_module_plan_c3"></a>However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.</p>
  2830           <li class="listitem" style="list-style-type: *">
   659 <div class="section" title="7.2.1. File monitoring">
  2831            <p id="ch8ult_module_plan_a4">
   660 <div class="titlepage"><div><div><h4 class="title">
  2832             <span class="emphasis">
   661 <a name="id2771929"></a>7.2.1. File monitoring</h4></div></div></div>
  2833              <em>
   662 <p id="ch8ult_module_plan_c4"></a><span class="emphasis"><em>tail</em></span> has a special command line option <span class="emphasis"><em>-f</em></span> (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:</p>
  2834               -r
   663 <pre class="programlisting">$ tail -f /var/adm/messages</pre>
  2835              </em>
   664 <p id="ch8ult_module_plan_c5"></a>To interrupt tail while it is monitoring, break-in with <span class="emphasis"><em>Ctrl+C</em></span>. This command can be run "in the background" with &amp;, see job control.</p>
  2836             </span>
   665 <p id="ch8ult_module_plan_c6"></a>If you have a command's result to monitor, you can use the <span class="emphasis"><em>watch</em></span> command.</p>
  2837             , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
   666 </div>
  2838            </p>
   667 </div>
  2839           </li>
   668 <div class="section" title="7.3. cut">
  2840           <li class="listitem" style="list-style-type: *">
   669 <div class="titlepage"><div><div><h3 class="title">
  2841            <p id="ch8ult_module_plan_a5">
   670 <a name="id2771978"></a>7.3. cut</h3></div></div></div>
  2842             <span class="emphasis">
   671 <p id="ch8ult_module_plan_c7"></a>In computing, <span class="emphasis"><em>cut</em></span> is a Unix command line utility which is used to extract sections from each line of input — usually from a file.</p>
  2843              <em>
   672 <p id="ch8ult_module_plan_c8"></a>Extraction of line segments can typically be done by <span class="emphasis"><em>bytes (-b), characters (-c)</em></span>, or <span class="emphasis"><em>fields (-f)</em></span> separated by a <span class="emphasis"><em>delimiter (-d — the tab character by default)</em></span>. A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.</p>
  2844               -i
   673 <p id="ch8ult_module_plan_c9"></a>Assuming a file named file containing the lines:</p>
  2845              </em>
   674 <pre class="programlisting">foo:bar:baz:qux:quux
  2846             </span>
       
  2847             , which asks for every deletion to be confirmed ("interactive")
       
  2848            </p>
       
  2849           </li>
       
  2850           <li class="listitem" style="list-style-type: *">
       
  2851            <p id="ch8ult_module_plan_a6">
       
  2852             <span class="emphasis">
       
  2853              <em>
       
  2854               -f
       
  2855              </em>
       
  2856             </span>
       
  2857             , which ignores non-existent files and overrides any confirmation prompts ("force")
       
  2858            </p>
       
  2859           </li>
       
  2860           <li class="listitem" style="list-style-type: *">
       
  2861            <p id="ch8ult_module_plan_a7">
       
  2862             <span class="emphasis">
       
  2863              <em>
       
  2864               -v
       
  2865              </em>
       
  2866             </span>
       
  2867             , which shows what is being removed as it happens ("verbose")
       
  2868            </p>
       
  2869           </li>
       
  2870          </ul>
       
  2871         </div>
       
  2872         &lt;/block_quote&gt;
       
  2873        </span>
       
  2874        <p id="ch8ult_module_plan_a8">
       
  2875         <span class="emphasis">
       
  2876          <em>
       
  2877           rm
       
  2878          </em>
       
  2879         </span>
       
  2880         is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
       
  2881        </p>
       
  2882        <p id="ch8ult_module_plan_a9">
       
  2883         <span class="emphasis">
       
  2884          <em>
       
  2885           rm -rf
       
  2886          </em>
       
  2887         </span>
       
  2888         (variously, rm -rf /, rm -rf
       
  2889         <span style="color: red">
       
  2890          &lt;title_reference&gt;*&lt;/title_reference&gt;
       
  2891         </span>
       
  2892         , and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
       
  2893        </p>
       
  2894        <p id="ch8ult_module_plan_aa">
       
  2895         <span class="emphasis">
       
  2896          <em>
       
  2897           rm
       
  2898          </em>
       
  2899         </span>
       
  2900         is often used in conjunction with xargs to supply a list of files to delete:
       
  2901        </p>
       
  2902        <pre class="programlisting">
       
  2903         xargs rm &lt; filelist
       
  2904        </pre>
       
  2905        <p id="ch8ult_module_plan_ab">
       
  2906         When
       
  2907         <span class="emphasis">
       
  2908          <em>
       
  2909           rm
       
  2910          </em>
       
  2911         </span>
       
  2912         is used on a symbolic link, it deletes the link, but does not affect the target of the link.
       
  2913        </p>
       
  2914       </div>
       
  2915       <div class="section" title="5.3.2.Permissions">
       
  2916        <div class="titlepage">
       
  2917         <div>
       
  2918          <div>
       
  2919           <h4 class="title">
       
  2920            <a name="id2662078">
       
  2921            </a>
       
  2922            5.3.2.Permissions
       
  2923           </h4>
       
  2924          </div>
       
  2925         </div>
       
  2926        </div>
       
  2927        <p id="ch8ult_module_plan_ac">
       
  2928         Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
       
  2929        </p>
       
  2930        <p id="ch8ult_module_plan_ad">
       
  2931         To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
       
  2932        </p>
       
  2933        <p id="ch8ult_module_plan_ae">
       
  2934         If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
       
  2935        </p>
       
  2936       </div>
       
  2937      </div>
       
  2938     </div>
       
  2939     <div class="section" title="6.Command Line Arguments">
       
  2940      <div class="titlepage">
       
  2941       <div>
       
  2942        <div>
       
  2943         <h2 class="title" style="clear: both">
       
  2944          <a name="id2664756">
       
  2945          </a>
       
  2946          6.Command Line Arguments
       
  2947         </h2>
       
  2948        </div>
       
  2949       </div>
       
  2950      </div>
       
  2951      <p id="ch8ult_module_plan_af">
       
  2952       In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
       
  2953      </p>
       
  2954      <p id="ch8ult_module_plan_b0">
       
  2955       For example, in Unix and Unix-like environments, an example of a command-line argument is:
       
  2956      </p>
       
  2957      <pre class="programlisting">
       
  2958       rm file.s
       
  2959      </pre>
       
  2960      <p id="ch8ult_module_plan_b1">
       
  2961       "file.s" is a command line argument which tells the program rm to remove the file "file.s".
       
  2962      </p>
       
  2963      <p id="ch8ult_module_plan_b2">
       
  2964       Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
       
  2965      </p>
       
  2966      <p id="ch8ult_module_plan_b3">
       
  2967       A command line option or simply
       
  2968       <span class="emphasis">
       
  2969        <em>
       
  2970         option
       
  2971        </em>
       
  2972       </span>
       
  2973       (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
       
  2974      </p>
       
  2975      <p id="ch8ult_module_plan_b4">
       
  2976       Long options are introduced via "--", and are typically whole words. For example,
       
  2977       <span class="emphasis">
       
  2978        <em>
       
  2979         ls --long --classify --all
       
  2980        </em>
       
  2981       </span>
       
  2982       . Arguments to long options are provided with "=", as
       
  2983       <span class="emphasis">
       
  2984        <em>
       
  2985         ls --block-size=1024
       
  2986        </em>
       
  2987       </span>
       
  2988       . Some Unix programs use long options with single dashes, for example MPlayer as in
       
  2989       <span class="emphasis">
       
  2990        <em>
       
  2991         mplayer -nosound
       
  2992        </em>
       
  2993       </span>
       
  2994       .
       
  2995      </p>
       
  2996      <p id="ch8ult_module_plan_b5">
       
  2997       Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
       
  2998       <span class="emphasis">
       
  2999        <em>
       
  3000         -file1
       
  3001        </em>
       
  3002       </span>
       
  3003       by using
       
  3004       <span class="emphasis">
       
  3005        <em>
       
  3006         rm -file1
       
  3007        </em>
       
  3008       </span>
       
  3009       may produce an error, since rm may interpret
       
  3010       <span class="emphasis">
       
  3011        <em>
       
  3012         -file1
       
  3013        </em>
       
  3014       </span>
       
  3015       as a command line switch. Using
       
  3016       <span class="emphasis">
       
  3017        <em>
       
  3018         rm -- -file1
       
  3019        </em>
       
  3020       </span>
       
  3021       removes ambiguity.
       
  3022      </p>
       
  3023     </div>
       
  3024     <div class="section" title="7.Basic Text Processing">
       
  3025      <div class="titlepage">
       
  3026       <div>
       
  3027        <div>
       
  3028         <h2 class="title" style="clear: both">
       
  3029          <a name="id2664849">
       
  3030          </a>
       
  3031          7.Basic Text Processing
       
  3032         </h2>
       
  3033        </div>
       
  3034       </div>
       
  3035      </div>
       
  3036      <div class="section" title="7.1.head">
       
  3037       <div class="titlepage">
       
  3038        <div>
       
  3039         <div>
       
  3040          <h3 class="title">
       
  3041           <a name="id2664858">
       
  3042           </a>
       
  3043           7.1.head
       
  3044          </h3>
       
  3045         </div>
       
  3046        </div>
       
  3047       </div>
       
  3048       <p id="ch8ult_module_plan_b6">
       
  3049        <span class="emphasis">
       
  3050         <em>
       
  3051          head
       
  3052         </em>
       
  3053        </span>
       
  3054        is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
       
  3055       </p>
       
  3056       <pre class="programlisting">
       
  3057        $ head [options] &lt;file_name&gt;
       
  3058       </pre>
       
  3059       <p id="ch8ult_module_plan_b7">
       
  3060        By default,
       
  3061        <span class="emphasis">
       
  3062         <em>
       
  3063          head
       
  3064         </em>
       
  3065        </span>
       
  3066        will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
       
  3067       </p>
       
  3068       <pre class="programlisting">
       
  3069        $ head -n 20 filename
       
  3070       </pre>
       
  3071       <p id="ch8ult_module_plan_b8">
       
  3072        This displays the first 5 lines of all files starting with
       
  3073        <span class="emphasis">
       
  3074         <em>
       
  3075          foo
       
  3076         </em>
       
  3077        </span>
       
  3078        :
       
  3079       </p>
       
  3080       <pre class="programlisting">
       
  3081        $ head -n 5 foo*
       
  3082       </pre>
       
  3083       <p id="ch8ult_module_plan_b9">
       
  3084        Some versions omit the n and just let you say -5.
       
  3085       </p>
       
  3086       <div class="section" title="7.1.1.Flags">
       
  3087        <div class="titlepage">
       
  3088         <div>
       
  3089          <div>
       
  3090           <h4 class="title">
       
  3091            <a name="id2664909">
       
  3092            </a>
       
  3093            7.1.1.Flags
       
  3094           </h4>
       
  3095          </div>
       
  3096         </div>
       
  3097        </div>
       
  3098        <pre class="programlisting">
       
  3099         -c &lt;x number of bytes&gt; Copy first x number of bytes.
       
  3100        </pre>
       
  3101        <p id="ch8ult_module_plan_ba">
       
  3102         Other options:
       
  3103         <span class="emphasis">
       
  3104          <em>
       
  3105           sed
       
  3106          </em>
       
  3107         </span>
       
  3108        </p>
       
  3109        <p id="ch8ult_module_plan_bb">
       
  3110         Many early versions of Unix did not have this command, and so documentation and books had
       
  3111         <span class="emphasis">
       
  3112          <em>
       
  3113           sed
       
  3114          </em>
       
  3115         </span>
       
  3116         do this job:
       
  3117        </p>
       
  3118        <pre class="programlisting">
       
  3119         sed 5q foo
       
  3120        </pre>
       
  3121        <p id="ch8ult_module_plan_bc">
       
  3122         This says to print every line (implicit), and quit after the fifth.
       
  3123        </p>
       
  3124       </div>
       
  3125      </div>
       
  3126      <div class="section" title="7.2.tail">
       
  3127       <div class="titlepage">
       
  3128        <div>
       
  3129         <div>
       
  3130          <h3 class="title">
       
  3131           <a name="id2664945">
       
  3132           </a>
       
  3133           7.2.tail
       
  3134          </h3>
       
  3135         </div>
       
  3136        </div>
       
  3137       </div>
       
  3138       <p id="ch8ult_module_plan_bd">
       
  3139        <span class="emphasis">
       
  3140         <em>
       
  3141          tail
       
  3142         </em>
       
  3143        </span>
       
  3144        is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
       
  3145       </p>
       
  3146       <p id="ch8ult_module_plan_be">
       
  3147        The command-syntax is:
       
  3148       </p>
       
  3149       <pre class="programlisting">
       
  3150        $ tail [options] &lt;file_name&gt;
       
  3151       </pre>
       
  3152       <p id="ch8ult_module_plan_bf">
       
  3153        By default,
       
  3154        <span class="emphasis">
       
  3155         <em>
       
  3156          tail
       
  3157         </em>
       
  3158        </span>
       
  3159        will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
       
  3160       </p>
       
  3161       <pre class="programlisting">
       
  3162        $ tail -n 20 filename
       
  3163       </pre>
       
  3164       <p id="ch8ult_module_plan_c0">
       
  3165        This example shows the last 15 bytes of all files starting with
       
  3166        <span class="emphasis">
       
  3167         <em>
       
  3168          foo
       
  3169         </em>
       
  3170        </span>
       
  3171        :
       
  3172       </p>
       
  3173       <pre class="programlisting">
       
  3174        $ tail -c 15 foo*
       
  3175       </pre>
       
  3176       <p id="ch8ult_module_plan_c1">
       
  3177        This example shows all lines of filename from the second line onwards:
       
  3178       </p>
       
  3179       <pre class="programlisting">
       
  3180        $ tail -n +2 filename
       
  3181       </pre>
       
  3182       <p id="ch8ult_module_plan_c2">
       
  3183        Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
       
  3184       </p>
       
  3185       <pre class="programlisting">
       
  3186        $ tail -20 filename
       
  3187 $ tail -50c filename
       
  3188       </pre>
       
  3189       <p id="ch8ult_module_plan_c3">
       
  3190        However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
       
  3191       </p>
       
  3192       <div class="section" title="7.2.1.File monitoring">
       
  3193        <div class="titlepage">
       
  3194         <div>
       
  3195          <div>
       
  3196           <h4 class="title">
       
  3197            <a name="id2665024">
       
  3198            </a>
       
  3199            7.2.1.File monitoring
       
  3200           </h4>
       
  3201          </div>
       
  3202         </div>
       
  3203        </div>
       
  3204        <p id="ch8ult_module_plan_c4">
       
  3205         <span class="emphasis">
       
  3206          <em>
       
  3207           tail
       
  3208          </em>
       
  3209         </span>
       
  3210         has a special command line option
       
  3211         <span class="emphasis">
       
  3212          <em>
       
  3213           -f
       
  3214          </em>
       
  3215         </span>
       
  3216         (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
       
  3217        </p>
       
  3218        <pre class="programlisting">
       
  3219         $ tail -f /var/adm/messages
       
  3220        </pre>
       
  3221        <p id="ch8ult_module_plan_c5">
       
  3222         To interrupt tail while it is monitoring, break-in with
       
  3223         <span class="emphasis">
       
  3224          <em>
       
  3225           Ctrl+C
       
  3226          </em>
       
  3227         </span>
       
  3228         . This command can be run "in the background" with &amp;, see job control.
       
  3229        </p>
       
  3230        <p id="ch8ult_module_plan_c6">
       
  3231         If you have a command's result to monitor, you can use the
       
  3232         <span class="emphasis">
       
  3233          <em>
       
  3234           watch
       
  3235          </em>
       
  3236         </span>
       
  3237         command.
       
  3238        </p>
       
  3239       </div>
       
  3240      </div>
       
  3241      <div class="section" title="7.3.cut">
       
  3242       <div class="titlepage">
       
  3243        <div>
       
  3244         <div>
       
  3245          <h3 class="title">
       
  3246           <a name="id2665073">
       
  3247           </a>
       
  3248           7.3.cut
       
  3249          </h3>
       
  3250         </div>
       
  3251        </div>
       
  3252       </div>
       
  3253       <p id="ch8ult_module_plan_c7">
       
  3254        In computing,
       
  3255        <span class="emphasis">
       
  3256         <em>
       
  3257          cut
       
  3258         </em>
       
  3259        </span>
       
  3260        is a Unix command line utility which is used to extract sections from each line of input  usually from a file.
       
  3261       </p>
       
  3262       <p id="ch8ult_module_plan_c8">
       
  3263        Extraction of line segments can typically be done by
       
  3264        <span class="emphasis">
       
  3265         <em>
       
  3266          bytes (-b), characters (-c)
       
  3267         </em>
       
  3268        </span>
       
  3269        , or
       
  3270        <span class="emphasis">
       
  3271         <em>
       
  3272          fields (-f)
       
  3273         </em>
       
  3274        </span>
       
  3275        separated by a
       
  3276        <span class="emphasis">
       
  3277         <em>
       
  3278          delimiter (-d  the tab character by default)
       
  3279         </em>
       
  3280        </span>
       
  3281        . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
       
  3282       </p>
       
  3283       <p id="ch8ult_module_plan_c9">
       
  3284        Assuming a file named file containing the lines:
       
  3285       </p>
       
  3286       <pre class="programlisting">
       
  3287        foo:bar:baz:qux:quux
   675 one:two:three:four:five:six:seven
  3288 one:two:three:four:five:six:seven
   676 alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu</pre>
  3289 alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
   677 <p id="ch8ult_module_plan_ca"></a>To output the fourth through tenth characters of each line:</p>
  3290       </pre>
   678 <pre class="programlisting">$ cut -c 4-10 file</pre>
  3291       <p id="ch8ult_module_plan_ca">
   679 <p id="ch8ult_module_plan_cb"></a>This gives the output:</p>
  3292        To output the fourth through tenth characters of each line:
   680 <pre class="programlisting">:bar:ba
  3293       </p>
       
  3294       <pre class="programlisting">
       
  3295        $ cut -c 4-10 file
       
  3296       </pre>
       
  3297       <p id="ch8ult_module_plan_cb">
       
  3298        This gives the output:
       
  3299       </p>
       
  3300       <pre class="programlisting">
       
  3301        :bar:ba
   681 :two:th
  3302 :two:th
   682 ha:beta</pre>
  3303 ha:beta
   683 <p id="ch8ult_module_plan_cc"></a>To output the fifth field through the end of the line of each line using the colon character as the field delimiter:</p>
  3304       </pre>
   684 <pre class="programlisting">$ cut -d : -f 5- file</pre>
  3305       <p id="ch8ult_module_plan_cc">
   685 <p id="ch8ult_module_plan_cd"></a>This gives the output:</p>
  3306        To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
   686 <pre class="programlisting">quux
  3307       </p>
       
  3308       <pre class="programlisting">
       
  3309        $ cut -d : -f 5- file
       
  3310       </pre>
       
  3311       <p id="ch8ult_module_plan_cd">
       
  3312        This gives the output:
       
  3313       </p>
       
  3314       <pre class="programlisting">
       
  3315        quux
   687 five:six:seven
  3316 five:six:seven
   688 epsilon:zeta:eta:teta:iota:kappa:lambda:mu</pre>
  3317 epsilon:zeta:eta:teta:iota:kappa:lambda:mu
   689 </div>
  3318       </pre>
   690 <div class="section" title="7.4. paste">
  3319      </div>
   691 <div class="titlepage"><div><div><h3 class="title">
  3320      <div class="section" title="7.4.paste">
   692 <a name="id2772065"></a>7.4. paste</h3></div></div></div>
  3321       <div class="titlepage">
   693 <p id="ch8ult_module_plan_ce"></a><span class="emphasis"><em>paste</em></span> is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility <span class="emphasis"><em>cat</em></span> command which operates on the vertical plane of two or more files.</p>
  3322        <div>
   694 <p id="ch8ult_module_plan_cf"></a>To paste several columns of data together into the file <span class="emphasis"><em>www</em></span> from files <span class="emphasis"><em>who</em></span>, <span class="emphasis"><em>where</em></span>, and <span class="emphasis"><em>when</em></span>:</p>
  3323         <div>
   695 <pre class="programlisting">$ paste who where when &gt; www</pre>
  3324          <h3 class="title">
   696 <p id="ch8ult_module_plan_d0"></a>If the files contain:</p>
  3325           <a name="id2665160">
   697 <table summary="paste" border="1"><colgroup>
  3326           </a>
   698 <col width="11">
  3327           7.4.paste
   699 <col width="12">
  3328          </h3>
   700 <col width="12">
  3329         </div>
   701 </colgroup></table>
  3330        </div>
   702 <p id="ch8ult_module_plan_dd"></a>This creates the file named <span class="emphasis"><em>www</em></span> containing:</p>
  3331       </div>
   703 <pre class="programlisting">Batman            GothamCity       January 3
  3332       <p id="ch8ult_module_plan_ce">
       
  3333        <span class="emphasis">
       
  3334         <em>
       
  3335          paste
       
  3336         </em>
       
  3337        </span>
       
  3338        is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
       
  3339        <span class="emphasis">
       
  3340         <em>
       
  3341          cat
       
  3342         </em>
       
  3343        </span>
       
  3344        command which operates on the vertical plane of two or more files.
       
  3345       </p>
       
  3346       <p id="ch8ult_module_plan_cf">
       
  3347        To paste several columns of data together into the file
       
  3348        <span class="emphasis">
       
  3349         <em>
       
  3350          www
       
  3351         </em>
       
  3352        </span>
       
  3353        from files
       
  3354        <span class="emphasis">
       
  3355         <em>
       
  3356          who
       
  3357         </em>
       
  3358        </span>
       
  3359        ,
       
  3360        <span class="emphasis">
       
  3361         <em>
       
  3362          where
       
  3363         </em>
       
  3364        </span>
       
  3365        , and
       
  3366        <span class="emphasis">
       
  3367         <em>
       
  3368          when
       
  3369         </em>
       
  3370        </span>
       
  3371        :
       
  3372       </p>
       
  3373       <pre class="programlisting">
       
  3374        $ paste who where when &gt; www
       
  3375       </pre>
       
  3376       <p id="ch8ult_module_plan_d0">
       
  3377        If the files contain:
       
  3378       </p>
       
  3379       <table summary="paste" border="1">
       
  3380        <colgroup>
       
  3381         <col width="11">
       
  3382         </col>
       
  3383         <col width="12">
       
  3384         </col>
       
  3385         <col width="12">
       
  3386         </col>
       
  3387        </colgroup>
       
  3388       </table>
       
  3389       <p id="ch8ult_module_plan_dd">
       
  3390        This creates the file named
       
  3391        <span class="emphasis">
       
  3392         <em>
       
  3393          www
       
  3394         </em>
       
  3395        </span>
       
  3396        containing:
       
  3397       </p>
       
  3398       <pre class="programlisting">
       
  3399        Batman            GothamCity       January 3
   704 Trillian          Andromeda        February 4
  3400 Trillian          Andromeda        February 4
   705 Jeeves            London           March 19</pre>
  3401 Jeeves            London           March 19
   706 </div>
  3402       </pre>
   707 </div>
  3403      </div>
   708 <div class="section" title="8. Shell Meta Characters">
  3404     </div>
   709 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  3405     <div class="section" title="8.Shell Meta Characters">
   710 <a name="id2772200"></a>8. Shell Meta Characters</h2></div></div></div>
  3406      <div class="titlepage">
   711 <p id="ch8ult_module_plan_de"></a>Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.</p>
  3407       <div>
   712 <p id="ch8ult_module_plan_df"></a>The shell meta characters include:</p>
  3408        <div>
   713 <p id="ch8ult_module_plan_e0"></a>/ &lt; &gt; ! $ % ^ &amp; * | { } [ ] " ' ` ~ ;</p>
  3409         <h2 class="title" style="clear: both">
   714 <p id="ch8ult_module_plan_e1"></a>Different shells may differ in the meta characters recognized.</p>
  3410          <a name="id2665294">
   715 <p id="ch8ult_module_plan_e2"></a>As an example,</p>
  3411          </a>
   716 <pre class="programlisting">$ ls file.*</pre>
  3412          8.Shell Meta Characters
   717 <p id="ch8ult_module_plan_e3"></a>run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:</p>
  3413         </h2>
   718 <pre class="programlisting">$ ls file.?</pre>
  3414        </div>
   719 <p id="ch8ult_module_plan_e4"></a>run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:</p>
  3415       </div>
   720 <pre class="programlisting">$ more c*</pre>
  3416      </div>
   721 <p id="ch8ult_module_plan_e5"></a>because the c* matches that long file name.</p>
  3417      <p id="ch8ult_module_plan_de">
   722 <p id="ch8ult_module_plan_e6"></a>Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the  to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named <span style="color: red">&lt;title_reference&gt;"``*`|more&lt;/title_reference&gt;</span>"` can be accomplished with:</p>
  3418       Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
   723 <pre class="programlisting">$ rm ??more</pre>
  3419      </p>
   724 <p id="ch8ult_module_plan_e7"></a>or:</p>
  3420      <p id="ch8ult_module_plan_df">
   725 <pre class="programlisting">$ rm $\backslash$*$\backslash$|more</pre>
  3421       The shell meta characters include:
   726 <p id="ch8ult_module_plan_e8"></a>or:</p>
  3422      </p>
   727 <pre class="programlisting">$ rm ''*|more''</pre>
  3423      <p id="ch8ult_module_plan_e0">
   728 </div>
  3424       / &lt; &gt; ! $ % ^ &amp; * | { } [ ] " ' ` ~ ;
   729 <div class="section" title="9. Looking At Files">
  3425      </p>
   730 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  3426      <p id="ch8ult_module_plan_e1">
   731 <a name="id2772308"></a>9. Looking At Files</h2></div></div></div>
  3427       Different shells may differ in the meta characters recognized.
   732 <div class="section" title="9.1. cat">
  3428      </p>
   733 <div class="titlepage"><div><div><h3 class="title">
  3429      <p id="ch8ult_module_plan_e2">
   734 <a name="id2772317"></a>9.1. cat</h3></div></div></div>
  3430       As an example,
   735 <p id="ch8ult_module_plan_e9"></a>The <span class="emphasis"><em>cat</em></span> command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of <span class="emphasis"><em>concatenate</em></span>.</p>
  3431      </p>
   736 <p id="ch8ult_module_plan_ea"></a>The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.</p>
  3432      <pre class="programlisting">
   737 <p id="ch8ult_module_plan_eb"></a>If the filename is specified as -, then <span class="emphasis"><em>cat</em></span> will read from standard input at that point in the sequence. If no files are specified, <span class="emphasis"><em>cat</em></span> will read from standard input entered.</p>
  3433       $ ls file.*
   738 <div class="section" title="9.1.1. Jargon File Definition">
  3434      </pre>
   739 <div class="titlepage"><div><div><h4 class="title">
  3435      <p id="ch8ult_module_plan_e3">
   740 <a name="id2772360"></a>9.1.1. Jargon File Definition</h4></div></div></div>
  3436       run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
   741 <p id="ch8ult_module_plan_ec"></a>The Jargon File version 4.4.7 lists this as the definition of <span class="emphasis"><em>cat</em></span>:</p>
  3437      </p>
   742 <pre class="programlisting">1. To spew an entire file to the screen or some other output sink without
  3438      <pre class="programlisting">
       
  3439       $ ls file.?
       
  3440      </pre>
       
  3441      <p id="ch8ult_module_plan_e4">
       
  3442       run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
       
  3443      </p>
       
  3444      <pre class="programlisting">
       
  3445       $ more c*
       
  3446      </pre>
       
  3447      <p id="ch8ult_module_plan_e5">
       
  3448       because the c* matches that long file name.
       
  3449      </p>
       
  3450      <p id="ch8ult_module_plan_e6">
       
  3451       Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the  to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named
       
  3452       <span style="color: red">
       
  3453        &lt;title_reference&gt;"``*`|more&lt;/title_reference&gt;
       
  3454       </span>
       
  3455       "` can be accomplished with:
       
  3456      </p>
       
  3457      <pre class="programlisting">
       
  3458       $ rm ??more
       
  3459      </pre>
       
  3460      <p id="ch8ult_module_plan_e7">
       
  3461       or:
       
  3462      </p>
       
  3463      <pre class="programlisting">
       
  3464       $ rm $\backslash$*$\backslash$|more
       
  3465      </pre>
       
  3466      <p id="ch8ult_module_plan_e8">
       
  3467       or:
       
  3468      </p>
       
  3469      <pre class="programlisting">
       
  3470       $ rm ''*|more''
       
  3471      </pre>
       
  3472     </div>
       
  3473     <div class="section" title="9.Looking At Files">
       
  3474      <div class="titlepage">
       
  3475       <div>
       
  3476        <div>
       
  3477         <h2 class="title" style="clear: both">
       
  3478          <a name="id2665403">
       
  3479          </a>
       
  3480          9.Looking At Files
       
  3481         </h2>
       
  3482        </div>
       
  3483       </div>
       
  3484      </div>
       
  3485      <div class="section" title="9.1.cat">
       
  3486       <div class="titlepage">
       
  3487        <div>
       
  3488         <div>
       
  3489          <h3 class="title">
       
  3490           <a name="id2665411">
       
  3491           </a>
       
  3492           9.1.cat
       
  3493          </h3>
       
  3494         </div>
       
  3495        </div>
       
  3496       </div>
       
  3497       <p id="ch8ult_module_plan_e9">
       
  3498        The
       
  3499        <span class="emphasis">
       
  3500         <em>
       
  3501          cat
       
  3502         </em>
       
  3503        </span>
       
  3504        command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
       
  3505        <span class="emphasis">
       
  3506         <em>
       
  3507          concatenate
       
  3508         </em>
       
  3509        </span>
       
  3510        .
       
  3511       </p>
       
  3512       <p id="ch8ult_module_plan_ea">
       
  3513        The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
       
  3514       </p>
       
  3515       <p id="ch8ult_module_plan_eb">
       
  3516        If the filename is specified as -, then
       
  3517        <span class="emphasis">
       
  3518         <em>
       
  3519          cat
       
  3520         </em>
       
  3521        </span>
       
  3522        will read from standard input at that point in the sequence. If no files are specified,
       
  3523        <span class="emphasis">
       
  3524         <em>
       
  3525          cat
       
  3526         </em>
       
  3527        </span>
       
  3528        will read from standard input entered.
       
  3529       </p>
       
  3530       <div class="section" title="9.1.1.Jargon File Definition">
       
  3531        <div class="titlepage">
       
  3532         <div>
       
  3533          <div>
       
  3534           <h4 class="title">
       
  3535            <a name="id2665455">
       
  3536            </a>
       
  3537            9.1.1.Jargon File Definition
       
  3538           </h4>
       
  3539          </div>
       
  3540         </div>
       
  3541        </div>
       
  3542        <p id="ch8ult_module_plan_ec">
       
  3543         The Jargon File version 4.4.7 lists this as the definition of
       
  3544         <span class="emphasis">
       
  3545          <em>
       
  3546           cat
       
  3547          </em>
       
  3548         </span>
       
  3549         :
       
  3550        </p>
       
  3551        <pre class="programlisting">
       
  3552         1. To spew an entire file to the screen or some other output sink without
   743      pause (syn. blast).
  3553      pause (syn. blast).
   744 
  3554 
   745 2. By extension, to dump large amounts of data at an unprepared target or
  3555 2. By extension, to dump large amounts of data at an unprepared target or
   746      with no intention of browsing it carefully. Usage: considered silly.
  3556      with no intention of browsing it carefully. Usage: considered silly.
   747      Rare outside Unix sites. See also dd, BLT.
  3557      Rare outside Unix sites. See also dd, BLT.
   756      bad user-interface design, because of its woefully unobvious name.
  3566      bad user-interface design, because of its woefully unobvious name.
   757      It is far more often used to blast a single file to standard output
  3567      It is far more often used to blast a single file to standard output
   758      than to concatenate two or more files. The name cat for the former
  3568      than to concatenate two or more files. The name cat for the former
   759      operation is just as unintuitive as, say, LISP's cdr.
  3569      operation is just as unintuitive as, say, LISP's cdr.
   760 
  3570 
   761      Of such oppositions are holy wars made...</pre>
  3571      Of such oppositions are holy wars made...
   762 </div>
  3572        </pre>
   763 <div class="section" title="9.1.2. Useless Use of 'cat'">
  3573       </div>
   764 <div class="titlepage"><div><div><h4 class="title">
  3574       <div class="section" title="9.1.2.Useless Use of 'cat'">
   765 <a name="id2772400"></a>9.1.2. Useless Use of 'cat'</h4></div></div></div>
  3575        <div class="titlepage">
   766 <p id="ch8ult_module_plan_ed"></a>UUOC (from comp.unix.shell on Usenet) stands for “Useless Use of cat”. As it is observed on <span class="emphasis"><em>comp.unix.shell</em></span>, “The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.”</p>
  3576         <div>
   767 <p id="ch8ult_module_plan_ee"></a>Nevertheless one sees people doing:</p>
  3577          <div>
   768 <pre class="programlisting">$ cat file | some_command and its args ...</pre>
  3578           <h4 class="title">
   769 <p id="ch8ult_module_plan_ef"></a>instead of the equivalent and cheaper:</p>
  3579            <a name="id2665494">
   770 <pre class="programlisting">&lt;file some_command and its args ...</pre>
  3580            </a>
   771 <p id="ch8ult_module_plan_f0"></a>or (equivalently and more classically):</p>
  3581            9.1.2.Useless Use of 'cat'
   772 <pre class="programlisting">some_command and its args ... &lt;file</pre>
  3582           </h4>
   773 <p id="ch8ult_module_plan_f1"></a>Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.</p>
  3583          </div>
   774 <p id="ch8ult_module_plan_f2"></a>Amongst many, it is still considered safer to use <span class="emphasis"><em>cat</em></span> for such cases given that the &lt; and &gt; keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using &gt; instead of &lt; can be high and prohibitive.</p>
  3584         </div>
   775 </div>
  3585        </div>
   776 <div class="section" title="9.1.3. zcat">
  3586        <p id="ch8ult_module_plan_ed">
   777 <div class="titlepage"><div><div><h4 class="title">
  3587         UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
   778 <a name="id2772471"></a>9.1.3. zcat</h4></div></div></div>
  3588         <span class="emphasis">
   779 <p id="ch8ult_module_plan_f3"></a><span class="emphasis"><em>zcat</em></span> is a Unix program similar to <span class="emphasis"><em>cat</em></span>, that decompresses individual files and concatenates them to standard output. Traditionally <span class="emphasis"><em>zcat</em></span> operated on files compressed by compress but today it is usually able to operate on <span class="emphasis"><em>gzip</em></span> or even <span class="emphasis"><em>bzip2</em></span> archives. On such systems, it is equivalent to <span class="emphasis"><em>gunzip -c</em></span></p>
  3589          <em>
   780 </div>
  3590           comp.unix.shell
   781 </div>
  3591          </em>
   782 <div class="section" title="9.2. more">
  3592         </span>
   783 <div class="titlepage"><div><div><h3 class="title">
  3593         , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
   784 <a name="id2772505"></a>9.2. more</h3></div></div></div>
  3594        </p>
   785 <p id="ch8ult_module_plan_f4"></a>In computing, <span class="emphasis"><em>more</em></span> is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.</p>
  3595        <p id="ch8ult_module_plan_ee">
   786 <div class="section" title="9.2.1. Usage">
  3596         Nevertheless one sees people doing:
   787 <div class="titlepage"><div><div><h4 class="title">
  3597        </p>
   788 <a name="id2772524"></a>9.2.1. Usage</h4></div></div></div>
  3598        <pre class="programlisting">
   789 <p id="ch8ult_module_plan_f5"></a>The command-syntax is:</p>
  3599         $ cat file | some_command and its args ...
   790 <pre class="programlisting">$ more [options] [file_name]</pre>
  3600        </pre>
   791 <p id="ch8ult_module_plan_f6"></a>If no file name is provided, <span class="emphasis"><em>more</em></span> looks for input from stdin.</p>
  3601        <p id="ch8ult_module_plan_ef">
   792 <p id="ch8ult_module_plan_f7"></a>Once <span class="emphasis"><em>more</em></span> has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause <span class="emphasis"><em>more</em></span> to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that <span class="emphasis"><em>more</em></span> has paged through. (This percentage includes the text displayed on the current screen.) When <span class="emphasis"><em>more</em></span> reaches the end of a file (100%) it exits. The most common methods of navigating through a file are <span class="emphasis"><em>Enter</em></span>, which advances the output by one line, and <span class="emphasis"><em>Space</em></span>, which advances the output by one screen.</p>
  3602         instead of the equivalent and cheaper:
   793 <p id="ch8ult_module_plan_f8"></a>There are also other commands that can be used while navigating through the document; consult <span class="emphasis"><em>more</em></span>'s <span class="emphasis"><em>man</em></span> page for more details.</p>
  3603        </p>
   794 <p id="ch8ult_module_plan_f9"></a><span class="emphasis"><em>Options</em></span> are typically entered before the file name, but can also be entered in the environment variable <span class="emphasis"><em>$MORE</em></span>. Options entered in the actual command line will override those entered in the <span class="emphasis"><em>$MORE</em></span> environment variable. Available options may vary between Unix systems.</p>
  3604        <pre class="programlisting">
   795 </div>
  3605         &lt;file some_command and its args ...
   796 </div>
  3606        </pre>
   797 <div class="section" title="9.3. less">
  3607        <p id="ch8ult_module_plan_f0">
   798 <div class="titlepage"><div><div><h3 class="title">
  3608         or (equivalently and more classically):
   799 <a name="id2772616"></a>9.3. less</h3></div></div></div>
  3609        </p>
   800 <p id="ch8ult_module_plan_fa"></a><span class="emphasis"><em>less</em></span> is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to <span class="emphasis"><em>more</em></span>, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, <span class="emphasis"><em>less</em></span> does not need to read the entire file before starting, resulting in faster load times with large files.</p>
  3610        <pre class="programlisting">
   801 <div class="section" title="9.3.1. Usage">
  3611         some_command and its args ... &lt;file
   802 <div class="titlepage"><div><div><h4 class="title">
  3612        </pre>
   803 <a name="id2772644"></a>9.3.1. Usage</h4></div></div></div>
  3613        <p id="ch8ult_module_plan_f1">
   804 <p id="ch8ult_module_plan_fb"></a><span class="emphasis"><em>less</em></span> can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While <span class="emphasis"><em>less</em></span> is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both <span class="emphasis"><em>more</em></span> and <span class="emphasis"><em>vi</em></span>. It is also possible to search for character patterns in the file.</p>
  3614         Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
   805 <p id="ch8ult_module_plan_fc"></a>By default, <span class="emphasis"><em>less</em></span> displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.</p>
  3615        </p>
   806 <p id="ch8ult_module_plan_fd"></a>The command-syntax is:</p>
  3616        <p id="ch8ult_module_plan_f2">
   807 <pre class="programlisting">$ less [options] file_name</pre>
  3617         Amongst many, it is still considered safer to use
   808 </div>
  3618         <span class="emphasis">
   809 <div class="section" title="9.3.2. Frequently Used Options">
  3619          <em>
   810 <div class="titlepage"><div><div><h4 class="title">
  3620           cat
   811 <a name="id2772699"></a>9.3.2. Frequently Used Options</h4></div></div></div>
  3621          </em>
   812 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  3622         </span>
   813 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_fe"></a>-g: Highlights just the current match of any searched string.</p></li>
  3623         for such cases given that the &lt; and &gt; keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using &gt; instead of &lt; can be high and prohibitive.
   814 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_ff"></a>-I: Case-insensitive searches.</p></li>
  3624        </p>
   815 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_100"></a>-M: Shows more detailed prompt, including file position.</p></li>
  3625       </div>
   816 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_101"></a>-N: Shows line numbers (useful for source code viewing).</p></li>
  3626       <div class="section" title="9.1.3.zcat">
   817 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_102"></a>-S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.</p></li>
  3627        <div class="titlepage">
   818 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_103"></a>-?: Shows help.</p></li>
  3628         <div>
   819 </ul></div>&lt;/block_quote&gt;</span>
  3629          <div>
   820 </div>
  3630           <h4 class="title">
   821 <div class="section" title="9.3.3. Frequently Used Commands">
  3631            <a name="id2665565">
   822 <div class="titlepage"><div><div><h4 class="title">
  3632            </a>
   823 <a name="id2772752"></a>9.3.3. Frequently Used Commands</h4></div></div></div>
  3633            9.1.3.zcat
   824 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  3634           </h4>
   825 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_104"></a>[Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.</p></li>
  3635          </div>
   826 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_105"></a>[Space bar]: Next page.</p></li>
  3636         </div>
   827 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_106"></a>b: Previous page.</p></li>
  3637        </div>
   828 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_107"></a>ng: Jump to line number n. Default is the start of the file.</p></li>
  3638        <p id="ch8ult_module_plan_f3">
   829 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_108"></a>nG: Jump to line number n. Default is the end of the file.</p></li>
  3639         <span class="emphasis">
   830 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_109"></a>/pattern: Search for pattern. Regular expressions can be used.</p></li>
  3640          <em>
   831 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_10a"></a>'^ or g: Go to start of file.</p></li>
  3641           zcat
   832 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_10b"></a>'$ or G: Go to end of file.</p></li>
  3642          </em>
   833 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_10c"></a>s: Save current content (got from another program like grep) in a file.</p></li>
  3643         </span>
   834 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_10d"></a>=: File information.</p></li>
  3644         is a Unix program similar to
   835 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_10e"></a>h: Help.</p></li>
  3645         <span class="emphasis">
   836 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_10f"></a>q: Quit.</p></li>
  3646          <em>
   837 </ul></div>&lt;/block_quote&gt;</span>
  3647           cat
   838 </div>
  3648          </em>
   839 <div class="section" title="9.3.4. Examples">
  3649         </span>
   840 <div class="titlepage"><div><div><h4 class="title">
  3650         , that decompresses individual files and concatenates them to standard output. Traditionally
   841 <a name="id2772843"></a>9.3.4. Examples</h4></div></div></div>
  3651         <span class="emphasis">
   842 <pre class="programlisting">$ less -M readme.txt                     #Read "readme.txt."
  3652          <em>
       
  3653           zcat
       
  3654          </em>
       
  3655         </span>
       
  3656         operated on files compressed by compress but today it is usually able to operate on
       
  3657         <span class="emphasis">
       
  3658          <em>
       
  3659           gzip
       
  3660          </em>
       
  3661         </span>
       
  3662         or even
       
  3663         <span class="emphasis">
       
  3664          <em>
       
  3665           bzip2
       
  3666          </em>
       
  3667         </span>
       
  3668         archives. On such systems, it is equivalent to
       
  3669         <span class="emphasis">
       
  3670          <em>
       
  3671           gunzip -c
       
  3672          </em>
       
  3673         </span>
       
  3674        </p>
       
  3675       </div>
       
  3676      </div>
       
  3677      <div class="section" title="9.2.more">
       
  3678       <div class="titlepage">
       
  3679        <div>
       
  3680         <div>
       
  3681          <h3 class="title">
       
  3682           <a name="id2665599">
       
  3683           </a>
       
  3684           9.2.more
       
  3685          </h3>
       
  3686         </div>
       
  3687        </div>
       
  3688       </div>
       
  3689       <p id="ch8ult_module_plan_f4">
       
  3690        In computing,
       
  3691        <span class="emphasis">
       
  3692         <em>
       
  3693          more
       
  3694         </em>
       
  3695        </span>
       
  3696        is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
       
  3697       </p>
       
  3698       <div class="section" title="9.2.1.Usage">
       
  3699        <div class="titlepage">
       
  3700         <div>
       
  3701          <div>
       
  3702           <h4 class="title">
       
  3703            <a name="id2665618">
       
  3704            </a>
       
  3705            9.2.1.Usage
       
  3706           </h4>
       
  3707          </div>
       
  3708         </div>
       
  3709        </div>
       
  3710        <p id="ch8ult_module_plan_f5">
       
  3711         The command-syntax is:
       
  3712        </p>
       
  3713        <pre class="programlisting">
       
  3714         $ more [options] [file_name]
       
  3715        </pre>
       
  3716        <p id="ch8ult_module_plan_f6">
       
  3717         If no file name is provided,
       
  3718         <span class="emphasis">
       
  3719          <em>
       
  3720           more
       
  3721          </em>
       
  3722         </span>
       
  3723         looks for input from stdin.
       
  3724        </p>
       
  3725        <p id="ch8ult_module_plan_f7">
       
  3726         Once
       
  3727         <span class="emphasis">
       
  3728          <em>
       
  3729           more
       
  3730          </em>
       
  3731         </span>
       
  3732         has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
       
  3733         <span class="emphasis">
       
  3734          <em>
       
  3735           more
       
  3736          </em>
       
  3737         </span>
       
  3738         to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
       
  3739         <span class="emphasis">
       
  3740          <em>
       
  3741           more
       
  3742          </em>
       
  3743         </span>
       
  3744         has paged through. (This percentage includes the text displayed on the current screen.) When
       
  3745         <span class="emphasis">
       
  3746          <em>
       
  3747           more
       
  3748          </em>
       
  3749         </span>
       
  3750         reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
       
  3751         <span class="emphasis">
       
  3752          <em>
       
  3753           Enter
       
  3754          </em>
       
  3755         </span>
       
  3756         , which advances the output by one line, and
       
  3757         <span class="emphasis">
       
  3758          <em>
       
  3759           Space
       
  3760          </em>
       
  3761         </span>
       
  3762         , which advances the output by one screen.
       
  3763        </p>
       
  3764        <p id="ch8ult_module_plan_f8">
       
  3765         There are also other commands that can be used while navigating through the document; consult
       
  3766         <span class="emphasis">
       
  3767          <em>
       
  3768           more
       
  3769          </em>
       
  3770         </span>
       
  3771         's
       
  3772         <span class="emphasis">
       
  3773          <em>
       
  3774           man
       
  3775          </em>
       
  3776         </span>
       
  3777         page for more details.
       
  3778        </p>
       
  3779        <p id="ch8ult_module_plan_f9">
       
  3780         <span class="emphasis">
       
  3781          <em>
       
  3782           Options
       
  3783          </em>
       
  3784         </span>
       
  3785         are typically entered before the file name, but can also be entered in the environment variable
       
  3786         <span class="emphasis">
       
  3787          <em>
       
  3788           $MORE
       
  3789          </em>
       
  3790         </span>
       
  3791         . Options entered in the actual command line will override those entered in the
       
  3792         <span class="emphasis">
       
  3793          <em>
       
  3794           $MORE
       
  3795          </em>
       
  3796         </span>
       
  3797         environment variable. Available options may vary between Unix systems.
       
  3798        </p>
       
  3799       </div>
       
  3800      </div>
       
  3801      <div class="section" title="9.3.less">
       
  3802       <div class="titlepage">
       
  3803        <div>
       
  3804         <div>
       
  3805          <h3 class="title">
       
  3806           <a name="id2665710">
       
  3807           </a>
       
  3808           9.3.less
       
  3809          </h3>
       
  3810         </div>
       
  3811        </div>
       
  3812       </div>
       
  3813       <p id="ch8ult_module_plan_fa">
       
  3814        <span class="emphasis">
       
  3815         <em>
       
  3816          less
       
  3817         </em>
       
  3818        </span>
       
  3819        is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
       
  3820        <span class="emphasis">
       
  3821         <em>
       
  3822          more
       
  3823         </em>
       
  3824        </span>
       
  3825        , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
       
  3826        <span class="emphasis">
       
  3827         <em>
       
  3828          less
       
  3829         </em>
       
  3830        </span>
       
  3831        does not need to read the entire file before starting, resulting in faster load times with large files.
       
  3832       </p>
       
  3833       <div class="section" title="9.3.1.Usage">
       
  3834        <div class="titlepage">
       
  3835         <div>
       
  3836          <div>
       
  3837           <h4 class="title">
       
  3838            <a name="id2665739">
       
  3839            </a>
       
  3840            9.3.1.Usage
       
  3841           </h4>
       
  3842          </div>
       
  3843         </div>
       
  3844        </div>
       
  3845        <p id="ch8ult_module_plan_fb">
       
  3846         <span class="emphasis">
       
  3847          <em>
       
  3848           less
       
  3849          </em>
       
  3850         </span>
       
  3851         can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
       
  3852         <span class="emphasis">
       
  3853          <em>
       
  3854           less
       
  3855          </em>
       
  3856         </span>
       
  3857         is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
       
  3858         <span class="emphasis">
       
  3859          <em>
       
  3860           more
       
  3861          </em>
       
  3862         </span>
       
  3863         and
       
  3864         <span class="emphasis">
       
  3865          <em>
       
  3866           vi
       
  3867          </em>
       
  3868         </span>
       
  3869         . It is also possible to search for character patterns in the file.
       
  3870        </p>
       
  3871        <p id="ch8ult_module_plan_fc">
       
  3872         By default,
       
  3873         <span class="emphasis">
       
  3874          <em>
       
  3875           less
       
  3876          </em>
       
  3877         </span>
       
  3878         displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
       
  3879        </p>
       
  3880        <p id="ch8ult_module_plan_fd">
       
  3881         The command-syntax is:
       
  3882        </p>
       
  3883        <pre class="programlisting">
       
  3884         $ less [options] file_name
       
  3885        </pre>
       
  3886       </div>
       
  3887       <div class="section" title="9.3.2.Frequently Used Options">
       
  3888        <div class="titlepage">
       
  3889         <div>
       
  3890          <div>
       
  3891           <h4 class="title">
       
  3892            <a name="id2665794">
       
  3893            </a>
       
  3894            9.3.2.Frequently Used Options
       
  3895           </h4>
       
  3896          </div>
       
  3897         </div>
       
  3898        </div>
       
  3899        <span style="color: red">
       
  3900         &lt;block_quote&gt;
       
  3901         <div class="itemizedlist">
       
  3902          <ul class="itemizedlist" type="*">
       
  3903           <li class="listitem" style="list-style-type: *">
       
  3904            <p id="ch8ult_module_plan_fe">
       
  3905             -g: Highlights just the current match of any searched string.
       
  3906            </p>
       
  3907           </li>
       
  3908           <li class="listitem" style="list-style-type: *">
       
  3909            <p id="ch8ult_module_plan_ff">
       
  3910             -I: Case-insensitive searches.
       
  3911            </p>
       
  3912           </li>
       
  3913           <li class="listitem" style="list-style-type: *">
       
  3914            <p id="ch8ult_module_plan_100">
       
  3915             -M: Shows more detailed prompt, including file position.
       
  3916            </p>
       
  3917           </li>
       
  3918           <li class="listitem" style="list-style-type: *">
       
  3919            <p id="ch8ult_module_plan_101">
       
  3920             -N: Shows line numbers (useful for source code viewing).
       
  3921            </p>
       
  3922           </li>
       
  3923           <li class="listitem" style="list-style-type: *">
       
  3924            <p id="ch8ult_module_plan_102">
       
  3925             -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
       
  3926            </p>
       
  3927           </li>
       
  3928           <li class="listitem" style="list-style-type: *">
       
  3929            <p id="ch8ult_module_plan_103">
       
  3930             -?: Shows help.
       
  3931            </p>
       
  3932           </li>
       
  3933          </ul>
       
  3934         </div>
       
  3935         &lt;/block_quote&gt;
       
  3936        </span>
       
  3937       </div>
       
  3938       <div class="section" title="9.3.3.Frequently Used Commands">
       
  3939        <div class="titlepage">
       
  3940         <div>
       
  3941          <div>
       
  3942           <h4 class="title">
       
  3943            <a name="id2665847">
       
  3944            </a>
       
  3945            9.3.3.Frequently Used Commands
       
  3946           </h4>
       
  3947          </div>
       
  3948         </div>
       
  3949        </div>
       
  3950        <span style="color: red">
       
  3951         &lt;block_quote&gt;
       
  3952         <div class="itemizedlist">
       
  3953          <ul class="itemizedlist" type="*">
       
  3954           <li class="listitem" style="list-style-type: *">
       
  3955            <p id="ch8ult_module_plan_104">
       
  3956             [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
       
  3957            </p>
       
  3958           </li>
       
  3959           <li class="listitem" style="list-style-type: *">
       
  3960            <p id="ch8ult_module_plan_105">
       
  3961             [Space bar]: Next page.
       
  3962            </p>
       
  3963           </li>
       
  3964           <li class="listitem" style="list-style-type: *">
       
  3965            <p id="ch8ult_module_plan_106">
       
  3966             b: Previous page.
       
  3967            </p>
       
  3968           </li>
       
  3969           <li class="listitem" style="list-style-type: *">
       
  3970            <p id="ch8ult_module_plan_107">
       
  3971             ng: Jump to line number n. Default is the start of the file.
       
  3972            </p>
       
  3973           </li>
       
  3974           <li class="listitem" style="list-style-type: *">
       
  3975            <p id="ch8ult_module_plan_108">
       
  3976             nG: Jump to line number n. Default is the end of the file.
       
  3977            </p>
       
  3978           </li>
       
  3979           <li class="listitem" style="list-style-type: *">
       
  3980            <p id="ch8ult_module_plan_109">
       
  3981             /pattern: Search for pattern. Regular expressions can be used.
       
  3982            </p>
       
  3983           </li>
       
  3984           <li class="listitem" style="list-style-type: *">
       
  3985            <p id="ch8ult_module_plan_10a">
       
  3986             '^ or g: Go to start of file.
       
  3987            </p>
       
  3988           </li>
       
  3989           <li class="listitem" style="list-style-type: *">
       
  3990            <p id="ch8ult_module_plan_10b">
       
  3991             '$ or G: Go to end of file.
       
  3992            </p>
       
  3993           </li>
       
  3994           <li class="listitem" style="list-style-type: *">
       
  3995            <p id="ch8ult_module_plan_10c">
       
  3996             s: Save current content (got from another program like grep) in a file.
       
  3997            </p>
       
  3998           </li>
       
  3999           <li class="listitem" style="list-style-type: *">
       
  4000            <p id="ch8ult_module_plan_10d">
       
  4001             =: File information.
       
  4002            </p>
       
  4003           </li>
       
  4004           <li class="listitem" style="list-style-type: *">
       
  4005            <p id="ch8ult_module_plan_10e">
       
  4006             h: Help.
       
  4007            </p>
       
  4008           </li>
       
  4009           <li class="listitem" style="list-style-type: *">
       
  4010            <p id="ch8ult_module_plan_10f">
       
  4011             q: Quit.
       
  4012            </p>
       
  4013           </li>
       
  4014          </ul>
       
  4015         </div>
       
  4016         &lt;/block_quote&gt;
       
  4017        </span>
       
  4018       </div>
       
  4019       <div class="section" title="9.3.4.Examples">
       
  4020        <div class="titlepage">
       
  4021         <div>
       
  4022          <div>
       
  4023           <h4 class="title">
       
  4024            <a name="id2665938">
       
  4025            </a>
       
  4026            9.3.4.Examples
       
  4027           </h4>
       
  4028          </div>
       
  4029         </div>
       
  4030        </div>
       
  4031        <pre class="programlisting">
       
  4032         $ less -M readme.txt                     #Read "readme.txt."
   843 $ less +F /var/log/mail.log              #Follow mode for log
  4033 $ less +F /var/log/mail.log              #Follow mode for log
   844 $ file * | less                          #Easier file analysis.
  4034 $ file * | less                          #Easier file analysis.
   845 $ grep -i void *.c | less -I -p void     #Case insensitive search                                                         for "void" in all .c files</pre>
  4035 $ grep -i void *.c | less -I -p void     #Case insensitive search                                                         for "void" in all .c files
   846 </div>
  4036        </pre>
   847 </div>
  4037       </div>
   848 </div>
  4038      </div>
   849 <div class="section" title="10. Directory Structure">
  4039     </div>
   850 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  4040     <div class="section" title="10.Directory Structure">
   851 <a name="id2772859"></a>10. Directory Structure</h2></div></div></div>
  4041      <div class="titlepage">
   852 <p id="ch8ult_module_plan_110"></a>In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.</p>
  4042       <div>
   853 <p id="ch8ult_module_plan_111"></a>The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.</p>
  4043        <div>
   854 <table summary="Directory Structure" border="1"><colgroup>
  4044         <h2 class="title" style="clear: both">
   855 <col width="15">
  4045          <a name="id2665953">
   856 <col width="48">
  4046          </a>
   857 </colgroup></table>
  4047          10.Directory Structure
   858 <div class="section" title="10.1. man hier">
  4048         </h2>
   859 <div class="titlepage"><div><div><h3 class="title">
  4049        </div>
   860 <a name="id2773133"></a>10.1. man hier</h3></div></div></div>
  4050       </div>
   861 <p id="ch8ult_module_plan_136"></a>This is the manual page on the UNIX filesystem. The syntax for this is:</p>
  4051      </div>
   862 <pre class="programlisting">$ man hier</pre>
  4052      <p id="ch8ult_module_plan_110">
   863 </div>
  4053       In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
   864 <div class="section" title="10.2. ls -l">
  4054      </p>
   865 <div class="titlepage"><div><div><h3 class="title">
  4055      <p id="ch8ult_module_plan_111">
   866 <a name="id2773150"></a>10.2. ls -l</h3></div></div></div>
  4056       The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
   867 <p id="ch8ult_module_plan_137"></a>Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is</p>
  4057      </p>
   868 <pre class="programlisting">$ ls -l</pre>
  4058      <table summary="Directory Structure" border="1">
   869 <p id="ch8ult_module_plan_138"></a>This can be done after entering the required directory.</p>
  4059       <colgroup>
   870 </div>
  4060        <col width="15">
   871 </div>
  4061        </col>
   872 <div class="section" title="11. Permissions and Ownership">
  4062        <col width="48">
   873 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  4063        </col>
   874 <a name="id2773173"></a>11. Permissions and Ownership</h2></div></div></div>
  4064       </colgroup>
   875 <div class="section" title="11.1. chmod">
  4065      </table>
   876 <div class="titlepage"><div><div><h3 class="title">
  4066      <div class="section" title="10.1.man hier">
   877 <a name="id2773182"></a>11.1. chmod</h3></div></div></div>
  4067       <div class="titlepage">
   878 <p id="ch8ult_module_plan_139"></a>The <span class="emphasis"><em>chmod</em></span> command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&amp;T Unix version 1, and is still used today on Unix-like machines.</p>
  4068        <div>
   879 <div class="section" title="11.1.1. Usage">
  4069         <div>
   880 <div class="titlepage"><div><div><h4 class="title">
  4070          <h3 class="title">
   881 <a name="id2773207"></a>11.1.1. Usage</h4></div></div></div>
  4071           <a name="id2666228">
   882 <p id="ch8ult_module_plan_13a"></a>The <span class="emphasis"><em>chmod</em></span> command options are specified like this:</p>
  4072           </a>
   883 <pre class="programlisting">$ chmod [options] mode[,mode] file1 [file2 ...]</pre>
  4073           10.1.man hier
   884 <p id="ch8ult_module_plan_13b"></a>To view what the permissions currently are, type:</p>
  4074          </h3>
   885 <pre class="programlisting">$ ls -l file</pre>
  4075         </div>
   886 </div>
  4076        </div>
   887 <div class="section" title="11.1.2. Command line options">
  4077       </div>
   888 <div class="titlepage"><div><div><h4 class="title">
  4078       <p id="ch8ult_module_plan_136">
   889 <a name="id2773236"></a>11.1.2. Command line options</h4></div></div></div>
  4079        This is the manual page on the UNIX filesystem. The syntax for this is:
   890 <p id="ch8ult_module_plan_13c"></a>The <span class="emphasis"><em>chmod</em></span> command has a number of command line options that affect its behavior. The most common options are:</p>
  4080       </p>
   891 <span style="color: red">&lt;block_quote&gt;<div class="itemizedlist"><ul class="itemizedlist" type="*">
  4081       <pre class="programlisting">
   892 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_13d"></a>-R: Changes the modes of directories and files recursively</p></li>
  4082        $ man hier
   893 <li class="listitem" style="list-style-type: *"><p id="ch8ult_module_plan_13e"></a>-v: Verbose mode; lists all files as they are being processed</p></li>
  4083       </pre>
   894 </ul></div>&lt;/block_quote&gt;</span><div class="section" title="11.1.2.1. Symbolic modes">
  4084      </div>
   895 <div class="titlepage"><div><div><h5 class="title">
  4085      <div class="section" title="10.2.ls -l">
   896 <a name="id2773272"></a>11.1.2.1. Symbolic modes</h5></div></div></div>
  4086       <div class="titlepage">
   897 <p id="ch8ult_module_plan_13f"></a>To the <span class="emphasis"><em>chmod</em></span> utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:</p>
  4087        <div>
   898 <pre class="programlisting">$ chmod [references][operator][modes] file1 ...</pre>
  4088         <div>
   899 <p id="ch8ult_module_plan_140"></a>The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to “all” but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:</p>
  4089          <h3 class="title">
   900 <table summary="Symbolic modes" border="1"><colgroup>
  4090           <a name="id2666244">
   901 <col width="14">
  4091           </a>
   902 <col width="8">
  4092           10.2.ls -l
   903 <col width="45">
  4093          </h3>
   904 </colgroup></table>
  4094         </div>
   905 <p id="ch8ult_module_plan_150"></a>The <span class="emphasis"><em>chmod</em></span> program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:</p>
  4095        </div>
   906 <table summary="Symbolic modes" border="1"><colgroup>
  4096       </div>
   907 <col width="14">
  4097       <p id="ch8ult_module_plan_137">
   908 <col width="54">
  4098        Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
   909 </colgroup></table>
  4099       </p>
   910 <p id="ch8ult_module_plan_157"></a>The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:</p>
  4100       <pre class="programlisting">
   911 <table summary="Symbolic modes" border="1"><colgroup>
  4101        $ ls -l
   912 <col width="5">
  4102       </pre>
   913 <col width="14">
  4103       <p id="ch8ult_module_plan_138">
   914 <col width="48">
  4104        This can be done after entering the required directory.
   915 </colgroup></table>
  4105       </p>
   916 <p id="ch8ult_module_plan_16d"></a>The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.</p>
  4106      </div>
   917 </div>
  4107     </div>
   918 <div class="section" title="11.1.2.2. Symbolic examples">
  4108     <div class="section" title="11.Permissions and Ownership">
   919 <div class="titlepage"><div><div><h5 class="title">
  4109      <div class="titlepage">
   920 <a name="id2773833"></a>11.1.2.2. Symbolic examples</h5></div></div></div>
  4110       <div>
   921 <p id="ch8ult_module_plan_16e"></a>Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:</p>
  4111        <div>
   922 <pre class="programlisting">$ chmod ug+rw mydir
  4112         <h2 class="title" style="clear: both">
       
  4113          <a name="id2666267">
       
  4114          </a>
       
  4115          11.Permissions and Ownership
       
  4116         </h2>
       
  4117        </div>
       
  4118       </div>
       
  4119      </div>
       
  4120      <div class="section" title="11.1.chmod">
       
  4121       <div class="titlepage">
       
  4122        <div>
       
  4123         <div>
       
  4124          <h3 class="title">
       
  4125           <a name="id2666276">
       
  4126           </a>
       
  4127           11.1.chmod
       
  4128          </h3>
       
  4129         </div>
       
  4130        </div>
       
  4131       </div>
       
  4132       <p id="ch8ult_module_plan_139">
       
  4133        The
       
  4134        <span class="emphasis">
       
  4135         <em>
       
  4136          chmod
       
  4137         </em>
       
  4138        </span>
       
  4139        command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&amp;T Unix version 1, and is still used today on Unix-like machines.
       
  4140       </p>
       
  4141       <div class="section" title="11.1.1.Usage">
       
  4142        <div class="titlepage">
       
  4143         <div>
       
  4144          <div>
       
  4145           <h4 class="title">
       
  4146            <a name="id2666302">
       
  4147            </a>
       
  4148            11.1.1.Usage
       
  4149           </h4>
       
  4150          </div>
       
  4151         </div>
       
  4152        </div>
       
  4153        <p id="ch8ult_module_plan_13a">
       
  4154         The
       
  4155         <span class="emphasis">
       
  4156          <em>
       
  4157           chmod
       
  4158          </em>
       
  4159         </span>
       
  4160         command options are specified like this:
       
  4161        </p>
       
  4162        <pre class="programlisting">
       
  4163         $ chmod [options] mode[,mode] file1 [file2 ...]
       
  4164        </pre>
       
  4165        <p id="ch8ult_module_plan_13b">
       
  4166         To view what the permissions currently are, type:
       
  4167        </p>
       
  4168        <pre class="programlisting">
       
  4169         $ ls -l file
       
  4170        </pre>
       
  4171       </div>
       
  4172       <div class="section" title="11.1.2.Command line options">
       
  4173        <div class="titlepage">
       
  4174         <div>
       
  4175          <div>
       
  4176           <h4 class="title">
       
  4177            <a name="id2666330">
       
  4178            </a>
       
  4179            11.1.2.Command line options
       
  4180           </h4>
       
  4181          </div>
       
  4182         </div>
       
  4183        </div>
       
  4184        <p id="ch8ult_module_plan_13c">
       
  4185         The
       
  4186         <span class="emphasis">
       
  4187          <em>
       
  4188           chmod
       
  4189          </em>
       
  4190         </span>
       
  4191         command has a number of command line options that affect its behavior. The most common options are:
       
  4192        </p>
       
  4193        <span style="color: red">
       
  4194         &lt;block_quote&gt;
       
  4195         <div class="itemizedlist">
       
  4196          <ul class="itemizedlist" type="*">
       
  4197           <li class="listitem" style="list-style-type: *">
       
  4198            <p id="ch8ult_module_plan_13d">
       
  4199             -R: Changes the modes of directories and files recursively
       
  4200            </p>
       
  4201           </li>
       
  4202           <li class="listitem" style="list-style-type: *">
       
  4203            <p id="ch8ult_module_plan_13e">
       
  4204             -v: Verbose mode; lists all files as they are being processed
       
  4205            </p>
       
  4206           </li>
       
  4207          </ul>
       
  4208         </div>
       
  4209         &lt;/block_quote&gt;
       
  4210        </span>
       
  4211        <div class="section" title="11.1.2.1.Symbolic modes">
       
  4212         <div class="titlepage">
       
  4213          <div>
       
  4214           <div>
       
  4215            <h5 class="title">
       
  4216             <a name="id2666367">
       
  4217             </a>
       
  4218             11.1.2.1.Symbolic modes
       
  4219            </h5>
       
  4220           </div>
       
  4221          </div>
       
  4222         </div>
       
  4223         <p id="ch8ult_module_plan_13f">
       
  4224          To the
       
  4225          <span class="emphasis">
       
  4226           <em>
       
  4227            chmod
       
  4228           </em>
       
  4229          </span>
       
  4230          utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
       
  4231         </p>
       
  4232         <pre class="programlisting">
       
  4233          $ chmod [references][operator][modes] file1 ...
       
  4234         </pre>
       
  4235         <p id="ch8ult_module_plan_140">
       
  4236          The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
       
  4237         </p>
       
  4238         <table summary="Symbolic modes" border="1">
       
  4239          <colgroup>
       
  4240           <col width="14">
       
  4241           </col>
       
  4242           <col width="8">
       
  4243           </col>
       
  4244           <col width="45">
       
  4245           </col>
       
  4246          </colgroup>
       
  4247         </table>
       
  4248         <p id="ch8ult_module_plan_150">
       
  4249          The
       
  4250          <span class="emphasis">
       
  4251           <em>
       
  4252            chmod
       
  4253           </em>
       
  4254          </span>
       
  4255          program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
       
  4256         </p>
       
  4257         <table summary="Symbolic modes" border="1">
       
  4258          <colgroup>
       
  4259           <col width="14">
       
  4260           </col>
       
  4261           <col width="54">
       
  4262           </col>
       
  4263          </colgroup>
       
  4264         </table>
       
  4265         <p id="ch8ult_module_plan_157">
       
  4266          The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
       
  4267         </p>
       
  4268         <table summary="Symbolic modes" border="1">
       
  4269          <colgroup>
       
  4270           <col width="5">
       
  4271           </col>
       
  4272           <col width="14">
       
  4273           </col>
       
  4274           <col width="48">
       
  4275           </col>
       
  4276          </colgroup>
       
  4277         </table>
       
  4278         <p id="ch8ult_module_plan_16d">
       
  4279          The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
       
  4280         </p>
       
  4281        </div>
       
  4282        <div class="section" title="11.1.2.2.Symbolic examples">
       
  4283         <div class="titlepage">
       
  4284          <div>
       
  4285           <div>
       
  4286            <h5 class="title">
       
  4287             <a name="id2666928">
       
  4288             </a>
       
  4289             11.1.2.2.Symbolic examples
       
  4290            </h5>
       
  4291           </div>
       
  4292          </div>
       
  4293         </div>
       
  4294         <p id="ch8ult_module_plan_16e">
       
  4295          Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
       
  4296         </p>
       
  4297         <pre class="programlisting">
       
  4298          $ chmod ug+rw mydir
   923 $ ls -ld mydir
  4299 $ ls -ld mydir
   924 drw-rw----   2 starwars  yoda  96 Dec 8 12:53 mydir</pre>
  4300 drw-rw----   2 starwars  yoda  96 Dec 8 12:53 mydir
   925 <p id="ch8ult_module_plan_16f"></a>For a file, remove <span class="emphasis"><em>write</em></span> permissions for all classes:</p>
  4301         </pre>
   926 <pre class="programlisting">$ chmod a-w myfile
  4302         <p id="ch8ult_module_plan_16f">
       
  4303          For a file, remove
       
  4304          <span class="emphasis">
       
  4305           <em>
       
  4306            write
       
  4307           </em>
       
  4308          </span>
       
  4309          permissions for all classes:
       
  4310         </p>
       
  4311         <pre class="programlisting">
       
  4312          $ chmod a-w myfile
   927 $ ls -l myfile
  4313 $ ls -l myfile
   928 -r-xr-xr-x   2 starwars  yoda 96 Dec 8 12:53 myfile</pre>
  4314 -r-xr-xr-x   2 starwars  yoda 96 Dec 8 12:53 myfile
   929 <p id="ch8ult_module_plan_170"></a>Set the permissions for the <span class="emphasis"><em>u*ser and the *g*roup to read and execute only (no write permission) on *mydir</em></span>.</p>
  4315         </pre>
   930 <pre class="programlisting">$ chmod ug=rx mydir
  4316         <p id="ch8ult_module_plan_170">
       
  4317          Set the permissions for the
       
  4318          <span class="emphasis">
       
  4319           <em>
       
  4320            u*ser and the *g*roup to read and execute only (no write permission) on *mydir
       
  4321           </em>
       
  4322          </span>
       
  4323          .
       
  4324         </p>
       
  4325         <pre class="programlisting">
       
  4326          $ chmod ug=rx mydir
   931 $ ls -ld mydir
  4327 $ ls -ld mydir
   932 dr-xr-x---   2 starwars  yoda 96 Dec 8 12:53 mydir</pre>
  4328 dr-xr-x---   2 starwars  yoda 96 Dec 8 12:53 mydir
   933 </div>
  4329         </pre>
   934 <div class="section" title="11.1.2.3. Octal numbers">
  4330        </div>
   935 <div class="titlepage"><div><div><h5 class="title">
  4331        <div class="section" title="11.1.2.3.Octal numbers">
   936 <a name="id2773877"></a>11.1.2.3. Octal numbers</h5></div></div></div>
  4332         <div class="titlepage">
   937 <p id="ch8ult_module_plan_171"></a>The <span class="emphasis"><em>chmod</em></span> command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :</p>
  4333          <div>
   938 <pre class="programlisting">$ chmod 664 myfile
  4334           <div>
       
  4335            <h5 class="title">
       
  4336             <a name="id2666971">
       
  4337             </a>
       
  4338             11.1.2.3.Octal numbers
       
  4339            </h5>
       
  4340           </div>
       
  4341          </div>
       
  4342         </div>
       
  4343         <p id="ch8ult_module_plan_171">
       
  4344          The
       
  4345          <span class="emphasis">
       
  4346           <em>
       
  4347            chmod
       
  4348           </em>
       
  4349          </span>
       
  4350          command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
       
  4351         </p>
       
  4352         <pre class="programlisting">
       
  4353          $ chmod 664 myfile
   939 $ ls -l myfile
  4354 $ ls -l myfile
   940 -rw-rw-r--  1   57 Jul  3 10:13  myfile</pre>
  4355 -rw-rw-r--  1   57 Jul  3 10:13  myfile
   941 <p id="ch8ult_module_plan_172"></a>Since the <span class="emphasis"><em>setuid</em></span>, <span class="emphasis"><em>setgid</em></span> and <span class="emphasis"><em>sticky</em></span> bits are not set, this is equivalent to:</p>
  4356         </pre>
   942 <pre class="programlisting">$ chmod 0664 myfile</pre>
  4357         <p id="ch8ult_module_plan_172">
   943 </div>
  4358          Since the
   944 <div class="section" title="11.1.2.4. Special modes">
  4359          <span class="emphasis">
   945 <div class="titlepage"><div><div><h5 class="title">
  4360           <em>
   946 <a name="id2773915"></a>11.1.2.4. Special modes</h5></div></div></div>
  4361            setuid
   947 <p id="ch8ult_module_plan_173"></a>The <span class="emphasis"><em>chmod</em></span> command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use <span class="strong"><strong>s</strong></span> to represent the <span class="emphasis"><em>setuid</em></span> and <span class="emphasis"><em>setgid</em></span> modes, and <span class="strong"><strong>t</strong></span> to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.</p>
  4362           </em>
   948 <p id="ch8ult_module_plan_174"></a>Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.</p>
  4363          </span>
   949 </div>
  4364          ,
   950 </div>
  4365          <span class="emphasis">
   951 </div>
  4366           <em>
   952 </div>
  4367            setgid
   953 <div class="section" title="12. Redirection and Piping">
  4368           </em>
   954 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  4369          </span>
   955 <a name="id2773959"></a>12. Redirection and Piping</h2></div></div></div>
  4370          and
   956 <p id="ch8ult_module_plan_175"></a>In computing, <span class="emphasis"><em>redirection</em></span> is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.</p>
  4371          <span class="emphasis">
   957 <p id="ch8ult_module_plan_176"></a>Programs do redirection with the <span class="emphasis"><em>dup2(2)</em></span> system call, or its less-flexible but higher-level stdio analogues, <span class="emphasis"><em>freopen(3)</em></span> and <span class="emphasis"><em>popen(3)</em></span>.</p>
  4372           <em>
   958 <div class="section" title="12.1. Redirecting standard input and standard output">
  4373            sticky
   959 <div class="titlepage"><div><div><h3 class="title">
  4374           </em>
   960 <a name="id2773995"></a>12.1. Redirecting standard input and standard output</h3></div></div></div>
  4375          </span>
   961 <p id="ch8ult_module_plan_177"></a>Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:</p>
  4376          bits are not set, this is equivalent to:
   962 <pre class="programlisting">$ command1 &gt; file1</pre>
  4377         </p>
   963 <p id="ch8ult_module_plan_178"></a>executes <span class="emphasis"><em>command1</em></span>, placing the output in file1. Note that this will truncate any existing data in <span class="emphasis"><em>file1</em></span>. To append output to the end of the file, use the &gt;&gt; operator.:</p>
  4378         <pre class="programlisting">
   964 <pre class="programlisting">$ command1 &lt; file1</pre>
  4379          $ chmod 0664 myfile
   965 <p id="ch8ult_module_plan_179"></a>executes <span class="emphasis"><em>command1</em></span>, using <span class="emphasis"><em>file1</em></span> as the source of input (as opposed to the keyboard).:</p>
  4380         </pre>
   966 <pre class="programlisting">$ command1 &lt; infile &gt; outfile</pre>
  4381        </div>
   967 <p id="ch8ult_module_plan_17a"></a>combines the two capabilities: <span class="emphasis"><em>command1</em></span> reads from <span class="emphasis"><em>infile</em></span> and writes to <span class="emphasis"><em>outfile</em></span></p>
  4382        <div class="section" title="11.1.2.4.Special modes">
   968 </div>
  4383         <div class="titlepage">
   969 <div class="section" title="12.2. Piping">
  4384          <div>
   970 <div class="titlepage"><div><div><h3 class="title">
  4385           <div>
   971 <a name="id2774063"></a>12.2. Piping</h3></div></div></div>
  4386            <h5 class="title">
   972 <p id="ch8ult_module_plan_17b"></a>Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
  4387             <a name="id2667009">
   973 A pipeline of three programs run on a text terminal:</p>
  4388             </a>
   974 <pre class="programlisting">$ command1 | command2</pre>
  4389             11.1.2.4.Special modes
   975 <p id="ch8ult_module_plan_17c"></a>executes <span class="emphasis"><em>command1</em></span>, using its output as the input for <span class="emphasis"><em>command2</em></span> (commonly called piping, since the "|" character is known as a "pipe").</p>
  4390            </h5>
   976 <p id="ch8ult_module_plan_17d"></a>This is equivalent to using two redirects and a temporary file:</p>
  4391           </div>
   977 <pre class="programlisting">$ command1 &gt; tempfile
  4392          </div>
       
  4393         </div>
       
  4394         <p id="ch8ult_module_plan_173">
       
  4395          The
       
  4396          <span class="emphasis">
       
  4397           <em>
       
  4398            chmod
       
  4399           </em>
       
  4400          </span>
       
  4401          command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
       
  4402          <span class="strong">
       
  4403           <strong>
       
  4404            s
       
  4405           </strong>
       
  4406          </span>
       
  4407          to represent the
       
  4408          <span class="emphasis">
       
  4409           <em>
       
  4410            setuid
       
  4411           </em>
       
  4412          </span>
       
  4413          and
       
  4414          <span class="emphasis">
       
  4415           <em>
       
  4416            setgid
       
  4417           </em>
       
  4418          </span>
       
  4419          modes, and
       
  4420          <span class="strong">
       
  4421           <strong>
       
  4422            t
       
  4423           </strong>
       
  4424          </span>
       
  4425          to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
       
  4426         </p>
       
  4427         <p id="ch8ult_module_plan_174">
       
  4428          Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
       
  4429         </p>
       
  4430        </div>
       
  4431       </div>
       
  4432      </div>
       
  4433     </div>
       
  4434     <div class="section" title="12.Redirection and Piping">
       
  4435      <div class="titlepage">
       
  4436       <div>
       
  4437        <div>
       
  4438         <h2 class="title" style="clear: both">
       
  4439          <a name="id2667054">
       
  4440          </a>
       
  4441          12.Redirection and Piping
       
  4442         </h2>
       
  4443        </div>
       
  4444       </div>
       
  4445      </div>
       
  4446      <p id="ch8ult_module_plan_175">
       
  4447       In computing,
       
  4448       <span class="emphasis">
       
  4449        <em>
       
  4450         redirection
       
  4451        </em>
       
  4452       </span>
       
  4453       is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
       
  4454      </p>
       
  4455      <p id="ch8ult_module_plan_176">
       
  4456       Programs do redirection with the
       
  4457       <span class="emphasis">
       
  4458        <em>
       
  4459         dup2(2)
       
  4460        </em>
       
  4461       </span>
       
  4462       system call, or its less-flexible but higher-level stdio analogues,
       
  4463       <span class="emphasis">
       
  4464        <em>
       
  4465         freopen(3)
       
  4466        </em>
       
  4467       </span>
       
  4468       and
       
  4469       <span class="emphasis">
       
  4470        <em>
       
  4471         popen(3)
       
  4472        </em>
       
  4473       </span>
       
  4474       .
       
  4475      </p>
       
  4476      <div class="section" title="12.1.Redirecting standard input and standard output">
       
  4477       <div class="titlepage">
       
  4478        <div>
       
  4479         <div>
       
  4480          <h3 class="title">
       
  4481           <a name="id2667089">
       
  4482           </a>
       
  4483           12.1.Redirecting standard input and standard output
       
  4484          </h3>
       
  4485         </div>
       
  4486        </div>
       
  4487       </div>
       
  4488       <p id="ch8ult_module_plan_177">
       
  4489        Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
       
  4490       </p>
       
  4491       <pre class="programlisting">
       
  4492        $ command1 &gt; file1
       
  4493       </pre>
       
  4494       <p id="ch8ult_module_plan_178">
       
  4495        executes
       
  4496        <span class="emphasis">
       
  4497         <em>
       
  4498          command1
       
  4499         </em>
       
  4500        </span>
       
  4501        , placing the output in file1. Note that this will truncate any existing data in
       
  4502        <span class="emphasis">
       
  4503         <em>
       
  4504          file1
       
  4505         </em>
       
  4506        </span>
       
  4507        . To append output to the end of the file, use the &gt;&gt; operator.:
       
  4508       </p>
       
  4509       <pre class="programlisting">
       
  4510        $ command1 &lt; file1
       
  4511       </pre>
       
  4512       <p id="ch8ult_module_plan_179">
       
  4513        executes
       
  4514        <span class="emphasis">
       
  4515         <em>
       
  4516          command1
       
  4517         </em>
       
  4518        </span>
       
  4519        , using
       
  4520        <span class="emphasis">
       
  4521         <em>
       
  4522          file1
       
  4523         </em>
       
  4524        </span>
       
  4525        as the source of input (as opposed to the keyboard).:
       
  4526       </p>
       
  4527       <pre class="programlisting">
       
  4528        $ command1 &lt; infile &gt; outfile
       
  4529       </pre>
       
  4530       <p id="ch8ult_module_plan_17a">
       
  4531        combines the two capabilities:
       
  4532        <span class="emphasis">
       
  4533         <em>
       
  4534          command1
       
  4535         </em>
       
  4536        </span>
       
  4537        reads from
       
  4538        <span class="emphasis">
       
  4539         <em>
       
  4540          infile
       
  4541         </em>
       
  4542        </span>
       
  4543        and writes to
       
  4544        <span class="emphasis">
       
  4545         <em>
       
  4546          outfile
       
  4547         </em>
       
  4548        </span>
       
  4549       </p>
       
  4550      </div>
       
  4551      <div class="section" title="12.2.Piping">
       
  4552       <div class="titlepage">
       
  4553        <div>
       
  4554         <div>
       
  4555          <h3 class="title">
       
  4556           <a name="id2667158">
       
  4557           </a>
       
  4558           12.2.Piping
       
  4559          </h3>
       
  4560         </div>
       
  4561        </div>
       
  4562       </div>
       
  4563       <p id="ch8ult_module_plan_17b">
       
  4564        Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
       
  4565 A pipeline of three programs run on a text terminal:
       
  4566       </p>
       
  4567       <pre class="programlisting">
       
  4568        $ command1 | command2
       
  4569       </pre>
       
  4570       <p id="ch8ult_module_plan_17c">
       
  4571        executes
       
  4572        <span class="emphasis">
       
  4573         <em>
       
  4574          command1
       
  4575         </em>
       
  4576        </span>
       
  4577        , using its output as the input for
       
  4578        <span class="emphasis">
       
  4579         <em>
       
  4580          command2
       
  4581         </em>
       
  4582        </span>
       
  4583        (commonly called piping, since the "|" character is known as a "pipe").
       
  4584       </p>
       
  4585       <p id="ch8ult_module_plan_17d">
       
  4586        This is equivalent to using two redirects and a temporary file:
       
  4587       </p>
       
  4588       <pre class="programlisting">
       
  4589        $ command1 &gt; tempfile
   978 $ command2 &lt; tempfile
  4590 $ command2 &lt; tempfile
   979 $ rm tempfile</pre>
  4591 $ rm tempfile
   980 <p id="ch8ult_module_plan_17e"></a>A good example for command piping is combining <span class="emphasis"><em>echo</em></span> with another command to achieve something interactive in a non-interactive shell, e.g.:</p>
  4592       </pre>
   981 <pre class="programlisting">$ echo -e "user\npass" | ftp localhost</pre>
  4593       <p id="ch8ult_module_plan_17e">
   982 <p id="ch8ult_module_plan_17f"></a>This runs the ftp client with input user, press return, then pass.</p>
  4594        A good example for command piping is combining
   983 </div>
  4595        <span class="emphasis">
   984 <div class="section" title="12.3. Redirecting to and from the standard file handles">
  4596         <em>
   985 <div class="titlepage"><div><div><h3 class="title">
  4597          echo
   986 <a name="id2774125"></a>12.3. Redirecting to and from the standard file handles</h3></div></div></div>
  4598         </em>
   987 <p id="ch8ult_module_plan_180"></a>In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:</p>
  4599        </span>
   988 <table summary="Redirecting to and from the standard file handles" border="1"><colgroup>
  4600        with another command to achieve something interactive in a non-interactive shell, e.g.:
   989 <col width="12">
  4601       </p>
   990 <col width="13">
  4602       <pre class="programlisting">
   991 <col width="24">
  4603        $ echo -e "user\npass" | ftp localhost
   992 </colgroup></table>
  4604       </pre>
   993 <p id="ch8ult_module_plan_18d"></a>For example:</p>
  4605       <p id="ch8ult_module_plan_17f">
   994 <pre class="programlisting">$ command1 2&gt; file1</pre>
  4606        This runs the ftp client with input user, press return, then pass.
   995 <p id="ch8ult_module_plan_18e"></a>executes <span class="emphasis"><em>command1</em></span>, directing the standard error stream to <span class="emphasis"><em>file1</em></span>.</p>
  4607       </p>
   996 <p id="ch8ult_module_plan_18f"></a>In shells derived from <span class="emphasis"><em>csh</em></span> (the C shell), the syntax instead appends the &amp; character to the redirect characters, thus achieving a similar result.</p>
  4608      </div>
   997 <p id="ch8ult_module_plan_190"></a>Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:</p>
  4609      <div class="section" title="12.3.Redirecting to and from the standard file handles">
   998 <pre class="programlisting">$ find / -name .profile &gt; results 2&gt;&amp;1</pre>
  4610       <div class="titlepage">
   999 <p id="ch8ult_module_plan_191"></a>will try to find all files named <span class="emphasis"><em>.profile</em></span>. Executed without redirection, it will output hits to <span class="emphasis"><em>stdout</em></span> and errors (e.g. for lack of privilege to traverse protected directories) to <span class="emphasis"><em>stderr</em></span>. If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge <span class="emphasis"><em>stderr</em></span> (handle 2) into <span class="emphasis"><em>stdout</em></span> (handle 1) using 2&gt;&amp;1 .</p>
  4611        <div>
  1000 <p id="ch8ult_module_plan_192"></a>It's possible use 2&gt;&amp;1 before "&gt;" but it doesn't work. In fact, when the interpreter reads 2&gt;&amp;1, it doesn't know yet where standard output is redirected and then standard error isn't merged.</p>
  4612         <div>
  1001 <p id="ch8ult_module_plan_193"></a>If the merged output is to be piped into another program, the file merge sequence 2&gt;&amp;1 must precede the pipe symbol, thus:</p>
  4613          <h3 class="title">
  1002 <pre class="programlisting">$ find / -name .profile 2&gt;&amp;1 | less</pre>
  4614           <a name="id2667219">
  1003 <p id="ch8ult_module_plan_194"></a>A simplified form of the command:</p>
  4615           </a>
  1004 <pre class="programlisting">$ command &gt; file 2&gt;&amp;1</pre>
  4616           12.3.Redirecting to and from the standard file handles
  1005 <p id="ch8ult_module_plan_195"></a>is:</p>
  4617          </h3>
  1006 <pre class="programlisting">$ command &amp;&gt;file</pre>
  4618         </div>
  1007 <p id="ch8ult_module_plan_196"></a>or:</p>
  4619        </div>
  1008 <pre class="programlisting">$command &gt;&amp;file</pre>
  4620       </div>
  1009 </div>
  4621       <p id="ch8ult_module_plan_180">
  1010 <div class="section" title="12.4. Chained pipelines">
  4622        In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
  1011 <div class="titlepage"><div><div><h3 class="title">
  4623       </p>
  1012 <a name="id2774332"></a>12.4. Chained pipelines</h3></div></div></div>
  4624       <table summary="Redirecting to and from the standard file handles" border="1">
  1013 <p id="ch8ult_module_plan_197"></a>The redirection and piping tokens can be chained together to create complex commands. For example:</p>
  4625        <colgroup>
  1014 <pre class="programlisting">$ ls | grep '\.sh' | sort &gt; shlist</pre>
  4626         <col width="12">
  1015 <p id="ch8ult_module_plan_198"></a>lists the contents of the current directory, where this output is filtered to only contain lines which contain <span class="emphasis"><em>.sh</em></span>, sort this resultant output lexicographically, and place the final output in <span class="emphasis"><em>shlist</em></span>. This type of construction is used very commonly in shell scripts and batch files.</p>
  4627         </col>
  1016 </div>
  4628         <col width="13">
  1017 <div class="section" title="12.5. Redirect to multiple outputs">
  4629         </col>
  1018 <div class="titlepage"><div><div><h3 class="title">
  4630         <col width="24">
  1019 <a name="id2774367"></a>12.5. Redirect to multiple outputs</h3></div></div></div>
  4631         </col>
  1020 <p id="ch8ult_module_plan_199"></a>The standard command <span class="emphasis"><em>tee</em></span> can redirect output from a command to several destinations.</p>
  4632        </colgroup>
  1021 <pre class="programlisting">$ ls -lrt | tee xyz</pre>
  4633       </table>
  1022 <p id="ch8ult_module_plan_19a"></a>This directs the file list output to both standard output as well as to the file <span class="emphasis"><em>xyz</em></span>.</p>
  4634       <p id="ch8ult_module_plan_18d">
  1023 </div>
  4635        For example:
  1024 </div>
  4636       </p>
  1025 <div class="section" title="13. More Text Processing">
  4637       <pre class="programlisting">
  1026 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  4638        $ command1 2&gt; file1
  1027 <a name="id2774397"></a>13. More Text Processing</h2></div></div></div>
  4639       </pre>
  1028 <div class="section" title="13.1. grep">
  4640       <p id="ch8ult_module_plan_18e">
  1029 <div class="titlepage"><div><div><h3 class="title">
  4641        executes
  1030 <a name="id2774406"></a>13.1. grep</h3></div></div></div>
  4642        <span class="emphasis">
  1031 <p id="ch8ult_module_plan_19b"></a><span class="emphasis"><em>grep</em></span> is a command line text search utility originally written for Unix. The name is taken from the first letters in <span class="emphasis"><em>global / regular expression / print</em></span>, a series of instructions for the <span class="emphasis"><em>ed</em></span> text editor. The <span class="emphasis"><em>grep</em></span> command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.</p>
  4643         <em>
  1032 <div class="section" title="13.1.1. Usage">
  4644          command1
  1033 <div class="titlepage"><div><div><h4 class="title">
  4645         </em>
  1034 <a name="id2774437"></a>13.1.1. Usage</h4></div></div></div>
  4646        </span>
  1035 <p id="ch8ult_module_plan_19c"></a>This is an example of a common <span class="emphasis"><em>grep</em></span> usage:</p>
  4647        , directing the standard error stream to
  1036 <pre class="programlisting">$ grep apple fruitlist.txt</pre>
  4648        <span class="emphasis">
  1037 <p id="ch8ult_module_plan_19d"></a>In this case, <span class="emphasis"><em>grep</em></span> prints all lines containing 'apple' from the file <span class="emphasis"><em>fruitlist.txt</em></span>, regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The <span class="emphasis"><em>grep</em></span> command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.</p>
  4649         <em>
  1038 <p id="ch8ult_module_plan_19e"></a>Like most Unix commands, <span class="emphasis"><em>grep</em></span> accepts command line arguments to change this and many other behaviors. For example:</p>
  4650          file1
  1039 <pre class="programlisting">$ grep -i apple fruitlist.txt</pre>
  4651         </em>
  1040 <p id="ch8ult_module_plan_19f"></a>This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells <span class="emphasis"><em>grep</em></span> to be case insensitive, or to ignore case.</p>
  4652        </span>
  1041 <p id="ch8ult_module_plan_1a0"></a>To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):</p>
  4653        .
  1042 <pre class="programlisting">$ grep -w apple fruitlist.txt</pre>
  4654       </p>
  1043 <p id="ch8ult_module_plan_1a1"></a>Regular expressions can be used to match more complicated queries.</p>
  4655       <p id="ch8ult_module_plan_18f">
  1044 <div class="section" title="13.1.1.1. Variations">
  4656        In shells derived from
  1045 <div class="titlepage"><div><div><h5 class="title">
  4657        <span class="emphasis">
  1046 <a name="id2774517"></a>13.1.1.1. Variations</h5></div></div></div>
  4658         <em>
  1047 <p id="ch8ult_module_plan_1a2"></a>There are countless implementations and derivatives of <span class="emphasis"><em>grep</em></span> available for many operating systems. Early variants of <span class="emphasis"><em>grep</em></span> included <span class="emphasis"><em>egrep</em></span> and <span class="emphasis"><em>fgrep</em></span>. The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern <span class="emphasis"><em>grep</em></span> implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations, <span class="emphasis"><em>grep</em></span> may also behave differently depending on the name by which it is invoked, allowing <span class="emphasis"><em>fgrep</em></span>, <span class="emphasis"><em>egrep</em></span>, and <span class="emphasis"><em>grep</em></span> to be links to the same program.</p>
  4659          csh
  1048 <p id="ch8ult_module_plan_1a3"></a><span class="emphasis"><em>pcregrep</em></span> is an implementation of <span class="emphasis"><em>grep</em></span> that uses Perl regular expression syntax.</p>
  4660         </em>
  1049 <p id="ch8ult_module_plan_1a4"></a>Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The <span class="emphasis"><em>pgrep</em></span> utility, for instance, displays the processes whose names match a given regular expression.</p>
  4661        </span>
  1050 </div>
  4662        (the C shell), the syntax instead appends the &amp; character to the redirect characters, thus achieving a similar result.
  1051 </div>
  4663       </p>
  1052 </div>
  4664       <p id="ch8ult_module_plan_190">
  1053 <div class="section" title="13.2. tr">
  4665        Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
  1054 <div class="titlepage"><div><div><h3 class="title">
  4666       </p>
  1055 <a name="id2774596"></a>13.2. tr</h3></div></div></div>
  4667       <pre class="programlisting">
  1056 <p id="ch8ult_module_plan_1a5"></a><span class="emphasis"><em>tr</em></span> (abbreviated from <span class="emphasis"><em>translate</em></span> or <span class="emphasis"><em>transliterate</em></span>) is a command in Unix-like operating systems.</p>
  4668        $ find / -name .profile &gt; results 2&gt;&amp;1
  1057 <p id="ch8ult_module_plan_1a6"></a>When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,</p>
  4669       </pre>
  1058 <pre class="programlisting">$ tr 'abcd' 'jkmn'</pre>
  4670       <p id="ch8ult_module_plan_191">
  1059 <p id="ch8ult_module_plan_1a7"></a>maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.</p>
  4671        will try to find all files named
  1060 <p id="ch8ult_module_plan_1a8"></a>Sets of characters may be abbreviated by using character ranges. The previous example could be written:</p>
  4672        <span class="emphasis">
  1061 <pre class="programlisting">$ tr 'a-d' 'jkmn'</pre>
  4673         <em>
  1062 <p id="ch8ult_module_plan_1a9"></a>In POSIX compliant versions of <span class="emphasis"><em>tr</em></span> the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].</p>
  4674          .profile
  1063 <p id="ch8ult_module_plan_1aa"></a>The <span class="emphasis"><em>-c</em></span> flag complements the first set of characters.</p>
  4675         </em>
  1064 <pre class="programlisting">$ tr -cd '[:alnum:]'</pre>
  4676        </span>
  1065 <p id="ch8ult_module_plan_1ab"></a>therefore removes all non-alphanumeric characters.</p>
  4677        . Executed without redirection, it will output hits to
  1066 <p id="ch8ult_module_plan_1ac"></a>The <span class="emphasis"><em>-s</em></span> flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,</p>
  4678        <span class="emphasis">
  1067 <pre class="programlisting">$ tr -s '\n' '\n'</pre>
  4679         <em>
  1068 <p id="ch8ult_module_plan_1ad"></a>replaces sequences of one or more newline characters with a single newline.</p>
  4680          stdout
  1069 <p id="ch8ult_module_plan_1ae"></a>The <span class="emphasis"><em>-d</em></span> flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.</p>
  4681         </em>
  1070 <pre class="programlisting">$ tr -d '\r'</pre>
  4682        </span>
  1071 <p id="ch8ult_module_plan_1af"></a>Most versions of <span class="emphasis"><em>tr</em></span>, including GNU <span class="emphasis"><em>tr</em></span> and classic Unix <span class="emphasis"><em>tr</em></span>, operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.</p>
  4683        and errors (e.g. for lack of privilege to traverse protected directories) to
  1072 <p id="ch8ult_module_plan_1b0"></a>Ruby and Perl also have an internal <span class="emphasis"><em>tr</em></span> operator, which operates analogously. Tcl's <span class="emphasis"><em>string map</em></span> command is more general in that it maps strings to strings while <span class="emphasis"><em>tr</em></span> maps characters to characters.</p>
  4684        <span class="emphasis">
  1073 </div>
  4685         <em>
  1074 </div>
  4686          stderr
  1075 <div class="section" title="14. Elementary Regex">
  4687         </em>
  1076 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  4688        </span>
  1077 <a name="id2774748"></a>14. Elementary Regex</h2></div></div></div>
  4689        . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
  1078 <p id="ch8ult_module_plan_1b1"></a>In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.</p>
  4690        <span class="emphasis">
  1079 <p id="ch8ult_module_plan_1b2"></a>Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributions—including the editor <span class="emphasis"><em>ed</em></span> and the filter <span class="emphasis"><em>grep</em></span> — were the first to popularize the concept of regular expressions.</p>
  4691         <em>
  1080 <p id="ch8ult_module_plan_1b3"></a>Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX <span class="emphasis"><em>Basic Regular Expressions</em></span> (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.</p>
  4692          stderr
  1081 <p id="ch8ult_module_plan_1b4"></a>In the BRE syntax, most characters are treated as literals — they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.</p>
  4693         </em>
  1082 <table summary="Elementary Regex" border="1"><colgroup>
  4694        </span>
  1083 <col width="13">
  4695        (handle 2) into
  1084 <col width="60">
  4696        <span class="emphasis">
  1085 </colgroup></table>
  4697         <em>
  1086 <div class="section" title="14.1. Lazy quantification">
  4698          stdout
  1087 <div class="titlepage"><div><div><h3 class="title">
  4699         </em>
  1088 <a name="id2774972"></a>14.1. Lazy quantification</h3></div></div></div>
  4700        </span>
  1089 <p id="ch8ult_module_plan_1c9"></a>The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between &lt; and &gt; symbols in this example:</p>
  4701        (handle 1) using 2&gt;&amp;1 .
  1090 <pre class="programlisting">Another whale explosion occurred on &lt;January 26&gt;, &lt;2004&gt;.</pre>
  4702       </p>
  1091 <p id="ch8ult_module_plan_1ca"></a>...would likely come up with the pattern &lt;.*&gt;, or similar. However, this pattern will actually return "&lt;January 26&gt;, &lt;2004&gt;" instead of the "&lt;January 26&gt;" which might be expected, because the <span style="color: red">&lt;title_reference&gt;*&lt;/title_reference&gt;</span> quantifier is greedy — it will consume as many characters as possible from the input, and "January 26&gt;, &lt;2004" has more characters than "January 26".</p>
  4703       <p id="ch8ult_module_plan_192">
  1092 <p id="ch8ult_module_plan_1cb"></a>Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: &lt;[^&gt;]*&gt;), modern regular expression tools allow a quantifier to be specified as <span class="emphasis"><em>lazy</em></span> (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., &lt;.*?&gt;), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.</p>
  4704        It's possible use 2&gt;&amp;1 before "&gt;" but it doesn't work. In fact, when the interpreter reads 2&gt;&amp;1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
  1093 </div>
  4705       </p>
  1094 </div>
  4706       <p id="ch8ult_module_plan_193">
  1095 <div class="section" title="15. One Liners">
  4707        If the merged output is to be piped into another program, the file merge sequence 2&gt;&amp;1 must precede the pipe symbol, thus:
  1096 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  4708       </p>
  1097 <a name="id2775048"></a>15. One Liners</h2></div></div></div>
  4709       <pre class="programlisting">
  1098 <p id="ch8ult_module_plan_1cc"></a>A <span class="emphasis"><em>one-liner</em></span> is textual input to the command-line of an operating system shell that performs some function in just one line of input.</p>
  4710        $ find / -name .profile 2&gt;&amp;1 | less
  1099 <p id="ch8ult_module_plan_1cd"></a>The one liner can be</p>
  4711       </pre>
  1100 <span style="color: red">&lt;block_quote&gt;<div class="orderedlist"><ol class="orderedlist" type="1">
  4712       <p id="ch8ult_module_plan_194">
  1101 <li class="listitem"><p id="ch8ult_module_plan_1ce"></a>An expression written in the language of the shell.</p></li>
  4713        A simplified form of the command:
  1102 <li class="listitem"><p id="ch8ult_module_plan_1cf"></a>The invocation of an interpreter together with program source for the interpreter to run.</p></li>
  4714       </p>
  1103 <li class="listitem"><p id="ch8ult_module_plan_1d0"></a>The invocation of a compiler together with source to compile and
  4715       <pre class="programlisting">
  1104 instructions for executing the compiled program.</p></li>
  4716        $ command &gt; file 2&gt;&amp;1
  1105 </ol></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_1d1"></a>Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.</p>
  4717       </pre>
  1106 <p id="ch8ult_module_plan_1d2"></a>The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.</p>
  4718       <p id="ch8ult_module_plan_195">
  1107 <p id="ch8ult_module_plan_1d3"></a>The word <span class="emphasis"><em>One-liner</em></span> has two references in the index of the book <span class="emphasis"><em>The AWK Programming Language</em></span> (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:</p>
  4719        is:
  1108 <pre class="programlisting">“The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.”</pre>
  4720       </p>
  1109 <p id="ch8ult_module_plan_1d4"></a>Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.</p>
  4721       <pre class="programlisting">
  1110 <p id="ch8ult_module_plan_1d5"></a>The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.</p>
  4722        $ command &amp;&gt;file
  1111 <p id="ch8ult_module_plan_1d6"></a>Here are the first few of them:</p>
  4723       </pre>
  1112 <span style="color: red">&lt;block_quote&gt;<div class="orderedlist"><ol class="orderedlist" type="1">
  4724       <p id="ch8ult_module_plan_196">
  1113 <li class="listitem">
  4725        or:
  1114 <p id="ch8ult_module_plan_1d7"></a>Print the total number of input lines:</p>
  4726       </p>
  1115 <p id="ch8ult_module_plan_1d8"></a>END { print NR }</p>
  4727       <pre class="programlisting">
  1116 </li>
  4728        $command &gt;&amp;file
  1117 <li class="listitem">
  4729       </pre>
  1118 <p id="ch8ult_module_plan_1d9"></a>Print the tenth input line:</p>
  4730      </div>
  1119 <p id="ch8ult_module_plan_1da"></a>NR == 10</p>
  4731      <div class="section" title="12.4.Chained pipelines">
  1120 </li>
  4732       <div class="titlepage">
  1121 <li class="listitem">
  4733        <div>
  1122 <p id="ch8ult_module_plan_1db"></a>Print the last field of every input line:</p>
  4734         <div>
  1123 <p id="ch8ult_module_plan_1dc"></a>{ print $NF }</p>
  4735          <h3 class="title">
  1124 </li>
  4736           <a name="id2667427">
  1125 </ol></div>&lt;/block_quote&gt;</span><p id="ch8ult_module_plan_1dd"></a>One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.</p>
  4737           </a>
  1126 <p id="ch8ult_module_plan_1de"></a>The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:</p>
  4738           12.4.Chained pipelines
  1127 <pre class="programlisting">main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
  4739          </h3>
  1128 *t-42?*s?63==*t|*s==*t&amp;&amp;m(s+1,t+1):!*t:m(s,t+1)||*s&amp;&amp;m(s+1,t);}</pre>
  4740         </div>
  1129 <p id="ch8ult_module_plan_1df"></a>This one-liner program is a <span class="emphasis"><em>glob pattern matcher</em></span>. It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.</p>
  4741        </div>
  1130 <p id="ch8ult_module_plan_1e0"></a>Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:</p>
  4742       </div>
  1131 <pre class="programlisting">$ prog foo 'f??'; echo $?
  4743       <p id="ch8ult_module_plan_197">
       
  4744        The redirection and piping tokens can be chained together to create complex commands. For example:
       
  4745       </p>
       
  4746       <pre class="programlisting">
       
  4747        $ ls | grep '\.sh' | sort &gt; shlist
       
  4748       </pre>
       
  4749       <p id="ch8ult_module_plan_198">
       
  4750        lists the contents of the current directory, where this output is filtered to only contain lines which contain
       
  4751        <span class="emphasis">
       
  4752         <em>
       
  4753          .sh
       
  4754         </em>
       
  4755        </span>
       
  4756        , sort this resultant output lexicographically, and place the final output in
       
  4757        <span class="emphasis">
       
  4758         <em>
       
  4759          shlist
       
  4760         </em>
       
  4761        </span>
       
  4762        . This type of construction is used very commonly in shell scripts and batch files.
       
  4763       </p>
       
  4764      </div>
       
  4765      <div class="section" title="12.5.Redirect to multiple outputs">
       
  4766       <div class="titlepage">
       
  4767        <div>
       
  4768         <div>
       
  4769          <h3 class="title">
       
  4770           <a name="id2667461">
       
  4771           </a>
       
  4772           12.5.Redirect to multiple outputs
       
  4773          </h3>
       
  4774         </div>
       
  4775        </div>
       
  4776       </div>
       
  4777       <p id="ch8ult_module_plan_199">
       
  4778        The standard command
       
  4779        <span class="emphasis">
       
  4780         <em>
       
  4781          tee
       
  4782         </em>
       
  4783        </span>
       
  4784        can redirect output from a command to several destinations.
       
  4785       </p>
       
  4786       <pre class="programlisting">
       
  4787        $ ls -lrt | tee xyz
       
  4788       </pre>
       
  4789       <p id="ch8ult_module_plan_19a">
       
  4790        This directs the file list output to both standard output as well as to the file
       
  4791        <span class="emphasis">
       
  4792         <em>
       
  4793          xyz
       
  4794         </em>
       
  4795        </span>
       
  4796        .
       
  4797       </p>
       
  4798      </div>
       
  4799     </div>
       
  4800     <div class="section" title="13.More Text Processing">
       
  4801      <div class="titlepage">
       
  4802       <div>
       
  4803        <div>
       
  4804         <h2 class="title" style="clear: both">
       
  4805          <a name="id2667492">
       
  4806          </a>
       
  4807          13.More Text Processing
       
  4808         </h2>
       
  4809        </div>
       
  4810       </div>
       
  4811      </div>
       
  4812      <div class="section" title="13.1.grep">
       
  4813       <div class="titlepage">
       
  4814        <div>
       
  4815         <div>
       
  4816          <h3 class="title">
       
  4817           <a name="id2667501">
       
  4818           </a>
       
  4819           13.1.grep
       
  4820          </h3>
       
  4821         </div>
       
  4822        </div>
       
  4823       </div>
       
  4824       <p id="ch8ult_module_plan_19b">
       
  4825        <span class="emphasis">
       
  4826         <em>
       
  4827          grep
       
  4828         </em>
       
  4829        </span>
       
  4830        is a command line text search utility originally written for Unix. The name is taken from the first letters in
       
  4831        <span class="emphasis">
       
  4832         <em>
       
  4833          global / regular expression / print
       
  4834         </em>
       
  4835        </span>
       
  4836        , a series of instructions for the
       
  4837        <span class="emphasis">
       
  4838         <em>
       
  4839          ed
       
  4840         </em>
       
  4841        </span>
       
  4842        text editor. The
       
  4843        <span class="emphasis">
       
  4844         <em>
       
  4845          grep
       
  4846         </em>
       
  4847        </span>
       
  4848        command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
       
  4849       </p>
       
  4850       <div class="section" title="13.1.1.Usage">
       
  4851        <div class="titlepage">
       
  4852         <div>
       
  4853          <div>
       
  4854           <h4 class="title">
       
  4855            <a name="id2667532">
       
  4856            </a>
       
  4857            13.1.1.Usage
       
  4858           </h4>
       
  4859          </div>
       
  4860         </div>
       
  4861        </div>
       
  4862        <p id="ch8ult_module_plan_19c">
       
  4863         This is an example of a common
       
  4864         <span class="emphasis">
       
  4865          <em>
       
  4866           grep
       
  4867          </em>
       
  4868         </span>
       
  4869         usage:
       
  4870        </p>
       
  4871        <pre class="programlisting">
       
  4872         $ grep apple fruitlist.txt
       
  4873        </pre>
       
  4874        <p id="ch8ult_module_plan_19d">
       
  4875         In this case,
       
  4876         <span class="emphasis">
       
  4877          <em>
       
  4878           grep
       
  4879          </em>
       
  4880         </span>
       
  4881         prints all lines containing 'apple' from the file
       
  4882         <span class="emphasis">
       
  4883          <em>
       
  4884           fruitlist.txt
       
  4885          </em>
       
  4886         </span>
       
  4887         , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
       
  4888         <span class="emphasis">
       
  4889          <em>
       
  4890           grep
       
  4891          </em>
       
  4892         </span>
       
  4893         command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
       
  4894        </p>
       
  4895        <p id="ch8ult_module_plan_19e">
       
  4896         Like most Unix commands,
       
  4897         <span class="emphasis">
       
  4898          <em>
       
  4899           grep
       
  4900          </em>
       
  4901         </span>
       
  4902         accepts command line arguments to change this and many other behaviors. For example:
       
  4903        </p>
       
  4904        <pre class="programlisting">
       
  4905         $ grep -i apple fruitlist.txt
       
  4906        </pre>
       
  4907        <p id="ch8ult_module_plan_19f">
       
  4908         This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
       
  4909         <span class="emphasis">
       
  4910          <em>
       
  4911           grep
       
  4912          </em>
       
  4913         </span>
       
  4914         to be case insensitive, or to ignore case.
       
  4915        </p>
       
  4916        <p id="ch8ult_module_plan_1a0">
       
  4917         To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
       
  4918        </p>
       
  4919        <pre class="programlisting">
       
  4920         $ grep -w apple fruitlist.txt
       
  4921        </pre>
       
  4922        <p id="ch8ult_module_plan_1a1">
       
  4923         Regular expressions can be used to match more complicated queries.
       
  4924        </p>
       
  4925        <div class="section" title="13.1.1.1.Variations">
       
  4926         <div class="titlepage">
       
  4927          <div>
       
  4928           <div>
       
  4929            <h5 class="title">
       
  4930             <a name="id2667611">
       
  4931             </a>
       
  4932             13.1.1.1.Variations
       
  4933            </h5>
       
  4934           </div>
       
  4935          </div>
       
  4936         </div>
       
  4937         <p id="ch8ult_module_plan_1a2">
       
  4938          There are countless implementations and derivatives of
       
  4939          <span class="emphasis">
       
  4940           <em>
       
  4941            grep
       
  4942           </em>
       
  4943          </span>
       
  4944          available for many operating systems. Early variants of
       
  4945          <span class="emphasis">
       
  4946           <em>
       
  4947            grep
       
  4948           </em>
       
  4949          </span>
       
  4950          included
       
  4951          <span class="emphasis">
       
  4952           <em>
       
  4953            egrep
       
  4954           </em>
       
  4955          </span>
       
  4956          and
       
  4957          <span class="emphasis">
       
  4958           <em>
       
  4959            fgrep
       
  4960           </em>
       
  4961          </span>
       
  4962          . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
       
  4963          <span class="emphasis">
       
  4964           <em>
       
  4965            grep
       
  4966           </em>
       
  4967          </span>
       
  4968          implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
       
  4969          <span class="emphasis">
       
  4970           <em>
       
  4971            grep
       
  4972           </em>
       
  4973          </span>
       
  4974          may also behave differently depending on the name by which it is invoked, allowing
       
  4975          <span class="emphasis">
       
  4976           <em>
       
  4977            fgrep
       
  4978           </em>
       
  4979          </span>
       
  4980          ,
       
  4981          <span class="emphasis">
       
  4982           <em>
       
  4983            egrep
       
  4984           </em>
       
  4985          </span>
       
  4986          , and
       
  4987          <span class="emphasis">
       
  4988           <em>
       
  4989            grep
       
  4990           </em>
       
  4991          </span>
       
  4992          to be links to the same program.
       
  4993         </p>
       
  4994         <p id="ch8ult_module_plan_1a3">
       
  4995          <span class="emphasis">
       
  4996           <em>
       
  4997            pcregrep
       
  4998           </em>
       
  4999          </span>
       
  5000          is an implementation of
       
  5001          <span class="emphasis">
       
  5002           <em>
       
  5003            grep
       
  5004           </em>
       
  5005          </span>
       
  5006          that uses Perl regular expression syntax.
       
  5007         </p>
       
  5008         <p id="ch8ult_module_plan_1a4">
       
  5009          Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
       
  5010          <span class="emphasis">
       
  5011           <em>
       
  5012            pgrep
       
  5013           </em>
       
  5014          </span>
       
  5015          utility, for instance, displays the processes whose names match a given regular expression.
       
  5016         </p>
       
  5017        </div>
       
  5018       </div>
       
  5019      </div>
       
  5020      <div class="section" title="13.2.tr">
       
  5021       <div class="titlepage">
       
  5022        <div>
       
  5023         <div>
       
  5024          <h3 class="title">
       
  5025           <a name="id2667691">
       
  5026           </a>
       
  5027           13.2.tr
       
  5028          </h3>
       
  5029         </div>
       
  5030        </div>
       
  5031       </div>
       
  5032       <p id="ch8ult_module_plan_1a5">
       
  5033        <span class="emphasis">
       
  5034         <em>
       
  5035          tr
       
  5036         </em>
       
  5037        </span>
       
  5038        (abbreviated from
       
  5039        <span class="emphasis">
       
  5040         <em>
       
  5041          translate
       
  5042         </em>
       
  5043        </span>
       
  5044        or
       
  5045        <span class="emphasis">
       
  5046         <em>
       
  5047          transliterate
       
  5048         </em>
       
  5049        </span>
       
  5050        ) is a command in Unix-like operating systems.
       
  5051       </p>
       
  5052       <p id="ch8ult_module_plan_1a6">
       
  5053        When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
       
  5054       </p>
       
  5055       <pre class="programlisting">
       
  5056        $ tr 'abcd' 'jkmn'
       
  5057       </pre>
       
  5058       <p id="ch8ult_module_plan_1a7">
       
  5059        maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
       
  5060       </p>
       
  5061       <p id="ch8ult_module_plan_1a8">
       
  5062        Sets of characters may be abbreviated by using character ranges. The previous example could be written:
       
  5063       </p>
       
  5064       <pre class="programlisting">
       
  5065        $ tr 'a-d' 'jkmn'
       
  5066       </pre>
       
  5067       <p id="ch8ult_module_plan_1a9">
       
  5068        In POSIX compliant versions of
       
  5069        <span class="emphasis">
       
  5070         <em>
       
  5071          tr
       
  5072         </em>
       
  5073        </span>
       
  5074        the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
       
  5075       </p>
       
  5076       <p id="ch8ult_module_plan_1aa">
       
  5077        The
       
  5078        <span class="emphasis">
       
  5079         <em>
       
  5080          -c
       
  5081         </em>
       
  5082        </span>
       
  5083        flag complements the first set of characters.
       
  5084       </p>
       
  5085       <pre class="programlisting">
       
  5086        $ tr -cd '[:alnum:]'
       
  5087       </pre>
       
  5088       <p id="ch8ult_module_plan_1ab">
       
  5089        therefore removes all non-alphanumeric characters.
       
  5090       </p>
       
  5091       <p id="ch8ult_module_plan_1ac">
       
  5092        The
       
  5093        <span class="emphasis">
       
  5094         <em>
       
  5095          -s
       
  5096         </em>
       
  5097        </span>
       
  5098        flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
       
  5099       </p>
       
  5100       <pre class="programlisting">
       
  5101        $ tr -s '\n' '\n'
       
  5102       </pre>
       
  5103       <p id="ch8ult_module_plan_1ad">
       
  5104        replaces sequences of one or more newline characters with a single newline.
       
  5105       </p>
       
  5106       <p id="ch8ult_module_plan_1ae">
       
  5107        The
       
  5108        <span class="emphasis">
       
  5109         <em>
       
  5110          -d
       
  5111         </em>
       
  5112        </span>
       
  5113        flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
       
  5114       </p>
       
  5115       <pre class="programlisting">
       
  5116        $ tr -d '\r'
       
  5117       </pre>
       
  5118       <p id="ch8ult_module_plan_1af">
       
  5119        Most versions of
       
  5120        <span class="emphasis">
       
  5121         <em>
       
  5122          tr
       
  5123         </em>
       
  5124        </span>
       
  5125        , including GNU
       
  5126        <span class="emphasis">
       
  5127         <em>
       
  5128          tr
       
  5129         </em>
       
  5130        </span>
       
  5131        and classic Unix
       
  5132        <span class="emphasis">
       
  5133         <em>
       
  5134          tr
       
  5135         </em>
       
  5136        </span>
       
  5137        , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
       
  5138       </p>
       
  5139       <p id="ch8ult_module_plan_1b0">
       
  5140        Ruby and Perl also have an internal
       
  5141        <span class="emphasis">
       
  5142         <em>
       
  5143          tr
       
  5144         </em>
       
  5145        </span>
       
  5146        operator, which operates analogously. Tcl's
       
  5147        <span class="emphasis">
       
  5148         <em>
       
  5149          string map
       
  5150         </em>
       
  5151        </span>
       
  5152        command is more general in that it maps strings to strings while
       
  5153        <span class="emphasis">
       
  5154         <em>
       
  5155          tr
       
  5156         </em>
       
  5157        </span>
       
  5158        maps characters to characters.
       
  5159       </p>
       
  5160      </div>
       
  5161     </div>
       
  5162     <div class="section" title="14.Elementary Regex">
       
  5163      <div class="titlepage">
       
  5164       <div>
       
  5165        <div>
       
  5166         <h2 class="title" style="clear: both">
       
  5167          <a name="id2667842">
       
  5168          </a>
       
  5169          14.Elementary Regex
       
  5170         </h2>
       
  5171        </div>
       
  5172       </div>
       
  5173      </div>
       
  5174      <p id="ch8ult_module_plan_1b1">
       
  5175       In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
       
  5176      </p>
       
  5177      <p id="ch8ult_module_plan_1b2">
       
  5178       Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
       
  5179       <span class="emphasis">
       
  5180        <em>
       
  5181         ed
       
  5182        </em>
       
  5183       </span>
       
  5184       and the filter
       
  5185       <span class="emphasis">
       
  5186        <em>
       
  5187         grep
       
  5188        </em>
       
  5189       </span>
       
  5190       were the first to popularize the concept of regular expressions.
       
  5191      </p>
       
  5192      <p id="ch8ult_module_plan_1b3">
       
  5193       Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
       
  5194       <span class="emphasis">
       
  5195        <em>
       
  5196         Basic Regular Expressions
       
  5197        </em>
       
  5198       </span>
       
  5199       (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
       
  5200      </p>
       
  5201      <p id="ch8ult_module_plan_1b4">
       
  5202       In the BRE syntax, most characters are treated as literals  they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
       
  5203      </p>
       
  5204      <table summary="Elementary Regex" border="1">
       
  5205       <colgroup>
       
  5206        <col width="13">
       
  5207        </col>
       
  5208        <col width="60">
       
  5209        </col>
       
  5210       </colgroup>
       
  5211      </table>
       
  5212      <div class="section" title="14.1.Lazy quantification">
       
  5213       <div class="titlepage">
       
  5214        <div>
       
  5215         <div>
       
  5216          <h3 class="title">
       
  5217           <a name="id2668066">
       
  5218           </a>
       
  5219           14.1.Lazy quantification
       
  5220          </h3>
       
  5221         </div>
       
  5222        </div>
       
  5223       </div>
       
  5224       <p id="ch8ult_module_plan_1c9">
       
  5225        The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between &lt; and &gt; symbols in this example:
       
  5226       </p>
       
  5227       <pre class="programlisting">
       
  5228        Another whale explosion occurred on &lt;January 26&gt;, &lt;2004&gt;.
       
  5229       </pre>
       
  5230       <p id="ch8ult_module_plan_1ca">
       
  5231        ...would likely come up with the pattern &lt;.*&gt;, or similar. However, this pattern will actually return "&lt;January 26&gt;, &lt;2004&gt;" instead of the "&lt;January 26&gt;" which might be expected, because the
       
  5232        <span style="color: red">
       
  5233         &lt;title_reference&gt;*&lt;/title_reference&gt;
       
  5234        </span>
       
  5235        quantifier is greedy  it will consume as many characters as possible from the input, and "January 26&gt;, &lt;2004" has more characters than "January 26".
       
  5236       </p>
       
  5237       <p id="ch8ult_module_plan_1cb">
       
  5238        Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: &lt;[^&gt;]*&gt;), modern regular expression tools allow a quantifier to be specified as
       
  5239        <span class="emphasis">
       
  5240         <em>
       
  5241          lazy
       
  5242         </em>
       
  5243        </span>
       
  5244        (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., &lt;.*?&gt;), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
       
  5245       </p>
       
  5246      </div>
       
  5247     </div>
       
  5248     <div class="section" title="15.One Liners">
       
  5249      <div class="titlepage">
       
  5250       <div>
       
  5251        <div>
       
  5252         <h2 class="title" style="clear: both">
       
  5253          <a name="id2668143">
       
  5254          </a>
       
  5255          15.One Liners
       
  5256         </h2>
       
  5257        </div>
       
  5258       </div>
       
  5259      </div>
       
  5260      <p id="ch8ult_module_plan_1cc">
       
  5261       A
       
  5262       <span class="emphasis">
       
  5263        <em>
       
  5264         one-liner
       
  5265        </em>
       
  5266       </span>
       
  5267       is textual input to the command-line of an operating system shell that performs some function in just one line of input.
       
  5268      </p>
       
  5269      <p id="ch8ult_module_plan_1cd">
       
  5270       The one liner can be
       
  5271      </p>
       
  5272      <span style="color: red">
       
  5273       &lt;block_quote&gt;
       
  5274       <div class="orderedlist">
       
  5275        <ol class="orderedlist" type="1">
       
  5276         <li class="listitem">
       
  5277          <p id="ch8ult_module_plan_1ce">
       
  5278           An expression written in the language of the shell.
       
  5279          </p>
       
  5280         </li>
       
  5281         <li class="listitem">
       
  5282          <p id="ch8ult_module_plan_1cf">
       
  5283           The invocation of an interpreter together with program source for the interpreter to run.
       
  5284          </p>
       
  5285         </li>
       
  5286         <li class="listitem">
       
  5287          <p id="ch8ult_module_plan_1d0">
       
  5288           The invocation of a compiler together with source to compile and
       
  5289 instructions for executing the compiled program.
       
  5290          </p>
       
  5291         </li>
       
  5292        </ol>
       
  5293       </div>
       
  5294       &lt;/block_quote&gt;
       
  5295      </span>
       
  5296      <p id="ch8ult_module_plan_1d1">
       
  5297       Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
       
  5298      </p>
       
  5299      <p id="ch8ult_module_plan_1d2">
       
  5300       The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
       
  5301      </p>
       
  5302      <p id="ch8ult_module_plan_1d3">
       
  5303       The word
       
  5304       <span class="emphasis">
       
  5305        <em>
       
  5306         One-liner
       
  5307        </em>
       
  5308       </span>
       
  5309       has two references in the index of the book
       
  5310       <span class="emphasis">
       
  5311        <em>
       
  5312         The AWK Programming Language
       
  5313        </em>
       
  5314       </span>
       
  5315       (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
       
  5316      </p>
       
  5317      <pre class="programlisting">
       
  5318       The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
       
  5319      </pre>
       
  5320      <p id="ch8ult_module_plan_1d4">
       
  5321       Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
       
  5322      </p>
       
  5323      <p id="ch8ult_module_plan_1d5">
       
  5324       The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
       
  5325      </p>
       
  5326      <p id="ch8ult_module_plan_1d6">
       
  5327       Here are the first few of them:
       
  5328      </p>
       
  5329      <span style="color: red">
       
  5330       &lt;block_quote&gt;
       
  5331       <div class="orderedlist">
       
  5332        <ol class="orderedlist" type="1">
       
  5333         <li class="listitem">
       
  5334          <p id="ch8ult_module_plan_1d7">
       
  5335           Print the total number of input lines:
       
  5336          </p>
       
  5337          <p id="ch8ult_module_plan_1d8">
       
  5338           END { print NR }
       
  5339          </p>
       
  5340         </li>
       
  5341         <li class="listitem">
       
  5342          <p id="ch8ult_module_plan_1d9">
       
  5343           Print the tenth input line:
       
  5344          </p>
       
  5345          <p id="ch8ult_module_plan_1da">
       
  5346           NR == 10
       
  5347          </p>
       
  5348         </li>
       
  5349         <li class="listitem">
       
  5350          <p id="ch8ult_module_plan_1db">
       
  5351           Print the last field of every input line:
       
  5352          </p>
       
  5353          <p id="ch8ult_module_plan_1dc">
       
  5354           { print $NF }
       
  5355          </p>
       
  5356         </li>
       
  5357        </ol>
       
  5358       </div>
       
  5359       &lt;/block_quote&gt;
       
  5360      </span>
       
  5361      <p id="ch8ult_module_plan_1dd">
       
  5362       One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
       
  5363      </p>
       
  5364      <p id="ch8ult_module_plan_1de">
       
  5365       The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
       
  5366      </p>
       
  5367      <pre class="programlisting">
       
  5368       main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
       
  5369 *t-42?*s?63==*t|*s==*t&amp;&amp;m(s+1,t+1):!*t:m(s,t+1)||*s&amp;&amp;m(s+1,t);}
       
  5370      </pre>
       
  5371      <p id="ch8ult_module_plan_1df">
       
  5372       This one-liner program is a
       
  5373       <span class="emphasis">
       
  5374        <em>
       
  5375         glob pattern matcher
       
  5376        </em>
       
  5377       </span>
       
  5378       . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
       
  5379      </p>
       
  5380      <p id="ch8ult_module_plan_1e0">
       
  5381       Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
       
  5382      </p>
       
  5383      <pre class="programlisting">
       
  5384       $ prog foo 'f??'; echo $?
  1132 
  5385 
  1133 $ prog 'best short program' '??st*o**p?*'; echo $?</pre>
  5386 $ prog 'best short program' '??st*o**p?*'; echo $?
  1134 <p id="ch8ult_module_plan_1e1"></a>Here is a one line shell script to show directories:</p>
  5387      </pre>
  1135 <pre class="programlisting">$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'</pre>
  5388      <p id="ch8ult_module_plan_1e1">
  1136 </div>
  5389       Here is a one line shell script to show directories:
  1137 </div>
  5390      </p>
  1138 </div></body>
  5391      <pre class="programlisting">
       
  5392       $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
       
  5393      </pre>
       
  5394     </div>
       
  5395    </div>
       
  5396   </div>
       
  5397  </body>
  1139 </html>
  5398 </html>