SEESenv/web/html/ch7interim_assessment.html
changeset 24 10074d1357ff
parent 16 2e3d2cadbcb6
child 25 ed38dd9bdb50
equal deleted inserted replaced
23:d2855b0d6df8 24:10074d1357ff
    25      </b>
    25      </b>
    26     </p>
    26     </p>
    27     <dl>
    27     <dl>
    28      <dt>
    28      <dt>
    29       <span class="article">
    29       <span class="article">
    30        <a href="#id2600384">
    30        <a href="#id2747157">
       
    31         Interim Assessment
    31        </a>
    32        </a>
    32       </span>
    33       </span>
    33      </dt>
    34      </dt>
    34      <dd>
       
    35       <dl>
       
    36        <dt>
       
    37         <span class="section">
       
    38          <a href="#id2410508">
       
    39           1. Introducing Linux
       
    40          </a>
       
    41         </span>
       
    42        </dt>
       
    43        <dd>
       
    44         <dl>
       
    45          <dt>
       
    46           <span class="section">
       
    47            <a href="#id2600188">
       
    48             1.1. Historical Background
       
    49            </a>
       
    50           </span>
       
    51          </dt>
       
    52          <dt>
       
    53           <span class="section">
       
    54            <a href="#id2651434">
       
    55             1.2. Design and Implications
       
    56            </a>
       
    57           </span>
       
    58          </dt>
       
    59          <dt>
       
    60           <span class="section">
       
    61            <a href="#id2651845">
       
    62             1.3. Reasons for Using Linux
       
    63            </a>
       
    64           </span>
       
    65          </dt>
       
    66         </dl>
       
    67        </dd>
       
    68        <dt>
       
    69         <span class="section">
       
    70          <a href="#id2651986">
       
    71           2. Getting Started
       
    72          </a>
       
    73         </span>
       
    74        </dt>
       
    75        <dd>
       
    76         <dl>
       
    77          <dt>
       
    78           <span class="section">
       
    79            <a href="#id2651994">
       
    80             2.1. Logging in, activating the user interface and logging out
       
    81            </a>
       
    82           </span>
       
    83          </dt>
       
    84         </dl>
       
    85        </dd>
       
    86        <dt>
       
    87         <span class="section">
       
    88          <a href="#id2652274">
       
    89           3. Basic Commands
       
    90          </a>
       
    91         </span>
       
    92        </dt>
       
    93        <dd>
       
    94         <dl>
       
    95          <dt>
       
    96           <span class="section">
       
    97            <a href="#id2652282">
       
    98             3.1. ls
       
    99            </a>
       
   100           </span>
       
   101          </dt>
       
   102          <dt>
       
   103           <span class="section">
       
   104            <a href="#id2652445">
       
   105             3.2. date
       
   106            </a>
       
   107           </span>
       
   108          </dt>
       
   109          <dt>
       
   110           <span class="section">
       
   111            <a href="#id2652506">
       
   112             3.3. cd
       
   113            </a>
       
   114           </span>
       
   115          </dt>
       
   116          <dt>
       
   117           <span class="section">
       
   118            <a href="#id2652607">
       
   119             3.4. who
       
   120            </a>
       
   121           </span>
       
   122          </dt>
       
   123          <dt>
       
   124           <span class="section">
       
   125            <a href="#id2652690">
       
   126             3.5. mkdir
       
   127            </a>
       
   128           </span>
       
   129          </dt>
       
   130         </dl>
       
   131        </dd>
       
   132        <dt>
       
   133         <span class="section">
       
   134          <a href="#id2652858">
       
   135           4. Getting Help
       
   136          </a>
       
   137         </span>
       
   138        </dt>
       
   139        <dd>
       
   140         <dl>
       
   141          <dt>
       
   142           <span class="section">
       
   143            <a href="#id2652866">
       
   144             4.1. apropos and whatis
       
   145            </a>
       
   146           </span>
       
   147          </dt>
       
   148          <dt>
       
   149           <span class="section">
       
   150            <a href="#id2652961">
       
   151             4.2. man
       
   152            </a>
       
   153           </span>
       
   154          </dt>
       
   155          <dt>
       
   156           <span class="section">
       
   157            <a href="#id2653155">
       
   158             4.3. info
       
   159            </a>
       
   160           </span>
       
   161          </dt>
       
   162          <dt>
       
   163           <span class="section">
       
   164            <a href="#id2653242">
       
   165             4.4. --help
       
   166            </a>
       
   167           </span>
       
   168          </dt>
       
   169         </dl>
       
   170        </dd>
       
   171        <dt>
       
   172         <span class="section">
       
   173          <a href="#id2653295">
       
   174           5. Basic file handling
       
   175          </a>
       
   176         </span>
       
   177        </dt>
       
   178        <dd>
       
   179         <dl>
       
   180          <dt>
       
   181           <span class="section">
       
   182            <a href="#id2653303">
       
   183             5.1. cp
       
   184            </a>
       
   185           </span>
       
   186          </dt>
       
   187          <dt>
       
   188           <span class="section">
       
   189            <a href="#id2653616">
       
   190             5.2. mv
       
   191            </a>
       
   192           </span>
       
   193          </dt>
       
   194          <dt>
       
   195           <span class="section">
       
   196            <a href="#id2653754">
       
   197             5.3. rm
       
   198            </a>
       
   199           </span>
       
   200          </dt>
       
   201         </dl>
       
   202        </dd>
       
   203        <dt>
       
   204         <span class="section">
       
   205          <a href="#id2653922">
       
   206           6. Command Line Arguments
       
   207          </a>
       
   208         </span>
       
   209        </dt>
       
   210        <dt>
       
   211         <span class="section">
       
   212          <a href="#id2654015">
       
   213           7. Basic Text Processing
       
   214          </a>
       
   215         </span>
       
   216        </dt>
       
   217        <dd>
       
   218         <dl>
       
   219          <dt>
       
   220           <span class="section">
       
   221            <a href="#id2654024">
       
   222             7.1. head
       
   223            </a>
       
   224           </span>
       
   225          </dt>
       
   226          <dt>
       
   227           <span class="section">
       
   228            <a href="#id2654111">
       
   229             7.2. tail
       
   230            </a>
       
   231           </span>
       
   232          </dt>
       
   233          <dt>
       
   234           <span class="section">
       
   235            <a href="#id2654239">
       
   236             7.3. cut
       
   237            </a>
       
   238           </span>
       
   239          </dt>
       
   240          <dt>
       
   241           <span class="section">
       
   242            <a href="#id2654326">
       
   243             7.4. paste
       
   244            </a>
       
   245           </span>
       
   246          </dt>
       
   247         </dl>
       
   248        </dd>
       
   249        <dt>
       
   250         <span class="section">
       
   251          <a href="#id2654460">
       
   252           8. Shell Meta Characters
       
   253          </a>
       
   254         </span>
       
   255        </dt>
       
   256        <dt>
       
   257         <span class="section">
       
   258          <a href="#id2654565">
       
   259           9. Looking At Files
       
   260          </a>
       
   261         </span>
       
   262        </dt>
       
   263        <dd>
       
   264         <dl>
       
   265          <dt>
       
   266           <span class="section">
       
   267            <a href="#id2654574">
       
   268             9.1. cat
       
   269            </a>
       
   270           </span>
       
   271          </dt>
       
   272          <dt>
       
   273           <span class="section">
       
   274            <a href="#id2654762">
       
   275             9.2. more
       
   276            </a>
       
   277           </span>
       
   278          </dt>
       
   279          <dt>
       
   280           <span class="section">
       
   281            <a href="#id2654872">
       
   282             9.3. less
       
   283            </a>
       
   284           </span>
       
   285          </dt>
       
   286         </dl>
       
   287        </dd>
       
   288        <dt>
       
   289         <span class="section">
       
   290          <a href="#id2655114">
       
   291           10. Directory Structure
       
   292          </a>
       
   293         </span>
       
   294        </dt>
       
   295        <dd>
       
   296         <dl>
       
   297          <dt>
       
   298           <span class="section">
       
   299            <a href="#id2655388">
       
   300             10.1. man hier
       
   301            </a>
       
   302           </span>
       
   303          </dt>
       
   304          <dt>
       
   305           <span class="section">
       
   306            <a href="#id2655404">
       
   307             10.2. ls -l
       
   308            </a>
       
   309           </span>
       
   310          </dt>
       
   311         </dl>
       
   312        </dd>
       
   313        <dt>
       
   314         <span class="section">
       
   315          <a href="#id2655428">
       
   316           11. Permissions and Ownership
       
   317          </a>
       
   318         </span>
       
   319        </dt>
       
   320        <dd>
       
   321         <dl>
       
   322          <dt>
       
   323           <span class="section">
       
   324            <a href="#id2655436">
       
   325             11.1. chmod
       
   326            </a>
       
   327           </span>
       
   328          </dt>
       
   329         </dl>
       
   330        </dd>
       
   331        <dt>
       
   332         <span class="section">
       
   333          <a href="#id2656213">
       
   334           12. Redirection and Piping
       
   335          </a>
       
   336         </span>
       
   337        </dt>
       
   338        <dd>
       
   339         <dl>
       
   340          <dt>
       
   341           <span class="section">
       
   342            <a href="#id2656248">
       
   343             12.1. Redirecting standard input and standard output
       
   344            </a>
       
   345           </span>
       
   346          </dt>
       
   347          <dt>
       
   348           <span class="section">
       
   349            <a href="#id2656318">
       
   350             12.2. Piping
       
   351            </a>
       
   352           </span>
       
   353          </dt>
       
   354          <dt>
       
   355           <span class="section">
       
   356            <a href="#id2656380">
       
   357             12.3. Redirecting to and from the standard file handles
       
   358            </a>
       
   359           </span>
       
   360          </dt>
       
   361          <dt>
       
   362           <span class="section">
       
   363            <a href="#id2656587">
       
   364             12.4. Chained pipelines
       
   365            </a>
       
   366           </span>
       
   367          </dt>
       
   368          <dt>
       
   369           <span class="section">
       
   370            <a href="#id2656622">
       
   371             12.5. Redirect to multiple outputs
       
   372            </a>
       
   373           </span>
       
   374          </dt>
       
   375         </dl>
       
   376        </dd>
       
   377        <dt>
       
   378         <span class="section">
       
   379          <a href="#id2656652">
       
   380           13. More Text Processing
       
   381          </a>
       
   382         </span>
       
   383        </dt>
       
   384        <dd>
       
   385         <dl>
       
   386          <dt>
       
   387           <span class="section">
       
   388            <a href="#id2656661">
       
   389             13.1. grep
       
   390            </a>
       
   391           </span>
       
   392          </dt>
       
   393          <dt>
       
   394           <span class="section">
       
   395            <a href="#id2656851">
       
   396             13.2. tr
       
   397            </a>
       
   398           </span>
       
   399          </dt>
       
   400         </dl>
       
   401        </dd>
       
   402        <dt>
       
   403         <span class="section">
       
   404          <a href="#id2657002">
       
   405           14. Elementary Regex
       
   406          </a>
       
   407         </span>
       
   408        </dt>
       
   409        <dd>
       
   410         <dl>
       
   411          <dt>
       
   412           <span class="section">
       
   413            <a href="#id2657216">
       
   414             14.1. Lazy quantification
       
   415            </a>
       
   416           </span>
       
   417          </dt>
       
   418         </dl>
       
   419        </dd>
       
   420        <dt>
       
   421         <span class="section">
       
   422          <a href="#id2657292">
       
   423           15. One Liners
       
   424          </a>
       
   425         </span>
       
   426        </dt>
       
   427       </dl>
       
   428      </dd>
       
   429     </dl>
    35     </dl>
   430    </div>
    36    </div>
   431    <div class="article">
    37    <div class="article" title="Interim Assessment">
   432     <div class="titlepage">
    38     <div class="titlepage">
   433      <div>
    39      <div>
   434       <div>
    40       <div>
   435        <h2 class="title" id="id2600384">
    41        <h2 class="title">
       
    42         <a name="id2747157">
       
    43         </a>
       
    44         Interim Assessment
   436        </h2>
    45        </h2>
   437       </div>
    46       </div>
   438      </div>
    47      </div>
   439      <hr />
    48      <hr />
   440     </div>
    49     </div>
   441     <div class="toc">
       
   442      <p>
       
   443       <b>
       
   444        Table of Contents
       
   445       </b>
       
   446      </p>
       
   447      <dl>
       
   448       <dt>
       
   449        <span class="section">
       
   450         <a href="#id2410508">
       
   451          1. Introducing Linux
       
   452         </a>
       
   453        </span>
       
   454       </dt>
       
   455       <dd>
       
   456        <dl>
       
   457         <dt>
       
   458          <span class="section">
       
   459           <a href="#id2600188">
       
   460            1.1. Historical Background
       
   461           </a>
       
   462          </span>
       
   463         </dt>
       
   464         <dt>
       
   465          <span class="section">
       
   466           <a href="#id2651434">
       
   467            1.2. Design and Implications
       
   468           </a>
       
   469          </span>
       
   470         </dt>
       
   471         <dt>
       
   472          <span class="section">
       
   473           <a href="#id2651845">
       
   474            1.3. Reasons for Using Linux
       
   475           </a>
       
   476          </span>
       
   477         </dt>
       
   478        </dl>
       
   479       </dd>
       
   480       <dt>
       
   481        <span class="section">
       
   482         <a href="#id2651986">
       
   483          2. Getting Started
       
   484         </a>
       
   485        </span>
       
   486       </dt>
       
   487       <dd>
       
   488        <dl>
       
   489         <dt>
       
   490          <span class="section">
       
   491           <a href="#id2651994">
       
   492            2.1. Logging in, activating the user interface and logging out
       
   493           </a>
       
   494          </span>
       
   495         </dt>
       
   496        </dl>
       
   497       </dd>
       
   498       <dt>
       
   499        <span class="section">
       
   500         <a href="#id2652274">
       
   501          3. Basic Commands
       
   502         </a>
       
   503        </span>
       
   504       </dt>
       
   505       <dd>
       
   506        <dl>
       
   507         <dt>
       
   508          <span class="section">
       
   509           <a href="#id2652282">
       
   510            3.1. ls
       
   511           </a>
       
   512          </span>
       
   513         </dt>
       
   514         <dt>
       
   515          <span class="section">
       
   516           <a href="#id2652445">
       
   517            3.2. date
       
   518           </a>
       
   519          </span>
       
   520         </dt>
       
   521         <dt>
       
   522          <span class="section">
       
   523           <a href="#id2652506">
       
   524            3.3. cd
       
   525           </a>
       
   526          </span>
       
   527         </dt>
       
   528         <dt>
       
   529          <span class="section">
       
   530           <a href="#id2652607">
       
   531            3.4. who
       
   532           </a>
       
   533          </span>
       
   534         </dt>
       
   535         <dt>
       
   536          <span class="section">
       
   537           <a href="#id2652690">
       
   538            3.5. mkdir
       
   539           </a>
       
   540          </span>
       
   541         </dt>
       
   542        </dl>
       
   543       </dd>
       
   544       <dt>
       
   545        <span class="section">
       
   546         <a href="#id2652858">
       
   547          4. Getting Help
       
   548         </a>
       
   549        </span>
       
   550       </dt>
       
   551       <dd>
       
   552        <dl>
       
   553         <dt>
       
   554          <span class="section">
       
   555           <a href="#id2652866">
       
   556            4.1. apropos and whatis
       
   557           </a>
       
   558          </span>
       
   559         </dt>
       
   560         <dt>
       
   561          <span class="section">
       
   562           <a href="#id2652961">
       
   563            4.2. man
       
   564           </a>
       
   565          </span>
       
   566         </dt>
       
   567         <dt>
       
   568          <span class="section">
       
   569           <a href="#id2653155">
       
   570            4.3. info
       
   571           </a>
       
   572          </span>
       
   573         </dt>
       
   574         <dt>
       
   575          <span class="section">
       
   576           <a href="#id2653242">
       
   577            4.4. --help
       
   578           </a>
       
   579          </span>
       
   580         </dt>
       
   581        </dl>
       
   582       </dd>
       
   583       <dt>
       
   584        <span class="section">
       
   585         <a href="#id2653295">
       
   586          5. Basic file handling
       
   587         </a>
       
   588        </span>
       
   589       </dt>
       
   590       <dd>
       
   591        <dl>
       
   592         <dt>
       
   593          <span class="section">
       
   594           <a href="#id2653303">
       
   595            5.1. cp
       
   596           </a>
       
   597          </span>
       
   598         </dt>
       
   599         <dt>
       
   600          <span class="section">
       
   601           <a href="#id2653616">
       
   602            5.2. mv
       
   603           </a>
       
   604          </span>
       
   605         </dt>
       
   606         <dt>
       
   607          <span class="section">
       
   608           <a href="#id2653754">
       
   609            5.3. rm
       
   610           </a>
       
   611          </span>
       
   612         </dt>
       
   613        </dl>
       
   614       </dd>
       
   615       <dt>
       
   616        <span class="section">
       
   617         <a href="#id2653922">
       
   618          6. Command Line Arguments
       
   619         </a>
       
   620        </span>
       
   621       </dt>
       
   622       <dt>
       
   623        <span class="section">
       
   624         <a href="#id2654015">
       
   625          7. Basic Text Processing
       
   626         </a>
       
   627        </span>
       
   628       </dt>
       
   629       <dd>
       
   630        <dl>
       
   631         <dt>
       
   632          <span class="section">
       
   633           <a href="#id2654024">
       
   634            7.1. head
       
   635           </a>
       
   636          </span>
       
   637         </dt>
       
   638         <dt>
       
   639          <span class="section">
       
   640           <a href="#id2654111">
       
   641            7.2. tail
       
   642           </a>
       
   643          </span>
       
   644         </dt>
       
   645         <dt>
       
   646          <span class="section">
       
   647           <a href="#id2654239">
       
   648            7.3. cut
       
   649           </a>
       
   650          </span>
       
   651         </dt>
       
   652         <dt>
       
   653          <span class="section">
       
   654           <a href="#id2654326">
       
   655            7.4. paste
       
   656           </a>
       
   657          </span>
       
   658         </dt>
       
   659        </dl>
       
   660       </dd>
       
   661       <dt>
       
   662        <span class="section">
       
   663         <a href="#id2654460">
       
   664          8. Shell Meta Characters
       
   665         </a>
       
   666        </span>
       
   667       </dt>
       
   668       <dt>
       
   669        <span class="section">
       
   670         <a href="#id2654565">
       
   671          9. Looking At Files
       
   672         </a>
       
   673        </span>
       
   674       </dt>
       
   675       <dd>
       
   676        <dl>
       
   677         <dt>
       
   678          <span class="section">
       
   679           <a href="#id2654574">
       
   680            9.1. cat
       
   681           </a>
       
   682          </span>
       
   683         </dt>
       
   684         <dt>
       
   685          <span class="section">
       
   686           <a href="#id2654762">
       
   687            9.2. more
       
   688           </a>
       
   689          </span>
       
   690         </dt>
       
   691         <dt>
       
   692          <span class="section">
       
   693           <a href="#id2654872">
       
   694            9.3. less
       
   695           </a>
       
   696          </span>
       
   697         </dt>
       
   698        </dl>
       
   699       </dd>
       
   700       <dt>
       
   701        <span class="section">
       
   702         <a href="#id2655114">
       
   703          10. Directory Structure
       
   704         </a>
       
   705        </span>
       
   706       </dt>
       
   707       <dd>
       
   708        <dl>
       
   709         <dt>
       
   710          <span class="section">
       
   711           <a href="#id2655388">
       
   712            10.1. man hier
       
   713           </a>
       
   714          </span>
       
   715         </dt>
       
   716         <dt>
       
   717          <span class="section">
       
   718           <a href="#id2655404">
       
   719            10.2. ls -l
       
   720           </a>
       
   721          </span>
       
   722         </dt>
       
   723        </dl>
       
   724       </dd>
       
   725       <dt>
       
   726        <span class="section">
       
   727         <a href="#id2655428">
       
   728          11. Permissions and Ownership
       
   729         </a>
       
   730        </span>
       
   731       </dt>
       
   732       <dd>
       
   733        <dl>
       
   734         <dt>
       
   735          <span class="section">
       
   736           <a href="#id2655436">
       
   737            11.1. chmod
       
   738           </a>
       
   739          </span>
       
   740         </dt>
       
   741        </dl>
       
   742       </dd>
       
   743       <dt>
       
   744        <span class="section">
       
   745         <a href="#id2656213">
       
   746          12. Redirection and Piping
       
   747         </a>
       
   748        </span>
       
   749       </dt>
       
   750       <dd>
       
   751        <dl>
       
   752         <dt>
       
   753          <span class="section">
       
   754           <a href="#id2656248">
       
   755            12.1. Redirecting standard input and standard output
       
   756           </a>
       
   757          </span>
       
   758         </dt>
       
   759         <dt>
       
   760          <span class="section">
       
   761           <a href="#id2656318">
       
   762            12.2. Piping
       
   763           </a>
       
   764          </span>
       
   765         </dt>
       
   766         <dt>
       
   767          <span class="section">
       
   768           <a href="#id2656380">
       
   769            12.3. Redirecting to and from the standard file handles
       
   770           </a>
       
   771          </span>
       
   772         </dt>
       
   773         <dt>
       
   774          <span class="section">
       
   775           <a href="#id2656587">
       
   776            12.4. Chained pipelines
       
   777           </a>
       
   778          </span>
       
   779         </dt>
       
   780         <dt>
       
   781          <span class="section">
       
   782           <a href="#id2656622">
       
   783            12.5. Redirect to multiple outputs
       
   784           </a>
       
   785          </span>
       
   786         </dt>
       
   787        </dl>
       
   788       </dd>
       
   789       <dt>
       
   790        <span class="section">
       
   791         <a href="#id2656652">
       
   792          13. More Text Processing
       
   793         </a>
       
   794        </span>
       
   795       </dt>
       
   796       <dd>
       
   797        <dl>
       
   798         <dt>
       
   799          <span class="section">
       
   800           <a href="#id2656661">
       
   801            13.1. grep
       
   802           </a>
       
   803          </span>
       
   804         </dt>
       
   805         <dt>
       
   806          <span class="section">
       
   807           <a href="#id2656851">
       
   808            13.2. tr
       
   809           </a>
       
   810          </span>
       
   811         </dt>
       
   812        </dl>
       
   813       </dd>
       
   814       <dt>
       
   815        <span class="section">
       
   816         <a href="#id2657002">
       
   817          14. Elementary Regex
       
   818         </a>
       
   819        </span>
       
   820       </dt>
       
   821       <dd>
       
   822        <dl>
       
   823         <dt>
       
   824          <span class="section">
       
   825           <a href="#id2657216">
       
   826            14.1. Lazy quantification
       
   827           </a>
       
   828          </span>
       
   829         </dt>
       
   830        </dl>
       
   831       </dd>
       
   832       <dt>
       
   833        <span class="section">
       
   834         <a href="#id2657292">
       
   835          15. One Liners
       
   836         </a>
       
   837        </span>
       
   838       </dt>
       
   839      </dl>
       
   840     </div>
       
   841     <div class="section" title="1.Introducing Linux">
       
   842      <div class="titlepage">
       
   843       <div>
       
   844        <div>
       
   845         <h2 class="title" style="clear: both">
       
   846          <a name="id2410508">
       
   847          </a>
       
   848          1.Introducing Linux
       
   849         </h2>
       
   850        </div>
       
   851       </div>
       
   852      </div>
       
   853      <p id="ch7interim_assessment_1">
       
   854       (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
       
   855      </p>
       
   856      <p id="ch7interim_assessment_2">
       
   857       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.
       
   858      </p>
       
   859      <p id="ch7interim_assessment_3">
       
   860       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.
       
   861      </p>
       
   862      <p id="ch7interim_assessment_4">
       
   863       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.
       
   864      </p>
       
   865      <div class="section" title="1.1.Historical Background">
       
   866       <div class="titlepage">
       
   867        <div>
       
   868         <div>
       
   869          <h3 class="title">
       
   870           <a name="id2600188">
       
   871           </a>
       
   872           1.1.Historical Background
       
   873          </h3>
       
   874         </div>
       
   875        </div>
       
   876       </div>
       
   877       <div class="section" title="1.1.1.Events leading to the creation">
       
   878        <div class="titlepage">
       
   879         <div>
       
   880          <div>
       
   881           <h4 class="title">
       
   882            <a name="id2598169">
       
   883            </a>
       
   884            1.1.1.Events leading to the creation
       
   885           </h4>
       
   886          </div>
       
   887         </div>
       
   888        </div>
       
   889        <div class="itemizedlist">
       
   890         <ul class="itemizedlist" type="*">
       
   891          <li class="listitem" style="list-style-type: *">
       
   892           <p id="ch7interim_assessment_5">
       
   893            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.
       
   894           </p>
       
   895          </li>
       
   896          <li class="listitem" style="list-style-type: *">
       
   897           <p id="ch7interim_assessment_6">
       
   898            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.
       
   899           </p>
       
   900          </li>
       
   901         </ul>
       
   902        </div>
       
   903       </div>
       
   904       <div class="section" title="1.1.2.The Creation of Linux">
       
   905        <div class="titlepage">
       
   906         <div>
       
   907          <div>
       
   908           <h4 class="title">
       
   909            <a name="id2651400">
       
   910            </a>
       
   911            1.1.2.The Creation of Linux
       
   912           </h4>
       
   913          </div>
       
   914         </div>
       
   915        </div>
       
   916        <p id="ch7interim_assessment_7">
       
   917         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).
       
   918        </p>
       
   919        <p id="ch7interim_assessment_8">
       
   920         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.
       
   921        </p>
       
   922       </div>
       
   923      </div>
       
   924      <div class="section" title="1.2.Design and Implications">
       
   925       <div class="titlepage">
       
   926        <div>
       
   927         <div>
       
   928          <h3 class="title">
       
   929           <a name="id2651434">
       
   930           </a>
       
   931           1.2.Design and Implications
       
   932          </h3>
       
   933         </div>
       
   934        </div>
       
   935       </div>
       
   936       <p id="ch7interim_assessment_9">
       
   937        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".
       
   938       </p>
       
   939       <div class="section" title="1.2.1.User Interface">
       
   940        <div class="titlepage">
       
   941         <div>
       
   942          <div>
       
   943           <h4 class="title">
       
   944            <a name="id2651459">
       
   945            </a>
       
   946            1.2.1.User Interface
       
   947           </h4>
       
   948          </div>
       
   949         </div>
       
   950        </div>
       
   951        <p id="ch7interim_assessment_a">
       
   952         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.
       
   953        </p>
       
   954        <p id="ch7interim_assessment_b">
       
   955         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.
       
   956        </p>
       
   957       </div>
       
   958       <div class="section" title="1.2.2.Development">
       
   959        <div class="titlepage">
       
   960         <div>
       
   961          <div>
       
   962           <h4 class="title">
       
   963            <a name="id2651513">
       
   964            </a>
       
   965            1.2.2.Development
       
   966           </h4>
       
   967          </div>
       
   968         </div>
       
   969        </div>
       
   970        <p id="ch7interim_assessment_c">
       
   971         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.
       
   972        </p>
       
   973        <p id="ch7interim_assessment_d">
       
   974         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.
       
   975        </p>
       
   976        <p id="ch7interim_assessment_e">
       
   977         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.
       
   978        </p>
       
   979       </div>
       
   980       <div class="section" title="1.2.3.Community">
       
   981        <div class="titlepage">
       
   982         <div>
       
   983          <div>
       
   984           <h4 class="title">
       
   985            <a name="id2651214">
       
   986            </a>
       
   987            1.2.3.Community
       
   988           </h4>
       
   989          </div>
       
   990         </div>
       
   991        </div>
       
   992        <p id="ch7interim_assessment_f">
       
   993         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.
       
   994        </p>
       
   995        <p id="ch7interim_assessment_10">
       
   996         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.
       
   997        </p>
       
   998        <p id="ch7interim_assessment_11">
       
   999         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.
       
  1000        </p>
       
  1001       </div>
       
  1002       <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
       
  1003        <div class="titlepage">
       
  1004         <div>
       
  1005          <div>
       
  1006           <h4 class="title">
       
  1007            <a name="id2651259">
       
  1008            </a>
       
  1009            1.2.4.Can I make a profit out of running a business involving Linux?
       
  1010           </h4>
       
  1011          </div>
       
  1012         </div>
       
  1013        </div>
       
  1014        <p id="ch7interim_assessment_12">
       
  1015         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.
       
  1016        </p>
       
  1017       </div>
       
  1018       <div class="section" title="1.2.5.Programming on Linux">
       
  1019        <div class="titlepage">
       
  1020         <div>
       
  1021          <div>
       
  1022           <h4 class="title">
       
  1023            <a name="id2651305">
       
  1024            </a>
       
  1025            1.2.5.Programming on Linux
       
  1026           </h4>
       
  1027          </div>
       
  1028         </div>
       
  1029        </div>
       
  1030        <p id="ch7interim_assessment_13">
       
  1031         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.
       
  1032        </p>
       
  1033        <p id="ch7interim_assessment_14">
       
  1034         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.
       
  1035        </p>
       
  1036        <p id="ch7interim_assessment_15">
       
  1037         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.
       
  1038        </p>
       
  1039       </div>
       
  1040      </div>
       
  1041      <div class="section" title="1.3.Reasons for Using Linux">
       
  1042       <div class="titlepage">
       
  1043        <div>
       
  1044         <div>
       
  1045          <h3 class="title">
       
  1046           <a name="id2651845">
       
  1047           </a>
       
  1048           1.3.Reasons for Using Linux
       
  1049          </h3>
       
  1050         </div>
       
  1051        </div>
       
  1052       </div>
       
  1053       <div class="itemizedlist">
       
  1054        <ul class="itemizedlist" type="*">
       
  1055         <li class="listitem" style="list-style-type: *">
       
  1056          <p id="ch7interim_assessment_16">
       
  1057           Linux is free:
       
  1058          </p>
       
  1059         </li>
       
  1060        </ul>
       
  1061       </div>
       
  1062       <p id="ch7interim_assessment_17">
       
  1063        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.
       
  1064 Most of all, Linux is free as in "free speech":
       
  1065 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.
       
  1066       </p>
       
  1067       <div class="itemizedlist">
       
  1068        <ul class="itemizedlist" type="*">
       
  1069         <li class="listitem" style="list-style-type: *">
       
  1070          <p id="ch7interim_assessment_18">
       
  1071           Linux is portable to any hardware platform:
       
  1072          </p>
       
  1073         </li>
       
  1074        </ul>
       
  1075       </div>
       
  1076       <p id="ch7interim_assessment_19">
       
  1077        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.
       
  1078       </p>
       
  1079       <div class="itemizedlist">
       
  1080        <ul class="itemizedlist" type="*">
       
  1081         <li class="listitem" style="list-style-type: *">
       
  1082          <p id="ch7interim_assessment_1a">
       
  1083           Linux was made to keep on running:
       
  1084          </p>
       
  1085         </li>
       
  1086        </ul>
       
  1087       </div>
       
  1088       <p id="ch7interim_assessment_1b">
       
  1089        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.
       
  1090       </p>
       
  1091       <div class="itemizedlist">
       
  1092        <ul class="itemizedlist" type="*">
       
  1093         <li class="listitem" style="list-style-type: *">
       
  1094          <p id="ch7interim_assessment_1c">
       
  1095           Linux is secure and versatile:
       
  1096          </p>
       
  1097         </li>
       
  1098        </ul>
       
  1099       </div>
       
  1100       <p id="ch7interim_assessment_1d">
       
  1101        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.
       
  1102       </p>
       
  1103       <div class="itemizedlist">
       
  1104        <ul class="itemizedlist" type="*">
       
  1105         <li class="listitem" style="list-style-type: *">
       
  1106          <p id="ch7interim_assessment_1e">
       
  1107           Linux is scalable:
       
  1108          </p>
       
  1109         </li>
       
  1110        </ul>
       
  1111       </div>
       
  1112       <p id="ch7interim_assessment_1f">
       
  1113        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.
       
  1114       </p>
       
  1115       <div class="itemizedlist">
       
  1116        <ul class="itemizedlist" type="*">
       
  1117         <li class="listitem" style="list-style-type: *">
       
  1118          <p id="ch7interim_assessment_20">
       
  1119           The Linux OS and Linux applications have very short debugtimes:
       
  1120          </p>
       
  1121         </li>
       
  1122        </ul>
       
  1123       </div>
       
  1124       <p id="ch7interim_assessment_21">
       
  1125        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.
       
  1126       </p>
       
  1127      </div>
       
  1128     </div>
       
  1129     <div class="section" title="2.Getting Started">
       
  1130      <div class="titlepage">
       
  1131       <div>
       
  1132        <div>
       
  1133         <h2 class="title" style="clear: both">
       
  1134          <a name="id2651986">
       
  1135          </a>
       
  1136          2.Getting Started
       
  1137         </h2>
       
  1138        </div>
       
  1139       </div>
       
  1140      </div>
       
  1141      <div class="section" title="2.1.Logging in, activating the user interface and logging out">
       
  1142       <div class="titlepage">
       
  1143        <div>
       
  1144         <div>
       
  1145          <h3 class="title">
       
  1146           <a name="id2651994">
       
  1147           </a>
       
  1148           2.1.Logging in, activating the user interface and logging out
       
  1149          </h3>
       
  1150         </div>
       
  1151        </div>
       
  1152       </div>
       
  1153       <p id="ch7interim_assessment_22">
       
  1154        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.
       
  1155       </p>
       
  1156       <div class="section" title="2.1.1.Graphical Mode">
       
  1157        <div class="titlepage">
       
  1158         <div>
       
  1159          <div>
       
  1160           <h4 class="title">
       
  1161            <a name="id2652025">
       
  1162            </a>
       
  1163            2.1.1.Graphical Mode
       
  1164           </h4>
       
  1165          </div>
       
  1166         </div>
       
  1167        </div>
       
  1168        <p id="ch7interim_assessment_23">
       
  1169         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.
       
  1170        </p>
       
  1171        <p id="ch7interim_assessment_24">
       
  1172         To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
       
  1173         <span class="emphasis">
       
  1174          <em>
       
  1175           OK
       
  1176          </em>
       
  1177         </span>
       
  1178         or press
       
  1179         <span class="emphasis">
       
  1180          <em>
       
  1181           Enter
       
  1182          </em>
       
  1183         </span>
       
  1184         .
       
  1185 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.
       
  1186        </p>
       
  1187        <p id="ch7interim_assessment_25">
       
  1188         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.
       
  1189        </p>
       
  1190        <p id="ch7interim_assessment_26">
       
  1191         To continue, you will need to open a
       
  1192         <span class="emphasis">
       
  1193          <em>
       
  1194           terminal window
       
  1195          </em>
       
  1196         </span>
       
  1197         or
       
  1198         <span class="emphasis">
       
  1199          <em>
       
  1200           xterm
       
  1201          </em>
       
  1202         </span>
       
  1203         for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
       
  1204         <span class="emphasis">
       
  1205          <em>
       
  1206           Applications&gt;Utilities-&gt;System Tools
       
  1207          </em>
       
  1208         </span>
       
  1209         or
       
  1210         <span class="emphasis">
       
  1211          <em>
       
  1212           Internet menu
       
  1213          </em>
       
  1214         </span>
       
  1215         , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
       
  1216         <span class="emphasis">
       
  1217          <em>
       
  1218           xterm
       
  1219          </em>
       
  1220         </span>
       
  1221         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.
       
  1222        </p>
       
  1223        <p id="ch7interim_assessment_27">
       
  1224         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.
       
  1225        </p>
       
  1226        <p id="ch7interim_assessment_28">
       
  1227         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 (~)
       
  1228        </p>
       
  1229        <p id="ch7interim_assessment_29">
       
  1230         Another common form for a prompt is this one:
       
  1231 [
       
  1232        </p>
       
  1233        <div class="reference">
       
  1234         <div class="titlepage">
       
  1235          <hr />
       
  1236         </div>
       
  1237         user@host
       
  1238        </div>
       
  1239        <p>
       
  1240         dir]
       
  1241        </p>
       
  1242        <p id="ch7interim_assessment_2a">
       
  1243         In the above example,
       
  1244         <span class="emphasis">
       
  1245          <em>
       
  1246           user
       
  1247          </em>
       
  1248         </span>
       
  1249         will be your login name,
       
  1250         <span class="emphasis">
       
  1251          <em>
       
  1252           hosts
       
  1253          </em>
       
  1254         </span>
       
  1255         the name of the machine you are working on, and
       
  1256         <span class="emphasis">
       
  1257          <em>
       
  1258           dir
       
  1259          </em>
       
  1260         </span>
       
  1261         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
       
  1262         <span class="emphasis">
       
  1263          <em>
       
  1264           logout
       
  1265          </em>
       
  1266         </span>
       
  1267         icon or find
       
  1268         <span class="emphasis">
       
  1269          <em>
       
  1270           Log Out
       
  1271          </em>
       
  1272         </span>
       
  1273         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.
       
  1274        </p>
       
  1275        <p id="ch7interim_assessment_2b">
       
  1276         When you see the login screen again, asking to enter user name and password, logout was successful.
       
  1277        </p>
       
  1278       </div>
       
  1279       <div class="section" title="2.1.2.Text Mode">
       
  1280        <div class="titlepage">
       
  1281         <div>
       
  1282          <div>
       
  1283           <h4 class="title">
       
  1284            <a name="id2652184">
       
  1285            </a>
       
  1286            2.1.2.Text Mode
       
  1287           </h4>
       
  1288          </div>
       
  1289         </div>
       
  1290        </div>
       
  1291        <p id="ch7interim_assessment_2c">
       
  1292         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.
       
  1293        </p>
       
  1294        <p id="ch7interim_assessment_2d">
       
  1295         The login is different from a graphical login, in that you have to hit the
       
  1296         <span class="emphasis">
       
  1297          <em>
       
  1298           Enter
       
  1299          </em>
       
  1300         </span>
       
  1301         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
       
  1302         <span class="emphasis">
       
  1303          <em>
       
  1304           Enter
       
  1305          </em>
       
  1306         </span>
       
  1307         . 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
       
  1308 reasons.
       
  1309        </p>
       
  1310        <p id="ch7interim_assessment_2e">
       
  1311         When the system has accepted you as a valid user, you may get some more information, called the
       
  1312         <span class="emphasis">
       
  1313          <em>
       
  1314           message of the day
       
  1315          </em>
       
  1316         </span>
       
  1317         , 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.
       
  1318        </p>
       
  1319        <p id="ch7interim_assessment_2f">
       
  1320         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.
       
  1321        </p>
       
  1322        <p id="ch7interim_assessment_30">
       
  1323         Logging out is done by entering the
       
  1324         <span class="emphasis">
       
  1325          <em>
       
  1326           logout
       
  1327          </em>
       
  1328         </span>
       
  1329         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!
       
  1330        </p>
       
  1331       </div>
       
  1332      </div>
       
  1333     </div>
       
  1334     <div class="section" title="3.Basic Commands">
       
  1335      <div class="titlepage">
       
  1336       <div>
       
  1337        <div>
       
  1338         <h2 class="title" style="clear: both">
       
  1339          <a name="id2652274">
       
  1340          </a>
       
  1341          3.Basic Commands
       
  1342         </h2>
       
  1343        </div>
       
  1344       </div>
       
  1345      </div>
       
  1346      <div class="section" title="3.1.ls">
       
  1347       <div class="titlepage">
       
  1348        <div>
       
  1349         <div>
       
  1350          <h3 class="title">
       
  1351           <a name="id2652282">
       
  1352           </a>
       
  1353           3.1.ls
       
  1354          </h3>
       
  1355         </div>
       
  1356        </div>
       
  1357       </div>
       
  1358       <p id="ch7interim_assessment_31">
       
  1359        When invoked without any arguments,
       
  1360        <span class="emphasis">
       
  1361         <em>
       
  1362          ls
       
  1363         </em>
       
  1364        </span>
       
  1365        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
       
  1366        <span class="emphasis">
       
  1367         <em>
       
  1368          ls
       
  1369         </em>
       
  1370        </span>
       
  1371        is derived from
       
  1372        <span class="emphasis">
       
  1373         <em>
       
  1374          list segments
       
  1375         </em>
       
  1376        </span>
       
  1377        which was used in earlier systems.
       
  1378       </p>
       
  1379       <p id="ch7interim_assessment_32">
       
  1380        Files whose names start with "." are not listed, unless the
       
  1381        <span class="emphasis">
       
  1382         <em>
       
  1383          -a
       
  1384         </em>
       
  1385        </span>
       
  1386        flag is specified or the files are specified explicitly.
       
  1387       </p>
       
  1388       <p id="ch7interim_assessment_33">
       
  1389        Without options,
       
  1390        <span class="emphasis">
       
  1391         <em>
       
  1392          ls
       
  1393         </em>
       
  1394        </span>
       
  1395        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:
       
  1396       </p>
       
  1397       <div class="itemizedlist">
       
  1398        <ul class="itemizedlist" type="*">
       
  1399         <li class="listitem" style="list-style-type: *">
       
  1400          <p id="ch7interim_assessment_34">
       
  1401           <span class="emphasis">
       
  1402            <em>
       
  1403             -l
       
  1404            </em>
       
  1405           </span>
       
  1406           long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
       
  1407          </p>
       
  1408         </li>
       
  1409         <li class="listitem" style="list-style-type: *">
       
  1410          <p id="ch7interim_assessment_35">
       
  1411           <span class="emphasis">
       
  1412            <em>
       
  1413             -F
       
  1414            </em>
       
  1415           </span>
       
  1416           appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
       
  1417          </p>
       
  1418         </li>
       
  1419         <li class="listitem" style="list-style-type: *">
       
  1420          <p id="ch7interim_assessment_36">
       
  1421           <span class="emphasis">
       
  1422            <em>
       
  1423             -a
       
  1424            </em>
       
  1425           </span>
       
  1426           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.
       
  1427          </p>
       
  1428         </li>
       
  1429         <li class="listitem" style="list-style-type: *">
       
  1430          <p id="ch7interim_assessment_37">
       
  1431           <span class="emphasis">
       
  1432            <em>
       
  1433             -R
       
  1434            </em>
       
  1435           </span>
       
  1436           recursively lists subdirectories. The command ls -R / would therefore list all files.
       
  1437          </p>
       
  1438         </li>
       
  1439         <li class="listitem" style="list-style-type: *">
       
  1440          <p id="ch7interim_assessment_38">
       
  1441           <span class="emphasis">
       
  1442            <em>
       
  1443             -d
       
  1444            </em>
       
  1445           </span>
       
  1446           shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
       
  1447          </p>
       
  1448         </li>
       
  1449         <li class="listitem" style="list-style-type: *">
       
  1450          <p id="ch7interim_assessment_39">
       
  1451           <span class="emphasis">
       
  1452            <em>
       
  1453             -t
       
  1454            </em>
       
  1455           </span>
       
  1456           sort the list of files by modification time.
       
  1457          </p>
       
  1458         </li>
       
  1459         <li class="listitem" style="list-style-type: *">
       
  1460          <p id="ch7interim_assessment_3a">
       
  1461           <span class="emphasis">
       
  1462            <em>
       
  1463             -h
       
  1464            </em>
       
  1465           </span>
       
  1466           print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
       
  1467          </p>
       
  1468         </li>
       
  1469        </ul>
       
  1470       </div>
       
  1471       <p id="ch7interim_assessment_3b">
       
  1472        In some environments, providing the option
       
  1473        <span class="emphasis">
       
  1474         <em>
       
  1475          --color
       
  1476         </em>
       
  1477        </span>
       
  1478        (for GNU ls) or
       
  1479        <span class="emphasis">
       
  1480         <em>
       
  1481          -G
       
  1482         </em>
       
  1483        </span>
       
  1484        (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
       
  1485        <span class="emphasis">
       
  1486         <em>
       
  1487          -F
       
  1488         </em>
       
  1489        </span>
       
  1490        would. To determine what color to use for a file, GNU
       
  1491        <span class="emphasis">
       
  1492         <em>
       
  1493          ls
       
  1494         </em>
       
  1495        </span>
       
  1496        checks the Unix file type, the file permissions, and the file extension, while FreeBSD
       
  1497        <span class="emphasis">
       
  1498         <em>
       
  1499          ls
       
  1500         </em>
       
  1501        </span>
       
  1502        checks only the Unix file type and file permissions.:
       
  1503       </p>
       
  1504       <pre class="programlisting">
       
  1505        $ ls
       
  1506 jeeves.rst psmith.html blandings.html
       
  1507 $ ls -l
       
  1508 drwxr--r--   1 plum  editors   4096  jeeves
       
  1509 -rw-r--r--   1 plum  editors  30405  psmith
       
  1510 -r-xr-xr-x   1 plum  plum      8460  blandings
       
  1511       </pre>
       
  1512       <p id="ch7interim_assessment_3c">
       
  1513        Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
       
  1514       </p>
       
  1515      </div>
       
  1516      <div class="section" title="3.2.date">
       
  1517       <div class="titlepage">
       
  1518        <div>
       
  1519         <div>
       
  1520          <h3 class="title">
       
  1521           <a name="id2652445">
       
  1522           </a>
       
  1523           3.2.date
       
  1524          </h3>
       
  1525         </div>
       
  1526        </div>
       
  1527       </div>
       
  1528       <p id="ch7interim_assessment_3d">
       
  1529        The Unix date command displays the time and date. The super-user can use it to set the system clock.
       
  1530       </p>
       
  1531       <p id="ch7interim_assessment_3e">
       
  1532        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:
       
  1533       </p>
       
  1534       <pre class="programlisting">
       
  1535        $date
       
  1536 Tue Sep  8 12:01:45 IST 2009
       
  1537       </pre>
       
  1538       <p id="ch7interim_assessment_3f">
       
  1539        On some systems to set the current date and time to September 8, 2004 01:22 you type:
       
  1540       </p>
       
  1541       <pre class="programlisting">
       
  1542        $date --set="20040908 01:22"
       
  1543       </pre>
       
  1544       <p id="ch7interim_assessment_40">
       
  1545        In order to view the various options for the
       
  1546        <span class="emphasis">
       
  1547         <em>
       
  1548          date
       
  1549         </em>
       
  1550        </span>
       
  1551        command, type:
       
  1552       </p>
       
  1553       <pre class="programlisting">
       
  1554        $man date
       
  1555       </pre>
       
  1556       <p id="ch7interim_assessment_41">
       
  1557        This will take you to the "Manual" page comprising of all the details on the
       
  1558        <span class="emphasis">
       
  1559         <em>
       
  1560          date
       
  1561         </em>
       
  1562        </span>
       
  1563        command. You can return to the terminal from the "man" page by pressing the
       
  1564        <span class="emphasis">
       
  1565         <em>
       
  1566          Esc
       
  1567         </em>
       
  1568        </span>
       
  1569        key in the keyboard and typing ":q" in that order.
       
  1570       </p>
       
  1571      </div>
       
  1572      <div class="section" title="3.3.cd">
       
  1573       <div class="titlepage">
       
  1574        <div>
       
  1575         <div>
       
  1576          <h3 class="title">
       
  1577           <a name="id2652506">
       
  1578           </a>
       
  1579           3.3.cd
       
  1580          </h3>
       
  1581         </div>
       
  1582        </div>
       
  1583       </div>
       
  1584       <p id="ch7interim_assessment_42">
       
  1585        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.
       
  1586       </p>
       
  1587       <p id="ch7interim_assessment_43">
       
  1588        One dot '.' represents the current directory while two dots '..' represent the parent directory.
       
  1589       </p>
       
  1590       <p id="ch7interim_assessment_44">
       
  1591        cd - will return you to the previous directory (a bit like an undo).
       
  1592       </p>
       
  1593       <p id="ch7interim_assessment_45">
       
  1594        You can also use cd absolute path or cd relative path (see below):
       
  1595       </p>
       
  1596       <p id="ch7interim_assessment_46">
       
  1597        Absolute paths:
       
  1598       </p>
       
  1599       <p id="ch7interim_assessment_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       <p id="ch7interim_assessment_48">
       
  1603        For example to get to /boot/grub you would type:
       
  1604       </p>
       
  1605       <pre class="programlisting">
       
  1606        $cd /boot/grub
       
  1607       </pre>
       
  1608       <p id="ch7interim_assessment_49">
       
  1609        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).
       
  1610       </p>
       
  1611       <p id="ch7interim_assessment_4a">
       
  1612        Relative paths:
       
  1613       </p>
       
  1614       <p id="ch7interim_assessment_4b">
       
  1615        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.
       
  1616       </p>
       
  1617       <p id="ch7interim_assessment_4c">
       
  1618        For example if you are in root's home directory and want to get to /root/music, you type:
       
  1619       </p>
       
  1620       <pre class="programlisting">
       
  1621        $ cd music
       
  1622       </pre>
       
  1623       <p id="ch7interim_assessment_4d">
       
  1624        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.
       
  1625       </p>
       
  1626      </div>
       
  1627      <div class="section" title="3.4.who">
       
  1628       <div class="titlepage">
       
  1629        <div>
       
  1630         <div>
       
  1631          <h3 class="title">
       
  1632           <a name="id2652607">
       
  1633           </a>
       
  1634           3.4.who
       
  1635          </h3>
       
  1636         </div>
       
  1637        </div>
       
  1638       </div>
       
  1639       <p id="ch7interim_assessment_4e">
       
  1640        The standard Unix command
       
  1641        <span class="emphasis">
       
  1642         <em>
       
  1643          who
       
  1644         </em>
       
  1645        </span>
       
  1646        displays a list of users who are currently logged into a computer.
       
  1647       </p>
       
  1648       <p id="ch7interim_assessment_4f">
       
  1649        The
       
  1650        <span class="emphasis">
       
  1651         <em>
       
  1652          who
       
  1653         </em>
       
  1654        </span>
       
  1655        command is related to the command
       
  1656        <span class="emphasis">
       
  1657         <em>
       
  1658          w
       
  1659         </em>
       
  1660        </span>
       
  1661        , which provides the same information but also displays additional data and statistics.:
       
  1662       </p>
       
  1663       <pre class="programlisting">
       
  1664        $who
       
  1665 beeblebrox tty7         2009-09-08 10:50 (:0)
       
  1666 beeblebrox pts/0        2009-09-08 11:25 (:0.0)
       
  1667 dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
       
  1668 beeblebrox pts/2        2009-09-08 18:53 (:0.0)
       
  1669       </pre>
       
  1670       <p id="ch7interim_assessment_50">
       
  1671        The command can be invoked with the arguments
       
  1672        <span class="emphasis">
       
  1673         <em>
       
  1674          am i
       
  1675         </em>
       
  1676        </span>
       
  1677        or
       
  1678        <span class="emphasis">
       
  1679         <em>
       
  1680          am I
       
  1681         </em>
       
  1682        </span>
       
  1683        (so it is invoked as
       
  1684        <span class="emphasis">
       
  1685         <em>
       
  1686          who am i
       
  1687         </em>
       
  1688        </span>
       
  1689        or * who am I*), showing information about the current terminal only (see the
       
  1690        <span class="emphasis">
       
  1691         <em>
       
  1692          -m
       
  1693         </em>
       
  1694        </span>
       
  1695        option below, of which this invocation is equivalent).
       
  1696       </p>
       
  1697       <p id="ch7interim_assessment_51">
       
  1698        In order to find out the various options that can be appended to the
       
  1699        <span class="emphasis">
       
  1700         <em>
       
  1701          who
       
  1702         </em>
       
  1703        </span>
       
  1704        command, check the
       
  1705        <span class="emphasis">
       
  1706         <em>
       
  1707          man
       
  1708         </em>
       
  1709        </span>
       
  1710        page by typing out the following in the terminal:
       
  1711       </p>
       
  1712       <pre class="programlisting">
       
  1713        $man who
       
  1714       </pre>
       
  1715       <p id="ch7interim_assessment_52">
       
  1716        This will take you to the "Manual" page containing details about the
       
  1717        <span class="emphasis">
       
  1718         <em>
       
  1719          who
       
  1720         </em>
       
  1721        </span>
       
  1722        command
       
  1723       </p>
       
  1724      </div>
       
  1725      <div class="section" title="3.5.mkdir">
       
  1726       <div class="titlepage">
       
  1727        <div>
       
  1728         <div>
       
  1729          <h3 class="title">
       
  1730           <a name="id2652690">
       
  1731           </a>
       
  1732           3.5.mkdir
       
  1733          </h3>
       
  1734         </div>
       
  1735        </div>
       
  1736       </div>
       
  1737       <p id="ch7interim_assessment_53">
       
  1738        This command is used to make a new directory. Normal usage is as straightforward as follows:
       
  1739       </p>
       
  1740       <pre class="programlisting">
       
  1741        $mkdir name_of_directory
       
  1742       </pre>
       
  1743       <p id="ch7interim_assessment_54">
       
  1744        Where
       
  1745        <span class="emphasis">
       
  1746         <em>
       
  1747          name_of_directory
       
  1748         </em>
       
  1749        </span>
       
  1750        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
       
  1751        <span class="emphasis">
       
  1752         <em>
       
  1753          mkdir
       
  1754         </em>
       
  1755        </span>
       
  1756        will try to create all of them.
       
  1757       </p>
       
  1758       <div class="section" title="3.5.1.Options">
       
  1759        <div class="titlepage">
       
  1760         <div>
       
  1761          <div>
       
  1762           <h4 class="title">
       
  1763            <a name="id2652722">
       
  1764            </a>
       
  1765            3.5.1.Options
       
  1766           </h4>
       
  1767          </div>
       
  1768         </div>
       
  1769        </div>
       
  1770        <p id="ch7interim_assessment_55">
       
  1771         On Unix-like operating systems,
       
  1772         <span class="emphasis">
       
  1773          <em>
       
  1774           mkdir
       
  1775          </em>
       
  1776         </span>
       
  1777         takes options. Three of the most common options are:
       
  1778        </p>
       
  1779        <div class="itemizedlist">
       
  1780         <ul class="itemizedlist" type="*">
       
  1781          <li class="listitem" style="list-style-type: *">
       
  1782           <p id="ch7interim_assessment_56">
       
  1783            <span class="emphasis">
       
  1784             <em>
       
  1785              -p
       
  1786             </em>
       
  1787            </span>
       
  1788            : 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.
       
  1789           </p>
       
  1790          </li>
       
  1791          <li class="listitem" style="list-style-type: *">
       
  1792           <p id="ch7interim_assessment_57">
       
  1793            <span class="emphasis">
       
  1794             <em>
       
  1795              -v
       
  1796             </em>
       
  1797            </span>
       
  1798            : display each directory that mkdir creates. Most often used with -p.
       
  1799           </p>
       
  1800          </li>
       
  1801          <li class="listitem" style="list-style-type: *">
       
  1802           <p id="ch7interim_assessment_58">
       
  1803            <span class="emphasis">
       
  1804             <em>
       
  1805              -m
       
  1806             </em>
       
  1807            </span>
       
  1808            : specify the octal permissions of directories created by mkdir.
       
  1809           </p>
       
  1810          </li>
       
  1811         </ul>
       
  1812        </div>
       
  1813        <p id="ch7interim_assessment_59">
       
  1814         <span class="emphasis">
       
  1815          <em>
       
  1816           -p
       
  1817          </em>
       
  1818         </span>
       
  1819         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.
       
  1820        </p>
       
  1821       </div>
       
  1822       <div class="section" title="3.5.2.Examples">
       
  1823        <div class="titlepage">
       
  1824         <div>
       
  1825          <div>
       
  1826           <h4 class="title">
       
  1827            <a name="id2652781">
       
  1828            </a>
       
  1829            3.5.2.Examples
       
  1830           </h4>
       
  1831          </div>
       
  1832         </div>
       
  1833        </div>
       
  1834        <p id="ch7interim_assessment_5a">
       
  1835         An example of
       
  1836         <span class="emphasis">
       
  1837          <em>
       
  1838           -p
       
  1839          </em>
       
  1840         </span>
       
  1841         in action is:
       
  1842        </p>
       
  1843        <pre class="programlisting">
       
  1844         $mkdir -p /tmp/a/b/c
       
  1845        </pre>
       
  1846        <p id="ch7interim_assessment_5b">
       
  1847         If
       
  1848         <span class="emphasis">
       
  1849          <em>
       
  1850           /tmp/a
       
  1851          </em>
       
  1852         </span>
       
  1853         exists but
       
  1854         <span class="emphasis">
       
  1855          <em>
       
  1856           /tmp/a/b
       
  1857          </em>
       
  1858         </span>
       
  1859         does not, mkdir will create
       
  1860         <span class="emphasis">
       
  1861          <em>
       
  1862           /tmp/a/b
       
  1863          </em>
       
  1864         </span>
       
  1865         before creating
       
  1866         <span class="emphasis">
       
  1867          <em>
       
  1868           /tmp/a/b/c
       
  1869          </em>
       
  1870         </span>
       
  1871         .
       
  1872        </p>
       
  1873        <p id="ch7interim_assessment_5c">
       
  1874         And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
       
  1875        </p>
       
  1876        <pre class="programlisting">
       
  1877         $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
       
  1878        </pre>
       
  1879        <p id="ch7interim_assessment_5d">
       
  1880         This will create:
       
  1881        </p>
       
  1882        tmpdir  - branches
       
  1883        <div class="itemizedlist">
       
  1884         <ul class="itemizedlist" type="*">
       
  1885          <li class="listitem" style="list-style-type: *">
       
  1886           <p id="ch7interim_assessment_5e">
       
  1887            tag
       
  1888           </p>
       
  1889          </li>
       
  1890          <li class="listitem" style="list-style-type: *">
       
  1891           trunk - sources - includes
       
  1892           <div class="itemizedlist">
       
  1893            <ul class="itemizedlist" type="*">
       
  1894             <li class="listitem" style="list-style-type: *">
       
  1895              <p id="ch7interim_assessment_5f">
       
  1896               docs
       
  1897              </p>
       
  1898             </li>
       
  1899            </ul>
       
  1900           </div>
       
  1901          </li>
       
  1902         </ul>
       
  1903        </div>
       
  1904       </div>
       
  1905      </div>
       
  1906     </div>
       
  1907     <div class="section" title="4.Getting Help">
       
  1908      <div class="titlepage">
       
  1909       <div>
       
  1910        <div>
       
  1911         <h2 class="title" style="clear: both">
       
  1912          <a name="id2652858">
       
  1913          </a>
       
  1914          4.Getting Help
       
  1915         </h2>
       
  1916        </div>
       
  1917       </div>
       
  1918      </div>
       
  1919      <div class="section" title="4.1.apropos and whatis">
       
  1920       <div class="titlepage">
       
  1921        <div>
       
  1922         <div>
       
  1923          <h3 class="title">
       
  1924           <a name="id2652866">
       
  1925           </a>
       
  1926           4.1.apropos and whatis
       
  1927          </h3>
       
  1928         </div>
       
  1929        </div>
       
  1930       </div>
       
  1931       <p id="ch7interim_assessment_60">
       
  1932        This is a command to search the manual pages files in Unix and Unix-like operating systems.
       
  1933       </p>
       
  1934       <pre class="programlisting">
       
  1935        $ apropos grep
       
  1936 egrep       egrep (1)       Search a file for a pattern using full regular expressions
       
  1937 fgrep       fgrep (1)       Search a file for a fixed-character string
       
  1938 fmlgrep     fmlgrep (1)     Search a file for a pattern
       
  1939 grep        grep (1)        Search a file for a pattern
       
  1940 gzgrep      gzgrep (1)      Search a possibly compressed file for a regular expression
       
  1941 nisgrep     nismatch (1)    Utilities for searching NIS+ tables
       
  1942 pgrep       pgrep (1)       Find or signal a process by name or other attribute
       
  1943 zgrep       zgrep (1)       Search a possibly compressed file for a regular expression
       
  1944 ...
       
  1945       </pre>
       
  1946       <p id="ch7interim_assessment_61">
       
  1947        In this example, the user uses
       
  1948        <span class="emphasis">
       
  1949         <em>
       
  1950          apropos
       
  1951         </em>
       
  1952        </span>
       
  1953        to search for the string "grep", and apropos returns the indicated
       
  1954        <span class="emphasis">
       
  1955         <em>
       
  1956          man
       
  1957         </em>
       
  1958        </span>
       
  1959        pages that include the term "grep".
       
  1960       </p>
       
  1961       <p id="ch7interim_assessment_62">
       
  1962        A short index of explanations for commands is available using the
       
  1963        <span class="emphasis">
       
  1964         <em>
       
  1965          whatis
       
  1966         </em>
       
  1967        </span>
       
  1968        command, like in the examples below:
       
  1969       </p>
       
  1970       <pre class="programlisting">
       
  1971        $whatis ls
       
  1972 ls (1)           - list directory contents
       
  1973       </pre>
       
  1974       <p id="ch7interim_assessment_63">
       
  1975        This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
       
  1976       </p>
       
  1977       <p id="ch7interim_assessment_64">
       
  1978        If you don't know where to get started and which man page to read,
       
  1979        <span class="emphasis">
       
  1980         <em>
       
  1981          apropos
       
  1982         </em>
       
  1983        </span>
       
  1984        gives more information. Say that you do not know how to start a browser, then you could enter the following command:
       
  1985       </p>
       
  1986       <pre class="programlisting">
       
  1987        $apropos browser
       
  1988 gmusicbrowser (1)    - Jukebox for large collections of audio files
       
  1989 infobrowser (1)      - read Info documents
       
  1990 libsmbclient (7)     - An extension library for browsers and that               can be used...
       
  1991 opera (1)            - a standards-compliant graphical Web browser
       
  1992 sensible-browser (1) - sensible editing, paging, and web browsing
       
  1993 smbtree (1)          - A text based smb network browser
       
  1994 tvtk_doc (1)         - A GUI based TVTK documentation search browser.
       
  1995 viewres (1)          - graphical class browser for Xt
       
  1996 w3m (1)              - a text based Web browser and pager
       
  1997 www-browser (1)      - a text based Web browser and pager
       
  1998 ...
       
  1999       </pre>
       
  2000      </div>
       
  2001      <div class="section" title="4.2.man">
       
  2002       <div class="titlepage">
       
  2003        <div>
       
  2004         <div>
       
  2005          <h3 class="title">
       
  2006           <a name="id2652961">
       
  2007           </a>
       
  2008           4.2.man
       
  2009          </h3>
       
  2010         </div>
       
  2011        </div>
       
  2012       </div>
       
  2013       <p id="ch7interim_assessment_65">
       
  2014        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
       
  2015        <span class="emphasis">
       
  2016         <em>
       
  2017          man
       
  2018         </em>
       
  2019        </span>
       
  2020        . Each page is a self-contained document.
       
  2021       </p>
       
  2022       <p id="ch7interim_assessment_66">
       
  2023        To read a manual page for a Unix command, one can use:
       
  2024       </p>
       
  2025       <pre class="programlisting">
       
  2026        $ man &lt;command_name&gt;
       
  2027       </pre>
       
  2028       <p id="ch7interim_assessment_67">
       
  2029        at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
       
  2030        <span class="emphasis">
       
  2031         <em>
       
  2032          man
       
  2033         </em>
       
  2034        </span>
       
  2035        generally uses the less terminal pager.
       
  2036       </p>
       
  2037       <p id="ch7interim_assessment_68">
       
  2038        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
       
  2039        <span class="emphasis">
       
  2040         <em>
       
  2041          man(1)
       
  2042         </em>
       
  2043        </span>
       
  2044        and
       
  2045        <span class="emphasis">
       
  2046         <em>
       
  2047          man(7)
       
  2048         </em>
       
  2049        </span>
       
  2050        , or
       
  2051        <span class="emphasis">
       
  2052         <em>
       
  2053          exit(2)
       
  2054         </em>
       
  2055        </span>
       
  2056        and
       
  2057        <span class="emphasis">
       
  2058         <em>
       
  2059          exit(3)
       
  2060         </em>
       
  2061        </span>
       
  2062        . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
       
  2063        <span class="emphasis">
       
  2064         <em>
       
  2065          BSD, for example, the syntax for reading *printf(3)
       
  2066         </em>
       
  2067        </span>
       
  2068        is:
       
  2069       </p>
       
  2070       <pre class="programlisting">
       
  2071        $man 3 printf
       
  2072       </pre>
       
  2073       <p id="ch7interim_assessment_69">
       
  2074        Another example:
       
  2075       </p>
       
  2076       <pre class="programlisting">
       
  2077        $man man
       
  2078       </pre>
       
  2079       <p id="ch7interim_assessment_6a">
       
  2080        The previous example will take you to the "Manual" page entry about manual pages!
       
  2081       </p>
       
  2082       <div class="section" title="4.2.1.Layout">
       
  2083        <div class="titlepage">
       
  2084         <div>
       
  2085          <div>
       
  2086           <h4 class="title">
       
  2087            <a name="id2653044">
       
  2088            </a>
       
  2089            4.2.1.Layout
       
  2090           </h4>
       
  2091          </div>
       
  2092         </div>
       
  2093        </div>
       
  2094        <p id="ch7interim_assessment_6b">
       
  2095         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:
       
  2096        </p>
       
  2097        NAME
       
  2098        <p id="ch7interim_assessment_6c">
       
  2099         The name of the command or function, followed by a one-line description of what it does.
       
  2100        </p>
       
  2101        SYNOPSIS
       
  2102        <p id="ch7interim_assessment_6d">
       
  2103         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.
       
  2104        </p>
       
  2105        DESCRIPTION
       
  2106        <p id="ch7interim_assessment_6e">
       
  2107         A textual description of the functioning of the command or function.
       
  2108        </p>
       
  2109        EXAMPLES
       
  2110        <p id="ch7interim_assessment_6f">
       
  2111         Some examples of common usage.
       
  2112        </p>
       
  2113        SEE ALSO
       
  2114        <p id="ch7interim_assessment_70">
       
  2115         A list of related commands or functions.
       
  2116        </p>
       
  2117        <p id="ch7interim_assessment_71">
       
  2118         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.
       
  2119        </p>
       
  2120        <p id="ch7interim_assessment_72">
       
  2121         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
       
  2122         <span class="emphasis">
       
  2123          <em>
       
  2124           man
       
  2125          </em>
       
  2126         </span>
       
  2127         have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
       
  2128        </p>
       
  2129        <p id="ch7interim_assessment_73">
       
  2130         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.
       
  2131        </p>
       
  2132        <p id="ch7interim_assessment_74">
       
  2133         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.
       
  2134        </p>
       
  2135        <p id="ch7interim_assessment_75">
       
  2136         Usually the man pages are written in English. Translations into other languages can be also available on the system.
       
  2137        </p>
       
  2138        <p id="ch7interim_assessment_76">
       
  2139         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.
       
  2140        </p>
       
  2141       </div>
       
  2142      </div>
       
  2143      <div class="section" title="4.3.info">
       
  2144       <div class="titlepage">
       
  2145        <div>
       
  2146         <div>
       
  2147          <h3 class="title">
       
  2148           <a name="id2653155">
       
  2149           </a>
       
  2150           4.3.info
       
  2151          </h3>
       
  2152         </div>
       
  2153        </div>
       
  2154       </div>
       
  2155       <p id="ch7interim_assessment_77">
       
  2156        <span class="emphasis">
       
  2157         <em>
       
  2158          info
       
  2159         </em>
       
  2160        </span>
       
  2161        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.
       
  2162       </p>
       
  2163       <p id="ch7interim_assessment_78">
       
  2164        The syntax is
       
  2165       </p>
       
  2166       <pre class="programlisting">
       
  2167        $ info &lt;command_name&gt;
       
  2168       </pre>
       
  2169       <p id="ch7interim_assessment_79">
       
  2170        <span class="emphasis">
       
  2171         <em>
       
  2172          info
       
  2173         </em>
       
  2174        </span>
       
  2175        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
       
  2176       </p>
       
  2177       <div class="itemizedlist">
       
  2178        <ul class="itemizedlist" type="*">
       
  2179         <li class="listitem" style="list-style-type: *">
       
  2180          <p id="ch7interim_assessment_7a">
       
  2181           <span class="emphasis">
       
  2182            <em>
       
  2183             n
       
  2184            </em>
       
  2185           </span>
       
  2186           goes to the next page.
       
  2187          </p>
       
  2188         </li>
       
  2189         <li class="listitem" style="list-style-type: *">
       
  2190          <p id="ch7interim_assessment_7b">
       
  2191           <span class="emphasis">
       
  2192            <em>
       
  2193             p
       
  2194            </em>
       
  2195           </span>
       
  2196           goes to the previous page.
       
  2197          </p>
       
  2198         </li>
       
  2199         <li class="listitem" style="list-style-type: *">
       
  2200          <p id="ch7interim_assessment_7c">
       
  2201           <span class="emphasis">
       
  2202            <em>
       
  2203             u
       
  2204            </em>
       
  2205           </span>
       
  2206           goes to the upper page.
       
  2207          </p>
       
  2208         </li>
       
  2209         <li class="listitem" style="list-style-type: *">
       
  2210          <p id="ch7interim_assessment_7d">
       
  2211           <span class="emphasis">
       
  2212            <em>
       
  2213             l
       
  2214            </em>
       
  2215           </span>
       
  2216           goes to the last(visited) node
       
  2217          </p>
       
  2218         </li>
       
  2219         <li class="listitem" style="list-style-type: *">
       
  2220          <p id="ch7interim_assessment_7e">
       
  2221           To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
       
  2222          </p>
       
  2223         </li>
       
  2224        </ul>
       
  2225       </div>
       
  2226       <p id="ch7interim_assessment_7f">
       
  2227        info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
       
  2228       </p>
       
  2229      </div>
       
  2230      <div class="section" title="4.4.--help">
       
  2231       <div class="titlepage">
       
  2232        <div>
       
  2233         <div>
       
  2234          <h3 class="title">
       
  2235           <a name="id2653242">
       
  2236           </a>
       
  2237           4.4.--help
       
  2238          </h3>
       
  2239         </div>
       
  2240        </div>
       
  2241       </div>
       
  2242       <p id="ch7interim_assessment_80">
       
  2243        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
       
  2244        <span class="emphasis">
       
  2245         <em>
       
  2246          cat
       
  2247         </em>
       
  2248        </span>
       
  2249        command:
       
  2250       </p>
       
  2251       <pre class="programlisting">
       
  2252        $ userprompt@host: cat --help
       
  2253 Usage: cat [OPTION] [FILE]...
       
  2254 Concatenate FILE(s), or standard input, to standard output.
       
  2255 
       
  2256   -A, --show-all           equivalent to -vET
       
  2257   -b, --number-nonblank    number nonempty output lines
       
  2258   -e                       equivalent to -vE
       
  2259   -E, --show-ends          display $ at end of each line
       
  2260   -n, --number             number all output lines
       
  2261   -s, --squeeze-blank      suppress repeated empty output lines
       
  2262   -t                       equivalent to -vT
       
  2263   -T, --show-tabs          display TAB characters as ^I
       
  2264   -u                       (ignored)
       
  2265   -v, --show-nonprinting   use ^ and M- notation, except for LFD and              TAB
       
  2266   --help     display this help and exit
       
  2267   --version  output version information and exit
       
  2268 
       
  2269 With no FILE, or when FILE is -, read standard input.
       
  2270 
       
  2271 Examples:
       
  2272   cat f - g  Output f's contents, then standard input, then g's           contents.
       
  2273   cat        Copy standard input to standard output.
       
  2274 
       
  2275 Report bugs to &lt;bug-coreutils@gnu.org&gt;.
       
  2276       </pre>
       
  2277      </div>
       
  2278     </div>
       
  2279     <div class="section" title="5.Basic file handling">
       
  2280      <div class="titlepage">
       
  2281       <div>
       
  2282        <div>
       
  2283         <h2 class="title" style="clear: both">
       
  2284          <a name="id2653295">
       
  2285          </a>
       
  2286          5.Basic file handling
       
  2287         </h2>
       
  2288        </div>
       
  2289       </div>
       
  2290      </div>
       
  2291      <div class="section" title="5.1.cp">
       
  2292       <div class="titlepage">
       
  2293        <div>
       
  2294         <div>
       
  2295          <h3 class="title">
       
  2296           <a name="id2653303">
       
  2297           </a>
       
  2298           5.1.cp
       
  2299          </h3>
       
  2300         </div>
       
  2301        </div>
       
  2302       </div>
       
  2303       <p id="ch7interim_assessment_81">
       
  2304        <span class="emphasis">
       
  2305         <em>
       
  2306          cp
       
  2307         </em>
       
  2308        </span>
       
  2309        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.
       
  2310       </p>
       
  2311       <div class="section" title="5.1.1.Usage">
       
  2312        <div class="titlepage">
       
  2313         <div>
       
  2314          <div>
       
  2315           <h4 class="title">
       
  2316            <a name="id2653321">
       
  2317            </a>
       
  2318            5.1.1.Usage
       
  2319           </h4>
       
  2320          </div>
       
  2321         </div>
       
  2322        </div>
       
  2323        <p id="ch7interim_assessment_82">
       
  2324         To copy a file to another file:
       
  2325        </p>
       
  2326        <pre class="programlisting">
       
  2327         $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
       
  2328        </pre>
       
  2329        <p id="ch7interim_assessment_83">
       
  2330         To copy a file to a directory:
       
  2331        </p>
       
  2332        <pre class="programlisting">
       
  2333         $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ...              TargetDirectory
       
  2334        </pre>
       
  2335        <p id="ch7interim_assessment_84">
       
  2336         To copy a directory to a directory:
       
  2337        </p>
       
  2338        <pre class="programlisting">
       
  2339         $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
       
  2340 SourceDirectory ... TargetDirectory
       
  2341        </pre>
       
  2342       </div>
       
  2343       <div class="section" title="5.1.2.Flags">
       
  2344        <div class="titlepage">
       
  2345         <div>
       
  2346          <div>
       
  2347           <h4 class="title">
       
  2348            <a name="id2653355">
       
  2349            </a>
       
  2350            5.1.2.Flags
       
  2351           </h4>
       
  2352          </div>
       
  2353         </div>
       
  2354        </div>
       
  2355        <p id="ch7interim_assessment_85">
       
  2356         <span class="emphasis">
       
  2357          <em>
       
  2358           -f
       
  2359          </em>
       
  2360         </span>
       
  2361         (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.
       
  2362        </p>
       
  2363        <p id="ch7interim_assessment_86">
       
  2364         <span class="emphasis">
       
  2365          <em>
       
  2366           -P
       
  2367          </em>
       
  2368         </span>
       
  2369         makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
       
  2370        </p>
       
  2371        <p id="ch7interim_assessment_87">
       
  2372         <span class="emphasis">
       
  2373          <em>
       
  2374           -i
       
  2375          </em>
       
  2376         </span>
       
  2377         (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.
       
  2378        </p>
       
  2379        <p id="ch7interim_assessment_88">
       
  2380         <span class="emphasis">
       
  2381          <em>
       
  2382           -p
       
  2383          </em>
       
  2384         </span>
       
  2385         (preserve)  duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
       
  2386        </p>
       
  2387        <div class="itemizedlist">
       
  2388         <ul class="itemizedlist" type="*">
       
  2389          <li class="listitem" style="list-style-type: *">
       
  2390           <p id="ch7interim_assessment_89">
       
  2391            The time of the last data modification and the time of the last access.
       
  2392           </p>
       
  2393          </li>
       
  2394          <li class="listitem" style="list-style-type: *">
       
  2395           <p id="ch7interim_assessment_8a">
       
  2396            The user ID and group ID (only if it has permissions to do this)
       
  2397           </p>
       
  2398          </li>
       
  2399          <li class="listitem" style="list-style-type: *">
       
  2400           <p id="ch7interim_assessment_8b">
       
  2401            The file permission bits and the SUID and SGID bits.
       
  2402           </p>
       
  2403          </li>
       
  2404         </ul>
       
  2405        </div>
       
  2406        <p id="ch7interim_assessment_8c">
       
  2407         <span class="emphasis">
       
  2408          <em>
       
  2409           -R
       
  2410          </em>
       
  2411         </span>
       
  2412         (recursive)  copy directories (recursively copying all the contents)
       
  2413        </p>
       
  2414       </div>
       
  2415       <div class="section" title="5.1.3.Examples">
       
  2416        <div class="titlepage">
       
  2417         <div>
       
  2418          <div>
       
  2419           <h4 class="title">
       
  2420            <a name="id2653453">
       
  2421            </a>
       
  2422            5.1.3.Examples
       
  2423           </h4>
       
  2424          </div>
       
  2425         </div>
       
  2426        </div>
       
  2427        <p id="ch7interim_assessment_8d">
       
  2428         To make a copy of a file in the current directory, enter:
       
  2429        </p>
       
  2430        <pre class="programlisting">
       
  2431         $ cp prog.c prog.bak
       
  2432        </pre>
       
  2433        <p id="ch7interim_assessment_8e">
       
  2434         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.
       
  2435        </p>
       
  2436        <p id="ch7interim_assessment_8f">
       
  2437         To copy a file in your current directory into another directory, enter:
       
  2438        </p>
       
  2439        <pre class="programlisting">
       
  2440         $ cp zaphod /home/books/hhgg
       
  2441        </pre>
       
  2442        <p id="ch7interim_assessment_90">
       
  2443         This copies the jones file to /home/books/hhgg/zaphod.
       
  2444        </p>
       
  2445        <p id="ch7interim_assessment_91">
       
  2446         To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
       
  2447        </p>
       
  2448        <pre class="programlisting">
       
  2449         $ cp -p martin_luther_king martin_luther_king.jr
       
  2450        </pre>
       
  2451        <p id="ch7interim_assessment_92">
       
  2452         This copies the
       
  2453         <span class="emphasis">
       
  2454          <em>
       
  2455           martin_luther_king
       
  2456          </em>
       
  2457         </span>
       
  2458         file to the
       
  2459         <span class="emphasis">
       
  2460          <em>
       
  2461           martin_luther_king.jr
       
  2462          </em>
       
  2463         </span>
       
  2464         file. Instead of creating the file with the current date and time stamp, the system gives the
       
  2465         <span class="emphasis">
       
  2466          <em>
       
  2467           martin_luther_king.jr
       
  2468          </em>
       
  2469         </span>
       
  2470         file the same date and time as the
       
  2471         <span class="emphasis">
       
  2472          <em>
       
  2473           martin_luther_king
       
  2474          </em>
       
  2475         </span>
       
  2476         file. The
       
  2477         <span class="emphasis">
       
  2478          <em>
       
  2479           martin_luther_king.jr
       
  2480          </em>
       
  2481         </span>
       
  2482         file also inherits the
       
  2483         <span class="emphasis">
       
  2484          <em>
       
  2485           martin_luther_king
       
  2486          </em>
       
  2487         </span>
       
  2488         file's access control protection.
       
  2489        </p>
       
  2490        <p id="ch7interim_assessment_93">
       
  2491         To copy all the files in a directory to a new directory, enter:
       
  2492        </p>
       
  2493        <pre class="programlisting">
       
  2494         $ cp /home/galactica/clients/* /home/hhgg/customers
       
  2495        </pre>
       
  2496        <p id="ch7interim_assessment_94">
       
  2497         This copies only the files in the clients directory to the customers directory.
       
  2498        </p>
       
  2499        <p id="ch7interim_assessment_95">
       
  2500         To copy a directory, including all its files and subdirectories, to another directory, enter:
       
  2501        </p>
       
  2502        <p id="ch7interim_assessment_96">
       
  2503         $ cp -R /home/hhgg/clients /home/hhgg/customers
       
  2504        </p>
       
  2505        <p id="ch7interim_assessment_97">
       
  2506         This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
       
  2507        </p>
       
  2508        <p id="ch7interim_assessment_98">
       
  2509         To copy a specific set of files of any extension to another directory, enter:
       
  2510        </p>
       
  2511        <pre class="programlisting">
       
  2512         $ cp zaphod arthur ford /home/hhgg/clients
       
  2513        </pre>
       
  2514        <p id="ch7interim_assessment_99">
       
  2515         This copies the
       
  2516         <span class="emphasis">
       
  2517          <em>
       
  2518           zaphod
       
  2519          </em>
       
  2520         </span>
       
  2521         ,
       
  2522         <span class="emphasis">
       
  2523          <em>
       
  2524           arthur
       
  2525          </em>
       
  2526         </span>
       
  2527         , and
       
  2528         <span class="emphasis">
       
  2529          <em>
       
  2530           ford
       
  2531          </em>
       
  2532         </span>
       
  2533         files in your current working directory to the /home/hhgg/clients directory.
       
  2534        </p>
       
  2535        <p id="ch7interim_assessment_9a">
       
  2536         To use pattern-matching characters to copy files, enter:
       
  2537        </p>
       
  2538        <pre class="programlisting">
       
  2539         $ cp programs/*.py .
       
  2540        </pre>
       
  2541        <p id="ch7interim_assessment_9b">
       
  2542         This copies the files in the programs directory that end with
       
  2543         <span class="emphasis">
       
  2544          <em>
       
  2545           .py
       
  2546          </em>
       
  2547         </span>
       
  2548         to the current directory, signified by the single "." (dot). You must type a space between the
       
  2549         <span class="emphasis">
       
  2550          <em>
       
  2551           py
       
  2552          </em>
       
  2553         </span>
       
  2554         and the final dot.
       
  2555        </p>
       
  2556       </div>
       
  2557      </div>
       
  2558      <div class="section" title="5.2.mv">
       
  2559       <div class="titlepage">
       
  2560        <div>
       
  2561         <div>
       
  2562          <h3 class="title">
       
  2563           <a name="id2653616">
       
  2564           </a>
       
  2565           5.2.mv
       
  2566          </h3>
       
  2567         </div>
       
  2568        </div>
       
  2569       </div>
       
  2570       <p id="ch7interim_assessment_9c">
       
  2571        <span class="emphasis">
       
  2572         <em>
       
  2573          mv
       
  2574         </em>
       
  2575        </span>
       
  2576        (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),
       
  2577        <span class="emphasis">
       
  2578         <em>
       
  2579          mv
       
  2580         </em>
       
  2581        </span>
       
  2582        will rename the file instead. Write permission is required on all directories being modified.
       
  2583       </p>
       
  2584       <div class="section" title="5.2.1.Conflicting existing file">
       
  2585        <div class="titlepage">
       
  2586         <div>
       
  2587          <div>
       
  2588           <h4 class="title">
       
  2589            <a name="id2653640">
       
  2590            </a>
       
  2591            5.2.1.Conflicting existing file
       
  2592           </h4>
       
  2593          </div>
       
  2594         </div>
       
  2595        </div>
       
  2596        <p id="ch7interim_assessment_9d">
       
  2597         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.
       
  2598        </p>
       
  2599       </div>
       
  2600       <div class="section" title="5.2.2.Differences with copy and delete">
       
  2601        <div class="titlepage">
       
  2602         <div>
       
  2603          <div>
       
  2604           <h4 class="title">
       
  2605            <a name="id2653665">
       
  2606            </a>
       
  2607            5.2.2.Differences with copy and delete
       
  2608           </h4>
       
  2609          </div>
       
  2610         </div>
       
  2611        </div>
       
  2612        <p id="ch7interim_assessment_9e">
       
  2613         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.
       
  2614        </p>
       
  2615       </div>
       
  2616       <div class="section" title="5.2.3.Examples">
       
  2617        <div class="titlepage">
       
  2618         <div>
       
  2619          <div>
       
  2620           <h4 class="title">
       
  2621            <a name="id2653695">
       
  2622            </a>
       
  2623            5.2.3.Examples
       
  2624           </h4>
       
  2625          </div>
       
  2626         </div>
       
  2627        </div>
       
  2628        <pre class="programlisting">
       
  2629         $ mv myfile mynewfilename    renames a file
       
  2630 $ mv myfile otherfilename    renames a file and deletes the existing            file "myfile"
       
  2631 $ mv myfile /myfile          moves 'myfile' from the current            directory to the root directory
       
  2632 $ mv myfile dir/myfile       moves 'myfile' to 'dir/myfile' relative            to the current directory
       
  2633 $ mv myfile dir              same as the previous command (the          filename is implied to be the same)
       
  2634 $ mv myfile dir/myfile2      moves 'myfile' to dir and renames it to            'myfile2'
       
  2635 $ mv foo bar baz dir         moves multiple files to directory dir
       
  2636 $ mv --help                  shows a very concise help about the                syntax of the command
       
  2637 $ man mv                     prints an extensive user manual for                'mv' in the terminal
       
  2638        </pre>
       
  2639        <p id="ch7interim_assessment_9f">
       
  2640         In all cases, the file or files being moved or renamed can be a directory.
       
  2641        </p>
       
  2642        <p id="ch7interim_assessment_a0">
       
  2643         Note that when the command is called with two arguments (as
       
  2644         <span class="emphasis">
       
  2645          <em>
       
  2646           mv name1 name2
       
  2647          </em>
       
  2648         </span>
       
  2649         or
       
  2650         <span class="emphasis">
       
  2651          <em>
       
  2652           mv name1 /dir/name2
       
  2653          </em>
       
  2654         </span>
       
  2655         ), it can have three different effects, depending on whether
       
  2656         <span class="emphasis">
       
  2657          <em>
       
  2658           name2
       
  2659          </em>
       
  2660         </span>
       
  2661         does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
       
  2662         <span class="emphasis">
       
  2663          <em>
       
  2664           /.
       
  2665          </em>
       
  2666         </span>
       
  2667         (or in some Unix versions
       
  2668         <span class="emphasis">
       
  2669          <em>
       
  2670           /
       
  2671          </em>
       
  2672         </span>
       
  2673         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.
       
  2674        </p>
       
  2675       </div>
       
  2676      </div>
       
  2677      <div class="section" title="5.3.rm">
       
  2678       <div class="titlepage">
       
  2679        <div>
       
  2680         <div>
       
  2681          <h3 class="title">
       
  2682           <a name="id2653754">
       
  2683           </a>
       
  2684           5.3.rm
       
  2685          </h3>
       
  2686         </div>
       
  2687        </div>
       
  2688       </div>
       
  2689       <p id="ch7interim_assessment_a1">
       
  2690        <span class="emphasis">
       
  2691         <em>
       
  2692          rm
       
  2693         </em>
       
  2694        </span>
       
  2695        (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.
       
  2696       </p>
       
  2697       <p id="ch7interim_assessment_a2">
       
  2698        Here's example to remove a file named "foo" from a directory, here shown with the -i option:
       
  2699       </p>
       
  2700       <pre class="programlisting">
       
  2701        $ rm -i foo
       
  2702 remove foo? y
       
  2703       </pre>
       
  2704       <div class="section" title="5.3.1.Options">
       
  2705        <div class="titlepage">
       
  2706         <div>
       
  2707          <div>
       
  2708           <h4 class="title">
       
  2709            <a name="id2653784">
       
  2710            </a>
       
  2711            5.3.1.Options
       
  2712           </h4>
       
  2713          </div>
       
  2714         </div>
       
  2715        </div>
       
  2716        <p id="ch7interim_assessment_a3">
       
  2717         Common options that rm accepts include:
       
  2718        </p>
       
  2719        <div class="itemizedlist">
       
  2720         <ul class="itemizedlist" type="*">
       
  2721          <li class="listitem" style="list-style-type: *">
       
  2722           <p id="ch7interim_assessment_a4">
       
  2723            <span class="emphasis">
       
  2724             <em>
       
  2725              -r
       
  2726             </em>
       
  2727            </span>
       
  2728            , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
       
  2729           </p>
       
  2730          </li>
       
  2731          <li class="listitem" style="list-style-type: *">
       
  2732           <p id="ch7interim_assessment_a5">
       
  2733            <span class="emphasis">
       
  2734             <em>
       
  2735              -i
       
  2736             </em>
       
  2737            </span>
       
  2738            , which asks for every deletion to be confirmed ("interactive")
       
  2739           </p>
       
  2740          </li>
       
  2741          <li class="listitem" style="list-style-type: *">
       
  2742           <p id="ch7interim_assessment_a6">
       
  2743            <span class="emphasis">
       
  2744             <em>
       
  2745              -f
       
  2746             </em>
       
  2747            </span>
       
  2748            , which ignores non-existent files and overrides any confirmation prompts ("force")
       
  2749           </p>
       
  2750          </li>
       
  2751          <li class="listitem" style="list-style-type: *">
       
  2752           <p id="ch7interim_assessment_a7">
       
  2753            <span class="emphasis">
       
  2754             <em>
       
  2755              -v
       
  2756             </em>
       
  2757            </span>
       
  2758            , which shows what is being removed as it happens ("verbose")
       
  2759           </p>
       
  2760          </li>
       
  2761         </ul>
       
  2762        </div>
       
  2763        <p id="ch7interim_assessment_a8">
       
  2764         <span class="emphasis">
       
  2765          <em>
       
  2766           rm
       
  2767          </em>
       
  2768         </span>
       
  2769         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).
       
  2770        </p>
       
  2771        <p id="ch7interim_assessment_a9">
       
  2772         <span class="emphasis">
       
  2773          <em>
       
  2774           rm -rf
       
  2775          </em>
       
  2776         </span>
       
  2777         (variously, rm -rf /, rm -rf *, 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.
       
  2778        </p>
       
  2779        <p id="ch7interim_assessment_aa">
       
  2780         <span class="emphasis">
       
  2781          <em>
       
  2782           rm
       
  2783          </em>
       
  2784         </span>
       
  2785         is often used in conjunction with xargs to supply a list of files to delete:
       
  2786        </p>
       
  2787        <pre class="programlisting">
       
  2788         xargs rm &lt; filelist
       
  2789        </pre>
       
  2790        <p id="ch7interim_assessment_ab">
       
  2791         When
       
  2792         <span class="emphasis">
       
  2793          <em>
       
  2794           rm
       
  2795          </em>
       
  2796         </span>
       
  2797         is used on a symbolic link, it deletes the link, but does not affect the target of the link.
       
  2798        </p>
       
  2799       </div>
       
  2800       <div class="section" title="5.3.2.Permissions">
       
  2801        <div class="titlepage">
       
  2802         <div>
       
  2803          <div>
       
  2804           <h4 class="title">
       
  2805            <a name="id2653882">
       
  2806            </a>
       
  2807            5.3.2.Permissions
       
  2808           </h4>
       
  2809          </div>
       
  2810         </div>
       
  2811        </div>
       
  2812        <p id="ch7interim_assessment_ac">
       
  2813         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.)
       
  2814        </p>
       
  2815        <p id="ch7interim_assessment_ad">
       
  2816         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.
       
  2817        </p>
       
  2818        <p id="ch7interim_assessment_ae">
       
  2819         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.
       
  2820        </p>
       
  2821       </div>
       
  2822      </div>
       
  2823     </div>
       
  2824     <div class="section" title="6.Command Line Arguments">
       
  2825      <div class="titlepage">
       
  2826       <div>
       
  2827        <div>
       
  2828         <h2 class="title" style="clear: both">
       
  2829          <a name="id2653922">
       
  2830          </a>
       
  2831          6.Command Line Arguments
       
  2832         </h2>
       
  2833        </div>
       
  2834       </div>
       
  2835      </div>
       
  2836      <p id="ch7interim_assessment_af">
       
  2837       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.
       
  2838      </p>
       
  2839      <p id="ch7interim_assessment_b0">
       
  2840       For example, in Unix and Unix-like environments, an example of a command-line argument is:
       
  2841      </p>
       
  2842      <pre class="programlisting">
       
  2843       rm file.s
       
  2844      </pre>
       
  2845      <p id="ch7interim_assessment_b1">
       
  2846       "file.s" is a command line argument which tells the program rm to remove the file "file.s".
       
  2847      </p>
       
  2848      <p id="ch7interim_assessment_b2">
       
  2849       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.
       
  2850      </p>
       
  2851      <p id="ch7interim_assessment_b3">
       
  2852       A command line option or simply
       
  2853       <span class="emphasis">
       
  2854        <em>
       
  2855         option
       
  2856        </em>
       
  2857       </span>
       
  2858       (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.
       
  2859      </p>
       
  2860      <p id="ch7interim_assessment_b4">
       
  2861       Long options are introduced via "--", and are typically whole words. For example,
       
  2862       <span class="emphasis">
       
  2863        <em>
       
  2864         ls --long --classify --all
       
  2865        </em>
       
  2866       </span>
       
  2867       . Arguments to long options are provided with "=", as
       
  2868       <span class="emphasis">
       
  2869        <em>
       
  2870         ls --block-size=1024
       
  2871        </em>
       
  2872       </span>
       
  2873       . Some Unix programs use long options with single dashes, for example MPlayer as in
       
  2874       <span class="emphasis">
       
  2875        <em>
       
  2876         mplayer -nosound
       
  2877        </em>
       
  2878       </span>
       
  2879       .
       
  2880      </p>
       
  2881      <p id="ch7interim_assessment_b5">
       
  2882       Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
       
  2883       <span class="emphasis">
       
  2884        <em>
       
  2885         -file1
       
  2886        </em>
       
  2887       </span>
       
  2888       by using
       
  2889       <span class="emphasis">
       
  2890        <em>
       
  2891         rm -file1
       
  2892        </em>
       
  2893       </span>
       
  2894       may produce an error, since rm may interpret
       
  2895       <span class="emphasis">
       
  2896        <em>
       
  2897         -file1
       
  2898        </em>
       
  2899       </span>
       
  2900       as a command line switch. Using
       
  2901       <span class="emphasis">
       
  2902        <em>
       
  2903         rm -- -file1
       
  2904        </em>
       
  2905       </span>
       
  2906       removes ambiguity.
       
  2907      </p>
       
  2908     </div>
       
  2909     <div class="section" title="7.Basic Text Processing">
       
  2910      <div class="titlepage">
       
  2911       <div>
       
  2912        <div>
       
  2913         <h2 class="title" style="clear: both">
       
  2914          <a name="id2654015">
       
  2915          </a>
       
  2916          7.Basic Text Processing
       
  2917         </h2>
       
  2918        </div>
       
  2919       </div>
       
  2920      </div>
       
  2921      <div class="section" title="7.1.head">
       
  2922       <div class="titlepage">
       
  2923        <div>
       
  2924         <div>
       
  2925          <h3 class="title">
       
  2926           <a name="id2654024">
       
  2927           </a>
       
  2928           7.1.head
       
  2929          </h3>
       
  2930         </div>
       
  2931        </div>
       
  2932       </div>
       
  2933       <p id="ch7interim_assessment_b6">
       
  2934        <span class="emphasis">
       
  2935         <em>
       
  2936          head
       
  2937         </em>
       
  2938        </span>
       
  2939        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:
       
  2940       </p>
       
  2941       <pre class="programlisting">
       
  2942        $ head [options] &lt;file_name&gt;
       
  2943       </pre>
       
  2944       <p id="ch7interim_assessment_b7">
       
  2945        By default,
       
  2946        <span class="emphasis">
       
  2947         <em>
       
  2948          head
       
  2949         </em>
       
  2950        </span>
       
  2951        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:
       
  2952       </p>
       
  2953       <pre class="programlisting">
       
  2954        $ head -n 20 filename
       
  2955       </pre>
       
  2956       <p id="ch7interim_assessment_b8">
       
  2957        This displays the first 5 lines of all files starting with
       
  2958        <span class="emphasis">
       
  2959         <em>
       
  2960          foo
       
  2961         </em>
       
  2962        </span>
       
  2963        :
       
  2964       </p>
       
  2965       <pre class="programlisting">
       
  2966        $ head -n 5 foo*
       
  2967       </pre>
       
  2968       <p id="ch7interim_assessment_b9">
       
  2969        Some versions omit the n and just let you say -5.
       
  2970       </p>
       
  2971       <div class="section" title="7.1.1.Flags">
       
  2972        <div class="titlepage">
       
  2973         <div>
       
  2974          <div>
       
  2975           <h4 class="title">
       
  2976            <a name="id2654075">
       
  2977            </a>
       
  2978            7.1.1.Flags
       
  2979           </h4>
       
  2980          </div>
       
  2981         </div>
       
  2982        </div>
       
  2983        <pre class="programlisting">
       
  2984         -c &lt;x number of bytes&gt; Copy first x number of bytes.
       
  2985        </pre>
       
  2986        <p id="ch7interim_assessment_ba">
       
  2987         Other options:
       
  2988         <span class="emphasis">
       
  2989          <em>
       
  2990           sed
       
  2991          </em>
       
  2992         </span>
       
  2993        </p>
       
  2994        <p id="ch7interim_assessment_bb">
       
  2995         Many early versions of Unix did not have this command, and so documentation and books had
       
  2996         <span class="emphasis">
       
  2997          <em>
       
  2998           sed
       
  2999          </em>
       
  3000         </span>
       
  3001         do this job:
       
  3002        </p>
       
  3003        <pre class="programlisting">
       
  3004         sed 5q foo
       
  3005        </pre>
       
  3006        <p id="ch7interim_assessment_bc">
       
  3007         This says to print every line (implicit), and quit after the fifth.
       
  3008        </p>
       
  3009       </div>
       
  3010      </div>
       
  3011      <div class="section" title="7.2.tail">
       
  3012       <div class="titlepage">
       
  3013        <div>
       
  3014         <div>
       
  3015          <h3 class="title">
       
  3016           <a name="id2654111">
       
  3017           </a>
       
  3018           7.2.tail
       
  3019          </h3>
       
  3020         </div>
       
  3021        </div>
       
  3022       </div>
       
  3023       <p id="ch7interim_assessment_bd">
       
  3024        <span class="emphasis">
       
  3025         <em>
       
  3026          tail
       
  3027         </em>
       
  3028        </span>
       
  3029        is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
       
  3030       </p>
       
  3031       <p id="ch7interim_assessment_be">
       
  3032        The command-syntax is:
       
  3033       </p>
       
  3034       <pre class="programlisting">
       
  3035        $ tail [options] &lt;file_name&gt;
       
  3036       </pre>
       
  3037       <p id="ch7interim_assessment_bf">
       
  3038        By default,
       
  3039        <span class="emphasis">
       
  3040         <em>
       
  3041          tail
       
  3042         </em>
       
  3043        </span>
       
  3044        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:
       
  3045       </p>
       
  3046       <pre class="programlisting">
       
  3047        $ tail -n 20 filename
       
  3048       </pre>
       
  3049       <p id="ch7interim_assessment_c0">
       
  3050        This example shows the last 15 bytes of all files starting with
       
  3051        <span class="emphasis">
       
  3052         <em>
       
  3053          foo
       
  3054         </em>
       
  3055        </span>
       
  3056        :
       
  3057       </p>
       
  3058       <pre class="programlisting">
       
  3059        $ tail -c 15 foo*
       
  3060       </pre>
       
  3061       <p id="ch7interim_assessment_c1">
       
  3062        This example shows all lines of filename from the second line onwards:
       
  3063       </p>
       
  3064       <pre class="programlisting">
       
  3065        $ tail -n +2 filename
       
  3066       </pre>
       
  3067       <p id="ch7interim_assessment_c2">
       
  3068        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:
       
  3069       </p>
       
  3070       <pre class="programlisting">
       
  3071        $ tail -20 filename
       
  3072 $ tail -50c filename
       
  3073       </pre>
       
  3074       <p id="ch7interim_assessment_c3">
       
  3075        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.
       
  3076       </p>
       
  3077       <div class="section" title="7.2.1.File monitoring">
       
  3078        <div class="titlepage">
       
  3079         <div>
       
  3080          <div>
       
  3081           <h4 class="title">
       
  3082            <a name="id2654190">
       
  3083            </a>
       
  3084            7.2.1.File monitoring
       
  3085           </h4>
       
  3086          </div>
       
  3087         </div>
       
  3088        </div>
       
  3089        <p id="ch7interim_assessment_c4">
       
  3090         <span class="emphasis">
       
  3091          <em>
       
  3092           tail
       
  3093          </em>
       
  3094         </span>
       
  3095         has a special command line option
       
  3096         <span class="emphasis">
       
  3097          <em>
       
  3098           -f
       
  3099          </em>
       
  3100         </span>
       
  3101         (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:
       
  3102        </p>
       
  3103        <pre class="programlisting">
       
  3104         $ tail -f /var/adm/messages
       
  3105        </pre>
       
  3106        <p id="ch7interim_assessment_c5">
       
  3107         To interrupt tail while it is monitoring, break-in with
       
  3108         <span class="emphasis">
       
  3109          <em>
       
  3110           Ctrl+C
       
  3111          </em>
       
  3112         </span>
       
  3113         . This command can be run "in the background" with &amp;, see job control.
       
  3114        </p>
       
  3115        <p id="ch7interim_assessment_c6">
       
  3116         If you have a command's result to monitor, you can use the
       
  3117         <span class="emphasis">
       
  3118          <em>
       
  3119           watch
       
  3120          </em>
       
  3121         </span>
       
  3122         command.
       
  3123        </p>
       
  3124       </div>
       
  3125      </div>
       
  3126      <div class="section" title="7.3.cut">
       
  3127       <div class="titlepage">
       
  3128        <div>
       
  3129         <div>
       
  3130          <h3 class="title">
       
  3131           <a name="id2654239">
       
  3132           </a>
       
  3133           7.3.cut
       
  3134          </h3>
       
  3135         </div>
       
  3136        </div>
       
  3137       </div>
       
  3138       <p id="ch7interim_assessment_c7">
       
  3139        In computing,
       
  3140        <span class="emphasis">
       
  3141         <em>
       
  3142          cut
       
  3143         </em>
       
  3144        </span>
       
  3145        is a Unix command line utility which is used to extract sections from each line of input  usually from a file.
       
  3146       </p>
       
  3147       <p id="ch7interim_assessment_c8">
       
  3148        Extraction of line segments can typically be done by
       
  3149        <span class="emphasis">
       
  3150         <em>
       
  3151          bytes (-b), characters (-c)
       
  3152         </em>
       
  3153        </span>
       
  3154        , or
       
  3155        <span class="emphasis">
       
  3156         <em>
       
  3157          fields (-f)
       
  3158         </em>
       
  3159        </span>
       
  3160        separated by a
       
  3161        <span class="emphasis">
       
  3162         <em>
       
  3163          delimiter (-d  the tab character by default)
       
  3164         </em>
       
  3165        </span>
       
  3166        . 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.
       
  3167       </p>
       
  3168       <p id="ch7interim_assessment_c9">
       
  3169        Assuming a file named file containing the lines:
       
  3170       </p>
       
  3171       <pre class="programlisting">
       
  3172        foo:bar:baz:qux:quux
       
  3173 one:two:three:four:five:six:seven
       
  3174 alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
       
  3175       </pre>
       
  3176       <p id="ch7interim_assessment_ca">
       
  3177        To output the fourth through tenth characters of each line:
       
  3178       </p>
       
  3179       <pre class="programlisting">
       
  3180        $ cut -c 4-10 file
       
  3181       </pre>
       
  3182       <p id="ch7interim_assessment_cb">
       
  3183        This gives the output:
       
  3184       </p>
       
  3185       <pre class="programlisting">
       
  3186        :bar:ba
       
  3187 :two:th
       
  3188 ha:beta
       
  3189       </pre>
       
  3190       <p id="ch7interim_assessment_cc">
       
  3191        To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
       
  3192       </p>
       
  3193       <pre class="programlisting">
       
  3194        $ cut -d : -f 5- file
       
  3195       </pre>
       
  3196       <p id="ch7interim_assessment_cd">
       
  3197        This gives the output:
       
  3198       </p>
       
  3199       <pre class="programlisting">
       
  3200        quux
       
  3201 five:six:seven
       
  3202 epsilon:zeta:eta:teta:iota:kappa:lambda:mu
       
  3203       </pre>
       
  3204      </div>
       
  3205      <div class="section" title="7.4.paste">
       
  3206       <div class="titlepage">
       
  3207        <div>
       
  3208         <div>
       
  3209          <h3 class="title">
       
  3210           <a name="id2654326">
       
  3211           </a>
       
  3212           7.4.paste
       
  3213          </h3>
       
  3214         </div>
       
  3215        </div>
       
  3216       </div>
       
  3217       <p id="ch7interim_assessment_ce">
       
  3218        <span class="emphasis">
       
  3219         <em>
       
  3220          paste
       
  3221         </em>
       
  3222        </span>
       
  3223        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
       
  3224        <span class="emphasis">
       
  3225         <em>
       
  3226          cat
       
  3227         </em>
       
  3228        </span>
       
  3229        command which operates on the vertical plane of two or more files.
       
  3230       </p>
       
  3231       <p id="ch7interim_assessment_cf">
       
  3232        To paste several columns of data together into the file
       
  3233        <span class="emphasis">
       
  3234         <em>
       
  3235          www
       
  3236         </em>
       
  3237        </span>
       
  3238        from files
       
  3239        <span class="emphasis">
       
  3240         <em>
       
  3241          who
       
  3242         </em>
       
  3243        </span>
       
  3244        ,
       
  3245        <span class="emphasis">
       
  3246         <em>
       
  3247          where
       
  3248         </em>
       
  3249        </span>
       
  3250        , and
       
  3251        <span class="emphasis">
       
  3252         <em>
       
  3253          when
       
  3254         </em>
       
  3255        </span>
       
  3256        :
       
  3257       </p>
       
  3258       <pre class="programlisting">
       
  3259        $ paste who where when &gt; www
       
  3260       </pre>
       
  3261       <p id="ch7interim_assessment_d0">
       
  3262        If the files contain:
       
  3263       </p>
       
  3264       <table summary="paste" border="1">
       
  3265        <colgroup>
       
  3266         <col width="11">
       
  3267         </col>
       
  3268         <col width="12">
       
  3269         </col>
       
  3270         <col width="12">
       
  3271         </col>
       
  3272        </colgroup>
       
  3273       </table>
       
  3274       <p id="ch7interim_assessment_dd">
       
  3275        This creates the file named
       
  3276        <span class="emphasis">
       
  3277         <em>
       
  3278          www
       
  3279         </em>
       
  3280        </span>
       
  3281        containing:
       
  3282       </p>
       
  3283       <pre class="programlisting">
       
  3284        Batman            GothamCity       January 3
       
  3285 Trillian          Andromeda        February 4
       
  3286 Jeeves            London           March 19
       
  3287       </pre>
       
  3288      </div>
       
  3289     </div>
       
  3290     <div class="section" title="8.Shell Meta Characters">
       
  3291      <div class="titlepage">
       
  3292       <div>
       
  3293        <div>
       
  3294         <h2 class="title" style="clear: both">
       
  3295          <a name="id2654460">
       
  3296          </a>
       
  3297          8.Shell Meta Characters
       
  3298         </h2>
       
  3299        </div>
       
  3300       </div>
       
  3301      </div>
       
  3302      <p id="ch7interim_assessment_de">
       
  3303       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.
       
  3304      </p>
       
  3305      <p id="ch7interim_assessment_df">
       
  3306       The shell meta characters include:
       
  3307      </p>
       
  3308      <p id="ch7interim_assessment_e0">
       
  3309       / &lt; &gt; ! $ % ^ &amp; * | { } [ ] " ' ` ~ ;
       
  3310      </p>
       
  3311      <p id="ch7interim_assessment_e1">
       
  3312       Different shells may differ in the meta characters recognized.
       
  3313      </p>
       
  3314      <p id="ch7interim_assessment_e2">
       
  3315       As an example,
       
  3316      </p>
       
  3317      <pre class="programlisting">
       
  3318       $ ls file.*
       
  3319      </pre>
       
  3320      <p id="ch7interim_assessment_e3">
       
  3321       run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
       
  3322      </p>
       
  3323      <pre class="programlisting">
       
  3324       $ ls file.?
       
  3325      </pre>
       
  3326      <p id="ch7interim_assessment_e4">
       
  3327       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:
       
  3328      </p>
       
  3329      <pre class="programlisting">
       
  3330       $ more c*
       
  3331      </pre>
       
  3332      <p id="ch7interim_assessment_e5">
       
  3333       because the c* matches that long file name.
       
  3334      </p>
       
  3335      <p id="ch7interim_assessment_e6">
       
  3336       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 "``*`|more"` can be accomplished with:
       
  3337      </p>
       
  3338      <pre class="programlisting">
       
  3339       $ rm ??more
       
  3340      </pre>
       
  3341      <p id="ch7interim_assessment_e7">
       
  3342       or:
       
  3343      </p>
       
  3344      <pre class="programlisting">
       
  3345       $ rm $\backslash$*$\backslash$|more
       
  3346      </pre>
       
  3347      <p id="ch7interim_assessment_e8">
       
  3348       or:
       
  3349      </p>
       
  3350      <pre class="programlisting">
       
  3351       $ rm ''*|more''
       
  3352      </pre>
       
  3353     </div>
       
  3354     <div class="section" title="9.Looking At Files">
       
  3355      <div class="titlepage">
       
  3356       <div>
       
  3357        <div>
       
  3358         <h2 class="title" style="clear: both">
       
  3359          <a name="id2654565">
       
  3360          </a>
       
  3361          9.Looking At Files
       
  3362         </h2>
       
  3363        </div>
       
  3364       </div>
       
  3365      </div>
       
  3366      <div class="section" title="9.1.cat">
       
  3367       <div class="titlepage">
       
  3368        <div>
       
  3369         <div>
       
  3370          <h3 class="title">
       
  3371           <a name="id2654574">
       
  3372           </a>
       
  3373           9.1.cat
       
  3374          </h3>
       
  3375         </div>
       
  3376        </div>
       
  3377       </div>
       
  3378       <p id="ch7interim_assessment_e9">
       
  3379        The
       
  3380        <span class="emphasis">
       
  3381         <em>
       
  3382          cat
       
  3383         </em>
       
  3384        </span>
       
  3385        command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
       
  3386        <span class="emphasis">
       
  3387         <em>
       
  3388          concatenate
       
  3389         </em>
       
  3390        </span>
       
  3391        .
       
  3392       </p>
       
  3393       <p id="ch7interim_assessment_ea">
       
  3394        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.
       
  3395       </p>
       
  3396       <p id="ch7interim_assessment_eb">
       
  3397        If the filename is specified as -, then
       
  3398        <span class="emphasis">
       
  3399         <em>
       
  3400          cat
       
  3401         </em>
       
  3402        </span>
       
  3403        will read from standard input at that point in the sequence. If no files are specified,
       
  3404        <span class="emphasis">
       
  3405         <em>
       
  3406          cat
       
  3407         </em>
       
  3408        </span>
       
  3409        will read from standard input entered.
       
  3410       </p>
       
  3411       <div class="section" title="9.1.1.Jargon File Definition">
       
  3412        <div class="titlepage">
       
  3413         <div>
       
  3414          <div>
       
  3415           <h4 class="title">
       
  3416            <a name="id2654617">
       
  3417            </a>
       
  3418            9.1.1.Jargon File Definition
       
  3419           </h4>
       
  3420          </div>
       
  3421         </div>
       
  3422        </div>
       
  3423        <p id="ch7interim_assessment_ec">
       
  3424         The Jargon File version 4.4.7 lists this as the definition of
       
  3425         <span class="emphasis">
       
  3426          <em>
       
  3427           cat
       
  3428          </em>
       
  3429         </span>
       
  3430         :
       
  3431        </p>
       
  3432        <pre class="programlisting">
       
  3433         1. To spew an entire file to the screen or some other output sink without
       
  3434      pause (syn. blast).
       
  3435 
       
  3436 2. By extension, to dump large amounts of data at an unprepared target or
       
  3437      with no intention of browsing it carefully. Usage: considered silly.
       
  3438      Rare outside Unix sites. See also dd, BLT.
       
  3439 
       
  3440      Among Unix fans, *cat(1)* is considered an excellent example of
       
  3441      user-interface design, because it delivers the file contents without
       
  3442      such verbosity as spacing or headers between the files, and because
       
  3443      it does not require the files to consist of lines of text, but works
       
  3444      with any sort of data.
       
  3445 
       
  3446      Among Unix critics, *cat(1)* is considered the canonical example of
       
  3447      bad user-interface design, because of its woefully unobvious name.
       
  3448      It is far more often used to blast a single file to standard output
       
  3449      than to concatenate two or more files. The name cat for the former
       
  3450      operation is just as unintuitive as, say, LISP's cdr.
       
  3451 
       
  3452      Of such oppositions are holy wars made...
       
  3453        </pre>
       
  3454       </div>
       
  3455       <div class="section" title="9.1.2.Useless Use of 'cat'">
       
  3456        <div class="titlepage">
       
  3457         <div>
       
  3458          <div>
       
  3459           <h4 class="title">
       
  3460            <a name="id2654657">
       
  3461            </a>
       
  3462            9.1.2.Useless Use of 'cat'
       
  3463           </h4>
       
  3464          </div>
       
  3465         </div>
       
  3466        </div>
       
  3467        <p id="ch7interim_assessment_ed">
       
  3468         UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
       
  3469         <span class="emphasis">
       
  3470          <em>
       
  3471           comp.unix.shell
       
  3472          </em>
       
  3473         </span>
       
  3474         , 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.
       
  3475        </p>
       
  3476        <p id="ch7interim_assessment_ee">
       
  3477         Nevertheless one sees people doing:
       
  3478        </p>
       
  3479        <pre class="programlisting">
       
  3480         $ cat file | some_command and its args ...
       
  3481        </pre>
       
  3482        <p id="ch7interim_assessment_ef">
       
  3483         instead of the equivalent and cheaper:
       
  3484        </p>
       
  3485        <pre class="programlisting">
       
  3486         &lt;file some_command and its args ...
       
  3487        </pre>
       
  3488        <p id="ch7interim_assessment_f0">
       
  3489         or (equivalently and more classically):
       
  3490        </p>
       
  3491        <pre class="programlisting">
       
  3492         some_command and its args ... &lt;file
       
  3493        </pre>
       
  3494        <p id="ch7interim_assessment_f1">
       
  3495         Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
       
  3496        </p>
       
  3497        <p id="ch7interim_assessment_f2">
       
  3498         Amongst many, it is still considered safer to use
       
  3499         <span class="emphasis">
       
  3500          <em>
       
  3501           cat
       
  3502          </em>
       
  3503         </span>
       
  3504         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.
       
  3505        </p>
       
  3506       </div>
       
  3507       <div class="section" title="9.1.3.zcat">
       
  3508        <div class="titlepage">
       
  3509         <div>
       
  3510          <div>
       
  3511           <h4 class="title">
       
  3512            <a name="id2654728">
       
  3513            </a>
       
  3514            9.1.3.zcat
       
  3515           </h4>
       
  3516          </div>
       
  3517         </div>
       
  3518        </div>
       
  3519        <p id="ch7interim_assessment_f3">
       
  3520         <span class="emphasis">
       
  3521          <em>
       
  3522           zcat
       
  3523          </em>
       
  3524         </span>
       
  3525         is a Unix program similar to
       
  3526         <span class="emphasis">
       
  3527          <em>
       
  3528           cat
       
  3529          </em>
       
  3530         </span>
       
  3531         , that decompresses individual files and concatenates them to standard output. Traditionally
       
  3532         <span class="emphasis">
       
  3533          <em>
       
  3534           zcat
       
  3535          </em>
       
  3536         </span>
       
  3537         operated on files compressed by compress but today it is usually able to operate on
       
  3538         <span class="emphasis">
       
  3539          <em>
       
  3540           gzip
       
  3541          </em>
       
  3542         </span>
       
  3543         or even
       
  3544         <span class="emphasis">
       
  3545          <em>
       
  3546           bzip2
       
  3547          </em>
       
  3548         </span>
       
  3549         archives. On such systems, it is equivalent to
       
  3550         <span class="emphasis">
       
  3551          <em>
       
  3552           gunzip -c
       
  3553          </em>
       
  3554         </span>
       
  3555        </p>
       
  3556       </div>
       
  3557      </div>
       
  3558      <div class="section" title="9.2.more">
       
  3559       <div class="titlepage">
       
  3560        <div>
       
  3561         <div>
       
  3562          <h3 class="title">
       
  3563           <a name="id2654762">
       
  3564           </a>
       
  3565           9.2.more
       
  3566          </h3>
       
  3567         </div>
       
  3568        </div>
       
  3569       </div>
       
  3570       <p id="ch7interim_assessment_f4">
       
  3571        In computing,
       
  3572        <span class="emphasis">
       
  3573         <em>
       
  3574          more
       
  3575         </em>
       
  3576        </span>
       
  3577        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.
       
  3578       </p>
       
  3579       <div class="section" title="9.2.1.Usage">
       
  3580        <div class="titlepage">
       
  3581         <div>
       
  3582          <div>
       
  3583           <h4 class="title">
       
  3584            <a name="id2654781">
       
  3585            </a>
       
  3586            9.2.1.Usage
       
  3587           </h4>
       
  3588          </div>
       
  3589         </div>
       
  3590        </div>
       
  3591        <p id="ch7interim_assessment_f5">
       
  3592         The command-syntax is:
       
  3593        </p>
       
  3594        <pre class="programlisting">
       
  3595         $ more [options] [file_name]
       
  3596        </pre>
       
  3597        <p id="ch7interim_assessment_f6">
       
  3598         If no file name is provided,
       
  3599         <span class="emphasis">
       
  3600          <em>
       
  3601           more
       
  3602          </em>
       
  3603         </span>
       
  3604         looks for input from stdin.
       
  3605        </p>
       
  3606        <p id="ch7interim_assessment_f7">
       
  3607         Once
       
  3608         <span class="emphasis">
       
  3609          <em>
       
  3610           more
       
  3611          </em>
       
  3612         </span>
       
  3613         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
       
  3614         <span class="emphasis">
       
  3615          <em>
       
  3616           more
       
  3617          </em>
       
  3618         </span>
       
  3619         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
       
  3620         <span class="emphasis">
       
  3621          <em>
       
  3622           more
       
  3623          </em>
       
  3624         </span>
       
  3625         has paged through. (This percentage includes the text displayed on the current screen.) When
       
  3626         <span class="emphasis">
       
  3627          <em>
       
  3628           more
       
  3629          </em>
       
  3630         </span>
       
  3631         reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
       
  3632         <span class="emphasis">
       
  3633          <em>
       
  3634           Enter
       
  3635          </em>
       
  3636         </span>
       
  3637         , which advances the output by one line, and
       
  3638         <span class="emphasis">
       
  3639          <em>
       
  3640           Space
       
  3641          </em>
       
  3642         </span>
       
  3643         , which advances the output by one screen.
       
  3644        </p>
       
  3645        <p id="ch7interim_assessment_f8">
       
  3646         There are also other commands that can be used while navigating through the document; consult
       
  3647         <span class="emphasis">
       
  3648          <em>
       
  3649           more
       
  3650          </em>
       
  3651         </span>
       
  3652         's
       
  3653         <span class="emphasis">
       
  3654          <em>
       
  3655           man
       
  3656          </em>
       
  3657         </span>
       
  3658         page for more details.
       
  3659        </p>
       
  3660        <p id="ch7interim_assessment_f9">
       
  3661         <span class="emphasis">
       
  3662          <em>
       
  3663           Options
       
  3664          </em>
       
  3665         </span>
       
  3666         are typically entered before the file name, but can also be entered in the environment variable
       
  3667         <span class="emphasis">
       
  3668          <em>
       
  3669           $MORE
       
  3670          </em>
       
  3671         </span>
       
  3672         . Options entered in the actual command line will override those entered in the
       
  3673         <span class="emphasis">
       
  3674          <em>
       
  3675           $MORE
       
  3676          </em>
       
  3677         </span>
       
  3678         environment variable. Available options may vary between Unix systems.
       
  3679        </p>
       
  3680       </div>
       
  3681      </div>
       
  3682      <div class="section" title="9.3.less">
       
  3683       <div class="titlepage">
       
  3684        <div>
       
  3685         <div>
       
  3686          <h3 class="title">
       
  3687           <a name="id2654872">
       
  3688           </a>
       
  3689           9.3.less
       
  3690          </h3>
       
  3691         </div>
       
  3692        </div>
       
  3693       </div>
       
  3694       <p id="ch7interim_assessment_fa">
       
  3695        <span class="emphasis">
       
  3696         <em>
       
  3697          less
       
  3698         </em>
       
  3699        </span>
       
  3700        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
       
  3701        <span class="emphasis">
       
  3702         <em>
       
  3703          more
       
  3704         </em>
       
  3705        </span>
       
  3706        , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
       
  3707        <span class="emphasis">
       
  3708         <em>
       
  3709          less
       
  3710         </em>
       
  3711        </span>
       
  3712        does not need to read the entire file before starting, resulting in faster load times with large files.
       
  3713       </p>
       
  3714       <div class="section" title="9.3.1.Usage">
       
  3715        <div class="titlepage">
       
  3716         <div>
       
  3717          <div>
       
  3718           <h4 class="title">
       
  3719            <a name="id2654901">
       
  3720            </a>
       
  3721            9.3.1.Usage
       
  3722           </h4>
       
  3723          </div>
       
  3724         </div>
       
  3725        </div>
       
  3726        <p id="ch7interim_assessment_fb">
       
  3727         <span class="emphasis">
       
  3728          <em>
       
  3729           less
       
  3730          </em>
       
  3731         </span>
       
  3732         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
       
  3733         <span class="emphasis">
       
  3734          <em>
       
  3735           less
       
  3736          </em>
       
  3737         </span>
       
  3738         is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
       
  3739         <span class="emphasis">
       
  3740          <em>
       
  3741           more
       
  3742          </em>
       
  3743         </span>
       
  3744         and
       
  3745         <span class="emphasis">
       
  3746          <em>
       
  3747           vi
       
  3748          </em>
       
  3749         </span>
       
  3750         . It is also possible to search for character patterns in the file.
       
  3751        </p>
       
  3752        <p id="ch7interim_assessment_fc">
       
  3753         By default,
       
  3754         <span class="emphasis">
       
  3755          <em>
       
  3756           less
       
  3757          </em>
       
  3758         </span>
       
  3759         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.
       
  3760        </p>
       
  3761        <p id="ch7interim_assessment_fd">
       
  3762         The command-syntax is:
       
  3763        </p>
       
  3764        <pre class="programlisting">
       
  3765         $ less [options] file_name
       
  3766        </pre>
       
  3767       </div>
       
  3768       <div class="section" title="9.3.2.Frequently Used Options">
       
  3769        <div class="titlepage">
       
  3770         <div>
       
  3771          <div>
       
  3772           <h4 class="title">
       
  3773            <a name="id2654956">
       
  3774            </a>
       
  3775            9.3.2.Frequently Used Options
       
  3776           </h4>
       
  3777          </div>
       
  3778         </div>
       
  3779        </div>
       
  3780        <div class="itemizedlist">
       
  3781         <ul class="itemizedlist" type="*">
       
  3782          <li class="listitem" style="list-style-type: *">
       
  3783           <p id="ch7interim_assessment_fe">
       
  3784            -g: Highlights just the current match of any searched string.
       
  3785           </p>
       
  3786          </li>
       
  3787          <li class="listitem" style="list-style-type: *">
       
  3788           <p id="ch7interim_assessment_ff">
       
  3789            -I: Case-insensitive searches.
       
  3790           </p>
       
  3791          </li>
       
  3792          <li class="listitem" style="list-style-type: *">
       
  3793           <p id="ch7interim_assessment_100">
       
  3794            -M: Shows more detailed prompt, including file position.
       
  3795           </p>
       
  3796          </li>
       
  3797          <li class="listitem" style="list-style-type: *">
       
  3798           <p id="ch7interim_assessment_101">
       
  3799            -N: Shows line numbers (useful for source code viewing).
       
  3800           </p>
       
  3801          </li>
       
  3802          <li class="listitem" style="list-style-type: *">
       
  3803           <p id="ch7interim_assessment_102">
       
  3804            -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
       
  3805           </p>
       
  3806          </li>
       
  3807          <li class="listitem" style="list-style-type: *">
       
  3808           <p id="ch7interim_assessment_103">
       
  3809            -?: Shows help.
       
  3810           </p>
       
  3811          </li>
       
  3812         </ul>
       
  3813        </div>
       
  3814       </div>
       
  3815       <div class="section" title="9.3.3.Frequently Used Commands">
       
  3816        <div class="titlepage">
       
  3817         <div>
       
  3818          <div>
       
  3819           <h4 class="title">
       
  3820            <a name="id2655008">
       
  3821            </a>
       
  3822            9.3.3.Frequently Used Commands
       
  3823           </h4>
       
  3824          </div>
       
  3825         </div>
       
  3826        </div>
       
  3827        <div class="itemizedlist">
       
  3828         <ul class="itemizedlist" type="*">
       
  3829          <li class="listitem" style="list-style-type: *">
       
  3830           <p id="ch7interim_assessment_104">
       
  3831            [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
       
  3832           </p>
       
  3833          </li>
       
  3834          <li class="listitem" style="list-style-type: *">
       
  3835           <p id="ch7interim_assessment_105">
       
  3836            [Space bar]: Next page.
       
  3837           </p>
       
  3838          </li>
       
  3839          <li class="listitem" style="list-style-type: *">
       
  3840           <p id="ch7interim_assessment_106">
       
  3841            b: Previous page.
       
  3842           </p>
       
  3843          </li>
       
  3844          <li class="listitem" style="list-style-type: *">
       
  3845           <p id="ch7interim_assessment_107">
       
  3846            ng: Jump to line number n. Default is the start of the file.
       
  3847           </p>
       
  3848          </li>
       
  3849          <li class="listitem" style="list-style-type: *">
       
  3850           <p id="ch7interim_assessment_108">
       
  3851            nG: Jump to line number n. Default is the end of the file.
       
  3852           </p>
       
  3853          </li>
       
  3854          <li class="listitem" style="list-style-type: *">
       
  3855           <p id="ch7interim_assessment_109">
       
  3856            /pattern: Search for pattern. Regular expressions can be used.
       
  3857           </p>
       
  3858          </li>
       
  3859          <li class="listitem" style="list-style-type: *">
       
  3860           <p id="ch7interim_assessment_10a">
       
  3861            '^ or g: Go to start of file.
       
  3862           </p>
       
  3863          </li>
       
  3864          <li class="listitem" style="list-style-type: *">
       
  3865           <p id="ch7interim_assessment_10b">
       
  3866            '$ or G: Go to end of file.
       
  3867           </p>
       
  3868          </li>
       
  3869          <li class="listitem" style="list-style-type: *">
       
  3870           <p id="ch7interim_assessment_10c">
       
  3871            s: Save current content (got from another program like grep) in a file.
       
  3872           </p>
       
  3873          </li>
       
  3874          <li class="listitem" style="list-style-type: *">
       
  3875           <p id="ch7interim_assessment_10d">
       
  3876            =: File information.
       
  3877           </p>
       
  3878          </li>
       
  3879          <li class="listitem" style="list-style-type: *">
       
  3880           <p id="ch7interim_assessment_10e">
       
  3881            h: Help.
       
  3882           </p>
       
  3883          </li>
       
  3884          <li class="listitem" style="list-style-type: *">
       
  3885           <p id="ch7interim_assessment_10f">
       
  3886            q: Quit.
       
  3887           </p>
       
  3888          </li>
       
  3889         </ul>
       
  3890        </div>
       
  3891       </div>
       
  3892       <div class="section" title="9.3.4.Examples">
       
  3893        <div class="titlepage">
       
  3894         <div>
       
  3895          <div>
       
  3896           <h4 class="title">
       
  3897            <a name="id2655098">
       
  3898            </a>
       
  3899            9.3.4.Examples
       
  3900           </h4>
       
  3901          </div>
       
  3902         </div>
       
  3903        </div>
       
  3904        <pre class="programlisting">
       
  3905         $ less -M readme.txt                     #Read "readme.txt."
       
  3906 $ less +F /var/log/mail.log              #Follow mode for log
       
  3907 $ file * | less                          #Easier file analysis.
       
  3908 $ grep -i void *.c | less -I -p void     #Case insensitive search                                                         for "void" in all .c files
       
  3909        </pre>
       
  3910       </div>
       
  3911      </div>
       
  3912     </div>
       
  3913     <div class="section" title="10.Directory Structure">
       
  3914      <div class="titlepage">
       
  3915       <div>
       
  3916        <div>
       
  3917         <h2 class="title" style="clear: both">
       
  3918          <a name="id2655114">
       
  3919          </a>
       
  3920          10.Directory Structure
       
  3921         </h2>
       
  3922        </div>
       
  3923       </div>
       
  3924      </div>
       
  3925      <p id="ch7interim_assessment_110">
       
  3926       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.
       
  3927      </p>
       
  3928      <p id="ch7interim_assessment_111">
       
  3929       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.
       
  3930      </p>
       
  3931      <table summary="Directory Structure" border="1">
       
  3932       <colgroup>
       
  3933        <col width="15">
       
  3934        </col>
       
  3935        <col width="48">
       
  3936        </col>
       
  3937       </colgroup>
       
  3938      </table>
       
  3939      <div class="section" title="10.1.man hier">
       
  3940       <div class="titlepage">
       
  3941        <div>
       
  3942         <div>
       
  3943          <h3 class="title">
       
  3944           <a name="id2655388">
       
  3945           </a>
       
  3946           10.1.man hier
       
  3947          </h3>
       
  3948         </div>
       
  3949        </div>
       
  3950       </div>
       
  3951       <p id="ch7interim_assessment_136">
       
  3952        This is the manual page on the UNIX filesystem. The syntax for this is:
       
  3953       </p>
       
  3954       <pre class="programlisting">
       
  3955        $ man hier
       
  3956       </pre>
       
  3957      </div>
       
  3958      <div class="section" title="10.2.ls -l">
       
  3959       <div class="titlepage">
       
  3960        <div>
       
  3961         <div>
       
  3962          <h3 class="title">
       
  3963           <a name="id2655404">
       
  3964           </a>
       
  3965           10.2.ls -l
       
  3966          </h3>
       
  3967         </div>
       
  3968        </div>
       
  3969       </div>
       
  3970       <p id="ch7interim_assessment_137">
       
  3971        Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
       
  3972       </p>
       
  3973       <pre class="programlisting">
       
  3974        $ ls -l
       
  3975       </pre>
       
  3976       <p id="ch7interim_assessment_138">
       
  3977        This can be done after entering the required directory.
       
  3978       </p>
       
  3979      </div>
       
  3980     </div>
       
  3981     <div class="section" title="11.Permissions and Ownership">
       
  3982      <div class="titlepage">
       
  3983       <div>
       
  3984        <div>
       
  3985         <h2 class="title" style="clear: both">
       
  3986          <a name="id2655428">
       
  3987          </a>
       
  3988          11.Permissions and Ownership
       
  3989         </h2>
       
  3990        </div>
       
  3991       </div>
       
  3992      </div>
       
  3993      <div class="section" title="11.1.chmod">
       
  3994       <div class="titlepage">
       
  3995        <div>
       
  3996         <div>
       
  3997          <h3 class="title">
       
  3998           <a name="id2655436">
       
  3999           </a>
       
  4000           11.1.chmod
       
  4001          </h3>
       
  4002         </div>
       
  4003        </div>
       
  4004       </div>
       
  4005       <p id="ch7interim_assessment_139">
       
  4006        The
       
  4007        <span class="emphasis">
       
  4008         <em>
       
  4009          chmod
       
  4010         </em>
       
  4011        </span>
       
  4012        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.
       
  4013       </p>
       
  4014       <div class="section" title="11.1.1.Usage">
       
  4015        <div class="titlepage">
       
  4016         <div>
       
  4017          <div>
       
  4018           <h4 class="title">
       
  4019            <a name="id2655462">
       
  4020            </a>
       
  4021            11.1.1.Usage
       
  4022           </h4>
       
  4023          </div>
       
  4024         </div>
       
  4025        </div>
       
  4026        <p id="ch7interim_assessment_13a">
       
  4027         The
       
  4028         <span class="emphasis">
       
  4029          <em>
       
  4030           chmod
       
  4031          </em>
       
  4032         </span>
       
  4033         command options are specified like this:
       
  4034        </p>
       
  4035        <pre class="programlisting">
       
  4036         $ chmod [options] mode[,mode] file1 [file2 ...]
       
  4037        </pre>
       
  4038        <p id="ch7interim_assessment_13b">
       
  4039         To view what the permissions currently are, type:
       
  4040        </p>
       
  4041        <pre class="programlisting">
       
  4042         $ ls -l file
       
  4043        </pre>
       
  4044       </div>
       
  4045       <div class="section" title="11.1.2.Command line options">
       
  4046        <div class="titlepage">
       
  4047         <div>
       
  4048          <div>
       
  4049           <h4 class="title">
       
  4050            <a name="id2655490">
       
  4051            </a>
       
  4052            11.1.2.Command line options
       
  4053           </h4>
       
  4054          </div>
       
  4055         </div>
       
  4056        </div>
       
  4057        <p id="ch7interim_assessment_13c">
       
  4058         The
       
  4059         <span class="emphasis">
       
  4060          <em>
       
  4061           chmod
       
  4062          </em>
       
  4063         </span>
       
  4064         command has a number of command line options that affect its behavior. The most common options are:
       
  4065        </p>
       
  4066        <div class="itemizedlist">
       
  4067         <ul class="itemizedlist" type="*">
       
  4068          <li class="listitem" style="list-style-type: *">
       
  4069           <p id="ch7interim_assessment_13d">
       
  4070            -R: Changes the modes of directories and files recursively
       
  4071           </p>
       
  4072          </li>
       
  4073          <li class="listitem" style="list-style-type: *">
       
  4074           <p id="ch7interim_assessment_13e">
       
  4075            -v: Verbose mode; lists all files as they are being processed
       
  4076           </p>
       
  4077          </li>
       
  4078         </ul>
       
  4079        </div>
       
  4080        <div class="section" title="11.1.2.1.Symbolic modes">
       
  4081         <div class="titlepage">
       
  4082          <div>
       
  4083           <div>
       
  4084            <h5 class="title">
       
  4085             <a name="id2655526">
       
  4086             </a>
       
  4087             11.1.2.1.Symbolic modes
       
  4088            </h5>
       
  4089           </div>
       
  4090          </div>
       
  4091         </div>
       
  4092         <p id="ch7interim_assessment_13f">
       
  4093          To the
       
  4094          <span class="emphasis">
       
  4095           <em>
       
  4096            chmod
       
  4097           </em>
       
  4098          </span>
       
  4099          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:
       
  4100         </p>
       
  4101         <pre class="programlisting">
       
  4102          $ chmod [references][operator][modes] file1 ...
       
  4103         </pre>
       
  4104         <p id="ch7interim_assessment_140">
       
  4105          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:
       
  4106         </p>
       
  4107         <table summary="Symbolic modes" border="1">
       
  4108          <colgroup>
       
  4109           <col width="14">
       
  4110           </col>
       
  4111           <col width="8">
       
  4112           </col>
       
  4113           <col width="45">
       
  4114           </col>
       
  4115          </colgroup>
       
  4116         </table>
       
  4117         <p id="ch7interim_assessment_150">
       
  4118          The
       
  4119          <span class="emphasis">
       
  4120           <em>
       
  4121            chmod
       
  4122           </em>
       
  4123          </span>
       
  4124          program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
       
  4125         </p>
       
  4126         <table summary="Symbolic modes" border="1">
       
  4127          <colgroup>
       
  4128           <col width="14">
       
  4129           </col>
       
  4130           <col width="54">
       
  4131           </col>
       
  4132          </colgroup>
       
  4133         </table>
       
  4134         <p id="ch7interim_assessment_157">
       
  4135          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:
       
  4136         </p>
       
  4137         <table summary="Symbolic modes" border="1">
       
  4138          <colgroup>
       
  4139           <col width="5">
       
  4140           </col>
       
  4141           <col width="14">
       
  4142           </col>
       
  4143           <col width="48">
       
  4144           </col>
       
  4145          </colgroup>
       
  4146         </table>
       
  4147         <p id="ch7interim_assessment_16d">
       
  4148          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.
       
  4149         </p>
       
  4150        </div>
       
  4151        <div class="section" title="11.1.2.2.Symbolic examples">
       
  4152         <div class="titlepage">
       
  4153          <div>
       
  4154           <div>
       
  4155            <h5 class="title">
       
  4156             <a name="id2656087">
       
  4157             </a>
       
  4158             11.1.2.2.Symbolic examples
       
  4159            </h5>
       
  4160           </div>
       
  4161          </div>
       
  4162         </div>
       
  4163         <p id="ch7interim_assessment_16e">
       
  4164          Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
       
  4165         </p>
       
  4166         <pre class="programlisting">
       
  4167          $ chmod ug+rw mydir
       
  4168 $ ls -ld mydir
       
  4169 drw-rw----   2 starwars  yoda  96 Dec 8 12:53 mydir
       
  4170         </pre>
       
  4171         <p id="ch7interim_assessment_16f">
       
  4172          For a file, remove
       
  4173          <span class="emphasis">
       
  4174           <em>
       
  4175            write
       
  4176           </em>
       
  4177          </span>
       
  4178          permissions for all classes:
       
  4179         </p>
       
  4180         <pre class="programlisting">
       
  4181          $ chmod a-w myfile
       
  4182 $ ls -l myfile
       
  4183 -r-xr-xr-x   2 starwars  yoda 96 Dec 8 12:53 myfile
       
  4184         </pre>
       
  4185         <p id="ch7interim_assessment_170">
       
  4186          Set the permissions for the
       
  4187          <span class="emphasis">
       
  4188           <em>
       
  4189            u*ser and the *g*roup to read and execute only (no write permission) on *mydir
       
  4190           </em>
       
  4191          </span>
       
  4192          .
       
  4193         </p>
       
  4194         <pre class="programlisting">
       
  4195          $ chmod ug=rx mydir
       
  4196 $ ls -ld mydir
       
  4197 dr-xr-x---   2 starwars  yoda 96 Dec 8 12:53 mydir
       
  4198         </pre>
       
  4199        </div>
       
  4200        <div class="section" title="11.1.2.3.Octal numbers">
       
  4201         <div class="titlepage">
       
  4202          <div>
       
  4203           <div>
       
  4204            <h5 class="title">
       
  4205             <a name="id2656130">
       
  4206             </a>
       
  4207             11.1.2.3.Octal numbers
       
  4208            </h5>
       
  4209           </div>
       
  4210          </div>
       
  4211         </div>
       
  4212         <p id="ch7interim_assessment_171">
       
  4213          The
       
  4214          <span class="emphasis">
       
  4215           <em>
       
  4216            chmod
       
  4217           </em>
       
  4218          </span>
       
  4219          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 :
       
  4220         </p>
       
  4221         <pre class="programlisting">
       
  4222          $ chmod 664 myfile
       
  4223 $ ls -l myfile
       
  4224 -rw-rw-r--  1   57 Jul  3 10:13  myfile
       
  4225         </pre>
       
  4226         <p id="ch7interim_assessment_172">
       
  4227          Since the
       
  4228          <span class="emphasis">
       
  4229           <em>
       
  4230            setuid
       
  4231           </em>
       
  4232          </span>
       
  4233          ,
       
  4234          <span class="emphasis">
       
  4235           <em>
       
  4236            setgid
       
  4237           </em>
       
  4238          </span>
       
  4239          and
       
  4240          <span class="emphasis">
       
  4241           <em>
       
  4242            sticky
       
  4243           </em>
       
  4244          </span>
       
  4245          bits are not set, this is equivalent to:
       
  4246         </p>
       
  4247         <pre class="programlisting">
       
  4248          $ chmod 0664 myfile
       
  4249         </pre>
       
  4250        </div>
       
  4251        <div class="section" title="11.1.2.4.Special modes">
       
  4252         <div class="titlepage">
       
  4253          <div>
       
  4254           <div>
       
  4255            <h5 class="title">
       
  4256             <a name="id2656169">
       
  4257             </a>
       
  4258             11.1.2.4.Special modes
       
  4259            </h5>
       
  4260           </div>
       
  4261          </div>
       
  4262         </div>
       
  4263         <p id="ch7interim_assessment_173">
       
  4264          The
       
  4265          <span class="emphasis">
       
  4266           <em>
       
  4267            chmod
       
  4268           </em>
       
  4269          </span>
       
  4270          command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
       
  4271          <span class="strong">
       
  4272           <strong>
       
  4273            s
       
  4274           </strong>
       
  4275          </span>
       
  4276          to represent the
       
  4277          <span class="emphasis">
       
  4278           <em>
       
  4279            setuid
       
  4280           </em>
       
  4281          </span>
       
  4282          and
       
  4283          <span class="emphasis">
       
  4284           <em>
       
  4285            setgid
       
  4286           </em>
       
  4287          </span>
       
  4288          modes, and
       
  4289          <span class="strong">
       
  4290           <strong>
       
  4291            t
       
  4292           </strong>
       
  4293          </span>
       
  4294          to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
       
  4295         </p>
       
  4296         <p id="ch7interim_assessment_174">
       
  4297          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.
       
  4298         </p>
       
  4299        </div>
       
  4300       </div>
       
  4301      </div>
       
  4302     </div>
       
  4303     <div class="section" title="12.Redirection and Piping">
       
  4304      <div class="titlepage">
       
  4305       <div>
       
  4306        <div>
       
  4307         <h2 class="title" style="clear: both">
       
  4308          <a name="id2656213">
       
  4309          </a>
       
  4310          12.Redirection and Piping
       
  4311         </h2>
       
  4312        </div>
       
  4313       </div>
       
  4314      </div>
       
  4315      <p id="ch7interim_assessment_175">
       
  4316       In computing,
       
  4317       <span class="emphasis">
       
  4318        <em>
       
  4319         redirection
       
  4320        </em>
       
  4321       </span>
       
  4322       is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
       
  4323      </p>
       
  4324      <p id="ch7interim_assessment_176">
       
  4325       Programs do redirection with the
       
  4326       <span class="emphasis">
       
  4327        <em>
       
  4328         dup2(2)
       
  4329        </em>
       
  4330       </span>
       
  4331       system call, or its less-flexible but higher-level stdio analogues,
       
  4332       <span class="emphasis">
       
  4333        <em>
       
  4334         freopen(3)
       
  4335        </em>
       
  4336       </span>
       
  4337       and
       
  4338       <span class="emphasis">
       
  4339        <em>
       
  4340         popen(3)
       
  4341        </em>
       
  4342       </span>
       
  4343       .
       
  4344      </p>
       
  4345      <div class="section" title="12.1.Redirecting standard input and standard output">
       
  4346       <div class="titlepage">
       
  4347        <div>
       
  4348         <div>
       
  4349          <h3 class="title">
       
  4350           <a name="id2656248">
       
  4351           </a>
       
  4352           12.1.Redirecting standard input and standard output
       
  4353          </h3>
       
  4354         </div>
       
  4355        </div>
       
  4356       </div>
       
  4357       <p id="ch7interim_assessment_177">
       
  4358        Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
       
  4359       </p>
       
  4360       <pre class="programlisting">
       
  4361        $ command1 &gt; file1
       
  4362       </pre>
       
  4363       <p id="ch7interim_assessment_178">
       
  4364        executes
       
  4365        <span class="emphasis">
       
  4366         <em>
       
  4367          command1
       
  4368         </em>
       
  4369        </span>
       
  4370        , placing the output in file1. Note that this will truncate any existing data in
       
  4371        <span class="emphasis">
       
  4372         <em>
       
  4373          file1
       
  4374         </em>
       
  4375        </span>
       
  4376        . To append output to the end of the file, use the &gt;&gt; operator.:
       
  4377       </p>
       
  4378       <pre class="programlisting">
       
  4379        $ command1 &lt; file1
       
  4380       </pre>
       
  4381       <p id="ch7interim_assessment_179">
       
  4382        executes
       
  4383        <span class="emphasis">
       
  4384         <em>
       
  4385          command1
       
  4386         </em>
       
  4387        </span>
       
  4388        , using
       
  4389        <span class="emphasis">
       
  4390         <em>
       
  4391          file1
       
  4392         </em>
       
  4393        </span>
       
  4394        as the source of input (as opposed to the keyboard).:
       
  4395       </p>
       
  4396       <pre class="programlisting">
       
  4397        $ command1 &lt; infile &gt; outfile
       
  4398       </pre>
       
  4399       <p id="ch7interim_assessment_17a">
       
  4400        combines the two capabilities:
       
  4401        <span class="emphasis">
       
  4402         <em>
       
  4403          command1
       
  4404         </em>
       
  4405        </span>
       
  4406        reads from
       
  4407        <span class="emphasis">
       
  4408         <em>
       
  4409          infile
       
  4410         </em>
       
  4411        </span>
       
  4412        and writes to
       
  4413        <span class="emphasis">
       
  4414         <em>
       
  4415          outfile
       
  4416         </em>
       
  4417        </span>
       
  4418       </p>
       
  4419      </div>
       
  4420      <div class="section" title="12.2.Piping">
       
  4421       <div class="titlepage">
       
  4422        <div>
       
  4423         <div>
       
  4424          <h3 class="title">
       
  4425           <a name="id2656318">
       
  4426           </a>
       
  4427           12.2.Piping
       
  4428          </h3>
       
  4429         </div>
       
  4430        </div>
       
  4431       </div>
       
  4432       <p id="ch7interim_assessment_17b">
       
  4433        Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
       
  4434 A pipeline of three programs run on a text terminal:
       
  4435       </p>
       
  4436       <pre class="programlisting">
       
  4437        $ command1 | command2
       
  4438       </pre>
       
  4439       <p id="ch7interim_assessment_17c">
       
  4440        executes
       
  4441        <span class="emphasis">
       
  4442         <em>
       
  4443          command1
       
  4444         </em>
       
  4445        </span>
       
  4446        , using its output as the input for
       
  4447        <span class="emphasis">
       
  4448         <em>
       
  4449          command2
       
  4450         </em>
       
  4451        </span>
       
  4452        (commonly called piping, since the "|" character is known as a "pipe").
       
  4453       </p>
       
  4454       <p id="ch7interim_assessment_17d">
       
  4455        This is equivalent to using two redirects and a temporary file:
       
  4456       </p>
       
  4457       <pre class="programlisting">
       
  4458        $ command1 &gt; tempfile
       
  4459 $ command2 &lt; tempfile
       
  4460 $ rm tempfile
       
  4461       </pre>
       
  4462       <p id="ch7interim_assessment_17e">
       
  4463        A good example for command piping is combining
       
  4464        <span class="emphasis">
       
  4465         <em>
       
  4466          echo
       
  4467         </em>
       
  4468        </span>
       
  4469        with another command to achieve something interactive in a non-interactive shell, e.g.:
       
  4470       </p>
       
  4471       <pre class="programlisting">
       
  4472        $ echo -e "user\npass" | ftp localhost
       
  4473       </pre>
       
  4474       <p id="ch7interim_assessment_17f">
       
  4475        This runs the ftp client with input user, press return, then pass.
       
  4476       </p>
       
  4477      </div>
       
  4478      <div class="section" title="12.3.Redirecting to and from the standard file handles">
       
  4479       <div class="titlepage">
       
  4480        <div>
       
  4481         <div>
       
  4482          <h3 class="title">
       
  4483           <a name="id2656380">
       
  4484           </a>
       
  4485           12.3.Redirecting to and from the standard file handles
       
  4486          </h3>
       
  4487         </div>
       
  4488        </div>
       
  4489       </div>
       
  4490       <p id="ch7interim_assessment_180">
       
  4491        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:
       
  4492       </p>
       
  4493       <table summary="Redirecting to and from the standard file handles" border="1">
       
  4494        <colgroup>
       
  4495         <col width="12">
       
  4496         </col>
       
  4497         <col width="13">
       
  4498         </col>
       
  4499         <col width="24">
       
  4500         </col>
       
  4501        </colgroup>
       
  4502       </table>
       
  4503       <p id="ch7interim_assessment_18d">
       
  4504        For example:
       
  4505       </p>
       
  4506       <pre class="programlisting">
       
  4507        $ command1 2&gt; file1
       
  4508       </pre>
       
  4509       <p id="ch7interim_assessment_18e">
       
  4510        executes
       
  4511        <span class="emphasis">
       
  4512         <em>
       
  4513          command1
       
  4514         </em>
       
  4515        </span>
       
  4516        , directing the standard error stream to
       
  4517        <span class="emphasis">
       
  4518         <em>
       
  4519          file1
       
  4520         </em>
       
  4521        </span>
       
  4522        .
       
  4523       </p>
       
  4524       <p id="ch7interim_assessment_18f">
       
  4525        In shells derived from
       
  4526        <span class="emphasis">
       
  4527         <em>
       
  4528          csh
       
  4529         </em>
       
  4530        </span>
       
  4531        (the C shell), the syntax instead appends the &amp; character to the redirect characters, thus achieving a similar result.
       
  4532       </p>
       
  4533       <p id="ch7interim_assessment_190">
       
  4534        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:
       
  4535       </p>
       
  4536       <pre class="programlisting">
       
  4537        $ find / -name .profile &gt; results 2&gt;&amp;1
       
  4538       </pre>
       
  4539       <p id="ch7interim_assessment_191">
       
  4540        will try to find all files named
       
  4541        <span class="emphasis">
       
  4542         <em>
       
  4543          .profile
       
  4544         </em>
       
  4545        </span>
       
  4546        . Executed without redirection, it will output hits to
       
  4547        <span class="emphasis">
       
  4548         <em>
       
  4549          stdout
       
  4550         </em>
       
  4551        </span>
       
  4552        and errors (e.g. for lack of privilege to traverse protected directories) to
       
  4553        <span class="emphasis">
       
  4554         <em>
       
  4555          stderr
       
  4556         </em>
       
  4557        </span>
       
  4558        . 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
       
  4559        <span class="emphasis">
       
  4560         <em>
       
  4561          stderr
       
  4562         </em>
       
  4563        </span>
       
  4564        (handle 2) into
       
  4565        <span class="emphasis">
       
  4566         <em>
       
  4567          stdout
       
  4568         </em>
       
  4569        </span>
       
  4570        (handle 1) using 2&gt;&amp;1 .
       
  4571       </p>
       
  4572       <p id="ch7interim_assessment_192">
       
  4573        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.
       
  4574       </p>
       
  4575       <p id="ch7interim_assessment_193">
       
  4576        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:
       
  4577       </p>
       
  4578       <pre class="programlisting">
       
  4579        $ find / -name .profile 2&gt;&amp;1 | less
       
  4580       </pre>
       
  4581       <p id="ch7interim_assessment_194">
       
  4582        A simplified form of the command:
       
  4583       </p>
       
  4584       <pre class="programlisting">
       
  4585        $ command &gt; file 2&gt;&amp;1
       
  4586       </pre>
       
  4587       <p id="ch7interim_assessment_195">
       
  4588        is:
       
  4589       </p>
       
  4590       <pre class="programlisting">
       
  4591        $ command &amp;&gt;file
       
  4592       </pre>
       
  4593       <p id="ch7interim_assessment_196">
       
  4594        or:
       
  4595       </p>
       
  4596       <pre class="programlisting">
       
  4597        $command &gt;&amp;file
       
  4598       </pre>
       
  4599      </div>
       
  4600      <div class="section" title="12.4.Chained pipelines">
       
  4601       <div class="titlepage">
       
  4602        <div>
       
  4603         <div>
       
  4604          <h3 class="title">
       
  4605           <a name="id2656587">
       
  4606           </a>
       
  4607           12.4.Chained pipelines
       
  4608          </h3>
       
  4609         </div>
       
  4610        </div>
       
  4611       </div>
       
  4612       <p id="ch7interim_assessment_197">
       
  4613        The redirection and piping tokens can be chained together to create complex commands. For example:
       
  4614       </p>
       
  4615       <pre class="programlisting">
       
  4616        $ ls | grep '\.sh' | sort &gt; shlist
       
  4617       </pre>
       
  4618       <p id="ch7interim_assessment_198">
       
  4619        lists the contents of the current directory, where this output is filtered to only contain lines which contain
       
  4620        <span class="emphasis">
       
  4621         <em>
       
  4622          .sh
       
  4623         </em>
       
  4624        </span>
       
  4625        , sort this resultant output lexicographically, and place the final output in
       
  4626        <span class="emphasis">
       
  4627         <em>
       
  4628          shlist
       
  4629         </em>
       
  4630        </span>
       
  4631        . This type of construction is used very commonly in shell scripts and batch files.
       
  4632       </p>
       
  4633      </div>
       
  4634      <div class="section" title="12.5.Redirect to multiple outputs">
       
  4635       <div class="titlepage">
       
  4636        <div>
       
  4637         <div>
       
  4638          <h3 class="title">
       
  4639           <a name="id2656622">
       
  4640           </a>
       
  4641           12.5.Redirect to multiple outputs
       
  4642          </h3>
       
  4643         </div>
       
  4644        </div>
       
  4645       </div>
       
  4646       <p id="ch7interim_assessment_199">
       
  4647        The standard command
       
  4648        <span class="emphasis">
       
  4649         <em>
       
  4650          tee
       
  4651         </em>
       
  4652        </span>
       
  4653        can redirect output from a command to several destinations.
       
  4654       </p>
       
  4655       <pre class="programlisting">
       
  4656        $ ls -lrt | tee xyz
       
  4657       </pre>
       
  4658       <p id="ch7interim_assessment_19a">
       
  4659        This directs the file list output to both standard output as well as to the file
       
  4660        <span class="emphasis">
       
  4661         <em>
       
  4662          xyz
       
  4663         </em>
       
  4664        </span>
       
  4665        .
       
  4666       </p>
       
  4667      </div>
       
  4668     </div>
       
  4669     <div class="section" title="13.More Text Processing">
       
  4670      <div class="titlepage">
       
  4671       <div>
       
  4672        <div>
       
  4673         <h2 class="title" style="clear: both">
       
  4674          <a name="id2656652">
       
  4675          </a>
       
  4676          13.More Text Processing
       
  4677         </h2>
       
  4678        </div>
       
  4679       </div>
       
  4680      </div>
       
  4681      <div class="section" title="13.1.grep">
       
  4682       <div class="titlepage">
       
  4683        <div>
       
  4684         <div>
       
  4685          <h3 class="title">
       
  4686           <a name="id2656661">
       
  4687           </a>
       
  4688           13.1.grep
       
  4689          </h3>
       
  4690         </div>
       
  4691        </div>
       
  4692       </div>
       
  4693       <p id="ch7interim_assessment_19b">
       
  4694        <span class="emphasis">
       
  4695         <em>
       
  4696          grep
       
  4697         </em>
       
  4698        </span>
       
  4699        is a command line text search utility originally written for Unix. The name is taken from the first letters in
       
  4700        <span class="emphasis">
       
  4701         <em>
       
  4702          global / regular expression / print
       
  4703         </em>
       
  4704        </span>
       
  4705        , a series of instructions for the
       
  4706        <span class="emphasis">
       
  4707         <em>
       
  4708          ed
       
  4709         </em>
       
  4710        </span>
       
  4711        text editor. The
       
  4712        <span class="emphasis">
       
  4713         <em>
       
  4714          grep
       
  4715         </em>
       
  4716        </span>
       
  4717        command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
       
  4718       </p>
       
  4719       <div class="section" title="13.1.1.Usage">
       
  4720        <div class="titlepage">
       
  4721         <div>
       
  4722          <div>
       
  4723           <h4 class="title">
       
  4724            <a name="id2656692">
       
  4725            </a>
       
  4726            13.1.1.Usage
       
  4727           </h4>
       
  4728          </div>
       
  4729         </div>
       
  4730        </div>
       
  4731        <p id="ch7interim_assessment_19c">
       
  4732         This is an example of a common
       
  4733         <span class="emphasis">
       
  4734          <em>
       
  4735           grep
       
  4736          </em>
       
  4737         </span>
       
  4738         usage:
       
  4739        </p>
       
  4740        <pre class="programlisting">
       
  4741         $ grep apple fruitlist.txt
       
  4742        </pre>
       
  4743        <p id="ch7interim_assessment_19d">
       
  4744         In this case,
       
  4745         <span class="emphasis">
       
  4746          <em>
       
  4747           grep
       
  4748          </em>
       
  4749         </span>
       
  4750         prints all lines containing 'apple' from the file
       
  4751         <span class="emphasis">
       
  4752          <em>
       
  4753           fruitlist.txt
       
  4754          </em>
       
  4755         </span>
       
  4756         , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
       
  4757         <span class="emphasis">
       
  4758          <em>
       
  4759           grep
       
  4760          </em>
       
  4761         </span>
       
  4762         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'.
       
  4763        </p>
       
  4764        <p id="ch7interim_assessment_19e">
       
  4765         Like most Unix commands,
       
  4766         <span class="emphasis">
       
  4767          <em>
       
  4768           grep
       
  4769          </em>
       
  4770         </span>
       
  4771         accepts command line arguments to change this and many other behaviors. For example:
       
  4772        </p>
       
  4773        <pre class="programlisting">
       
  4774         $ grep -i apple fruitlist.txt
       
  4775        </pre>
       
  4776        <p id="ch7interim_assessment_19f">
       
  4777         This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
       
  4778         <span class="emphasis">
       
  4779          <em>
       
  4780           grep
       
  4781          </em>
       
  4782         </span>
       
  4783         to be case insensitive, or to ignore case.
       
  4784        </p>
       
  4785        <p id="ch7interim_assessment_1a0">
       
  4786         To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
       
  4787        </p>
       
  4788        <pre class="programlisting">
       
  4789         $ grep -w apple fruitlist.txt
       
  4790        </pre>
       
  4791        <p id="ch7interim_assessment_1a1">
       
  4792         Regular expressions can be used to match more complicated queries.
       
  4793        </p>
       
  4794        <div class="section" title="13.1.1.1.Variations">
       
  4795         <div class="titlepage">
       
  4796          <div>
       
  4797           <div>
       
  4798            <h5 class="title">
       
  4799             <a name="id2656772">
       
  4800             </a>
       
  4801             13.1.1.1.Variations
       
  4802            </h5>
       
  4803           </div>
       
  4804          </div>
       
  4805         </div>
       
  4806         <p id="ch7interim_assessment_1a2">
       
  4807          There are countless implementations and derivatives of
       
  4808          <span class="emphasis">
       
  4809           <em>
       
  4810            grep
       
  4811           </em>
       
  4812          </span>
       
  4813          available for many operating systems. Early variants of
       
  4814          <span class="emphasis">
       
  4815           <em>
       
  4816            grep
       
  4817           </em>
       
  4818          </span>
       
  4819          included
       
  4820          <span class="emphasis">
       
  4821           <em>
       
  4822            egrep
       
  4823           </em>
       
  4824          </span>
       
  4825          and
       
  4826          <span class="emphasis">
       
  4827           <em>
       
  4828            fgrep
       
  4829           </em>
       
  4830          </span>
       
  4831          . 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
       
  4832          <span class="emphasis">
       
  4833           <em>
       
  4834            grep
       
  4835           </em>
       
  4836          </span>
       
  4837          implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
       
  4838          <span class="emphasis">
       
  4839           <em>
       
  4840            grep
       
  4841           </em>
       
  4842          </span>
       
  4843          may also behave differently depending on the name by which it is invoked, allowing
       
  4844          <span class="emphasis">
       
  4845           <em>
       
  4846            fgrep
       
  4847           </em>
       
  4848          </span>
       
  4849          ,
       
  4850          <span class="emphasis">
       
  4851           <em>
       
  4852            egrep
       
  4853           </em>
       
  4854          </span>
       
  4855          , and
       
  4856          <span class="emphasis">
       
  4857           <em>
       
  4858            grep
       
  4859           </em>
       
  4860          </span>
       
  4861          to be links to the same program.
       
  4862         </p>
       
  4863         <p id="ch7interim_assessment_1a3">
       
  4864          <span class="emphasis">
       
  4865           <em>
       
  4866            pcregrep
       
  4867           </em>
       
  4868          </span>
       
  4869          is an implementation of
       
  4870          <span class="emphasis">
       
  4871           <em>
       
  4872            grep
       
  4873           </em>
       
  4874          </span>
       
  4875          that uses Perl regular expression syntax.
       
  4876         </p>
       
  4877         <p id="ch7interim_assessment_1a4">
       
  4878          Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
       
  4879          <span class="emphasis">
       
  4880           <em>
       
  4881            pgrep
       
  4882           </em>
       
  4883          </span>
       
  4884          utility, for instance, displays the processes whose names match a given regular expression.
       
  4885         </p>
       
  4886        </div>
       
  4887       </div>
       
  4888      </div>
       
  4889      <div class="section" title="13.2.tr">
       
  4890       <div class="titlepage">
       
  4891        <div>
       
  4892         <div>
       
  4893          <h3 class="title">
       
  4894           <a name="id2656851">
       
  4895           </a>
       
  4896           13.2.tr
       
  4897          </h3>
       
  4898         </div>
       
  4899        </div>
       
  4900       </div>
       
  4901       <p id="ch7interim_assessment_1a5">
       
  4902        <span class="emphasis">
       
  4903         <em>
       
  4904          tr
       
  4905         </em>
       
  4906        </span>
       
  4907        (abbreviated from
       
  4908        <span class="emphasis">
       
  4909         <em>
       
  4910          translate
       
  4911         </em>
       
  4912        </span>
       
  4913        or
       
  4914        <span class="emphasis">
       
  4915         <em>
       
  4916          transliterate
       
  4917         </em>
       
  4918        </span>
       
  4919        ) is a command in Unix-like operating systems.
       
  4920       </p>
       
  4921       <p id="ch7interim_assessment_1a6">
       
  4922        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,
       
  4923       </p>
       
  4924       <pre class="programlisting">
       
  4925        $ tr 'abcd' 'jkmn'
       
  4926       </pre>
       
  4927       <p id="ch7interim_assessment_1a7">
       
  4928        maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
       
  4929       </p>
       
  4930       <p id="ch7interim_assessment_1a8">
       
  4931        Sets of characters may be abbreviated by using character ranges. The previous example could be written:
       
  4932       </p>
       
  4933       <pre class="programlisting">
       
  4934        $ tr 'a-d' 'jkmn'
       
  4935       </pre>
       
  4936       <p id="ch7interim_assessment_1a9">
       
  4937        In POSIX compliant versions of
       
  4938        <span class="emphasis">
       
  4939         <em>
       
  4940          tr
       
  4941         </em>
       
  4942        </span>
       
  4943        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:].
       
  4944       </p>
       
  4945       <p id="ch7interim_assessment_1aa">
       
  4946        The
       
  4947        <span class="emphasis">
       
  4948         <em>
       
  4949          -c
       
  4950         </em>
       
  4951        </span>
       
  4952        flag complements the first set of characters.
       
  4953       </p>
       
  4954       <pre class="programlisting">
       
  4955        $ tr -cd '[:alnum:]'
       
  4956       </pre>
       
  4957       <p id="ch7interim_assessment_1ab">
       
  4958        therefore removes all non-alphanumeric characters.
       
  4959       </p>
       
  4960       <p id="ch7interim_assessment_1ac">
       
  4961        The
       
  4962        <span class="emphasis">
       
  4963         <em>
       
  4964          -s
       
  4965         </em>
       
  4966        </span>
       
  4967        flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
       
  4968       </p>
       
  4969       <pre class="programlisting">
       
  4970        $ tr -s '\n' '\n'
       
  4971       </pre>
       
  4972       <p id="ch7interim_assessment_1ad">
       
  4973        replaces sequences of one or more newline characters with a single newline.
       
  4974       </p>
       
  4975       <p id="ch7interim_assessment_1ae">
       
  4976        The
       
  4977        <span class="emphasis">
       
  4978         <em>
       
  4979          -d
       
  4980         </em>
       
  4981        </span>
       
  4982        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.
       
  4983       </p>
       
  4984       <pre class="programlisting">
       
  4985        $ tr -d '\r'
       
  4986       </pre>
       
  4987       <p id="ch7interim_assessment_1af">
       
  4988        Most versions of
       
  4989        <span class="emphasis">
       
  4990         <em>
       
  4991          tr
       
  4992         </em>
       
  4993        </span>
       
  4994        , including GNU
       
  4995        <span class="emphasis">
       
  4996         <em>
       
  4997          tr
       
  4998         </em>
       
  4999        </span>
       
  5000        and classic Unix
       
  5001        <span class="emphasis">
       
  5002         <em>
       
  5003          tr
       
  5004         </em>
       
  5005        </span>
       
  5006        , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
       
  5007       </p>
       
  5008       <p id="ch7interim_assessment_1b0">
       
  5009        Ruby and Perl also have an internal
       
  5010        <span class="emphasis">
       
  5011         <em>
       
  5012          tr
       
  5013         </em>
       
  5014        </span>
       
  5015        operator, which operates analogously. Tcl's
       
  5016        <span class="emphasis">
       
  5017         <em>
       
  5018          string map
       
  5019         </em>
       
  5020        </span>
       
  5021        command is more general in that it maps strings to strings while
       
  5022        <span class="emphasis">
       
  5023         <em>
       
  5024          tr
       
  5025         </em>
       
  5026        </span>
       
  5027        maps characters to characters.
       
  5028       </p>
       
  5029      </div>
       
  5030     </div>
       
  5031     <div class="section" title="14.Elementary Regex">
       
  5032      <div class="titlepage">
       
  5033       <div>
       
  5034        <div>
       
  5035         <h2 class="title" style="clear: both">
       
  5036          <a name="id2657002">
       
  5037          </a>
       
  5038          14.Elementary Regex
       
  5039         </h2>
       
  5040        </div>
       
  5041       </div>
       
  5042      </div>
       
  5043      <p id="ch7interim_assessment_1b1">
       
  5044       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.
       
  5045      </p>
       
  5046      <p id="ch7interim_assessment_1b2">
       
  5047       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
       
  5048       <span class="emphasis">
       
  5049        <em>
       
  5050         ed
       
  5051        </em>
       
  5052       </span>
       
  5053       and the filter
       
  5054       <span class="emphasis">
       
  5055        <em>
       
  5056         grep
       
  5057        </em>
       
  5058       </span>
       
  5059       were the first to popularize the concept of regular expressions.
       
  5060      </p>
       
  5061      <p id="ch7interim_assessment_1b3">
       
  5062       Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
       
  5063       <span class="emphasis">
       
  5064        <em>
       
  5065         Basic Regular Expressions
       
  5066        </em>
       
  5067       </span>
       
  5068       (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.
       
  5069      </p>
       
  5070      <p id="ch7interim_assessment_1b4">
       
  5071       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.
       
  5072      </p>
       
  5073      <table summary="Elementary Regex" border="1">
       
  5074       <colgroup>
       
  5075        <col width="13">
       
  5076        </col>
       
  5077        <col width="60">
       
  5078        </col>
       
  5079       </colgroup>
       
  5080      </table>
       
  5081      <div class="section" title="14.1.Lazy quantification">
       
  5082       <div class="titlepage">
       
  5083        <div>
       
  5084         <div>
       
  5085          <h3 class="title">
       
  5086           <a name="id2657216">
       
  5087           </a>
       
  5088           14.1.Lazy quantification
       
  5089          </h3>
       
  5090         </div>
       
  5091        </div>
       
  5092       </div>
       
  5093       <p id="ch7interim_assessment_1c9">
       
  5094        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:
       
  5095       </p>
       
  5096       <pre class="programlisting">
       
  5097        Another whale explosion occurred on &lt;January 26&gt;, &lt;2004&gt;.
       
  5098       </pre>
       
  5099       <p id="ch7interim_assessment_1ca">
       
  5100        ...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 * 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".
       
  5101       </p>
       
  5102       <p id="ch7interim_assessment_1cb">
       
  5103        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
       
  5104        <span class="emphasis">
       
  5105         <em>
       
  5106          lazy
       
  5107         </em>
       
  5108        </span>
       
  5109        (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.
       
  5110       </p>
       
  5111      </div>
       
  5112     </div>
       
  5113     <div class="section" title="15.One Liners">
       
  5114      <div class="titlepage">
       
  5115       <div>
       
  5116        <div>
       
  5117         <h2 class="title" style="clear: both">
       
  5118          <a name="id2657292">
       
  5119          </a>
       
  5120          15.One Liners
       
  5121         </h2>
       
  5122        </div>
       
  5123       </div>
       
  5124      </div>
       
  5125      <p id="ch7interim_assessment_1cc">
       
  5126       A
       
  5127       <span class="emphasis">
       
  5128        <em>
       
  5129         one-liner
       
  5130        </em>
       
  5131       </span>
       
  5132       is textual input to the command-line of an operating system shell that performs some function in just one line of input.
       
  5133      </p>
       
  5134      <p id="ch7interim_assessment_1cd">
       
  5135       The one liner can be
       
  5136      </p>
       
  5137      <div class="orderedlist">
       
  5138       <ol class="orderedlist" type="1">
       
  5139        <li class="listitem">
       
  5140         <p id="ch7interim_assessment_1ce">
       
  5141          An expression written in the language of the shell.
       
  5142         </p>
       
  5143        </li>
       
  5144        <li class="listitem">
       
  5145         <p id="ch7interim_assessment_1cf">
       
  5146          The invocation of an interpreter together with program source for the interpreter to run.
       
  5147         </p>
       
  5148        </li>
       
  5149        <li class="listitem">
       
  5150         <p id="ch7interim_assessment_1d0">
       
  5151          The invocation of a compiler together with source to compile and
       
  5152 instructions for executing the compiled program.
       
  5153         </p>
       
  5154        </li>
       
  5155       </ol>
       
  5156      </div>
       
  5157      <p id="ch7interim_assessment_1d1">
       
  5158       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.
       
  5159      </p>
       
  5160      <p id="ch7interim_assessment_1d2">
       
  5161       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.
       
  5162      </p>
       
  5163      <p id="ch7interim_assessment_1d3">
       
  5164       The word
       
  5165       <span class="emphasis">
       
  5166        <em>
       
  5167         One-liner
       
  5168        </em>
       
  5169       </span>
       
  5170       has two references in the index of the book
       
  5171       <span class="emphasis">
       
  5172        <em>
       
  5173         The AWK Programming Language
       
  5174        </em>
       
  5175       </span>
       
  5176       (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:
       
  5177      </p>
       
  5178      <pre class="programlisting">
       
  5179       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.
       
  5180      </pre>
       
  5181      <p id="ch7interim_assessment_1d4">
       
  5182       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.
       
  5183      </p>
       
  5184      <p id="ch7interim_assessment_1d5">
       
  5185       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.
       
  5186      </p>
       
  5187      <p id="ch7interim_assessment_1d6">
       
  5188       Here are the first few of them:
       
  5189      </p>
       
  5190      <div class="orderedlist">
       
  5191       <ol class="orderedlist" type="1">
       
  5192        <li class="listitem">
       
  5193         <p id="ch7interim_assessment_1d7">
       
  5194          Print the total number of input lines:
       
  5195         </p>
       
  5196         <p id="ch7interim_assessment_1d8">
       
  5197          END { print NR }
       
  5198         </p>
       
  5199        </li>
       
  5200        <li class="listitem">
       
  5201         <p id="ch7interim_assessment_1d9">
       
  5202          Print the tenth input line:
       
  5203         </p>
       
  5204         <p id="ch7interim_assessment_1da">
       
  5205          NR == 10
       
  5206         </p>
       
  5207        </li>
       
  5208        <li class="listitem">
       
  5209         <p id="ch7interim_assessment_1db">
       
  5210          Print the last field of every input line:
       
  5211         </p>
       
  5212         <p id="ch7interim_assessment_1dc">
       
  5213          { print $NF }
       
  5214         </p>
       
  5215        </li>
       
  5216       </ol>
       
  5217      </div>
       
  5218      <p id="ch7interim_assessment_1dd">
       
  5219       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.
       
  5220      </p>
       
  5221      <p id="ch7interim_assessment_1de">
       
  5222       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).:
       
  5223      </p>
       
  5224      <pre class="programlisting">
       
  5225       main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
       
  5226 *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);}
       
  5227      </pre>
       
  5228      <p id="ch7interim_assessment_1df">
       
  5229       This one-liner program is a
       
  5230       <span class="emphasis">
       
  5231        <em>
       
  5232         glob pattern matcher
       
  5233        </em>
       
  5234       </span>
       
  5235       . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
       
  5236      </p>
       
  5237      <p id="ch7interim_assessment_1e0">
       
  5238       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:
       
  5239      </p>
       
  5240      <pre class="programlisting">
       
  5241       $ prog foo 'f??'; echo $?
       
  5242 
       
  5243 $ prog 'best short program' '??st*o**p?*'; echo $?
       
  5244      </pre>
       
  5245      <p id="ch7interim_assessment_1e1">
       
  5246       Here is a one line shell script to show directories:
       
  5247      </p>
       
  5248      <pre class="programlisting">
       
  5249       $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
       
  5250      </pre>
       
  5251     </div>
       
  5252    </div>
    50    </div>
  5253   </div>
    51   </div>
  5254  </body>
    52  </body>
  5255 </html>
    53 </html>