SEESenv/web/html/ch9Using_Linux_Tools.html
author amit@thunder
Thu, 25 Feb 2010 00:45:20 +0530
changeset 28 514098969b11
parent 27 cb14131583c6
permissions -rw-r--r--
Testing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents:
diff changeset
     1
<html>
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     2
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Chapter. Using_Linux_Tools</title><link rel="stylesheet" href="/review/support/styles.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.74.3" /><link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png" /><script type="text/javascript" src="/review/support/jquery-min.js"></script><script type="text/javascript" src="/review/support/form.js"></script><script type="text/javascript" src="/review/support/hsbook.js"></script></head>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     3
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter" id="ch9Using_Linux_Tools">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     4
<div class="titlepage"></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     5
<div class="toc">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     6
<p><b>Table of Contents</b></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     7
<dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     8
<dt><span class="article"><a href="#id2915025"></a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
     9
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    10
<dt><span class="section"><a href="#id2725116">1. Introducing Linux</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    11
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    12
<dt><span class="section"><a href="#id2722785">1.1. Historical Background</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    13
<dt><span class="section"><a href="#id2966078">1.2. Design and Implications</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    14
<dt><span class="section"><a href="#id2966362">1.3. Reasons for Using Linux</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    15
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    16
<dt><span class="section"><a href="#id2966502">2. Getting Started</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    17
<dd><dl><dt><span class="section"><a href="#id2966511">2.1. Logging in, activating the user interface and logging out</a></span></dt></dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    18
<dt><span class="section"><a href="#id2966791">3. Basic Commands</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    19
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    20
<dt><span class="section"><a href="#id2966799">3.1. ls</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    21
<dt><span class="section"><a href="#id2966962">3.2. date</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    22
<dt><span class="section"><a href="#id2967022">3.3. cd</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    23
<dt><span class="section"><a href="#id2967124">3.4. who</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    24
<dt><span class="section"><a href="#id2967207">3.5. mkdir</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    25
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    26
<dt><span class="section"><a href="#id2967374">4. Getting Help</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    27
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    28
<dt><span class="section"><a href="#id2967383">4.1. apropos and whatis</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    29
<dt><span class="section"><a href="#id2967478">4.2. man</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    30
<dt><span class="section"><a href="#id2967672">4.3. info</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    31
<dt><span class="section"><a href="#id2967759">4.4. --help</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    32
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    33
<dt><span class="section"><a href="#id2967812">5. Basic file handling</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    34
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    35
<dt><span class="section"><a href="#id2967820">5.1. cp</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    36
<dt><span class="section"><a href="#id2968133">5.2. mv</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    37
<dt><span class="section"><a href="#id2968265">5.3. rm</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    38
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    39
<dt><span class="section"><a href="#id2968433">6. Command Line Arguments</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    40
<dt><span class="section"><a href="#id2968526">7. Basic Text Processing</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    41
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    42
<dt><span class="section"><a href="#id2968535">7.1. head</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    43
<dt><span class="section"><a href="#id2968622">7.2. tail</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    44
<dt><span class="section"><a href="#id2968750">7.3. cut</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    45
<dt><span class="section"><a href="#id2968837">7.4. paste</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    46
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    47
<dt><span class="section"><a href="#id2968957">8. Shell Meta Characters</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    48
<dt><span class="section"><a href="#id2969064">9. Looking At Files</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    49
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    50
<dt><span class="section"><a href="#id2969072">9.1. cat</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    51
<dt><span class="section"><a href="#id2969260">9.2. more</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    52
<dt><span class="section"><a href="#id2969371">9.3. less</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    53
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    54
<dt><span class="section"><a href="#id2969612">10. Directory Structure</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    55
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    56
<dt><span class="section"><a href="#id2969877">10.1. man hier</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    57
<dt><span class="section"><a href="#id2969893">10.2. ls -l</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    58
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    59
<dt><span class="section"><a href="#id2969916">11. Permissions and Ownership</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    60
<dd><dl><dt><span class="section"><a href="#id2969925">11.1. chmod</a></span></dt></dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    61
<dt><span class="section"><a href="#id2965366">12. Redirection and Piping</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    62
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    63
<dt><span class="section"><a href="#id2970852">12.1. Redirecting standard input and standard output</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    64
<dt><span class="section"><a href="#id2970920">12.2. Piping</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    65
<dt><span class="section"><a href="#id2970982">12.3. Redirecting to and from the standard file handles</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    66
<dt><span class="section"><a href="#id2971176">12.4. Chained pipelines</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    67
<dt><span class="section"><a href="#id2971209">12.5. Redirect to multiple outputs</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    68
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    69
<dt><span class="section"><a href="#id2971240">13. More Text Processing</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    70
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    71
<dt><span class="section"><a href="#id2971248">13.1. grep</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    72
<dt><span class="section"><a href="#id2971438">13.2. tr</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    73
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    74
<dt><span class="section"><a href="#id2971585">14. Elementary Regex</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    75
<dd><dl><dt><span class="section"><a href="#id2971786">14.1. Lazy quantification</a></span></dt></dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    76
<dt><span class="section"><a href="#id2971862">15. One Liners</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    77
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    78
</dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    79
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    80
<div class="article">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    81
<div class="titlepage">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    82
<div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    83
<div><h2 class="title" id="id2915025"></h2></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    84
<div><h2 class="title" id="id2915025"></h2></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    85
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    86
<hr />
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    87
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    88
<div class="toc">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    89
<p><b>Table of Contents</b></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    90
<dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    91
<dt><span class="section"><a href="#id2725116">1. Introducing Linux</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    92
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    93
<dt><span class="section"><a href="#id2722785">1.1. Historical Background</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    94
<dt><span class="section"><a href="#id2966078">1.2. Design and Implications</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    95
<dt><span class="section"><a href="#id2966362">1.3. Reasons for Using Linux</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    96
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    97
<dt><span class="section"><a href="#id2966502">2. Getting Started</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    98
<dd><dl><dt><span class="section"><a href="#id2966511">2.1. Logging in, activating the user interface and logging out</a></span></dt></dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
    99
<dt><span class="section"><a href="#id2966791">3. Basic Commands</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   100
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   101
<dt><span class="section"><a href="#id2966799">3.1. ls</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   102
<dt><span class="section"><a href="#id2966962">3.2. date</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   103
<dt><span class="section"><a href="#id2967022">3.3. cd</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   104
<dt><span class="section"><a href="#id2967124">3.4. who</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   105
<dt><span class="section"><a href="#id2967207">3.5. mkdir</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   106
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   107
<dt><span class="section"><a href="#id2967374">4. Getting Help</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   108
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   109
<dt><span class="section"><a href="#id2967383">4.1. apropos and whatis</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   110
<dt><span class="section"><a href="#id2967478">4.2. man</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   111
<dt><span class="section"><a href="#id2967672">4.3. info</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   112
<dt><span class="section"><a href="#id2967759">4.4. --help</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   113
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   114
<dt><span class="section"><a href="#id2967812">5. Basic file handling</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   115
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   116
<dt><span class="section"><a href="#id2967820">5.1. cp</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   117
<dt><span class="section"><a href="#id2968133">5.2. mv</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   118
<dt><span class="section"><a href="#id2968265">5.3. rm</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   119
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   120
<dt><span class="section"><a href="#id2968433">6. Command Line Arguments</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   121
<dt><span class="section"><a href="#id2968526">7. Basic Text Processing</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   122
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   123
<dt><span class="section"><a href="#id2968535">7.1. head</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   124
<dt><span class="section"><a href="#id2968622">7.2. tail</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   125
<dt><span class="section"><a href="#id2968750">7.3. cut</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   126
<dt><span class="section"><a href="#id2968837">7.4. paste</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   127
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   128
<dt><span class="section"><a href="#id2968957">8. Shell Meta Characters</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   129
<dt><span class="section"><a href="#id2969064">9. Looking At Files</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   130
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   131
<dt><span class="section"><a href="#id2969072">9.1. cat</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   132
<dt><span class="section"><a href="#id2969260">9.2. more</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   133
<dt><span class="section"><a href="#id2969371">9.3. less</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   134
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   135
<dt><span class="section"><a href="#id2969612">10. Directory Structure</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   136
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   137
<dt><span class="section"><a href="#id2969877">10.1. man hier</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   138
<dt><span class="section"><a href="#id2969893">10.2. ls -l</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   139
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   140
<dt><span class="section"><a href="#id2969916">11. Permissions and Ownership</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   141
<dd><dl><dt><span class="section"><a href="#id2969925">11.1. chmod</a></span></dt></dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   142
<dt><span class="section"><a href="#id2965366">12. Redirection and Piping</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   143
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   144
<dt><span class="section"><a href="#id2970852">12.1. Redirecting standard input and standard output</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   145
<dt><span class="section"><a href="#id2970920">12.2. Piping</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   146
<dt><span class="section"><a href="#id2970982">12.3. Redirecting to and from the standard file handles</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   147
<dt><span class="section"><a href="#id2971176">12.4. Chained pipelines</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   148
<dt><span class="section"><a href="#id2971209">12.5. Redirect to multiple outputs</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   149
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   150
<dt><span class="section"><a href="#id2971240">13. More Text Processing</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   151
<dd><dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   152
<dt><span class="section"><a href="#id2971248">13.1. grep</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   153
<dt><span class="section"><a href="#id2971438">13.2. tr</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   154
</dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   155
<dt><span class="section"><a href="#id2971585">14. Elementary Regex</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   156
<dd><dl><dt><span class="section"><a href="#id2971786">14.1. Lazy quantification</a></span></dt></dl></dd>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   157
<dt><span class="section"><a href="#id2971862">15. One Liners</a></span></dt>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   158
</dl>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   159
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   160
<div class="section" title="1.Introducing Linux">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   161
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   162
<a name="id2725116"></a>1.Introducing Linux</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   163
<p id="ch9Using_Linux_Tools_1">(Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   164
<p id="ch9Using_Linux_Tools_2">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.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   165
<p id="ch9Using_Linux_Tools_3">Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   166
<p id="ch9Using_Linux_Tools_4">The name "Linux"  comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   167
<div class="section" title="1.1.Historical Background">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   168
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   169
<a name="id2722785"></a>1.1.Historical Background</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   170
<div class="section" title="1.1.1.Events leading to the creation">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   171
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   172
<a name="id2913514"></a>1.1.1.Events leading to the creation</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   173
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   174
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_5">The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   175
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_6">In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   176
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   177
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   178
<div class="section" title="1.1.2.The Creation of Linux">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   179
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   180
<a name="id2966043"></a>1.1.2.The Creation of Linux</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   181
<p id="ch9Using_Linux_Tools_7">In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   182
<p id="ch9Using_Linux_Tools_8">Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   183
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   184
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   185
<div class="section" title="1.2.Design and Implications">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   186
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   187
<a name="id2966078"></a>1.2.Design and Implications</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   188
<p id="ch9Using_Linux_Tools_9">A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   189
<div class="section" title="1.2.1.User Interface">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   190
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   191
<a name="id2966102"></a>1.2.1.User Interface</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   192
<p id="ch9Using_Linux_Tools_a">Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   193
<p id="ch9Using_Linux_Tools_b">A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   194
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   195
<div class="section" title="1.2.2.Development">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   196
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   197
<a name="id2966156"></a>1.2.2.Development</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   198
<p id="ch9Using_Linux_Tools_c">The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   199
<p id="ch9Using_Linux_Tools_d">Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   200
<p id="ch9Using_Linux_Tools_e">A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   201
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   202
<div class="section" title="1.2.3.Community">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   203
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   204
<a name="id2966223"></a>1.2.3.Community</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   205
<p id="ch9Using_Linux_Tools_f">A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   206
<p id="ch9Using_Linux_Tools_10">In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   207
<p id="ch9Using_Linux_Tools_11">Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   208
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   209
<div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   210
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   211
<a name="id2966268"></a>1.2.4.Can I make a profit out of running a business involving Linux?</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   212
<p id="ch9Using_Linux_Tools_12">The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   213
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   214
<div class="section" title="1.2.5.Programming on Linux">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   215
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   216
<a name="id2966314"></a>1.2.5.Programming on Linux</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   217
<p id="ch9Using_Linux_Tools_13">Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   218
<p id="ch9Using_Linux_Tools_14">Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   219
<p id="ch9Using_Linux_Tools_15">The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   220
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   221
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   222
<div class="section" title="1.3.Reasons for Using Linux">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   223
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   224
<a name="id2966362"></a>1.3.Reasons for Using Linux</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   225
<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_16">Linux is free:</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   226
<p id="ch9Using_Linux_Tools_17">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.
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   227
Most of all, Linux is free as in "free speech":
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   228
The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   229
<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_18">Linux is portable to any hardware platform:</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   230
<p id="ch9Using_Linux_Tools_19">A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   231
<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_1a">Linux was made to keep on running:</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   232
<p id="ch9Using_Linux_Tools_1b">As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   233
<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_1c">Linux is secure and versatile:</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   234
<p id="ch9Using_Linux_Tools_1d">The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   235
<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_1e">Linux is scalable:</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   236
<p id="ch9Using_Linux_Tools_1f">From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   237
<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_20">The Linux OS and Linux applications have very short debugtimes:</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   238
<p id="ch9Using_Linux_Tools_21">Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   239
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   240
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   241
<div class="section" title="2.Getting Started">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   242
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   243
<a name="id2966502"></a>2.Getting Started</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   244
<div class="section" title="2.1.Logging in, activating the user interface and logging out">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   245
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   246
<a name="id2966511"></a>2.1.Logging in, activating the user interface and logging out</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   247
<p id="ch9Using_Linux_Tools_22">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.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   248
<div class="section" title="2.1.1.Graphical Mode">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   249
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   250
<a name="id2966541"></a>2.1.1.Graphical Mode</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   251
<p id="ch9Using_Linux_Tools_23">This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   252
<p id="ch9Using_Linux_Tools_24">To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click <span class="emphasis"><em>OK</em></span> or press <span class="emphasis"><em>Enter</em></span>.
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   253
It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   254
<p id="ch9Using_Linux_Tools_25">After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   255
<p id="ch9Using_Linux_Tools_26">To continue, you will need to open a <span class="emphasis"><em>terminal window</em></span> or <span class="emphasis"><em>xterm</em></span> for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the <span class="emphasis"><em>Applications&gt;Utilities-&gt;System Tools</em></span> or <span class="emphasis"><em>Internet menu</em></span>, depending on what window manager you are using. There might be icons that you can use as a shortcut to get an <span class="emphasis"><em>xterm</em></span> window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   256
<p id="ch9Using_Linux_Tools_27">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.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   257
<p id="ch9Using_Linux_Tools_28">A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   258
<p id="ch9Using_Linux_Tools_29">Another common form for a prompt is this one:
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   259
[</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   260
<div class="reference">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   261
<div class="titlepage"><hr /></div>user@host</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   262
<p> dir]</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   263
<p id="ch9Using_Linux_Tools_2a">In the above example, <span class="emphasis"><em>user</em></span> will be your login name, <span class="emphasis"><em>hosts</em></span> the name of the machine you are working on, and <span class="emphasis"><em>dir</em></span> an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the <span class="emphasis"><em>logout</em></span> icon or find <span class="emphasis"><em>Log Out</em></span> in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   264
<p id="ch9Using_Linux_Tools_2b">When you see the login screen again, asking to enter user name and password, logout was successful.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   265
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   266
<div class="section" title="2.1.2.Text Mode">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   267
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   268
<a name="id2966701"></a>2.1.2.Text Mode</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   269
<p id="ch9Using_Linux_Tools_2c">One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   270
<p id="ch9Using_Linux_Tools_2d">The login is different from a graphical login, in that you have to hit the <span class="emphasis"><em>Enter</em></span> key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another <span class="emphasis"><em>Enter</em></span>. You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   271
reasons.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   272
<p id="ch9Using_Linux_Tools_2e">When the system has accepted you as a valid user, you may get some more information, called the <span class="emphasis"><em>message of the day</em></span>, which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   273
<p id="ch9Using_Linux_Tools_2f">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.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   274
<p id="ch9Using_Linux_Tools_30">Logging out is done by entering the <span class="emphasis"><em>logout</em></span> command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't 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!</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   275
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   276
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   277
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   278
<div class="section" title="3.Basic Commands">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   279
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   280
<a name="id2966791"></a>3.Basic Commands</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   281
<div class="section" title="3.1.ls">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   282
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   283
<a name="id2966799"></a>3.1.ls</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   284
<p id="ch9Using_Linux_Tools_31">When invoked without any arguments, <span class="emphasis"><em>ls</em></span> lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name <span class="emphasis"><em>ls</em></span> is derived from <span class="emphasis"><em>list segments</em></span> which was used in earlier systems.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   285
<p id="ch9Using_Linux_Tools_32">Files whose names start with "." are not listed, unless the <span class="emphasis"><em>-a</em></span> flag is specified or the files are specified explicitly.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   286
<p id="ch9Using_Linux_Tools_33">Without options, <span class="emphasis"><em>ls</em></span> displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   287
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   288
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_34"><span class="emphasis"><em>-l</em></span> long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   289
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_35"><span class="emphasis"><em>-F</em></span> appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   290
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_36"><span class="emphasis"><em>-a</em></span> lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   291
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_37"><span class="emphasis"><em>-R</em></span> recursively lists subdirectories. The command ls -R / would therefore list all files.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   292
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_38"><span class="emphasis"><em>-d</em></span> shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   293
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_39"><span class="emphasis"><em>-t</em></span> sort the list of files by modification time.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   294
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_3a"><span class="emphasis"><em>-h</em></span> print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   295
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   296
<p id="ch9Using_Linux_Tools_3b">In some environments, providing the option <span class="emphasis"><em>--color</em></span> (for GNU ls) or <span class="emphasis"><em>-G</em></span> (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as <span class="emphasis"><em>-F</em></span> would. To determine what color to use for a file, GNU <span class="emphasis"><em>ls</em></span> checks the Unix file type, the file permissions, and the file extension, while FreeBSD <span class="emphasis"><em>ls</em></span> checks only the Unix file type and file permissions.:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   297
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   298
$ ls
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   299
jeeves.rst psmith.html blandings.html
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   300
$ ls -l
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   301
drwxr--r--   1 plum  editors   4096  jeeves
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   302
-rw-r--r--   1 plum  editors  30405  psmith
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   303
-r-xr-xr-x   1 plum  plum      8460  blandings</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   304
<p id="ch9Using_Linux_Tools_3c">Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   305
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   306
<div class="section" title="3.2.date">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   307
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   308
<a name="id2966962"></a>3.2.date</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   309
<p id="ch9Using_Linux_Tools_3d">The Unix date command displays the time and date. The super-user can use it to set the system clock.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   310
<p id="ch9Using_Linux_Tools_3e">With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   311
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   312
$date
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   313
Tue Sep  8 12:01:45 IST 2009</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   314
<p id="ch9Using_Linux_Tools_3f">On some systems to set the current date and time to September 8, 2004 01:22 you type:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   315
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   316
$date --set="20040908 01:22"</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   317
<p id="ch9Using_Linux_Tools_40">In order to view the various options for the <span class="emphasis"><em>date</em></span> command, type:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   318
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   319
$man date</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   320
<p id="ch9Using_Linux_Tools_41">This will take you to the "Manual" page comprising of all the details on the <span class="emphasis"><em>date</em></span> command. You can return to the terminal from the "man" page by pressing the <span class="emphasis"><em>Esc</em></span> key in the keyboard and typing ":q" in that order.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   321
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   322
<div class="section" title="3.3.cd">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   323
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   324
<a name="id2967022"></a>3.3.cd</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   325
<p id="ch9Using_Linux_Tools_42">This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered,  cd .. can be used.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   326
<p id="ch9Using_Linux_Tools_43">One dot '.' represents the current directory while two dots '..' represent the parent directory.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   327
<p id="ch9Using_Linux_Tools_44"> cd - will return you to the previous directory (a bit like an undo).</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   328
<p id="ch9Using_Linux_Tools_45">You can also use cd absolute path or cd relative path (see below):</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   329
<p id="ch9Using_Linux_Tools_46">Absolute paths:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   330
<p id="ch9Using_Linux_Tools_47">An  absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   331
<p id="ch9Using_Linux_Tools_48">For example to get to /boot/grub you would type:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   332
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   333
$cd /boot/grub</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   334
<p id="ch9Using_Linux_Tools_49">This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   335
<p id="ch9Using_Linux_Tools_4a">Relative paths:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   336
<p id="ch9Using_Linux_Tools_4b">A  relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   337
<p id="ch9Using_Linux_Tools_4c">For example if you are in root's home directory and want to get to /root/music, you type:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   338
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   339
$ cd music</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   340
<p id="ch9Using_Linux_Tools_4d">Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   341
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   342
<div class="section" title="3.4.who">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   343
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   344
<a name="id2967124"></a>3.4.who</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   345
<p id="ch9Using_Linux_Tools_4e">The standard Unix command <span class="emphasis"><em>who</em></span> displays a list of users who are currently logged into a computer.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   346
<p id="ch9Using_Linux_Tools_4f">The <span class="emphasis"><em>who</em></span> command is related to the command <span class="emphasis"><em>w</em></span>, which provides the same information but also displays additional data and statistics.:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   347
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   348
$who
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   349
beeblebrox tty7         2009-09-08 10:50 (:0)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   350
beeblebrox pts/0        2009-09-08 11:25 (:0.0)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   351
dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   352
beeblebrox pts/2        2009-09-08 18:53 (:0.0)</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   353
<p id="ch9Using_Linux_Tools_50">The command can be invoked with the arguments <span class="emphasis"><em>am i</em></span> or <span class="emphasis"><em>am I</em></span> (so it is invoked as <span class="emphasis"><em>who am i</em></span> or * who am I*), showing information about the current terminal only (see the <span class="emphasis"><em>-m</em></span> option below, of which this invocation is equivalent).</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   354
<p id="ch9Using_Linux_Tools_51">In order to find out the various options that can be appended to the <span class="emphasis"><em>who</em></span> command, check the <span class="emphasis"><em>man</em></span> page by typing out the following in the terminal:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   355
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   356
$man who</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   357
<p id="ch9Using_Linux_Tools_52">This will take you to the "Manual" page containing details about the <span class="emphasis"><em>who</em></span> command</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   358
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   359
<div class="section" title="3.5.mkdir">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   360
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   361
<a name="id2967207"></a>3.5.mkdir</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   362
<p id="ch9Using_Linux_Tools_53">This command is used to make a new directory. Normal usage is as straightforward as follows:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   363
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   364
$mkdir name_of_directory</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   365
<p id="ch9Using_Linux_Tools_54">Where <span class="emphasis"><em>name_of_directory</em></span> is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and <span class="emphasis"><em>mkdir</em></span> will try to create all of them.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   366
<div class="section" title="3.5.1.Options">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   367
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   368
<a name="id2967239"></a>3.5.1.Options</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   369
<p id="ch9Using_Linux_Tools_55">On Unix-like operating systems, <span class="emphasis"><em>mkdir</em></span> takes options. Three of the most common options are:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   370
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   371
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_56"><span class="emphasis"><em>-p</em></span>: will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   372
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_57"><span class="emphasis"><em>-v</em></span>: display each directory that mkdir creates. Most often used with -p.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   373
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_58"><span class="emphasis"><em>-m</em></span>: specify the octal permissions of directories created by mkdir.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   374
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   375
<p id="ch9Using_Linux_Tools_59"><span class="emphasis"><em>-p</em></span> is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   376
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   377
<div class="section" title="3.5.2.Examples">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   378
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   379
<a name="id2967298"></a>3.5.2.Examples</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   380
<p id="ch9Using_Linux_Tools_5a">An example of <span class="emphasis"><em>-p</em></span> in action is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   381
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   382
$mkdir -p /tmp/a/b/c</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   383
<p id="ch9Using_Linux_Tools_5b">If <span class="emphasis"><em>/tmp/a</em></span> exists but <span class="emphasis"><em>/tmp/a/b</em></span> does not, mkdir will create <span class="emphasis"><em>/tmp/a/b</em></span> before creating <span class="emphasis"><em>/tmp/a/b/c</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   384
<p id="ch9Using_Linux_Tools_5c">And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   385
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   386
$mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   387
<p id="ch9Using_Linux_Tools_5d">This will create:</p>tmpdir  - branches<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   388
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_5e">tag</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   389
<li class="listitem" style="list-style-type: *">trunk - sources - includes<div class="itemizedlist"><ul class="itemizedlist" type="*"><li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_5f">docs</p></li></ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   390
</li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   391
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   392
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   393
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   394
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   395
<div class="section" title="4.Getting Help">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   396
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   397
<a name="id2967374"></a>4.Getting Help</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   398
<div class="section" title="4.1.apropos and whatis">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   399
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   400
<a name="id2967383"></a>4.1.apropos and whatis</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   401
<p id="ch9Using_Linux_Tools_60">This is a command to search the manual pages files in Unix and Unix-like operating systems.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   402
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   403
$ apropos grep
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   404
egrep       egrep (1)       Search a file for a pattern using full regular expressions
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   405
fgrep       fgrep (1)       Search a file for a fixed-character string
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   406
fmlgrep     fmlgrep (1)     Search a file for a pattern
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   407
grep        grep (1)        Search a file for a pattern
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   408
gzgrep      gzgrep (1)      Search a possibly compressed file for a regular expression
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   409
nisgrep     nismatch (1)    Utilities for searching NIS+ tables
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   410
pgrep       pgrep (1)       Find or signal a process by name or other attribute
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   411
zgrep       zgrep (1)       Search a possibly compressed file for a regular expression
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   412
...</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   413
<p id="ch9Using_Linux_Tools_61">In this example, the user uses <span class="emphasis"><em>apropos</em></span> to search for the string "grep", and apropos returns the indicated <span class="emphasis"><em>man</em></span> pages that include the term "grep".</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   414
<p id="ch9Using_Linux_Tools_62">A short index of explanations for commands is available using the <span class="emphasis"><em>whatis</em></span> command, like in the examples below:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   415
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   416
$whatis ls
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   417
ls (1)           - list directory contents</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   418
<p id="ch9Using_Linux_Tools_63">This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   419
<p id="ch9Using_Linux_Tools_64">If you don't know where to get started and which man page to read, <span class="emphasis"><em>apropos</em></span> gives more information. Say that you do not know how to start a browser, then you could enter the following command:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   420
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   421
$apropos browser
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   422
gmusicbrowser (1)    - Jukebox for large collections of audio files
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   423
infobrowser (1)      - read Info documents
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   424
libsmbclient (7)     - An extension library for browsers and that               can be used...
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   425
opera (1)            - a standards-compliant graphical Web browser
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   426
sensible-browser (1) - sensible editing, paging, and web browsing
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   427
smbtree (1)          - A text based smb network browser
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   428
tvtk_doc (1)         - A GUI based TVTK documentation search browser.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   429
viewres (1)          - graphical class browser for Xt
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   430
w3m (1)              - a text based Web browser and pager
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   431
www-browser (1)      - a text based Web browser and pager
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   432
...</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   433
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   434
<div class="section" title="4.2.man">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   435
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   436
<a name="id2967478"></a>4.2.man</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   437
<p id="ch9Using_Linux_Tools_65">Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is <span class="emphasis"><em>man</em></span>. Each page is a self-contained document.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   438
<p id="ch9Using_Linux_Tools_66">To read a manual page for a Unix command, one can use:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   439
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   440
$ man &lt;command_name&gt;</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   441
<p id="ch9Using_Linux_Tools_67">at a shell prompt; for example, "man ftp". In order to simplify navigation through the output, <span class="emphasis"><em>man</em></span> generally uses the less terminal pager.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   442
<p id="ch9Using_Linux_Tools_68">Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are <span class="emphasis"><em>man(1)</em></span> and <span class="emphasis"><em>man(7)</em></span>, or <span class="emphasis"><em>exit(2)</em></span> and <span class="emphasis"><em>exit(3)</em></span>. The syntax for accessing the non-default manual section varies between different man implementations. On Linux and <span class="emphasis"><em>BSD, for example, the syntax for reading *printf(3)</em></span> is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   443
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   444
$man 3 printf</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   445
<p id="ch9Using_Linux_Tools_69">Another example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   446
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   447
$man man</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   448
<p id="ch9Using_Linux_Tools_6a">The previous example will take you to the "Manual" page entry about manual pages!</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   449
<div class="section" title="4.2.1.Layout">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   450
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   451
<a name="id2967561"></a>4.2.1.Layout</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   452
<p id="ch9Using_Linux_Tools_6b">All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:</p>NAME<p id="ch9Using_Linux_Tools_6c">The name of the command or function, followed by a one-line description of what it does.</p>SYNOPSIS<p id="ch9Using_Linux_Tools_6d">In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.</p>DESCRIPTION<p id="ch9Using_Linux_Tools_6e">A textual description of the functioning of the command or function.</p>EXAMPLES<p id="ch9Using_Linux_Tools_6f">Some examples of common usage.</p>SEE ALSO<p id="ch9Using_Linux_Tools_70">A list of related commands or functions.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   453
<p id="ch9Using_Linux_Tools_71">Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   454
<p id="ch9Using_Linux_Tools_72">These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to <span class="emphasis"><em>man</em></span> have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   455
<p id="ch9Using_Linux_Tools_73">However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   456
<p id="ch9Using_Linux_Tools_74">Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   457
<p id="ch9Using_Linux_Tools_75">Usually the man pages are written in English. Translations into other languages can be also available on the system.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   458
<p id="ch9Using_Linux_Tools_76">The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   459
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   460
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   461
<div class="section" title="4.3.info">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   462
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   463
<a name="id2967672"></a>4.3.info</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   464
<p id="ch9Using_Linux_Tools_77"><span class="emphasis"><em>info</em></span> is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   465
<p id="ch9Using_Linux_Tools_78">The syntax is</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   466
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   467
$ info &lt;command_name&gt;</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   468
<p id="ch9Using_Linux_Tools_79"><span class="emphasis"><em>info</em></span> processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   469
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   470
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_7a"><span class="emphasis"><em>n</em></span> goes to the next page.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   471
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_7b"><span class="emphasis"><em>p</em></span> goes to the previous page.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   472
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_7c"><span class="emphasis"><em>u</em></span> goes to the upper page.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   473
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_7d"><span class="emphasis"><em>l</em></span> goes to the last(visited) node</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   474
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_7e">To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   475
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   476
<p id="ch9Using_Linux_Tools_7f">info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   477
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   478
<div class="section" title="4.4.--help">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   479
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   480
<a name="id2967759"></a>4.4.--help</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   481
<p id="ch9Using_Linux_Tools_80">Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the <span class="emphasis"><em>cat</em></span> command:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   482
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   483
$ userprompt@host: cat --help
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   484
Usage: cat [OPTION] [FILE]...
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   485
Concatenate FILE(s), or standard input, to standard output.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   486
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   487
  -A, --show-all           equivalent to -vET
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   488
  -b, --number-nonblank    number nonempty output lines
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   489
  -e                       equivalent to -vE
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   490
  -E, --show-ends          display $ at end of each line
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   491
  -n, --number             number all output lines
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   492
  -s, --squeeze-blank      suppress repeated empty output lines
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   493
  -t                       equivalent to -vT
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   494
  -T, --show-tabs          display TAB characters as ^I
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   495
  -u                       (ignored)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   496
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and              TAB
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   497
  --help     display this help and exit
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   498
  --version  output version information and exit
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   499
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   500
With no FILE, or when FILE is -, read standard input.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   501
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   502
Examples:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   503
  cat f - g  Output f's contents, then standard input, then g's           contents.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   504
  cat        Copy standard input to standard output.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   505
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   506
Report bugs to &lt;bug-coreutils@gnu.org&gt;.</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   507
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   508
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   509
<div class="section" title="5.Basic file handling">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   510
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   511
<a name="id2967812"></a>5.Basic file handling</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   512
<div class="section" title="5.1.cp">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   513
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   514
<a name="id2967820"></a>5.1.cp</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   515
<p id="ch9Using_Linux_Tools_81"><span class="emphasis"><em>cp</em></span> is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   516
<div class="section" title="5.1.1.Usage">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   517
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   518
<a name="id2967838"></a>5.1.1.Usage</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   519
<p id="ch9Using_Linux_Tools_82">To copy a file to another file:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   520
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   521
$ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   522
<p id="ch9Using_Linux_Tools_83">To copy a file to a directory:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   523
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   524
$ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ...              TargetDirectory</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   525
<p id="ch9Using_Linux_Tools_84">To copy a directory to a directory:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   526
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   527
$ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   528
SourceDirectory ... TargetDirectory</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   529
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   530
<div class="section" title="5.1.2.Flags">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   531
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   532
<a name="id2967872"></a>5.1.2.Flags</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   533
<p id="ch9Using_Linux_Tools_85"><span class="emphasis"><em>-f</em></span> (force)  specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   534
<p id="ch9Using_Linux_Tools_86"><span class="emphasis"><em>-P</em></span>  makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   535
<p id="ch9Using_Linux_Tools_87"><span class="emphasis"><em>-i</em></span> (interactive)  prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   536
<p id="ch9Using_Linux_Tools_88"><span class="emphasis"><em>-p</em></span> (preserve)  duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   537
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   538
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_89">The time of the last data modification and the time of the last access.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   539
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_8a">The user ID and group ID (only if it has permissions to do this)</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   540
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_8b">The file permission bits and the SUID and SGID bits.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   541
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   542
<p id="ch9Using_Linux_Tools_8c"><span class="emphasis"><em>-R</em></span> (recursive)  copy directories (recursively copying all the contents)</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   543
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   544
<div class="section" title="5.1.3.Examples">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   545
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   546
<a name="id2967970"></a>5.1.3.Examples</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   547
<p id="ch9Using_Linux_Tools_8d">To make a copy of a file in the current directory, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   548
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   549
$ cp prog.c prog.bak</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   550
<p id="ch9Using_Linux_Tools_8e">This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   551
<p id="ch9Using_Linux_Tools_8f">To copy a file in your current directory into another directory, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   552
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   553
$ cp zaphod /home/books/hhgg</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   554
<p id="ch9Using_Linux_Tools_90">This copies the jones file to /home/books/hhgg/zaphod.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   555
<p id="ch9Using_Linux_Tools_91">To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   556
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   557
$ cp -p martin_luther_king martin_luther_king.jr</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   558
<p id="ch9Using_Linux_Tools_92">This copies the <span class="emphasis"><em>martin_luther_king</em></span> file to the <span class="emphasis"><em>martin_luther_king.jr</em></span> file. Instead of creating the file with the current date and time stamp, the system gives the <span class="emphasis"><em>martin_luther_king.jr</em></span> file the same date and time as the <span class="emphasis"><em>martin_luther_king</em></span> file. The <span class="emphasis"><em>martin_luther_king.jr</em></span> file also inherits the <span class="emphasis"><em>martin_luther_king</em></span> file's access control protection.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   559
<p id="ch9Using_Linux_Tools_93">To copy all the files in a directory to a new directory, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   560
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   561
$ cp /home/galactica/clients/* /home/hhgg/customers</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   562
<p id="ch9Using_Linux_Tools_94">This copies only the files in the clients directory to the customers directory.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   563
<p id="ch9Using_Linux_Tools_95">To copy a directory, including all its files and subdirectories, to another directory, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   564
<p id="ch9Using_Linux_Tools_96">$ cp -R /home/hhgg/clients /home/hhgg/customers</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   565
<p id="ch9Using_Linux_Tools_97">This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   566
<p id="ch9Using_Linux_Tools_98">To copy a specific set of files of any extension to another directory, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   567
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   568
$ cp zaphod arthur ford /home/hhgg/clients</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   569
<p id="ch9Using_Linux_Tools_99">This copies the <span class="emphasis"><em>zaphod</em></span>, <span class="emphasis"><em>arthur</em></span>, and <span class="emphasis"><em>ford</em></span> files in your current working directory to the /home/hhgg/clients directory.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   570
<p id="ch9Using_Linux_Tools_9a">To use pattern-matching characters to copy files, enter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   571
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   572
$ cp programs/*.py .</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   573
<p id="ch9Using_Linux_Tools_9b">This copies the files in the programs directory that end with <span class="emphasis"><em>.py</em></span> to the current directory, signified by the single "." (dot). You must type a space between the <span class="emphasis"><em>py</em></span> and the final dot.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   574
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   575
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   576
<div class="section" title="5.2.mv">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   577
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   578
<a name="id2968133"></a>5.2.mv</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   579
<p id="ch9Using_Linux_Tools_9c"><span class="emphasis"><em>mv</em></span> (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system), <span class="emphasis"><em>mv</em></span> will rename the file instead. Write permission is required on all directories being modified.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   580
<div class="section" title="5.2.1.Conflicting existing file">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   581
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   582
<a name="id2968157"></a>5.2.1.Conflicting existing file</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   583
<p id="ch9Using_Linux_Tools_9d">In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   584
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   585
<div class="section" title="5.2.2.Differences with copy and delete">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   586
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   587
<a name="id2968176"></a>5.2.2.Differences with copy and delete</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   588
<p id="ch9Using_Linux_Tools_9e">Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   589
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   590
<div class="section" title="5.2.3.Examples">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   591
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   592
<a name="id2968207"></a>5.2.3.Examples</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   593
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   594
$ mv myfile mynewfilename    renames a file
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   595
$ mv myfile otherfilename    renames a file and deletes the existing            file "myfile"
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   596
$ mv myfile /myfile          moves 'myfile' from the current            directory to the root directory
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   597
$ mv myfile dir/myfile       moves 'myfile' to 'dir/myfile' relative            to the current directory
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   598
$ mv myfile dir              same as the previous command (the          filename is implied to be the same)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   599
$ mv myfile dir/myfile2      moves 'myfile' to dir and renames it to            'myfile2'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   600
$ mv foo bar baz dir         moves multiple files to directory dir
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   601
$ mv --help                  shows a very concise help about the                syntax of the command
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   602
$ man mv                     prints an extensive user manual for                'mv' in the terminal</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   603
<p id="ch9Using_Linux_Tools_9f">In all cases, the file or files being moved or renamed can be a directory.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   604
<p id="ch9Using_Linux_Tools_a0">Note that when the command is called with two arguments (as <span class="emphasis"><em>mv name1 name2</em></span> or <span class="emphasis"><em>mv name1 /dir/name2</em></span>), it can have three different effects, depending on whether <span class="emphasis"><em>name2</em></span> does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory, <span class="emphasis"><em>/.</em></span> (or in some Unix versions <span class="emphasis"><em>/</em></span> is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   605
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   606
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   607
<div class="section" title="5.3.rm">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   608
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   609
<a name="id2968265"></a>5.3.rm</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   610
<p id="ch9Using_Linux_Tools_a1"><span class="emphasis"><em>rm</em></span> (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   611
<p id="ch9Using_Linux_Tools_a2">Here's example to remove a file named "foo" from a directory, here shown with the -i option:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   612
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   613
$ rm -i foo
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   614
remove foo? y</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   615
<div class="section" title="5.3.1.Options">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   616
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   617
<a name="id2968295"></a>5.3.1.Options</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   618
<p id="ch9Using_Linux_Tools_a3">Common options that rm accepts include:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   619
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   620
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_a4"><span class="emphasis"><em>-r</em></span>, which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   621
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_a5"><span class="emphasis"><em>-i</em></span>, which asks for every deletion to be confirmed ("interactive")</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   622
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_a6"><span class="emphasis"><em>-f</em></span>, which ignores non-existent files and overrides any confirmation prompts ("force")</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   623
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_a7"><span class="emphasis"><em>-v</em></span>, which shows what is being removed as it happens ("verbose")</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   624
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   625
<p id="ch9Using_Linux_Tools_a8"><span class="emphasis"><em>rm</em></span> is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   626
<p id="ch9Using_Linux_Tools_a9"><span class="emphasis"><em>rm -rf</em></span> (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.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   627
<p id="ch9Using_Linux_Tools_aa"><span class="emphasis"><em>rm</em></span> is often used in conjunction with xargs to supply a list of files to delete:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   628
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   629
xargs rm &lt; filelist</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   630
<p id="ch9Using_Linux_Tools_ab">When <span class="emphasis"><em>rm</em></span> is used on a symbolic link, it deletes the link, but does not affect the target of the link.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   631
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   632
<div class="section" title="5.3.2.Permissions">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   633
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   634
<a name="id2968394"></a>5.3.2.Permissions</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   635
<p id="ch9Using_Linux_Tools_ac">Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   636
<p id="ch9Using_Linux_Tools_ad">To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   637
<p id="ch9Using_Linux_Tools_ae">If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   638
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   639
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   640
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   641
<div class="section" title="6.Command Line Arguments">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   642
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   643
<a name="id2968433"></a>6.Command Line Arguments</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   644
<p id="ch9Using_Linux_Tools_af">In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   645
<p id="ch9Using_Linux_Tools_b0">For example, in Unix and Unix-like environments, an example of a command-line argument is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   646
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   647
rm file.s</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   648
<p id="ch9Using_Linux_Tools_b1">"file.s" is a command line argument which tells the program rm to remove the file "file.s".</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   649
<p id="ch9Using_Linux_Tools_b2">Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   650
<p id="ch9Using_Linux_Tools_b3">A command line option or simply <span class="emphasis"><em>option</em></span> (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   651
<p id="ch9Using_Linux_Tools_b4">Long options are introduced via "--", and are typically whole words. For example, <span class="emphasis"><em>ls --long --classify --all</em></span>. Arguments to long options are provided with "=", as <span class="emphasis"><em>ls --block-size=1024</em></span>. Some Unix programs use long options with single dashes, for example MPlayer as in <span class="emphasis"><em>mplayer -nosound</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   652
<p id="ch9Using_Linux_Tools_b5">Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called <span class="emphasis"><em>-file1</em></span> by using <span class="emphasis"><em>rm -file1</em></span> may produce an error, since rm may interpret <span class="emphasis"><em>-file1</em></span> as a command line switch. Using <span class="emphasis"><em>rm -- -file1</em></span> removes ambiguity.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   653
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   654
<div class="section" title="7.Basic Text Processing">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   655
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   656
<a name="id2968526"></a>7.Basic Text Processing</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   657
<div class="section" title="7.1.head">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   658
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   659
<a name="id2968535"></a>7.1.head</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   660
<p id="ch9Using_Linux_Tools_b6"><span class="emphasis"><em>head</em></span> is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   661
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   662
$ head [options] &lt;file_name&gt;</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   663
<p id="ch9Using_Linux_Tools_b7">By default, <span class="emphasis"><em>head</em></span> will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   664
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   665
$ head -n 20 filename</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   666
<p id="ch9Using_Linux_Tools_b8">This displays the first 5 lines of all files starting with <span class="emphasis"><em>foo</em></span>:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   667
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   668
$ head -n 5 foo*</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   669
<p id="ch9Using_Linux_Tools_b9">Some versions omit the n and just let you say -5.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   670
<div class="section" title="7.1.1.Flags">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   671
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   672
<a name="id2968586"></a>7.1.1.Flags</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   673
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   674
-c &lt;x number of bytes&gt; Copy first x number of bytes.</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   675
<p id="ch9Using_Linux_Tools_ba">Other options: <span class="emphasis"><em>sed</em></span></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   676
<p id="ch9Using_Linux_Tools_bb">Many early versions of Unix did not have this command, and so documentation and books had <span class="emphasis"><em>sed</em></span> do this job:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   677
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   678
sed 5q foo</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   679
<p id="ch9Using_Linux_Tools_bc">This says to print every line (implicit), and quit after the fifth.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   680
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   681
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   682
<div class="section" title="7.2.tail">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   683
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   684
<a name="id2968622"></a>7.2.tail</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   685
<p id="ch9Using_Linux_Tools_bd"><span class="emphasis"><em>tail</em></span> is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   686
<p id="ch9Using_Linux_Tools_be">The command-syntax is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   687
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   688
$ tail [options] &lt;file_name&gt;</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   689
<p id="ch9Using_Linux_Tools_bf">By default, <span class="emphasis"><em>tail</em></span> will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   690
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   691
$ tail -n 20 filename</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   692
<p id="ch9Using_Linux_Tools_c0">This example shows the last 15 bytes of all files starting with <span class="emphasis"><em>foo</em></span>:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   693
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   694
$ tail -c 15 foo*</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   695
<p id="ch9Using_Linux_Tools_c1">This example shows all lines of filename from the second line onwards:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   696
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   697
$ tail -n +2 filename</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   698
<p id="ch9Using_Linux_Tools_c2">Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   699
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   700
$ tail -20 filename
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   701
$ tail -50c filename</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   702
<p id="ch9Using_Linux_Tools_c3">However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   703
<div class="section" title="7.2.1.File monitoring">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   704
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   705
<a name="id2968701"></a>7.2.1.File monitoring</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   706
<p id="ch9Using_Linux_Tools_c4"><span class="emphasis"><em>tail</em></span> has a special command line option <span class="emphasis"><em>-f</em></span> (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   707
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   708
$ tail -f /var/adm/messages</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   709
<p id="ch9Using_Linux_Tools_c5">To interrupt tail while it is monitoring, break-in with <span class="emphasis"><em>Ctrl+C</em></span>. This command can be run "in the background" with &amp;, see job control.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   710
<p id="ch9Using_Linux_Tools_c6">If you have a command's result to monitor, you can use the <span class="emphasis"><em>watch</em></span> command.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   711
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   712
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   713
<div class="section" title="7.3.cut">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   714
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   715
<a name="id2968750"></a>7.3.cut</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   716
<p id="ch9Using_Linux_Tools_c7">In computing, <span class="emphasis"><em>cut</em></span> is a Unix command line utility which is used to extract sections from each line of input  usually from a file.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   717
<p id="ch9Using_Linux_Tools_c8">Extraction of line segments can typically be done by <span class="emphasis"><em>bytes (-b), characters (-c)</em></span>, or <span class="emphasis"><em>fields (-f)</em></span> separated by a <span class="emphasis"><em>delimiter (-d  the tab character by default)</em></span>. A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   718
<p id="ch9Using_Linux_Tools_c9">Assuming a file named file containing the lines:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   719
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   720
foo:bar:baz:qux:quux
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   721
one:two:three:four:five:six:seven
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   722
alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   723
<p id="ch9Using_Linux_Tools_ca">To output the fourth through tenth characters of each line:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   724
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   725
$ cut -c 4-10 file</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   726
<p id="ch9Using_Linux_Tools_cb">This gives the output:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   727
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   728
:bar:ba
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   729
:two:th
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   730
ha:beta</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   731
<p id="ch9Using_Linux_Tools_cc">To output the fifth field through the end of the line of each line using the colon character as the field delimiter:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   732
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   733
$ cut -d : -f 5- file</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   734
<p id="ch9Using_Linux_Tools_cd">This gives the output:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   735
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   736
quux
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   737
five:six:seven
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   738
epsilon:zeta:eta:teta:iota:kappa:lambda:mu</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   739
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   740
<div class="section" title="7.4.paste">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   741
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   742
<a name="id2968837"></a>7.4.paste</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   743
<p id="ch9Using_Linux_Tools_ce"><span class="emphasis"><em>paste</em></span> is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility <span class="emphasis"><em>cat</em></span> command which operates on the vertical plane of two or more files.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   744
<p id="ch9Using_Linux_Tools_cf">To paste several columns of data together into the file <span class="emphasis"><em>www</em></span> from files <span class="emphasis"><em>who</em></span>, <span class="emphasis"><em>where</em></span>, and <span class="emphasis"><em>when</em></span>:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   745
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   746
$ paste who where when &gt; www</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   747
<p id="ch9Using_Linux_Tools_d0">If the files contain:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   748
<p id="ch9Using_Linux_Tools_d1">who</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   749
<p id="ch9Using_Linux_Tools_d2">where</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   750
<p id="ch9Using_Linux_Tools_d3">when</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   751
<p id="ch9Using_Linux_Tools_d4">Batman</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   752
<p id="ch9Using_Linux_Tools_d5">GothamCity</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   753
<p id="ch9Using_Linux_Tools_d6">January 3</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   754
<p id="ch9Using_Linux_Tools_d7">Trillian</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   755
<p id="ch9Using_Linux_Tools_d8">Andromeda</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   756
<p id="ch9Using_Linux_Tools_d9">February 4</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   757
<p id="ch9Using_Linux_Tools_da">Jeeves</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   758
<p id="ch9Using_Linux_Tools_db">London</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   759
<p id="ch9Using_Linux_Tools_dc">March 19</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   760
<p id="ch9Using_Linux_Tools_dd">This creates the file named <span class="emphasis"><em>www</em></span> containing:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   761
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   762
Batman            GothamCity       January 3
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   763
Trillian          Andromeda        February 4
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   764
Jeeves            London           March 19</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   765
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   766
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   767
<div class="section" title="8.Shell Meta Characters">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   768
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   769
<a name="id2968957"></a>8.Shell Meta Characters</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   770
<p id="ch9Using_Linux_Tools_de">Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   771
<p id="ch9Using_Linux_Tools_df">The shell meta characters include:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   772
<p id="ch9Using_Linux_Tools_e0">/ &lt; &gt; ! $ % ^ &amp; * | { } [ ] " ' ` ~ ;</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   773
<p id="ch9Using_Linux_Tools_e1">Different shells may differ in the meta characters recognized.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   774
<p id="ch9Using_Linux_Tools_e2">As an example,</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   775
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   776
$ ls file.*</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   777
<p id="ch9Using_Linux_Tools_e3">run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   778
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   779
$ ls file.?</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   780
<p id="ch9Using_Linux_Tools_e4">run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   781
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   782
$ more c*</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   783
<p id="ch9Using_Linux_Tools_e5">because the c* matches that long file name.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   784
<p id="ch9Using_Linux_Tools_e6">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:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   785
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   786
$ rm ??more</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   787
<p id="ch9Using_Linux_Tools_e7">or:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   788
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   789
$ rm $ backslash$*$ backslash$|more</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   790
<p id="ch9Using_Linux_Tools_e8">or:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   791
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   792
$ rm ''*|more''</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   793
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   794
<div class="section" title="9.Looking At Files">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   795
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   796
<a name="id2969064"></a>9.Looking At Files</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   797
<div class="section" title="9.1.cat">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   798
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   799
<a name="id2969072"></a>9.1.cat</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   800
<p id="ch9Using_Linux_Tools_e9">The <span class="emphasis"><em>cat</em></span> command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of <span class="emphasis"><em>concatenate</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   801
<p id="ch9Using_Linux_Tools_ea">The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   802
<p id="ch9Using_Linux_Tools_eb">If the filename is specified as -, then <span class="emphasis"><em>cat</em></span> will read from standard input at that point in the sequence. If no files are specified, <span class="emphasis"><em>cat</em></span> will read from standard input entered.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   803
<div class="section" title="9.1.1.Jargon File Definition">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   804
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   805
<a name="id2969116"></a>9.1.1.Jargon File Definition</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   806
<p id="ch9Using_Linux_Tools_ec">The Jargon File version 4.4.7 lists this as the definition of <span class="emphasis"><em>cat</em></span>:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   807
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   808
1. To spew an entire file to the screen or some other output sink without
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   809
     pause (syn. blast).
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   810
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   811
2. By extension, to dump large amounts of data at an unprepared target or
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   812
     with no intention of browsing it carefully. Usage: considered silly.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   813
     Rare outside Unix sites. See also dd, BLT.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   814
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   815
     Among Unix fans, *cat(1)* is considered an excellent example of
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   816
     user-interface design, because it delivers the file contents without
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   817
     such verbosity as spacing or headers between the files, and because
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   818
     it does not require the files to consist of lines of text, but works
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   819
     with any sort of data.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   820
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   821
     Among Unix critics, *cat(1)* is considered the canonical example of
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   822
     bad user-interface design, because of its woefully unobvious name.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   823
     It is far more often used to blast a single file to standard output
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   824
     than to concatenate two or more files. The name cat for the former
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   825
     operation is just as unintuitive as, say, LISP's cdr.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   826
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   827
     Of such oppositions are holy wars made...</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   828
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   829
<div class="section" title="9.1.2.Useless Use of 'cat'">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   830
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   831
<a name="id2969155"></a>9.1.2.Useless Use of 'cat'</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   832
<p id="ch9Using_Linux_Tools_ed">UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on <span class="emphasis"><em>comp.unix.shell</em></span>, The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   833
<p id="ch9Using_Linux_Tools_ee">Nevertheless one sees people doing:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   834
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   835
$ cat file | some_command and its args ...</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   836
<p id="ch9Using_Linux_Tools_ef">instead of the equivalent and cheaper:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   837
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   838
&lt;file some_command and its args ...</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   839
<p id="ch9Using_Linux_Tools_f0">or (equivalently and more classically):</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   840
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   841
some_command and its args ... &lt;file</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   842
<p id="ch9Using_Linux_Tools_f1">Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   843
<p id="ch9Using_Linux_Tools_f2">Amongst many, it is still considered safer to use <span class="emphasis"><em>cat</em></span> for such cases given that the &lt; and &gt; keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using &gt; instead of &lt; can be high and prohibitive.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   844
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   845
<div class="section" title="9.1.3.zcat">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   846
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   847
<a name="id2969226"></a>9.1.3.zcat</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   848
<p id="ch9Using_Linux_Tools_f3"><span class="emphasis"><em>zcat</em></span> is a Unix program similar to <span class="emphasis"><em>cat</em></span>, that decompresses individual files and concatenates them to standard output. Traditionally <span class="emphasis"><em>zcat</em></span> operated on files compressed by compress but today it is usually able to operate on <span class="emphasis"><em>gzip</em></span> or even <span class="emphasis"><em>bzip2</em></span> archives. On such systems, it is equivalent to <span class="emphasis"><em>gunzip -c</em></span></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   849
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   850
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   851
<div class="section" title="9.2.more">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   852
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   853
<a name="id2969260"></a>9.2.more</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   854
<p id="ch9Using_Linux_Tools_f4">In computing, <span class="emphasis"><em>more</em></span> is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   855
<div class="section" title="9.2.1.Usage">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   856
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   857
<a name="id2969280"></a>9.2.1.Usage</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   858
<p id="ch9Using_Linux_Tools_f5">The command-syntax is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   859
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   860
$ more [options] [file_name]</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   861
<p id="ch9Using_Linux_Tools_f6">If no file name is provided, <span class="emphasis"><em>more</em></span> looks for input from stdin.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   862
<p id="ch9Using_Linux_Tools_f7">Once <span class="emphasis"><em>more</em></span> has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause <span class="emphasis"><em>more</em></span> to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that <span class="emphasis"><em>more</em></span> has paged through. (This percentage includes the text displayed on the current screen.) When <span class="emphasis"><em>more</em></span> reaches the end of a file (100%) it exits. The most common methods of navigating through a file are <span class="emphasis"><em>Enter</em></span>, which advances the output by one line, and <span class="emphasis"><em>Space</em></span>, which advances the output by one screen.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   863
<p id="ch9Using_Linux_Tools_f8">There are also other commands that can be used while navigating through the document; consult <span class="emphasis"><em>more</em></span>'s <span class="emphasis"><em>man</em></span> page for more details.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   864
<p id="ch9Using_Linux_Tools_f9"><span class="emphasis"><em>Options</em></span> are typically entered before the file name, but can also be entered in the environment variable <span class="emphasis"><em>$MORE</em></span>. Options entered in the actual command line will override those entered in the <span class="emphasis"><em>$MORE</em></span> environment variable. Available options may vary between Unix systems.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   865
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   866
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   867
<div class="section" title="9.3.less">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   868
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   869
<a name="id2969371"></a>9.3.less</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   870
<p id="ch9Using_Linux_Tools_fa"><span class="emphasis"><em>less</em></span> is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to <span class="emphasis"><em>more</em></span>, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, <span class="emphasis"><em>less</em></span> does not need to read the entire file before starting, resulting in faster load times with large files.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   871
<div class="section" title="9.3.1.Usage">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   872
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   873
<a name="id2969400"></a>9.3.1.Usage</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   874
<p id="ch9Using_Linux_Tools_fb"><span class="emphasis"><em>less</em></span> can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While <span class="emphasis"><em>less</em></span> is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both <span class="emphasis"><em>more</em></span> and <span class="emphasis"><em>vi</em></span>. It is also possible to search for character patterns in the file.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   875
<p id="ch9Using_Linux_Tools_fc">By default, <span class="emphasis"><em>less</em></span> displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   876
<p id="ch9Using_Linux_Tools_fd">The command-syntax is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   877
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   878
$ less [options] file_name</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   879
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   880
<div class="section" title="9.3.2.Frequently Used Options">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   881
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   882
<a name="id2969455"></a>9.3.2.Frequently Used Options</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   883
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   884
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_fe">-g: Highlights just the current match of any searched string.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   885
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_ff">-I: Case-insensitive searches.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   886
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_100">-M: Shows more detailed prompt, including file position.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   887
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_101">-N: Shows line numbers (useful for source code viewing).</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   888
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_102">-S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   889
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_103">-?: Shows help.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   890
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   891
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   892
<div class="section" title="9.3.3.Frequently Used Commands">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   893
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   894
<a name="id2969507"></a>9.3.3.Frequently Used Commands</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   895
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   896
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_104">[Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   897
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_105">[Space bar]: Next page.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   898
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_106">b: Previous page.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   899
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_107">ng: Jump to line number n. Default is the start of the file.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   900
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_108">nG: Jump to line number n. Default is the end of the file.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   901
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_109">/pattern: Search for pattern. Regular expressions can be used.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   902
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_10a">'^ or g: Go to start of file.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   903
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_10b">'$ or G: Go to end of file.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   904
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_10c">s: Save current content (got from another program like grep) in a file.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   905
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_10d">=: File information.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   906
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_10e">h: Help.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   907
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_10f">q: Quit.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   908
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   909
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   910
<div class="section" title="9.3.4.Examples">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   911
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   912
<a name="id2969597"></a>9.3.4.Examples</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   913
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   914
$ less -M readme.txt                     #Read "readme.txt."
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   915
$ less +F /var/log/mail.log              #Follow mode for log
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   916
$ file * | less                          #Easier file analysis.
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   917
$ grep -i void *.c | less -I -p void     #Case insensitive search                                                         for "void" in all .c files</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   918
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   919
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   920
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   921
<div class="section" title="10.Directory Structure">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   922
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   923
<a name="id2969612"></a>10.Directory Structure</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   924
<p id="ch9Using_Linux_Tools_110">In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   925
<p id="ch9Using_Linux_Tools_111">The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   926
<p id="ch9Using_Linux_Tools_112">Directory</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   927
<p id="ch9Using_Linux_Tools_113">Description</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   928
<p id="ch9Using_Linux_Tools_114">/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   929
<p id="ch9Using_Linux_Tools_115">Primary hierarchy root and root directory of
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   930
the entire file system hierarchy.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   931
<p id="ch9Using_Linux_Tools_116">/bin/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   932
<p id="ch9Using_Linux_Tools_117">Essential command binaries that need to be
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   933
available in single user mode; for all users,
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   934
e.g., <span class="emphasis"><em>cat</em></span>, <span class="emphasis"><em>ls</em></span>, <span class="emphasis"><em>cp</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   935
<p id="ch9Using_Linux_Tools_118">/boot/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   936
<p id="ch9Using_Linux_Tools_119">Boot loader files, e.g., <span class="emphasis"><em>kernels</em></span>, <span class="emphasis"><em>initrd</em></span>;
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   937
often a separate partition.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   938
<p id="ch9Using_Linux_Tools_11a">/dev/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   939
<p id="ch9Using_Linux_Tools_11b">Essential devices, e.g., /dev/null</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   940
<p id="ch9Using_Linux_Tools_11c">/etc/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   941
<p id="ch9Using_Linux_Tools_11d">Host-specific system-wide configuration files
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   942
(the name comes from <span class="emphasis"><em>et cetera</em></span>)</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   943
<p id="ch9Using_Linux_Tools_11e">/home/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   944
<p id="ch9Using_Linux_Tools_11f">User's home directories, containing saved
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   945
files, personal settings, etc.; often a
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   946
separate partition.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   947
<p id="ch9Using_Linux_Tools_120">/lib/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   948
<p id="ch9Using_Linux_Tools_121">Libraries essential for the binaries in
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   949
<span class="emphasis"><em>/bin/</em></span> and <span class="emphasis"><em>/sbin/</em></span></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   950
<p id="ch9Using_Linux_Tools_122">/media/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   951
<p id="ch9Using_Linux_Tools_123">Mount points for removable media such as
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   952
CD-ROMs, external hard disks, USB sticks, etc.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   953
<p id="ch9Using_Linux_Tools_124">/mnt/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   954
<p id="ch9Using_Linux_Tools_125">Temporarily mounted file systems</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   955
<p id="ch9Using_Linux_Tools_126">/opt/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   956
<p id="ch9Using_Linux_Tools_127">Optional application software packages</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   957
<p id="ch9Using_Linux_Tools_128">/proc/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   958
<p id="ch9Using_Linux_Tools_129">Virtual filesystem documenting kernel and
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   959
process status as text files; e.g., uptime,
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   960
network. In Linux, corresponds to a <span class="emphasis"><em>Procfs</em></span>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   961
mount.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   962
<p id="ch9Using_Linux_Tools_12a">/root/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   963
<p id="ch9Using_Linux_Tools_12b">Home directory for the root user</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   964
<p id="ch9Using_Linux_Tools_12c">/sbin/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   965
<p id="ch9Using_Linux_Tools_12d">Essential system binaries; e.g., <span class="emphasis"><em>init</em></span>,
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   966
<span class="emphasis"><em>route</em></span>, <span class="emphasis"><em>mount</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   967
<p id="ch9Using_Linux_Tools_12e">/srv/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   968
<p id="ch9Using_Linux_Tools_12f">Site-specific data which is served by the
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   969
system.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   970
<p id="ch9Using_Linux_Tools_130">/tmp/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   971
<p id="ch9Using_Linux_Tools_131">Temporary files. Often not preserved between
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   972
system reboots.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   973
<p id="ch9Using_Linux_Tools_132">/usr/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   974
<p id="ch9Using_Linux_Tools_133">Secondary hierarchy for read-only user data;
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   975
contains the majority of (multi-)user
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   976
utilities and applications.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   977
<p id="ch9Using_Linux_Tools_134">/var/</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   978
<p id="ch9Using_Linux_Tools_135">Variable files - files whose content is
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   979
expected to continually change during normal
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   980
operation of the system - such as logs, spool
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   981
files, and temporary e-mail files.
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   982
Sometimes a separate partition.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   983
<div class="section" title="10.1.man hier">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   984
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   985
<a name="id2969877"></a>10.1.man hier</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   986
<p id="ch9Using_Linux_Tools_136">This is the manual page on the UNIX filesystem. The syntax for this is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   987
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   988
$ man hier</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   989
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   990
<div class="section" title="10.2.ls -l">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   991
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   992
<a name="id2969893"></a>10.2.ls -l</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   993
<p id="ch9Using_Linux_Tools_137">Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   994
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   995
$ ls -l</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   996
<p id="ch9Using_Linux_Tools_138">This can be done after entering the required directory.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   997
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   998
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
   999
<div class="section" title="11.Permissions and Ownership">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1000
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1001
<a name="id2969916"></a>11.Permissions and Ownership</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1002
<div class="section" title="11.1.chmod">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1003
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1004
<a name="id2969925"></a>11.1.chmod</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1005
<p id="ch9Using_Linux_Tools_139">The <span class="emphasis"><em>chmod</em></span> command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&amp;T Unix version 1, and is still used today on Unix-like machines.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1006
<div class="section" title="11.1.1.Usage">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1007
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1008
<a name="id2969951"></a>11.1.1.Usage</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1009
<p id="ch9Using_Linux_Tools_13a">The <span class="emphasis"><em>chmod</em></span> command options are specified like this:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1010
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1011
$ chmod [options] mode[,mode] file1 [file2 ...]</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1012
<p id="ch9Using_Linux_Tools_13b">To view what the permissions currently are, type:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1013
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1014
$ ls -l file</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1015
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1016
<div class="section" title="11.1.2.Command line options">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1017
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1018
<a name="id2969979"></a>11.1.2.Command line options</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1019
<p id="ch9Using_Linux_Tools_13c">The <span class="emphasis"><em>chmod</em></span> command has a number of command line options that affect its behavior. The most common options are:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1020
<div class="itemizedlist"><ul class="itemizedlist" type="*">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1021
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_13d">-R: Changes the modes of directories and files recursively</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1022
<li class="listitem" style="list-style-type: *"><p id="ch9Using_Linux_Tools_13e">-v: Verbose mode; lists all files as they are being processed</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1023
</ul></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1024
<div class="section" title="11.1.2.1.Symbolic modes">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1025
<div class="titlepage"><div><div><h5 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1026
<a name="id2970015"></a>11.1.2.1.Symbolic modes</h5></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1027
<p id="ch9Using_Linux_Tools_13f">To the <span class="emphasis"><em>chmod</em></span> utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1028
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1029
$ chmod [references][operator][modes] file1 ...</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1030
<p id="ch9Using_Linux_Tools_140">The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1031
<p id="ch9Using_Linux_Tools_141">Reference</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1032
<p id="ch9Using_Linux_Tools_142">Class</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1033
<p id="ch9Using_Linux_Tools_143">Description</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1034
<p id="ch9Using_Linux_Tools_144">u</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1035
<p id="ch9Using_Linux_Tools_145">user</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1036
<p id="ch9Using_Linux_Tools_146">the owner of the file</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1037
<p id="ch9Using_Linux_Tools_147">g</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1038
<p id="ch9Using_Linux_Tools_148">group</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1039
<p id="ch9Using_Linux_Tools_149">users who are members of the file's group</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1040
<p id="ch9Using_Linux_Tools_14a">o</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1041
<p id="ch9Using_Linux_Tools_14b">others</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1042
<p id="ch9Using_Linux_Tools_14c">users who are not hte owner of the file or
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1043
members of the group</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1044
<p id="ch9Using_Linux_Tools_14d">a</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1045
<p id="ch9Using_Linux_Tools_14e">all</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1046
<p id="ch9Using_Linux_Tools_14f">all three of the above; is the same as <span class="emphasis"><em>ugo</em></span></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1047
<p id="ch9Using_Linux_Tools_150">The <span class="emphasis"><em>chmod</em></span> program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1048
<p id="ch9Using_Linux_Tools_151">Operator</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1049
<p id="ch9Using_Linux_Tools_152">Description</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1050
<div class="itemizedlist">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1051
<span style="color: red">&lt;list_item&gt;&lt;/list_item&gt;</span><ul class="itemizedlist" type="*"></ul>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1052
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1053
<p id="ch9Using_Linux_Tools_153">adds the specified modes to the specified classes</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1054
<div class="itemizedlist">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1055
<span style="color: red">&lt;list_item&gt;&lt;/list_item&gt;</span><ul class="itemizedlist" type="*"></ul>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1056
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1057
<p id="ch9Using_Linux_Tools_154">removes the specified modes from the specified
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1058
classes</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1059
<p id="ch9Using_Linux_Tools_155">=</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1060
<p id="ch9Using_Linux_Tools_156">the modes specified are to be made the exact modes
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1061
for the specified classes</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1062
<p id="ch9Using_Linux_Tools_157">The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1063
<p id="ch9Using_Linux_Tools_158">Mode</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1064
<p id="ch9Using_Linux_Tools_159">Name</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1065
<p id="ch9Using_Linux_Tools_15a">Description</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1066
<p id="ch9Using_Linux_Tools_15b">r</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1067
<p id="ch9Using_Linux_Tools_15c">read</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1068
<p id="ch9Using_Linux_Tools_15d">read a file or list a directory's contents</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1069
<p id="ch9Using_Linux_Tools_15e">w</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1070
<p id="ch9Using_Linux_Tools_15f">write</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1071
<p id="ch9Using_Linux_Tools_160">write to a file or directory</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1072
<p id="ch9Using_Linux_Tools_161">x</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1073
<p id="ch9Using_Linux_Tools_162">execute</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1074
<p id="ch9Using_Linux_Tools_163">execute a file or recurse a directory tree</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1075
<p id="ch9Using_Linux_Tools_164">X</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1076
<p id="ch9Using_Linux_Tools_165">special
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1077
execute</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1078
<p id="ch9Using_Linux_Tools_166">which is not a permission in itself but rather
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1079
can be used instead of 'x'. It applies execute
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1080
permissions to directories regardless of their
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1081
current permissions and applies execute
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1082
permissions to a file which already has at
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1083
least 1 execute permission bit already set
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1084
(either user, group or other). It is only
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1085
really useful when used with '+' and usually
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1086
in combination with the <span class="emphasis"><em>-R</em></span> option for giving
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1087
group or other access to a big directory tree
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1088
without setting execute permission on normal
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1089
files (such as text files), which would
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1090
normally happen if one just used 'chmod -R
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1091
a+rx .', whereas with 'X' one can do 'chmod -R
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1092
a+rX .' instead.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1093
<p id="ch9Using_Linux_Tools_167">s</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1094
<p id="ch9Using_Linux_Tools_168">setuid/gid</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1095
<p id="ch9Using_Linux_Tools_169">are Unix access rights flags that allow users
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1096
to run an executable with the permissions of
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1097
the executable's owner or group.They are often
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1098
used to allow users on a computer system to run
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1099
programs with temporarily elevated privileges
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1100
in order to perform a specific task. While the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1101
assumed user id or group id privileges provided
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1102
are not always elevated, at a minimum they are
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1103
specific.They are needed for tasks that require
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1104
higher privileges than those which a common
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1105
user has, such as changing his or her login
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1106
password.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1107
<p id="ch9Using_Linux_Tools_16a">t</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1108
<p id="ch9Using_Linux_Tools_16b">sticky</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1109
<p id="ch9Using_Linux_Tools_16c">The most common use of the sticky bit today is
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1110
on directories, where, when set, items inside
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1111
the directory can be renamed or deleted only by
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1112
the item's owner, the directory's owner, or the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1113
superuser; without the sticky bit set, any user
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1114
with write and execute permissions for the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1115
directory can rename or delete contained files,
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1116
regardless of owner.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1117
<p id="ch9Using_Linux_Tools_16d">The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1118
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1119
<div class="section" title="11.1.2.2.Symbolic examples">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1120
<div class="titlepage"><div><div><h5 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1121
<a name="id2965880"></a>11.1.2.2.Symbolic examples</h5></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1122
<p id="ch9Using_Linux_Tools_16e">Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1123
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1124
$ chmod ug+rw mydir
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1125
$ ls -ld mydir
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1126
drw-rw----   2 starwars  yoda  96 Dec 8 12:53 mydir</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1127
<p id="ch9Using_Linux_Tools_16f">For a file, remove <span class="emphasis"><em>write</em></span> permissions for all classes:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1128
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1129
$ chmod a-w myfile
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1130
$ ls -l myfile
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1131
-r-xr-xr-x   2 starwars  yoda 96 Dec 8 12:53 myfile</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1132
<p id="ch9Using_Linux_Tools_170">Set the permissions for the <span class="emphasis"><em>u*ser and the *g*roup to read and execute only (no write permission) on *mydir</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1133
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1134
$ chmod ug=rx mydir
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1135
$ ls -ld mydir
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1136
dr-xr-x---   2 starwars  yoda 96 Dec 8 12:53 mydir</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1137
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1138
<div class="section" title="11.1.2.3.Octal numbers">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1139
<div class="titlepage"><div><div><h5 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1140
<a name="id2965925"></a>11.1.2.3.Octal numbers</h5></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1141
<p id="ch9Using_Linux_Tools_171">The <span class="emphasis"><em>chmod</em></span> command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1142
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1143
$ chmod 664 myfile
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1144
$ ls -l myfile
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1145
-rw-rw-r--  1   57 Jul  3 10:13  myfile</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1146
<p id="ch9Using_Linux_Tools_172">Since the <span class="emphasis"><em>setuid</em></span>, <span class="emphasis"><em>setgid</em></span> and <span class="emphasis"><em>sticky</em></span> bits are not set, this is equivalent to:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1147
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1148
$ chmod 0664 myfile</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1149
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1150
<div class="section" title="11.1.2.4.Special modes">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1151
<div class="titlepage"><div><div><h5 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1152
<a name="id2970552"></a>11.1.2.4.Special modes</h5></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1153
<p id="ch9Using_Linux_Tools_173">The <span class="emphasis"><em>chmod</em></span> command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use <span class="strong"><strong>s</strong></span> to represent the <span class="emphasis"><em>setuid</em></span> and <span class="emphasis"><em>setgid</em></span> modes, and <span class="strong"><strong>t</strong></span> to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1154
<p id="ch9Using_Linux_Tools_174">Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1155
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1156
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1157
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1158
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1159
<div class="section" title="12.Redirection and Piping">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1160
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1161
<a name="id2965366"></a>12.Redirection and Piping</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1162
<p id="ch9Using_Linux_Tools_175">In computing, <span class="emphasis"><em>redirection</em></span> is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1163
<p id="ch9Using_Linux_Tools_176">Programs do redirection with the <span class="emphasis"><em>dup2(2)</em></span> system call, or its less-flexible but higher-level stdio analogues, <span class="emphasis"><em>freopen(3)</em></span> and <span class="emphasis"><em>popen(3)</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1164
<div class="section" title="12.1.Redirecting standard input and standard output">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1165
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1166
<a name="id2970852"></a>12.1.Redirecting standard input and standard output</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1167
<p id="ch9Using_Linux_Tools_177">Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1168
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1169
$ command1 &gt; file1</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1170
<p id="ch9Using_Linux_Tools_178">executes <span class="emphasis"><em>command1</em></span>, placing the output in file1. Note that this will truncate any existing data in <span class="emphasis"><em>file1</em></span>. To append output to the end of the file, use the &gt;&gt; operator.:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1171
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1172
$ command1 &lt; file1</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1173
<p id="ch9Using_Linux_Tools_179">executes <span class="emphasis"><em>command1</em></span>, using <span class="emphasis"><em>file1</em></span> as the source of input (as opposed to the keyboard).:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1174
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1175
$ command1 &lt; infile &gt; outfile</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1176
<p id="ch9Using_Linux_Tools_17a">combines the two capabilities: <span class="emphasis"><em>command1</em></span> reads from <span class="emphasis"><em>infile</em></span> and writes to <span class="emphasis"><em>outfile</em></span></p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1177
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1178
<div class="section" title="12.2.Piping">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1179
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1180
<a name="id2970920"></a>12.2.Piping</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1181
<p id="ch9Using_Linux_Tools_17b">Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1182
A pipeline of three programs run on a text terminal:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1183
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1184
$ command1 | command2</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1185
<p id="ch9Using_Linux_Tools_17c">executes <span class="emphasis"><em>command1</em></span>, using its output as the input for <span class="emphasis"><em>command2</em></span> (commonly called piping, since the "|" character is known as a "pipe").</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1186
<p id="ch9Using_Linux_Tools_17d">This is equivalent to using two redirects and a temporary file:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1187
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1188
$ command1 &gt; tempfile
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1189
$ command2 &lt; tempfile
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1190
$ rm tempfile</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1191
<p id="ch9Using_Linux_Tools_17e">A good example for command piping is combining <span class="emphasis"><em>echo</em></span> with another command to achieve something interactive in a non-interactive shell, e.g.:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1192
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1193
$ echo -e "user npass" | ftp localhost</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1194
<p id="ch9Using_Linux_Tools_17f">This runs the ftp client with input user, press return, then pass.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1195
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1196
<div class="section" title="12.3.Redirecting to and from the standard file handles">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1197
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1198
<a name="id2970982"></a>12.3.Redirecting to and from the standard file handles</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1199
<p id="ch9Using_Linux_Tools_180">In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1200
<p id="ch9Using_Linux_Tools_181">Handle</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1201
<p id="ch9Using_Linux_Tools_182">Name</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1202
<p id="ch9Using_Linux_Tools_183">Description</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1203
<p id="ch9Using_Linux_Tools_184">0</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1204
<p id="ch9Using_Linux_Tools_185">stdin</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1205
<p id="ch9Using_Linux_Tools_186">Standard input</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1206
<p id="ch9Using_Linux_Tools_187">1</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1207
<p id="ch9Using_Linux_Tools_188">stdout</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1208
<p id="ch9Using_Linux_Tools_189">Standard output</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1209
<p id="ch9Using_Linux_Tools_18a">2</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1210
<p id="ch9Using_Linux_Tools_18b">stderr</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1211
<p id="ch9Using_Linux_Tools_18c">Standard error</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1212
<p id="ch9Using_Linux_Tools_18d">For example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1213
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1214
$ command1 2&gt; file1</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1215
<p id="ch9Using_Linux_Tools_18e">executes <span class="emphasis"><em>command1</em></span>, directing the standard error stream to <span class="emphasis"><em>file1</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1216
<p id="ch9Using_Linux_Tools_18f">In shells derived from <span class="emphasis"><em>csh</em></span> (the C shell), the syntax instead appends the &amp; character to the redirect characters, thus achieving a similar result.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1217
<p id="ch9Using_Linux_Tools_190">Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1218
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1219
$ find / -name .profile &gt; results 2&gt;&amp;1</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1220
<p id="ch9Using_Linux_Tools_191">will try to find all files named <span class="emphasis"><em>.profile</em></span>. Executed without redirection, it will output hits to <span class="emphasis"><em>stdout</em></span> and errors (e.g. for lack of privilege to traverse protected directories) to <span class="emphasis"><em>stderr</em></span>. If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge <span class="emphasis"><em>stderr</em></span> (handle 2) into <span class="emphasis"><em>stdout</em></span> (handle 1) using 2&gt;&amp;1 .</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1221
<p id="ch9Using_Linux_Tools_192">It's possible use 2&gt;&amp;1 before "&gt;" but it doesn't work. In fact, when the interpreter reads 2&gt;&amp;1, it doesn't know yet where standard output is redirected and then standard error isn't merged.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1222
<p id="ch9Using_Linux_Tools_193">If the merged output is to be piped into another program, the file merge sequence 2&gt;&amp;1 must precede the pipe symbol, thus:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1223
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1224
$ find / -name .profile 2&gt;&amp;1 | less</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1225
<p id="ch9Using_Linux_Tools_194">A simplified form of the command:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1226
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1227
$ command &gt; file 2&gt;&amp;1</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1228
<p id="ch9Using_Linux_Tools_195">is:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1229
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1230
$ command &amp;&gt;file</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1231
<p id="ch9Using_Linux_Tools_196">or:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1232
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1233
$command &gt;&amp;file</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1234
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1235
<div class="section" title="12.4.Chained pipelines">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1236
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1237
<a name="id2971176"></a>12.4.Chained pipelines</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1238
<p id="ch9Using_Linux_Tools_197">The redirection and piping tokens can be chained together to create complex commands. For example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1239
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1240
$ ls | grep ' .sh' | sort &gt; shlist</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1241
<p id="ch9Using_Linux_Tools_198">lists the contents of the current directory, where this output is filtered to only contain lines which contain <span class="emphasis"><em>.sh</em></span>, sort this resultant output lexicographically, and place the final output in <span class="emphasis"><em>shlist</em></span>. This type of construction is used very commonly in shell scripts and batch files.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1242
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1243
<div class="section" title="12.5.Redirect to multiple outputs">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1244
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1245
<a name="id2971209"></a>12.5.Redirect to multiple outputs</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1246
<p id="ch9Using_Linux_Tools_199">The standard command <span class="emphasis"><em>tee</em></span> can redirect output from a command to several destinations.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1247
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1248
$ ls -lrt | tee xyz</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1249
<p id="ch9Using_Linux_Tools_19a">This directs the file list output to both standard output as well as to the file <span class="emphasis"><em>xyz</em></span>.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1250
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1251
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1252
<div class="section" title="13.More Text Processing">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1253
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1254
<a name="id2971240"></a>13.More Text Processing</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1255
<div class="section" title="13.1.grep">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1256
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1257
<a name="id2971248"></a>13.1.grep</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1258
<p id="ch9Using_Linux_Tools_19b"><span class="emphasis"><em>grep</em></span> is a command line text search utility originally written for Unix. The name is taken from the first letters in <span class="emphasis"><em>global / regular expression / print</em></span>, a series of instructions for the <span class="emphasis"><em>ed</em></span> text editor. The <span class="emphasis"><em>grep</em></span> command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1259
<div class="section" title="13.1.1.Usage">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1260
<div class="titlepage"><div><div><h4 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1261
<a name="id2971279"></a>13.1.1.Usage</h4></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1262
<p id="ch9Using_Linux_Tools_19c">This is an example of a common <span class="emphasis"><em>grep</em></span> usage:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1263
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1264
$ grep apple fruitlist.txt</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1265
<p id="ch9Using_Linux_Tools_19d">In this case, <span class="emphasis"><em>grep</em></span> prints all lines containing 'apple' from the file <span class="emphasis"><em>fruitlist.txt</em></span>, regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The <span class="emphasis"><em>grep</em></span> command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1266
<p id="ch9Using_Linux_Tools_19e">Like most Unix commands, <span class="emphasis"><em>grep</em></span> accepts command line arguments to change this and many other behaviors. For example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1267
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1268
$ grep -i apple fruitlist.txt</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1269
<p id="ch9Using_Linux_Tools_19f">This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells <span class="emphasis"><em>grep</em></span> to be case insensitive, or to ignore case.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1270
<p id="ch9Using_Linux_Tools_1a0">To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1271
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1272
$ grep -w apple fruitlist.txt</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1273
<p id="ch9Using_Linux_Tools_1a1">Regular expressions can be used to match more complicated queries.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1274
<div class="section" title="13.1.1.1.Variations">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1275
<div class="titlepage"><div><div><h5 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1276
<a name="id2971358"></a>13.1.1.1.Variations</h5></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1277
<p id="ch9Using_Linux_Tools_1a2">There are countless implementations and derivatives of <span class="emphasis"><em>grep</em></span> available for many operating systems. Early variants of <span class="emphasis"><em>grep</em></span> included <span class="emphasis"><em>egrep</em></span> and <span class="emphasis"><em>fgrep</em></span>. The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern <span class="emphasis"><em>grep</em></span> implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations, <span class="emphasis"><em>grep</em></span> may also behave differently depending on the name by which it is invoked, allowing <span class="emphasis"><em>fgrep</em></span>, <span class="emphasis"><em>egrep</em></span>, and <span class="emphasis"><em>grep</em></span> to be links to the same program.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1278
<p id="ch9Using_Linux_Tools_1a3"><span class="emphasis"><em>pcregrep</em></span> is an implementation of <span class="emphasis"><em>grep</em></span> that uses Perl regular expression syntax.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1279
<p id="ch9Using_Linux_Tools_1a4">Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The <span class="emphasis"><em>pgrep</em></span> utility, for instance, displays the processes whose names match a given regular expression.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1280
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1281
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1282
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1283
<div class="section" title="13.2.tr">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1284
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1285
<a name="id2971438"></a>13.2.tr</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1286
<p id="ch9Using_Linux_Tools_1a5"><span class="emphasis"><em>tr</em></span> (abbreviated from <span class="emphasis"><em>translate</em></span> or <span class="emphasis"><em>transliterate</em></span>) is a command in Unix-like operating systems.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1287
<p id="ch9Using_Linux_Tools_1a6">When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1288
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1289
$ tr 'abcd' 'jkmn'</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1290
<p id="ch9Using_Linux_Tools_1a7">maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1291
<p id="ch9Using_Linux_Tools_1a8">Sets of characters may be abbreviated by using character ranges. The previous example could be written:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1292
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1293
$ tr 'a-d' 'jkmn'</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1294
<p id="ch9Using_Linux_Tools_1a9">In POSIX compliant versions of <span class="emphasis"><em>tr</em></span> the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1295
<p id="ch9Using_Linux_Tools_1aa">The <span class="emphasis"><em>-c</em></span> flag complements the first set of characters.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1296
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1297
$ tr -cd '[:alnum:]'</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1298
<p id="ch9Using_Linux_Tools_1ab">therefore removes all non-alphanumeric characters.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1299
<p id="ch9Using_Linux_Tools_1ac">The <span class="emphasis"><em>-s</em></span> flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1300
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1301
$ tr -s ' n' ' n'</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1302
<p id="ch9Using_Linux_Tools_1ad">replaces sequences of one or more newline characters with a single newline.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1303
<p id="ch9Using_Linux_Tools_1ae">The <span class="emphasis"><em>-d</em></span> flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1304
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1305
$ tr -d ' r'</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1306
<p id="ch9Using_Linux_Tools_1af">Most versions of <span class="emphasis"><em>tr</em></span>, including GNU <span class="emphasis"><em>tr</em></span> and classic Unix <span class="emphasis"><em>tr</em></span>, operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1307
<p id="ch9Using_Linux_Tools_1b0">Ruby and Perl also have an internal <span class="emphasis"><em>tr</em></span> operator, which operates analogously. Tcl's <span class="emphasis"><em>string map</em></span> command is more general in that it maps strings to strings while <span class="emphasis"><em>tr</em></span> maps characters to characters.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1308
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1309
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1310
<div class="section" title="14.Elementary Regex">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1311
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1312
<a name="id2971585"></a>14.Elementary Regex</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1313
<p id="ch9Using_Linux_Tools_1b1">In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1314
<p id="ch9Using_Linux_Tools_1b2">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 <span class="emphasis"><em>ed</em></span> and the filter <span class="emphasis"><em>grep</em></span>  were the first to popularize the concept of regular expressions.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1315
<p id="ch9Using_Linux_Tools_1b3">Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX <span class="emphasis"><em>Basic Regular Expressions</em></span> (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1316
<p id="ch9Using_Linux_Tools_1b4">In the BRE syntax, most characters are treated as literals  they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1317
<p id="ch9Using_Linux_Tools_1b5">Metacharacter</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1318
<p id="ch9Using_Linux_Tools_1b6">Description</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1319
<p id="ch9Using_Linux_Tools_1b7">.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1320
<p id="ch9Using_Linux_Tools_1b8">Matches any single character (many applications exclude
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1321
newlines, and exactly which characters are considered
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1322
newlines is flavor, character encoding, and platform
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1323
specific, but it is safe to assume that the line feed
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1324
character is included). Within POSIX bracket expressions,
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1325
the dot character matches a literal dot. For example, a.c
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1326
matches abc, etc., but [a.c] matches only a, ., or
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1327
c.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1328
<p id="ch9Using_Linux_Tools_1b9">[ ]</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1329
<p id="ch9Using_Linux_Tools_1ba">A bracket expression. Matches a single character that is
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1330
contained within the brackets. For example, [abc] matches
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1331
a, b, or c. [a-z] specifies a range which matches any
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1332
lowercase letter from a to z. These forms can be mixed:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1333
[abcx-z] matches a, b, c, x, y, or z, as does
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1334
[a-cx-z]. The - character is treated as a literal character
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1335
if it is the last or the first character within the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1336
brackets, or if it is escaped with a backslash: [abc-],
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1337
[-abc], or [a-bc].</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1338
<p id="ch9Using_Linux_Tools_1bb">[^ ]</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1339
<p id="ch9Using_Linux_Tools_1bc">Matches a single character that is not contained within the
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1340
brackets. For example, [^abc] matches any character other
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1341
than a, b, or c. [^a-z] matches any single character
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1342
that is not a lowercase letter from a to z. As above,
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1343
literal characters and ranges can be mixed.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1344
<p id="ch9Using_Linux_Tools_1bd">^</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1345
<p id="ch9Using_Linux_Tools_1be">Matches the starting position within the string. In
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1346
line-based tools, it matches the starting position of any
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1347
line.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1348
<p id="ch9Using_Linux_Tools_1bf">$</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1349
<p id="ch9Using_Linux_Tools_1c0">Matches the ending position of the string or the position
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1350
just before a string-ending newline. In line-based tools,
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1351
it matches the ending position of any line.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1352
<p id="ch9Using_Linux_Tools_1c1">*</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1353
<p id="ch9Using_Linux_Tools_1c2">Matches the preceding element zero or more times. For
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1354
example, ab*c matches "ac", "abc", "abbbc", etc. [xyz]*
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1355
matches "", "x", "y", "z", "zx", "zyx", "xyzzy", and so on.
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1356
(ab)* matches "", "ab", "abab", "ababab", and so on.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1357
<p id="ch9Using_Linux_Tools_1c3">?</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1358
<p id="ch9Using_Linux_Tools_1c4">Matches the preceding element zero or one time. For
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1359
example, ba? matches "b" or "ba".</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1360
<p id="ch9Using_Linux_Tools_1c5">+</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1361
<p id="ch9Using_Linux_Tools_1c6">Matches the preceding element one or more times. For
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1362
example, ba+ matches "ba", "baa", "baaa", and so on.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1363
<p id="ch9Using_Linux_Tools_1c7">|</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1364
<p id="ch9Using_Linux_Tools_1c8">The choice (aka alternation or set union) operator matches
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1365
either the expression before or the expression after the
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1366
operator. For example, abc|def matches "abc" or "def".</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1367
<div class="section" title="14.1.Lazy quantification">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1368
<div class="titlepage"><div><div><h3 class="title">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1369
<a name="id2971786"></a>14.1.Lazy quantification</h3></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1370
<p id="ch9Using_Linux_Tools_1c9">The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between &lt; and &gt; symbols in this example:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1371
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1372
Another whale explosion occurred on &lt;January 26&gt;, &lt;2004&gt;.</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1373
<p id="ch9Using_Linux_Tools_1ca">...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".</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1374
<p id="ch9Using_Linux_Tools_1cb">Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: &lt;[^&gt;]*&gt;), modern regular expression tools allow a quantifier to be specified as <span class="emphasis"><em>lazy</em></span> (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., &lt;.*?&gt;), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1375
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1376
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1377
<div class="section" title="15.One Liners">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1378
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1379
<a name="id2971862"></a>15.One Liners</h2></div></div></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1380
<p id="ch9Using_Linux_Tools_1cc">A <span class="emphasis"><em>one-liner</em></span> is textual input to the command-line of an operating system shell that performs some function in just one line of input.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1381
<p id="ch9Using_Linux_Tools_1cd">The one liner can be</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1382
<div class="orderedlist"><ol class="orderedlist" type="1">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1383
<li class="listitem"><p id="ch9Using_Linux_Tools_1ce">An expression written in the language of the shell.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1384
<li class="listitem"><p id="ch9Using_Linux_Tools_1cf">The invocation of an interpreter together with program source for the interpreter to run.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1385
<li class="listitem"><p id="ch9Using_Linux_Tools_1d0">The invocation of a compiler together with source to compile and
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1386
instructions for executing the compiled program.</p></li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1387
</ol></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1388
<p id="ch9Using_Linux_Tools_1d1">Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1389
<p id="ch9Using_Linux_Tools_1d2">The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1390
<p id="ch9Using_Linux_Tools_1d3">The word <span class="emphasis"><em>One-liner</em></span> has two references in the index of the book <span class="emphasis"><em>The AWK Programming Language</em></span> (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1391
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1392
The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1393
<p id="ch9Using_Linux_Tools_1d4">Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1394
<p id="ch9Using_Linux_Tools_1d5">The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1395
<p id="ch9Using_Linux_Tools_1d6">Here are the first few of them:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1396
<div class="orderedlist"><ol class="orderedlist" type="1">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1397
<li class="listitem">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1398
<p id="ch9Using_Linux_Tools_1d7">Print the total number of input lines:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1399
<p id="ch9Using_Linux_Tools_1d8">END { print NR }</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1400
</li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1401
<li class="listitem">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1402
<p id="ch9Using_Linux_Tools_1d9">Print the tenth input line:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1403
<p id="ch9Using_Linux_Tools_1da">NR == 10</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1404
</li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1405
<li class="listitem">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1406
<p id="ch9Using_Linux_Tools_1db">Print the last field of every input line:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1407
<p id="ch9Using_Linux_Tools_1dc">{ print $NF }</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1408
</li>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1409
</ol></div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1410
<p id="ch9Using_Linux_Tools_1dd">One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1411
<p id="ch9Using_Linux_Tools_1de">The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1412
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1413
main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1414
*t-42?*s?63==*t|*s==*t&amp;&amp;m(s+1,t+1):!*t:m(s,t+1)||*s&amp;&amp;m(s+1,t);}</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1415
<p id="ch9Using_Linux_Tools_1df">This one-liner program is a <span class="emphasis"><em>glob pattern matcher</em></span>. It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1416
<p id="ch9Using_Linux_Tools_1e0">Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1417
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1418
$ prog foo 'f??'; echo $?
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1419
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1420
$ prog 'best short program' '??st*o**p?*'; echo $?</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1421
<p id="ch9Using_Linux_Tools_1e1">Here is a one line shell script to show directories:</p>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1422
<pre class="programlisting">
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1423
$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^ /]* //--/g' -e 's/^/   /' -e 's/-/|/'</pre>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1424
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1425
</div>
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1426
</div></body>
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents:
diff changeset
  1427
</html>
28
514098969b11 Testing
amit@thunder
parents: 27
diff changeset
  1428