LDP/LDP/guide/docbook/GNU-Linux-Tools-Summary/GNU-Linux-Tools-Summary.sgml

1825 lines
431 KiB
Plaintext

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN"
[
<!entity index SYSTEM "index.sgml">
<!entity bibliography SYSTEM "bibliography.sgml">
<!entity appendix SYSTEM "appendix.sgml">
<!ENTITY % output.print.png "IGNORE">
<!ENTITY % output.print.pdf "IGNORE">
<!ENTITY % output.print.eps "IGNORE">
<!ENTITY % output.print.bmp "IGNORE">
]>
<book lang="en"><!-- DocBook file was created by LyX 1.2
See http://www.lyx.org/ for more information -->
<bookinfo><title>GNU/Linux Command-Line Tools Summary</title><authorgroup>
<author>
<firstname>Gareth</firstname> <surname>Anderson</surname>
<affiliation>
<address>
<email>somecsstudent(at)gmail.com</email>
</address>
</affiliation>
</author>
<othercredit role="converter">
<contrib>Conversion from LyX to DocBook SGML, Index generation</contrib>
<firstname>Chris</firstname> <surname>Karakas</surname>
</othercredit>
</authorgroup>
<keywordset>
<keyword>Linux</keyword>
<keyword>Unix</keyword>
<keyword>commands</keyword>
<keyword>Linux commands</keyword>
<keyword>Unix commands</keyword>
<keyword>Linux tools</keyword>
<keyword>Unix tools</keyword>
<keyword>tutorial</keyword>
<keyword>command line</keyword>
<keyword>prompt</keyword>
<keyword>command reference</keyword>
<keyword>command tutorial</keyword>
<keyword>command line reference</keyword>
<keyword>command line tutorial</keyword>
<keyword>tools tutorial</keyword>
<keyword>tools reference</keyword>
<keyword>tool</keyword>
<keyword>linux command reference</keyword>
<keyword>linux command tutorial</keyword>
<keyword>linux command line reference</keyword>
<keyword>linux command line tutorial</keyword>
<keyword>linux tools tutorial</keyword>
<keyword>linux tools reference</keyword>
<keyword>linux tool</keyword>
<keyword>Unix command reference</keyword>
<keyword>Unix command tutorial</keyword>
<keyword>Unix command line reference</keyword>
<keyword>Unix command line tutorial</keyword>
<keyword>Unix tools tutorial</keyword>
<keyword>Unix tools reference</keyword>
<keyword>Unix tool</keyword>
</keywordset>
<abstract><para>This document is an attempt to provide a summary of useful command-line tools available to a GNU/Linux based operating system, the tools listed are designed to benefit the majority of users and have being chosen at the authors discretion. This document is not a comprehensive list of <emphasis>every </emphasis>existent tool available to a GNU/Linux based system, nor does it have in-depth explanations of how things work. It is a summary which can be used to learn about and how to use many of the tools available to a GNU/Linux based operating system.</para></abstract><revhistory>
<revision>
<revnumber>1.2</revnumber>
<date>15th April 2006</date>
<authorinitials>GA</authorinitials>
<revremark>
Corrected typing errors, generated new, much smaller index (more accurate in my opinion). Updated errors in document for TLDP.
</revremark>
</revision>
<revision>
<revnumber>1.1</revnumber>
<date>28th February 2006</date>
<authorinitials>CK</authorinitials>
<revremark>
Corrected typos, generated new index (9000 index entries!).
</revremark>
</revision>
<revision>
<revnumber>1.0</revnumber>
<date>6th February 2006</date>
<authorinitials>GA</authorinitials>
<revremark>
Major restructuring, now in a docbook book format. Removed large chunks of content and revised other parts (removed chapters and sectioned some areas more). This is likely the final release by the author, I hope that someone finds this guide useful as I do not intend to continue work on this guide.
</revremark>
</revision>
<revision>
<revnumber>0.7.1</revnumber>
<date>25th February 2005</date>
<authorinitials>CK</authorinitials>
<revremark>
Set special characters in math mode, produced PDF and PS with Computer Modern fonts in OT1 encoding and created correct SGML for key combinations.
</revremark>
</revision>
<revision>
<revnumber>0.7</revnumber>
<date>5th December 2004</date>
<authorinitials>GA</authorinitials>
<revremark>
Updated document with new grammatical review. Re-ordered the entire Text section. Removed a fair amount of content.
</revremark>
</revision>
<revision>
<revnumber>v0.6</revnumber>
<date>20th April 2004</date>
<authorinitials>GA</authorinitials>
<revremark>
<remark>Attempted to fix document according to TLDP criticisms. Added notes and tips more sectioning. Now complying to the open group standards for the <productname>UNIX</productname> system trademark. Document should be ready for TLDP site.</remark>
</revremark>
</revision>
<revision>
<revnumber>v0.5</revnumber>
<date>6th October 2003</date>
<authorinitials>GA</authorinitials>
<revremark>
Fixed a variety of errors as according to the review and made some consistency improvements to the document.
</revremark>
</revision>
<revision>
<revnumber>v0.4</revnumber>
<date>15th July 2003</date>
<authorinitials>GA</authorinitials>
<revremark>
Made small improvements to the document as suggested (so far) by the thorough TLDP review, improved consistency of document and made small content additions.
</revremark>
</revision>
<revision>
<revnumber>v0.3</revnumber>
<date>26th June 2003</date>
<authorinitials>GA</authorinitials>
<revremark>
Minor errors fixed, updated the appendix with information for finding where a tool is from. Fixed referencing/citation problems and improved further reading and intro sections, added an audio section.
</revremark>
</revision>
<revision>
<revnumber>v0.2</revnumber>
<date>20th April 2003</date>
<authorinitials>GA</authorinitials>
<revremark>
This is the initial public release. Added more code-style then before, broke text-section into more subsections. Improved consistency of document and fixed various index entries.
</revremark>
</revision>
<revision>
<revnumber>v0.1</revnumber>
<date>27th March 2003</date>
<authorinitials>GA</authorinitials>
<revremark>
This is the initial draft release (the first release to be converted from LyX to DocBook SGML).
</revremark>
</revision>
</revhistory>
</bookinfo>
<chapter id="Introduction"><title>Introduction</title><para>This document is an attempt to summarise <indexterm><primary>summarise</primary></indexterm>the many command-line based <indexterm><primary>command-line-based</primary></indexterm>tools available to a GNU/Linux based operating system. This guide <indexterm><primary>guide</primary></indexterm>is not a complete listing (I doubt it's possible to document<indexterm><primary>document</primary></indexterm> all available programs), this document lists many tools which are available to GNU/Linux systems and which are, or can be useful to the majority <indexterm><primary>majority</primary></indexterm>of users.</para><para>Each tool description <indexterm><primary>description</primary></indexterm>provides a quick overview of it's function <indexterm><primary>function</primary></indexterm>and some useful options <indexterm><primary>options</primary></indexterm>for that individual tool.</para><para>The tools listed <indexterm><primary>listed</primary></indexterm>that require a GUI,<indexterm><primary>GUI</primary></indexterm> usually the X windowing <indexterm><primary>X windowing</primary></indexterm>system, are those listed in the Graphics <indexterm><primary>Graphics</primary></indexterm>Tools section. All other tools are completely command-line-based <indexterm><primary>command-line-based</primary></indexterm>and do not require a <acronym>GUI</acronym> <indexterm><primary>GUI</primary></indexterm>to run. </para><para>If you are looking <indexterm><primary>looking</primary></indexterm>for information on <acronym>GUI</acronym> <indexterm><primary>GUI</primary></indexterm>based tools you will need to look elsewhere.</para><para>Also note that a few of the tools in this guide are bash <indexterm><primary>bash</primary></indexterm>(the Bourne-Again-SHell<indexterm><primary>Bourne-Again-SHell</primary></indexterm>) specific, tools specific <indexterm><primary>specific</primary></indexterm>to other shells <indexterm><primary>shells</primary></indexterm>are not listed in this document.</para><para>For some of the tools that are harder to use, or perform a more complex<indexterm><primary>complex</primary></indexterm> task,<indexterm><primary>task</primary></indexterm> there are several mini-tutorials <indexterm><primary>mini-tutorials</primary></indexterm>(or mini-guides;<indexterm><primary>mini-guides</primary></indexterm> <xref linkend="Mini-guides">) within this document.</para><para>Where a mini-guide <indexterm><primary>mini-guide</primary></indexterm>was considered unncessary, detailed descriptions that explain in detail how a particular tool works, and some examples <indexterm><primary>examples</primary></indexterm>of how to use it are provided.<indexterm><primary>provided</primary></indexterm></para><para>Please note that the word &ldquo;tool&rdquo; is used interchangeably <indexterm><primary>interchangeably</primary></indexterm>with the word &ldquo;command&rdquo;, both have the same meaning (at least in this guide). For a more detailed <indexterm><primary>detailed</primary></indexterm>explanation, read about the <productname>UNIX</productname> Tools Philosophy <indexterm><primary>UNIX Tools Philosophy</primary></indexterm>here: <xref linkend="The-UNIX-Tools-Philosophy"> or visit the links in the appendix,<indexterm><primary>appendix</primary></indexterm> <xref linkend="unix-tools-further-reading">.<indexterm><primary>enable</primary></indexterm></para><tip>
<title>To find out which tools are bash specific</title>
<para>To find out which tools are bash specific you can type:
<screen>enable -a</screen>
</para>
</tip>
<sect1 id="who-would-want-to-read-this-guide"><title>Who would want to read this guide?</title><para>Anyone who is interested in learning <indexterm><primary>learning</primary></indexterm>about the tools (also known as commands) available to them when using their GNU/Linux based operating system.</para><para>Why would you want to learn <indexterm><primary>learn</primary></indexterm>how to use the command-line<indexterm><primary>command-line</primary></indexterm> (and available tools)? The <emphasis>C</emphasis>ommand <emphasis>L</emphasis>ine<emphasis>-I</emphasis>nterface (CLI)<indexterm><primary>CLI</primary></indexterm><indexterm><primary>command line-interface</primary></indexterm>, while difficult to learn, is the quickest <indexterm><primary>quickest</primary></indexterm>and most efficient <indexterm><primary>efficient</primary></indexterm>way to use a computer for many different tasks. The CLI <indexterm><primary>CLI</primary></indexterm>is the normal method of use for most <productname>UNIX</productname> <indexterm><primary>UNIX system</primary></indexterm>system administrators,<indexterm><primary>administrators</primary></indexterm> programmers <indexterm><primary>programmers</primary></indexterm>and some power users<indexterm><primary>power users</primary></indexterm>. While a <acronym>GUI</acronym> <indexterm><primary>GUI</primary></indexterm>is better suited <indexterm><primary>suited</primary></indexterm>to some tasks, many operations are best suited to the CLI.<indexterm><primary>CLI</primary></indexterm></para><para>The major motivation<indexterm><primary>motivation</primary></indexterm> behind learning <indexterm><primary>learning</primary></indexterm>the GNU/Linux CLI <indexterm><primary>CLI</primary></indexterm>is the authors <indexterm><primary>authors</primary></indexterm>idea<indexterm><primary>idea</primary></indexterm> that, with software <indexterm><primary>software</primary></indexterm>in general, the more time spent learning something equals less time spent performing that particular task <emphasis>(authors opinion only<indexterm><primary>authors opinion</primary></indexterm>)</emphasis>.</para><para>This guide is aimed at beginners<indexterm><primary>beginners</primary></indexterm> to intermediate <indexterm><primary>intermediate</primary></indexterm>users who want to learn<indexterm><primary>learn</primary></indexterm> about the command-line <indexterm><primary>command-line</primary></indexterm>tools available to them. Advanced users may wish to use it as a command reference,<indexterm><primary>reference</primary></indexterm> however this document aims to list <indexterm><primary>list</primary></indexterm>commands of interest, as judged <indexterm><primary>judged</primary></indexterm>by the authors opinion,<indexterm><primary>authors opinion</primary></indexterm> it is not designed <indexterm><primary>designed</primary></indexterm>to be completely comprehensive,<indexterm><primary>comprehensive</primary></indexterm> see the appendix,<indexterm><primary>appendix</primary></indexterm> <xref linkend="general-further-reading"> for further information. Or if you are not looking for a command reference <indexterm><primary>reference</primary></indexterm>guide, but a more gentle introduction to GNU/Linux you may be interested in the <ulink url="http://www.tldp.org/LDP/intro-linux/html/">Introduction to <productname>Linux</productname> guide</ulink><indexterm><primary>Introduction to <productname>Linux</productname> guide</primary></indexterm> authored <indexterm><primary>authored</primary></indexterm>by Machtelt Garrels.<indexterm><primary>Machtelt Garrels</primary></indexterm></para><para>This guide could also be considered a summarised <indexterm><primary>summarised</primary></indexterm>version of the <productname>Linux</productname> Cookbook.<indexterm><primary>Linux Cookbook</primary></indexterm> If you are looking for a book <indexterm><primary>book</primary></indexterm>with more detailed descriptions of each tool have a look at the <ulink url="http://dsl.org/cookbook/">Linux Cookbook Homepage</ulink>, also check out the <ulink url="http://www.onlamp.com/linux/cmd/">command list from "Linux in a Nutshell 3rd Edition"</ulink><indexterm><primary>command list</primary></indexterm><indexterm><primary>Linux in a Nutshell 3rd Edition</primary></indexterm> for an index <indexterm><primary>index</primary></indexterm>of 300+ commands and their explanations.<indexterm><primary>explanations</primary></indexterm></para></sect1>
<sect1 id="who-would-not-want-to-read-this-guide"><title>Who would not want to read this guide?</title><para>Anyone who is not interested in the command-line<indexterm><primary>command-line</primary></indexterm>, or anyone looking for a detailed reference to all available GNU/Linux tools should look elsewhere. This is only a summary,<indexterm><primary>summary</primary></indexterm> while it does list many commands, it's not a complete<indexterm><primary>complete</primary></indexterm> listing <indexterm><primary>listing</primary></indexterm>(I don't think it's possible to make a complete listing anyway).</para><para>This document would not be of interest to those who already have an expert <indexterm><primary>expert</primary></indexterm>knowledge <indexterm><primary>knowledge</primary></indexterm>of the command-line interface <indexterm><primary>command-line interface</primary></indexterm>and do require any reference <indexterm><primary>reference</primary></indexterm>information.<indexterm><primary>information</primary></indexterm> Or those readers <indexterm><primary>readers</primary></indexterm>who require detailed <indexterm><primary>detailed</primary></indexterm>lists <indexterm><primary>lists</primary></indexterm>of options <indexterm><primary>options</primary></indexterm>for each command, the man pages<indexterm><primary>man pages</primary></indexterm> are better suited <indexterm><primary>suited</primary></indexterm>to this purpose.<indexterm><primary>purpose</primary></indexterm></para></sect1>
<sect1 id="sources-of-document"><title>Availability of sources</title><para>The modifiable <indexterm><primary>modifiable</primary></indexterm>sources <indexterm><primary>sources</primary></indexterm>of the original <indexterm><primary>original</primary></indexterm>book <indexterm><primary>book</primary></indexterm>(in english), are available<indexterm><primary>available</primary></indexterm> in LyX <indexterm><primary>LyX</primary></indexterm>format <indexterm><primary>format</primary></indexterm>(LyX Document Processor) or Machine-translated <indexterm><primary>Machine-translated</primary></indexterm>SGML <indexterm><primary>SGML</primary></indexterm>(SGML markup language<indexterm><primary>markup language</primary></indexterm>). </para><para>LyX is a completely free document processor <indexterm><primary>document processor</primary></indexterm>based on LaTeX,<indexterm><primary>LaTeX</primary></indexterm> downloadable<indexterm><primary>downloadable</primary></indexterm> from <ulink url="http://www.lyx.org">the LyX homepage.</ulink>.</para><para>See <!-- <xref linkend="formats"> --> for the modifiable <indexterm><primary>modifiable</primary></indexterm>sources <indexterm><primary>sources</primary></indexterm>of this document. These are the official <indexterm><primary>official</primary></indexterm>versions.<indexterm><primary>versions</primary></indexterm> We (the translators <indexterm><primary>translators</primary></indexterm>and current maintainers<indexterm><primary>maintainers</primary></indexterm>) plan to continue work on this document and add new chapters and enhancements.<indexterm><primary>enhancements</primary></indexterm> If you want to see the version <indexterm><primary>version</primary></indexterm>we are currently working on (the &quot;bleeding edge&quot; version), check the <ulink url="http://www.karakas-online.de/gnu-linux-tools-summary/">GNU/Linux Command-Line Tools Summary Homepage</ulink><indexterm><primary>GNU/Linux Tools Summary Homepage</primary></indexterm> from time to time (kindly hosted <indexterm><primary>hosted</primary></indexterm>by <ulink url="http://www.karakas-online.de">Chris Karakas</ulink><indexterm><primary>Chris Karakas</primary></indexterm>).</para></sect1>
<sect1 id="conventions"><title>Conventions used in this guide</title><para>The following conventions <indexterm><primary>conventions</primary></indexterm>are used within this guide:</para><variablelist><varlistentry><term>italic
</term><listitem><para><indexterm><primary>italic</primary></indexterm>Anything appearing in italic, <emphasis>like&nbsp;this </emphasis>is either an executable <indexterm><primary>executable</primary></indexterm>command or emphasized <indexterm><primary>emphasized</primary></indexterm>text. Tools (executable commands) are in italics <indexterm><primary>italics</primary></indexterm>to prevent confusion. Some tools have names which are real english <indexterm><primary>english</primary></indexterm>words, such as the &ldquo;locate&rdquo; tool.</para></listitem></varlistentry><varlistentry><term>key&nbsp;combinations
</term><listitem><para><indexterm><primary>key combinations</primary></indexterm>Are represented by using a '-' (dash sign)<indexterm><primary>dash sign</primary></indexterm> in-between the key(s), which must be used in combination.<indexterm><primary>combination</primary></indexterm> All combinations <indexterm><primary>combinations</primary></indexterm>are also printed <indexterm><primary>printed</primary></indexterm>in italics <indexterm><primary>italics</primary></indexterm>to improve clarity.<indexterm><primary>clarity</primary></indexterm> For example
<keycombo>
<keycap>CTRL</keycap>
<keycap>Z</keycap>
</keycombo>
<indexterm>
<primary>CTRL-Z</primary>
</indexterm>
means hold down the<emphasis> Control key<indexterm><primary>Control key</primary></indexterm></emphasis> and press the <emphasis>z</emphasis> <emphasis>key.</emphasis></para></listitem></varlistentry><varlistentry><term>admonitions
</term><listitem><para><indexterm><primary>admonitions</primary></indexterm>Admonitions are little pictures <indexterm><primary>pictures</primary></indexterm>used to emphasize <indexterm><primary>emphasize</primary></indexterm>something of importance <indexterm><primary>importance</primary></indexterm>to the reader.<indexterm><primary>reader</primary></indexterm> </para><para>The five types used are:</para><note>
<title>This is a note</title>
<para>
Notes often give important information about a tool.
</para>
</note>
<tip>
<title>This is a tip</title>
<para>
This will offer a useful switch or useful way to use a tool.
</para>
</tip>
<important>
<title>This is something important</title>
<para>
This is something that is considered very important. Consider it like a note with extra importance, they are usually there to save the reader time.
</para>
</important>
<caution>
<title>This is a caution</title>
<para>
This will inform you of something that you be careful about (because it could be harmful to your system).
</para>
</caution>
<warning>
<title>This is a warning</title>
<para>
This will inform you of something that you shouldn't do (because it probably will break something within your system).
</para>
</warning>
</listitem></varlistentry><varlistentry><term>code&nbsp;examples
</term><listitem><para>Code <indexterm><primary>Code</primary></indexterm>examples <indexterm><primary>examples</primary></indexterm>are shown for most commands. </para><para>Below is an example of what code <indexterm><primary>code</primary></indexterm>looks like:</para><screen><![CDATA[Hello World, I'm a code example. :)
]]></screen></listitem></varlistentry><varlistentry><term>command&nbsp;syntax
</term><listitem><para><indexterm><primary>command syntax</primary></indexterm>(or a similar phrase) simply shows how you would normally use the command. Often real examples <indexterm><primary>examples</primary></indexterm>are used instead of explaining <indexterm><primary>explaining</primary></indexterm>the command syntax. </para><para>The phrase &ldquo; Command syntax&rdquo; is always followed by the way you would type a command in a shell.<indexterm><primary>shell</primary></indexterm></para><para>The standard <indexterm><primary>standard</primary></indexterm>syntax <indexterm><primary>syntax</primary></indexterm>for any tool is usually:</para><screen><![CDATA[command -options file
]]></screen><note>
<title>Note</title>
<para>Note that some tools do not accept options.</para>
</note>
</listitem></varlistentry><varlistentry><term>wildcards
</term><listitem><para><indexterm><primary>wildcards</primary></indexterm>Also note that most commands, even when not explicitly <indexterm><primary>explicitly</primary></indexterm>stated, will work with standard wildcards <indexterm><primary>standard wildcards</primary></indexterm> (or globbing patterns<indexterm><primary>globbing patterns</primary></indexterm>) such as *, [A-Z] and various other standard wildcards. Refer <indexterm><primary>Refer</primary></indexterm>to <xref linkend="standard-wildcards"> for further information.</para></listitem></varlistentry><varlistentry><term>access&nbsp;keys
</term><listitem><para><indexterm><primary>access keys</primary></indexterm>Access keys enable <indexterm><primary>enable</primary></indexterm>navigation through the document, without relying on a mouse.<indexterm><primary>mouse</primary></indexterm> The following keys have been given special <indexterm><primary>special</primary></indexterm>meaning in this document:</para><variablelist><varlistentry><term>P
</term><listitem><para>Previous <indexterm><primary>Previous</primary></indexterm>page.<indexterm><primary>page</primary></indexterm></para></listitem></varlistentry><varlistentry><term>N
</term><listitem><para>Next <indexterm><primary>Next</primary></indexterm>page.</para></listitem></varlistentry><varlistentry><term>H
</term><listitem><para>Home <indexterm><primary>Home</primary></indexterm>of the document (Table of Contents).<indexterm><primary>Table of Contents</primary></indexterm></para></listitem></varlistentry><varlistentry><term>U
</term><listitem><para>Up<indexterm><primary>Up</primary></indexterm> (takes you one level <indexterm><primary>level</primary></indexterm>up the section <indexterm><primary>section</primary></indexterm>hierarchy).</para></listitem></varlistentry></variablelist><para>If you also happen to be reading <indexterm><primary>reading</primary></indexterm>the document from its original <indexterm><primary>original</primary></indexterm>location, then the following access keys can also be used:</para><variablelist><varlistentry><term>S
</term><listitem><para>Start <indexterm><primary>Start</primary></indexterm>(takes you to the author's start page).</para></listitem></varlistentry><varlistentry><term>T
</term><listitem><para>The current <indexterm><primary>current</primary></indexterm>(&ldquo;This&rdquo;) page, without the Sitemenu <indexterm><primary>Sitemenu</primary></indexterm>on the left.</para></listitem></varlistentry><varlistentry><term>M
</term><listitem><para>The current page in a frameset,<indexterm><primary>frameset</primary></indexterm> where the left frame <indexterm><primary>frame</primary></indexterm>contains a Menu.<indexterm><primary>Menu</primary></indexterm></para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist><para>
To use the access keys, you have to simultaneously press a modifier key, which may vary from browser to browser. For example in NN6+/Mozilla, the modifier key is <keycap>ALT</keycap>, so you have to use
<keycombo>
<keycap>ALT</keycap>
<keycap>N</keycap>
</keycombo>
to go to the next page, and
<keycombo>
<keycap>ALT</keycap>
<keycap>P</keycap>
</keycombo>
to come back. In other browsers such as IE6, the access keys just give focus to the associated link, so the sequence becomes
<keycombo action='seq'>
<keycombo>
<keycap>ALT</keycap>
<keycap>N</keycap>
</keycombo>
<keycap>Enter</keycap>
</keycombo>
. Try it, you'll like it! <!-- <inlinemediaobject> <![ %output.print.png; [ <imageobject> <imagedata fileref="icon_smile.png" format="PNG"/> </imageobject> ]]> <![ %output.print.pdf; [ <imageobject> <imagedata fileref="icon_smile.pdf" format="PDF" scale="65"/> </imageobject> ]]> <![ %output.print.eps; [ <imageobject> <imagedata fileref="icon_smile.eps" format="EPS"/> </imageobject> ]]> <![ %output.print.bmp; [ <imageobject> <imagedata fileref="icon_smile.bmp" format="BMP"/> </imageobject> ]]> <textobject> <phrase>Inline graphic</phrase> </textobject> </inlinemediaobject> --></para>
</sect1>
<sect1 id="resources-used-to-create-this-document"><title>Resources used to create this document </title><para>To create the GNU/Linux Command-Line <indexterm><primary>Command-Line</primary></indexterm>Tools Summary,<indexterm><primary>Summary</primary></indexterm> I used <ulink url="http://www.lyx.org">LyX</ulink>, the document processor.<indexterm><primary>document processor</primary></indexterm> To convert <indexterm><primary>convert</primary></indexterm>the LyX files to DocBook <indexterm><primary>DocBook</primary></indexterm>SGML <indexterm><primary>SGML</primary></indexterm>I used the <ulink url="http://www.karakas-online.de/mySGML/">lyxtox Scripts</ulink><indexterm><primary>lyxtox</primary></indexterm> created by <ulink url="http://www.karakas-online.de">Chris Karakas</ulink><indexterm><primary>Chris Karakas</primary></indexterm>.</para><para>You may also want to check out the <ulink url="http://bgu.chez.tiscali.fr/">db2lyx </ulink><indexterm><primary>db2lyx</primary></indexterm> package,<indexterm><primary>package</primary></indexterm> created by Dr. B Guillion<indexterm><primary>Dr. B. Guillion</primary></indexterm>, which can be used to convert LyX files to XML <indexterm><primary>XML</primary></indexterm>DocBook and XML DocBook <indexterm><primary>DocBook</primary></indexterm>back to LyX. </para><para>I also had assistance <indexterm><primary>assistance</primary></indexterm>from various <ulink url="http://www.tldp.org">The <productname>Linux</productname> Documentation Project</ulink><indexterm><primary>The <productname>Linux</productname> Documentation Project</primary></indexterm> volunteers <indexterm><primary>volunteers</primary></indexterm>(see the contributors <indexterm><primary>contributors</primary></indexterm>section <indexterm><primary>section</primary></indexterm><xref linkend="contributors"> for specific <indexterm><primary>specific</primary></indexterm>details).</para></sect1>
<sect1 id="feedback"><title>Feedback</title><para>Feedback <indexterm><primary>Feedback</primary></indexterm>is necessary for the advancement <indexterm><primary>advancement</primary></indexterm>of this guide. Positive,<indexterm><primary>Positive</primary></indexterm> constructive criticism <indexterm><primary>criticism</primary></indexterm>is encouraged.<indexterm><primary>encouraged</primary></indexterm> If you have ideas,<indexterm><primary>ideas</primary></indexterm> suggestions,<indexterm><primary>suggestions</primary></indexterm> advice,<indexterm><primary>advice</primary></indexterm> or problems <indexterm><primary>problems</primary></indexterm>with this guide, please send <indexterm><primary>send</primary></indexterm>an email <indexterm><primary>email</primary></indexterm>to the author <indexterm><primary>author</primary></indexterm><ulink url="mailto:somecsstudent(at)gmail.com">Gareth Anderson</ulink><indexterm><primary>Gareth Anderson</primary></indexterm>. </para><important>
<title>Contributions</title>
<para>
If you wish to make contributions it is recommended (if possible) to read the LyX file(s) for this document. They contain various notes which you can't see in the other versions.</para>
<para>These notes highlight the areas that need contributions, certain tools which I cannot understand, tools which have not been added, or tools which were removed. These notes also explain some of the structure of this document.
</para>
</important>
</sect1>
<sect1 id="contributors"><title>Contributors </title><para>As you may be able to see, parts <indexterm><primary>parts</primary></indexterm>of this guide are based off <indexterm><primary>based off</primary></indexterm>various advice<indexterm><primary>advice</primary></indexterm> columns <indexterm><primary>columns</primary></indexterm>on GNU/Linux, anything that has being directly quoted <indexterm><primary>quoted</primary></indexterm>from an article<indexterm><primary>article</primary></indexterm> can be found <indexterm><primary>found</primary></indexterm>in the references,<indexterm><primary>references</primary></indexterm> <xref linkend="references">, section <indexterm><primary>section</primary></indexterm>of this document. </para><para>The following is a list <indexterm><primary>list</primary></indexterm>of people <indexterm><primary>people</primary></indexterm>who have made a significant contribution<indexterm><primary>contribution</primary></indexterm> to this document, in a rough <indexterm><primary>rough</primary></indexterm>chronological <indexterm><primary>chronological</primary></indexterm>order.</para><variablelist><varlistentry><term><ulink url="http://www.karakas-online.de">Chris Karakas</ulink>:
</term><listitem><para>Chris allowed the use of his lyxtox <indexterm><primary>lyxtox</primary></indexterm>scripts <indexterm><primary>scripts</primary></indexterm>to convert the LyX <indexterm><primary>LyX</primary></indexterm>file of the document to working DocBook SGML <indexterm><primary>SGML</primary></indexterm>output (to learn <indexterm><primary>learn</primary></indexterm>how to use the lyxtox<indexterm><primary>lyxtox</primary></indexterm> scripts <indexterm><primary>scripts</primary></indexterm>yourself, see <ulink url="http://www.karakas-online.de/mySGML/">Document processing with LyX and SGML</ulink>).</para><itemizedlist><listitem><para>Chris provided useful suggestions <indexterm><primary>suggestions</primary></indexterm>and advice,<indexterm><primary>advice</primary></indexterm> and added an index <indexterm><primary>index</primary></indexterm>listing<indexterm><primary>listing</primary></indexterm> for many of the commands. </para></listitem><listitem><para>Chris is also responsible for the great looking HTML <indexterm><primary>HTML</primary></indexterm>file for this document<indexterm><primary>document</primary></indexterm> (the CSS <indexterm><primary>CSS</primary></indexterm>file and HTML <indexterm><primary>HTML</primary></indexterm>customisations <indexterm><primary>customisations</primary></indexterm>are completely his work).</para></listitem><listitem><para>Chris has also helped fix up problems <indexterm><primary>problems</primary></indexterm>in the document (many times), especially with docbook/sgml, and LyX related issues.<indexterm><primary>issues</primary></indexterm></para></listitem><listitem><para>Chris has also improved <indexterm><primary>improved</primary></indexterm>the structure <indexterm><primary>structure</primary></indexterm>of the document by adding labels and fixing <indexterm><primary>fixing</primary></indexterm>minor errors.</para></listitem></itemizedlist></listitem></varlistentry><varlistentry><term>William&nbsp;West:
</term><listitem><para><indexterm><primary>William West</primary></indexterm>William provided a thorough review <indexterm><primary>review</primary></indexterm>of the document as required<indexterm><primary>required</primary></indexterm> by the <ulink url="http://www.tldp.org">Linux Documentation Project</ulink><indexterm><primary>Linux Documentation Project</primary></indexterm>. He is responsible <indexterm><primary>responsible</primary></indexterm>for a variety of improvements <indexterm><primary>improvements</primary></indexterm>to the quality <indexterm><primary>quality</primary></indexterm>of this document.</para><para>His contributions <indexterm><primary>contributions</primary></indexterm>include:<indexterm><primary>include</primary></indexterm> </para><itemizedlist><listitem><para>Improvements <indexterm><primary>Improvements</primary></indexterm>to the readability <indexterm><primary>readability</primary></indexterm>of this document. </para></listitem><listitem><para>Improvements <indexterm><primary>Improvements</primary></indexterm>to the structure <indexterm><primary>structure</primary></indexterm>and consistency <indexterm><primary>consistency</primary></indexterm>of this document. </para></listitem><listitem><para>Various grammar <indexterm><primary>grammar</primary></indexterm>improvements throughout the document. </para></listitem><listitem><para>Repair <indexterm><primary>Repair</primary></indexterm>of some minor <indexterm><primary>minor</primary></indexterm>technical errors.<indexterm><primary>errors</primary></indexterm></para></listitem></itemizedlist></listitem></varlistentry><varlistentry><term><ulink url="http://www.merlinmonroe.com/">Tabatha Persad/Marshall</ulink>:
</term><listitem><para><indexterm><primary>Tabatha Persad</primary></indexterm><indexterm><primary>Tabatha Marshall</primary></indexterm>Tabatha, as the <ulink url="http://www.tldp.org">Linux Documentation Project</ulink><indexterm><primary>Linux Documentation Project</primary></indexterm> Review Coordinator<indexterm><primary>Review Coordinator</primary></indexterm> (at the time) also gave a brief review <indexterm><primary>review</primary></indexterm>of this document. Her general advice was used to improve <indexterm><primary>improve</primary></indexterm>the structure,<indexterm><primary>structure</primary></indexterm> language <indexterm><primary>language</primary></indexterm>and grammar<indexterm><primary>grammar</primary></indexterm> of the document.</para></listitem></varlistentry><varlistentry><term><ulink url="http://rahulsundaram.livejournal.com/">Rahul Sundaram</ulink>:
</term><listitem><para><indexterm><primary>Rahul Sundaram</primary></indexterm>Rahul provided a brief review <indexterm><primary>review</primary></indexterm>of this document for the <ulink url="http://www.tldp.org">Linux Documentation Project</ulink><indexterm><primary>Linux Documentation Project</primary></indexterm>. Advice from his brief review <indexterm><primary>review</primary></indexterm>was integrated <indexterm><primary>integrated</primary></indexterm>into this document to improve<indexterm><primary>improve</primary></indexterm> readability <indexterm><primary>readability</primary></indexterm>and structure,<indexterm><primary>structure</primary></indexterm> several <indexterm><primary>several</primary></indexterm>references <indexterm><primary>references</primary></indexterm>were added as recommended<indexterm><primary>recommended</primary></indexterm> by Rahul.</para></listitem></varlistentry><varlistentry><term><ulink url="http://www.lafn.org/~dave/">David Lawyer</ulink>:
</term><listitem><para><indexterm><primary>David Lawyer</primary></indexterm>David's criticism <indexterm><primary>criticism</primary></indexterm>of the document <indexterm><primary>document</primary></indexterm>(via the TLDP <indexterm><primary>TLDP</primary></indexterm>discuss list<indexterm><primary>discuss list</primary></indexterm>) were listened to, and attempts to improve the document were made. A number of his criticisms <indexterm><primary>criticisms</primary></indexterm>were addressed <indexterm><primary>addressed</primary></indexterm>and improved.<indexterm><primary>improved</primary></indexterm> </para></listitem></varlistentry><varlistentry><term>George&nbsp;Harmon:
</term><listitem><para><indexterm><primary>George Harmon</primary></indexterm>George provided <indexterm><primary>provided</primary></indexterm>a second language review<indexterm><primary>language review</primary></indexterm>. His detailed <indexterm><primary>detailed</primary></indexterm>review of the material <indexterm><primary>material</primary></indexterm>allowed me to improve the general grammar<indexterm><primary>grammar</primary></indexterm> of the document and some minor <indexterm><primary>minor</primary></indexterm>errors.</para></listitem></varlistentry><varlistentry><term><ulink url="http://tille.xalasys.com">Machtelt Garrels (tille)</ulink>:
</term><listitem><para><indexterm><primary>tille</primary></indexterm><indexterm><primary>Machtelt Garrels</primary></indexterm>Machtelt provided tips in regard to referencing<indexterm><primary>referencing</primary></indexterm> the correct <indexterm><primary>correct</primary></indexterm>LDP documents <indexterm><primary>documents</primary></indexterm>from this guide.<indexterm><primary>guide</primary></indexterm> As well as general <indexterm><primary>general</primary></indexterm>advice on improvements <indexterm><primary>improvements</primary></indexterm>to the guide.</para></listitem></varlistentry><varlistentry><term>Michael&nbsp;Kerrisk:
</term><listitem><para><indexterm><primary>Michael Kerrisk</primary></indexterm>Michael pointed out a number of technical errors in the document after his brief review <indexterm><primary>review</primary></indexterm>on behalf of the TLDP <indexterm><primary>TLDP</primary></indexterm>during posts to the discussion list.<indexterm><primary>discuss list</primary></indexterm></para></listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Legal"><title>Legal</title><para>The legal <indexterm><primary>legal</primary></indexterm>chapter provides information <indexterm><primary>information</primary></indexterm>about the disclaimer <indexterm><primary>disclaimer</primary></indexterm>that applies to the entire document and the licensing <indexterm><primary>licensing</primary></indexterm>information.</para><sect1 id="disclaimer"><title>Disclaimer</title><para>No liability <indexterm><primary>liability</primary></indexterm>for the contents <indexterm><primary>contents</primary></indexterm>of this document <indexterm><primary>documents</primary></indexterm>can be accepted. Use the concepts,<indexterm><primary>concepts</primary></indexterm> examples <indexterm><primary>examples</primary></indexterm>and other content <indexterm><primary>content</primary></indexterm>at your own risk.<indexterm><primary>risk</primary></indexterm> There may be errors <indexterm><primary>errors</primary></indexterm>and inaccuracies,<indexterm><primary>inaccuracies</primary></indexterm> that may of course be damaging to your system. Although this is highly <indexterm><primary>highly</primary></indexterm>unlikely, you should proceed <indexterm><primary>proceed</primary></indexterm>with caution.<indexterm><primary>caution</primary></indexterm> The author <indexterm><primary>author</primary></indexterm>does not accept any responsibility <indexterm><primary>responsibility</primary></indexterm>for any damage <indexterm><primary>damage</primary></indexterm>incurred.</para><para>All copyrights <indexterm><primary>copyrights</primary></indexterm>are held by their respective owners<indexterm><primary>respective owners</primary></indexterm>, unless specifically<indexterm><primary>specifically</primary></indexterm> noted otherwise. Use of a term <indexterm><primary>term</primary></indexterm>in this document should not be regarded <indexterm><primary>regarded</primary></indexterm>as affecting the validity <indexterm><primary>validity</primary></indexterm>of any trademark <indexterm><primary>trademark</primary></indexterm>or service mark<indexterm><primary>service mark</primary></indexterm>.</para><para>Naming <indexterm><primary>Naming</primary></indexterm>of particular products <indexterm><primary>products</primary></indexterm>or brands <indexterm><primary>brands</primary></indexterm>should not be seen as endorsements.<indexterm><primary>endorsements</primary></indexterm></para><para>UNIX <indexterm><primary>UNIX</primary></indexterm>is a registered trademark <indexterm><primary>trademark</primary></indexterm>of The Open Group<indexterm><primary>The Open Group</primary></indexterm>.</para></sect1>
<sect1 id="license"><title>License</title><para>Copyright <indexterm><primary>Copyright</primary></indexterm>&copy; 2003 - 2006 Gareth Anderson.<indexterm><primary>Gareth Anderson</primary></indexterm> Permission <indexterm><primary>Permission</primary></indexterm>is granted <indexterm><primary>granted</primary></indexterm>to copy,<indexterm><primary>copy</primary></indexterm> distribute <indexterm><primary>distribute</primary></indexterm>and/or modify <indexterm><primary>modify</primary></indexterm>this document under the terms <indexterm><primary>terms</primary></indexterm>of the <acronym>GNU</acronym> <indexterm><primary>GNU</primary></indexterm>Free Documentation License,<indexterm><primary>GNU Free Documentation License</primary></indexterm><indexterm><primary>GFDL</primary></indexterm> Version <indexterm><primary>Version</primary></indexterm>1.1 or any later version <indexterm><primary>version</primary></indexterm>published by the Free Software Foundation;<indexterm><primary>FSF</primary></indexterm><indexterm><primary>Free Software Foundation</primary></indexterm> with no Invariant <indexterm><primary>Invariant</primary></indexterm>Sections,<indexterm><primary>Sections</primary></indexterm> with no Front-Cover <indexterm><primary>Front-Cover</primary></indexterm>Texts, and with no Back-Cover <indexterm><primary>Back-Cover</primary></indexterm>Texts.<indexterm><primary>Texts</primary></indexterm> A copy of the license <indexterm><primary>license</primary></indexterm>can be found in the section called the <acronym>GNU</acronym> Free Documentation License or at the <ulink url="http://www.gnu.org/licenses/licenses.html">GNU Documentation License Site</ulink>.<indexterm><primary>GNU Documentation License Site</primary></indexterm></para></sect1>
</chapter>
<chapter id="The-UNIX-Tools-Philosophy"><title>The Unix Tools Philosophy</title><para>A tool is a simple program,<indexterm><primary>program</primary></indexterm> usually designed for a specific purpose, it is sometimes referred <indexterm><primary>referred</primary></indexterm>to (at least throughout this document) as a command.</para><para>The &ldquo; Unix tools philosophy&rdquo;<indexterm><primary>Unix Tools Philosophy</primary></indexterm> emerged <indexterm><primary>emerged</primary></indexterm>during the creation of the <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>operating system, after the breakthrough invention <indexterm><primary>invention</primary></indexterm>of the pipe <indexterm><primary>pipe</primary></indexterm>'|' (refer to <xref linkend="Directing-input-ouput"> for information on using the pipe).</para><para>The pipe <indexterm><primary>pipe</primary></indexterm>allowed the output <indexterm><primary>output</primary></indexterm>of one program to be sent to the input <indexterm><primary>input</primary></indexterm>of another. The tools philosophy was to have small programs to accomplish a particular task instead of trying to develop large monolithic programs to do a large number of tasks. To accomplish more complex <indexterm><primary>complex</primary></indexterm>tasks,<indexterm><primary>tasks</primary></indexterm> tools would simply be connected <indexterm><primary>connected</primary></indexterm>together, using pipes.<indexterm><primary>pipes</primary></indexterm></para><para>All the core <indexterm><primary>core</primary></indexterm>UNIX system <indexterm><primary>UNIX system</primary></indexterm>tools were designed <indexterm><primary>designed</primary></indexterm>so that they could operate<indexterm><primary>operate</primary></indexterm> together. The original text-based <indexterm><primary>text-based</primary></indexterm>editors (and even <application>TeX</application> <indexterm><primary>TeX</primary></indexterm>and LaTeX<indexterm><primary>LaTeX</primary></indexterm>) use <acronym>ASCII</acronym> <indexterm><primary>ASCII</primary></indexterm>(the American text encoding standard;<indexterm><primary>American text encoding standard</primary></indexterm> an open standard) and you can use tools such as; <emphasis>sed</emphasis>, <emphasis>awk</emphasis>, <emphasis>vi</emphasis>, <emphasis>grep</emphasis>, <emphasis>cat</emphasis>, <emphasis>more</emphasis>, <emphasis>tr</emphasis> and various other text-based <indexterm><primary>text-based</primary></indexterm>tools in conjunction <indexterm><primary>conjunction</primary></indexterm>with these editors.<indexterm><primary>editors</primary></indexterm> </para><para>Using this philosophy <indexterm><primary>philosophy</primary></indexterm>programmers <indexterm><primary>programmers</primary></indexterm>avoided writing <indexterm><primary>writing</primary></indexterm>a program (within their larger program) that had already been written by someone else (this could be considered a form of code <indexterm><primary>code</primary></indexterm>recycling). For example, command-line<indexterm><primary>command-line</primary></indexterm> spell <indexterm><primary>spell</primary></indexterm>checkers are used by a number of different applications instead of having each application <indexterm><primary>application</primary></indexterm>create its own spell checker.<indexterm><primary>checker</primary></indexterm></para><para>This philosophy <indexterm><primary>philosophy</primary></indexterm>lives on today <indexterm><primary>today</primary></indexterm>in GNU/Linux and various other <productname>UNIX</productname> system-based operating systems (FreeBSD,<indexterm><primary>FreeBSD</primary></indexterm> NetBSD,<indexterm><primary>NetBSD</primary></indexterm> OpenBSD,<indexterm><primary>OpenBSD</primary></indexterm> etc.).</para><para>For further information (articles) on the <productname>UNIX</productname> tools philosophy <indexterm><primary>UNIX tools philosophy</primary></indexterm>please see the further reading <indexterm><primary>further reading</primary></indexterm>section, here: <xref linkend="unix-tools-further-reading"></para><para></para></chapter>
<chapter id="Shell-Tips"><title>Shell Tips</title><para>The shell <indexterm><primary>shell</primary></indexterm>tips chapter provides handy tricks that you may wish to use when you are using a GNU/Linux shell (the command-line<indexterm><primary>command-line</primary></indexterm> interface). This information includes handy <indexterm><primary>handy</primary></indexterm>shortcut <indexterm><primary>shortcut</primary></indexterm>key combinations,<indexterm><primary>key combinations</primary></indexterm> the shell's command history<indexterm><primary>command history</primary></indexterm> and information on virtual terminals.<indexterm><primary>virtual terminals</primary></indexterm></para><tip>
<title>If you can't boot into your system</title>
<para>If your having problems booting into your system you may like to use a shell so you can boot into your system and attempt to fix things up again.</para>
<para>To do this you need to pass the &ldquo;init=/bin/sh&rdquo; to your system before you boot up.</para>
<para>If you don't know how to do this please see <xref linkend="Security"><indexterm><primary>Security</primary></indexterm>, the technique is the same except this time you pass "init=bin/sh" rather than "single".</para>
</tip>
<sect1 id="general-Shell-Tips"><title>General Shell Tips</title><variablelist><varlistentry><term>Automatic&nbsp;Command&nbsp;Completion
</term><listitem><para><indexterm><primary>Automatic Command Completion</primary></indexterm>Use the TAB <indexterm><primary>TAB</primary></indexterm>key and bash <indexterm><primary>bash</primary></indexterm>will attempt <indexterm><primary>attempt</primary></indexterm>to complete<indexterm><primary>complete</primary></indexterm> the command for you automatically.<indexterm><primary>automatically</primary></indexterm> You can use it to complete command (tool) names. You can also use it when working with the file-system,<indexterm><primary>file-system</primary></indexterm> when changing directories, copying <indexterm><primary>copying</primary></indexterm>files et cetera.</para><para>There are also other lesser <indexterm><primary>lesser</primary></indexterm>known ways to use automatic command completion<indexterm><primary>automatic command completion</primary></indexterm> (for example completing user names):<footnote><para>This information was adopted (with editing) from Mandrakesoft's Command Line Manual, see [7] in the <xref linkend="references"> for further information.</para></footnote></para><variablelist><varlistentry><term>
<keycombo>
<keycap>ESC</keycap>
<keycap>Y</keycap>
</keycombo>
<indexterm>
<primary>ESC-Y</primary>
</indexterm>
&nbsp;(Y:&nbsp;special&nbsp;character)
</term><listitem><para>testing autoindexing Will attempt to complete the command name for you. If it fails it will either list <indexterm><primary>list</primary></indexterm>the possible completions <indexterm><primary>completions</primary></indexterm>(if they exist). If there are none <indexterm><primary>none</primary></indexterm>it will simply beep <indexterm><primary>beep</primary></indexterm>(and/or) flash <indexterm><primary>flash</primary></indexterm>the screen.<indexterm><primary>screen</primary></indexterm> </para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>X</keycap>
<keycap>Y</keycap>
</keycombo>
<indexterm>
<primary>CTRL-X-Y</primary>
</indexterm>
&nbsp;(Y:&nbsp;special&nbsp;character)
</term><listitem><para>Lists the possible completions (it won't attempt<indexterm><primary>attempt</primary></indexterm> to complete it for you) or beep <indexterm><primary>beep</primary></indexterm>if there are no possible <indexterm><primary>possible</primary></indexterm>completions.</para></listitem></varlistentry></variablelist><para>Special-characters:</para><para>Use the following <indexterm><primary>following</primary></indexterm>special characters<indexterm><primary>special characters</primary></indexterm> combined with either
<keycombo>
<keycap>ESC</keycap>
<keycap>Y</keycap>
</keycombo>
<indexterm>
<primary>ESC-Y</primary>
</indexterm>
or
<keycombo>
<keycap>CTRL</keycap>
<keycap>X</keycap>
<keycap>Y</keycap>
</keycombo>
<indexterm>
<primary>CTRL-X-Y</primary>
</indexterm>
, where Y is some special characters. For example
<keycombo>
<keycap>ESC</keycap>
<keycap>$</keycap>
</keycombo>
<indexterm>
<primary>ESC-$</primary>
</indexterm>
or
<keycombo>
<keycap>CTRL</keycap>
<keycap>X</keycap>
<keycap>$</keycap>
</keycombo>
<indexterm>
<primary>CTRL-X-$</primary>
</indexterm>
to complete an environment variable<indexterm><primary>environment variable</primary></indexterm> name.</para><itemizedlist><listitem><para>~ (tilde)<indexterm><primary>tilde</primary></indexterm><indexterm><primary>~</primary></indexterm> complete a user name<indexterm><primary>user name</primary></indexterm></para></listitem><listitem><para>@ (at sign)<indexterm><primary>@</primary></indexterm> complete a machine name<indexterm><primary>machine name</primary></indexterm></para></listitem><listitem><para>$ (dollars sign)<indexterm><primary>$</primary></indexterm> complete an environment variable<indexterm><primary>environment variable</primary></indexterm> name</para></listitem><listitem><para>! (exclamation mark)<indexterm><primary>!</primary></indexterm> a magic character<indexterm><primary>magic character</primary></indexterm> for completing a command name<indexterm><primary>command name</primary></indexterm> or a file name.<indexterm><primary>file name</primary></indexterm> The ! special character <indexterm><primary>special character</primary></indexterm>has the same function <indexterm><primary>function</primary></indexterm>as the TAB <indexterm><primary>TAB</primary></indexterm>key. It works in some other situations; for example when completing man page<indexterm><primary>man page</primary></indexterm> names.</para></listitem></itemizedlist></listitem></varlistentry><varlistentry><term>alias
</term><listitem><para><indexterm><primary>alias</primary></indexterm>The <emphasis>alias</emphasis> command will list your current aliases.<indexterm><primary>aliases</primary></indexterm> You can use <emphasis>unalias</emphasis> <indexterm><primary>unalias</primary></indexterm>to remove <indexterm><primary>remove</primary></indexterm>the alias (to disable <indexterm><primary>disable</primary></indexterm>it just for one command add a &ldquo;\&rdquo;<indexterm><primary>\</primary></indexterm> (back-slash) before the command)...</para><para>An alias allows one command to be substituted <indexterm><primary>substituted</primary></indexterm>for another. This is used to make a command do something else or to automatically <indexterm><primary>automatically</primary></indexterm>add<indexterm><primary>add</primary></indexterm> certain options.<indexterm><primary>options</primary></indexterm> This can be either be done during one session <indexterm><primary>session</primary></indexterm>using the alias command (see below) or the information <indexterm><primary>information</primary></indexterm>can be added to the <emphasis>.bashrc</emphasis> file (found in the users home directory).</para><para>Below is an example of what an alias section (within your <emphasis>.bashrc</emphasis> file) might look like:</para><screen><![CDATA[# my personal aliases
]]><![CDATA[alias cp='cp -vi' #to prompt when copying if you want to overwrite and will tell you where information is going
]]><![CDATA[alias rm='rm -i' #Prompts you if you really want to remove it.
]]><![CDATA[alias mv='mv -i' #Prompts you if you are going to overwrite something
]]></screen><para>On any Mandriva GNU/Linux system the global aliases <indexterm><primary>global aliases</primary></indexterm>(for all users) are all in /etc/profile.d/alias.sh. The above listed <indexterm><primary>listed</primary></indexterm>commands already have aliases,<indexterm><primary>aliases</primary></indexterm> as well as several <indexterm><primary>several</primary></indexterm>other commonly <indexterm><primary>commonly</primary></indexterm>used commands.</para></listitem></varlistentry><varlistentry><term>set&nbsp;-x
</term><listitem><para><indexterm><primary>-x</primary></indexterm><emphasis> set <indexterm><primary>set</primary></indexterm></emphasis>is one of bash's inbuilt <indexterm><primary>inbuilt</primary></indexterm>commands, try looking in the bash <indexterm><primary>bash</primary></indexterm>manual for its many usage <indexterm><primary>usage</primary></indexterm>options.</para><para>Using <emphasis>set</emphasis> with the<emphasis> -x</emphasis> option <indexterm><primary>option</primary></indexterm>will make bash <indexterm><primary>bash</primary></indexterm>print out each command it is going to run <indexterm><primary>run</primary></indexterm>before it runs it. </para><para>This can be useful to find <indexterm><primary>find</primary></indexterm>out what is happening with certain commands such as things being quoted <indexterm><primary>quoted</primary></indexterm>that contain wildcards <indexterm><primary>wildcards</primary></indexterm>or special symbols <indexterm><primary>special symbols</primary></indexterm>that could cause <indexterm><primary>cause</primary></indexterm>problems, or complex <indexterm><primary>complex</primary></indexterm>aliases. Use<emphasis> set +x</emphasis> to turn <indexterm><primary>turn</primary></indexterm>this back off.<indexterm><primary>back off</primary></indexterm></para><para>Examples</para><para>After using <emphasis> set -x</emphasis> you can run the command:</para><screen><![CDATA[ls
]]></screen><para><indexterm><primary>ls</primary></indexterm><indexterm><primary>-F</primary></indexterm><indexterm><primary>--color=auto</primary></indexterm>The output <indexterm><primary>output</primary></indexterm>printed <indexterm><primary>printed</primary></indexterm>before the command runs (for example):</para><screen><![CDATA[+ ls -F --color=auto
]]></screen><para>Which means that the command is really an alias to run <emphasis>ls</emphasis> with the <emphasis>-F</emphasis> and <emphasis>--color=auto</emphasis> options. Use a &ldquo;\&rdquo; (backslash) before the command to run <indexterm><primary>run</primary></indexterm>it without the alias.</para></listitem></varlistentry><varlistentry><term>\&nbsp;(backslash)
</term><listitem><para><indexterm><primary>\</primary></indexterm>The backslash <indexterm><primary>backslash</primary></indexterm>escape character <indexterm><primary>character</primary></indexterm>can be used before a shell command to override <indexterm><primary>override</primary></indexterm>any aliases.</para><para>For example if <emphasis>rm</emphasis> was made into an alias for<emphasis> rm -i<indexterm><primary>-i</primary></indexterm><indexterm><primary>rm -i</primary></indexterm></emphasis> then typing &ldquo;rm&rdquo; would actually run<emphasis> rm -i</emphasis>. </para><para>However, typing <emphasis>\rm</emphasis> lets the shell ignore the alias <indexterm><primary>alias</primary></indexterm>and just run <emphasis>rm</emphasis> (its runs exactly <indexterm><primary>exactly</primary></indexterm>what you type), this way it won't confirm <indexterm><primary>confirm</primary></indexterm>if you want to delete <indexterm><primary>delete</primary></indexterm>things.</para><caution>
<title>Using rm</title>
<para>Please note that the alias for the remove command is there for a reason. Using it incorrectly could remove files which you don't want removed.</para>
<para>Only use <emphasis>\rm</emphasis> if you know exactly what you are doing (recovering files is not easy, <emphasis>rm</emphasis> does not send things to a recycle bin).</para>
</caution>
<para>The &ldquo;\&rdquo; character <indexterm><primary>character</primary></indexterm>can be used before special characters<indexterm><primary>special characters</primary></indexterm> (such as a space <indexterm><primary>space</primary></indexterm>or a wildcard<indexterm><primary>wildcard</primary></indexterm>), to stop <indexterm><primary>stop</primary></indexterm>bash <indexterm><primary>bash</primary></indexterm>from trying to expand <indexterm><primary>expand</primary></indexterm>them. You can make a directory <indexterm><primary>directory</primary></indexterm>name with a space<indexterm><primary>space</primary></indexterm> in it using a backslash before the space. For example you could type <emphasis>cd</emphasis> <emphasis>My</emphasis>\<emphasis> Directory</emphasis>\<emphasis> With</emphasis>\<emphasis> Spaces</emphasis> which normally wouldn't work. </para><para>The &ldquo;\&rdquo; character <indexterm><primary>character</primary></indexterm>can also be used to stop <indexterm><primary>stop</primary></indexterm>bash <indexterm><primary>bash</primary></indexterm>from expanding <indexterm><primary>expanding</primary></indexterm>certain symbols<indexterm><primary>symbols</primary></indexterm> (as an alternative <indexterm><primary>alternative</primary></indexterm>you could use single quotation <indexterm><primary>quotation</primary></indexterm>marks, although you may need to use both).</para><tip>
<title>The TAB Key<indexterm><primary>TAB key</primary></indexterm></title>
<para>Please note that using the TAB key (automatic-command-completion) will automatically use escapes for spaces (so you don't have to type them manually).</para>
</tip>
</listitem></varlistentry><varlistentry><term>script
</term><listitem><para><indexterm><primary>script</primary></indexterm>The &ldquo;<emphasis>script</emphasis>&rdquo; command creates a typescript,<indexterm><primary>typescript</primary></indexterm> or &quot;capture log&quot; of a shell session - it writes a copy <indexterm><primary>copy</primary></indexterm>of your session <indexterm><primary>session</primary></indexterm>to a file, including <indexterm><primary>including</primary></indexterm>commands you type and their output.</para></listitem></varlistentry><varlistentry><term>~&nbsp;(tilde&nbsp;character)
</term><listitem><para><indexterm><primary>~</primary></indexterm>The tilde <indexterm><primary>tilde</primary></indexterm>character <indexterm><primary>character</primary></indexterm>is used as an alias to a users home directory. </para><para>For example, if your user-name <indexterm><primary>user-name</primary></indexterm>was &ldquo;fred&rdquo;, instead of typing<emphasis> cd /home/fred </emphasis>you could simply type<emphasis> cd <indexterm><primary>cd</primary></indexterm>~. </emphasis>Or to get to fred's tmp directory (under his home <indexterm><primary>home</primary></indexterm>directory) you could type<emphasis> cd <indexterm><primary>cd</primary></indexterm>~/tmp.</emphasis></para><tip>
<title>Home directory shortcut</title>
<para>~ (tilde) can also be used as a shortcut to other users home directories, simply type: <emphasis>~user_name</emphasis> and it will take you to the users home directory. Note that you need to spell the username exactly correct, no wildcards.</para>
</tip>
</listitem></varlistentry><varlistentry><term></term>
<listitem><para>&nbsp;</para></listitem></varlistentry><varlistentry><term>set&nbsp;bell-style&nbsp;none
</term><listitem><para><indexterm><primary>set bell-style</primary></indexterm>This particular <indexterm><primary>particular</primary></indexterm><emphasis>set</emphasis> command will turn off <indexterm><primary>turn off</primary></indexterm>the system bell<indexterm><primary>system bell</primary></indexterm> from the command-line <indexterm><primary>command-line</primary></indexterm>(use xset <indexterm><primary>xset</primary></indexterm>-b for X windows). If you want the bell <indexterm><primary>bell</primary></indexterm>to stay off pernamently (no audible <indexterm><primary>audible</primary></indexterm>bell) then you can add this command to your &ldquo;.bashrc&rdquo; or &ldquo;.bash_profile&rdquo; (just add it to the same one you have your alises in...).</para></listitem></varlistentry><varlistentry><term>reset
</term><listitem><para><indexterm><primary>reset</primary></indexterm>The <emphasis>reset</emphasis> command re-initializes your current terminal.<indexterm><primary>terminal</primary></indexterm> This can be useful when the text <indexterm><primary>text</primary></indexterm>from your terminal <indexterm><primary>terminal</primary></indexterm> becomes garbled,<indexterm><primary>garbled</primary></indexterm> simply type &ldquo;reset&rdquo; and this will fix <indexterm><primary>fix</primary></indexterm>your terminal.</para></listitem></varlistentry><varlistentry><term>exit
</term><listitem><para><indexterm><primary>exit</primary></indexterm>Closes your current terminal (with x-terminals) or logs-out.<indexterm><primary>logs-out</primary></indexterm> Also try
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
.</para></listitem></varlistentry><varlistentry><term>logout
</term><listitem><para><indexterm><primary>logout</primary></indexterm>Logs out of a terminal, also try
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
.</para></listitem></varlistentry><varlistentry><term>echo
</term><listitem><para><indexterm><primary>echo</primary></indexterm>A little command that repeats <indexterm><primary>repeats</primary></indexterm>anything you type.</para><para>Example:</para><screen><![CDATA[echo ]]>&ldquo;<![CDATA[hello world]]>&rdquo;<![CDATA[
]]></screen><para>Simply displays &ldquo; hello world&rdquo;. </para><para>Example:</para><screen><![CDATA[echo rm -R *
]]></screen><para>This will output what will be passed <indexterm><primary>passed</primary></indexterm>to the <emphasis>rm<indexterm><primary>rm</primary></indexterm></emphasis> command (and therefore what would be deleted), putting <indexterm><primary>putting</primary></indexterm>echo before a command renders <indexterm><primary>renders</primary></indexterm>it harmless <indexterm><primary>harmless</primary></indexterm>(it just expands <indexterm><primary>expands</primary></indexterm>wildcards so you know what it will do).</para><para>Also try using the<emphasis> -e <indexterm><primary>-e</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>with echo.<indexterm><primary>echo</primary></indexterm> This will allow <indexterm><primary>allow</primary></indexterm>you to use the escape <indexterm><primary>escape</primary></indexterm>character sequences<indexterm><primary>character sequences</primary></indexterm> to format <indexterm><primary>format</primary></indexterm>the output of a line.<indexterm><primary>line</primary></indexterm> Such as '\t' for tab,<indexterm><primary>tab</primary></indexterm> '\n' for newline <indexterm><primary>newline</primary></indexterm>etc.</para><tip>
<title>Using echo to prevent accidents</title>
<para>
Typing: <emphasis>echo command(s) </emphasis>could<emphasis> </emphasis>save you the trouble of accidentally doing something you didn't expect.
</para>
<para>
Using <emphasis>echo</emphasis> allows you to expand the wildcards to understand what will happen before you actually run the command.
</para>
</tip>
</listitem></varlistentry></variablelist></sect1>
<sect1 id="the-command-line-history"><title>The command-line history</title><variablelist><varlistentry><term>Using&nbsp;the&nbsp;command&nbsp;history
</term><listitem><para><indexterm><primary>command history</primary></indexterm>Use the up and down key's to scroll <indexterm><primary>scroll</primary></indexterm>through previously typed commands. Press [Enter] to execute <indexterm><primary>execute</primary></indexterm>them or use the left and right arrow <indexterm><primary>arrow</primary></indexterm>keys to edit<indexterm><primary>edit</primary></indexterm> the command first. Also see <emphasis>history</emphasis> (below).</para></listitem></varlistentry><varlistentry><term>The&nbsp;history&nbsp;command
</term><listitem><para>The<emphasis> history <indexterm><primary>history</primary></indexterm></emphasis> command can be used to list Bash's log <indexterm><primary>log</primary></indexterm>of the commands you have typed:</para><para>This log <indexterm><primary>log</primary></indexterm>is called the &ldquo;history&rdquo;. To access <indexterm><primary>access</primary></indexterm>it type:</para><screen><![CDATA[history n
]]></screen><para>This will only list the last <indexterm><primary>last</primary></indexterm><emphasis>n</emphasis> commands. Type &ldquo;history&rdquo; (without options) to see the entire history <indexterm><primary>history</primary></indexterm>list.<indexterm><primary>list</primary></indexterm></para><para>You can also type <emphasis>!n</emphasis><indexterm><primary>!n</primary></indexterm> to execute command number<indexterm><primary>command number</primary></indexterm> n. Use <emphasis>!!<indexterm><primary>!!</primary></indexterm></emphasis> to execute the last command you typed.</para><para><emphasis>!-n<indexterm><primary>!-n</primary></indexterm> </emphasis>will execute the command n times <indexterm><primary>times</primary></indexterm>before (in other words <emphasis>!-1</emphasis> is equivalent <indexterm><primary>equivalent</primary></indexterm>to <emphasis>!!</emphasis>). </para><para><emphasis>!string<indexterm><primary>!string</primary></indexterm> </emphasis>will execute the last command starting <indexterm><primary>starting</primary></indexterm>with that &ldquo;string&rdquo; and <emphasis>!?string?</emphasis> will execute the last command containing the word &ldquo;string&rdquo;. For example:</para><screen><![CDATA[!cd
]]></screen><para>Will re-run the command that you last typed starting with &ldquo;cd&rdquo;.</para><para></para><para><emphasis>&ldquo; commandName <indexterm><primary>commandName</primary></indexterm>!*&rdquo;</emphasis> will execute the &ldquo;commandName&rdquo; with any arguments <indexterm><primary>arguments</primary></indexterm>you used on your last command. This maybe useful if you make a spelling <indexterm><primary>spelling</primary></indexterm>mistake, for example. If you typed:</para><screen><![CDATA[emasc /home/fred/mywork.java /tmp/testme.java
]]></screen><para>In an attempt <indexterm><primary>attempt</primary></indexterm>to execute emacs <indexterm><primary>emacs</primary></indexterm>on the above two files this will obviously fail.<indexterm><primary>fail</primary></indexterm> So what you can do is type:</para><screen><![CDATA[emacs !*
]]></screen><para>This will execute emacs <indexterm><primary>emacs</primary></indexterm>with the arguments <indexterm><primary>arguments</primary></indexterm>that you last typed on the command-line.<indexterm><primary>command-line</primary></indexterm> In other words this is equivalent <indexterm><primary>equivalent</primary></indexterm>to typing:</para><screen><![CDATA[emacs /home/fred/mywork.java /tmp/testme.java
]]></screen></listitem></varlistentry><varlistentry><term>Searching&nbsp;through&nbsp;the&nbsp;Command&nbsp;History&nbsp;(
<keycombo>
<keycap>CTRL</keycap>
<keycap>R</keycap>
</keycombo>
<indexterm>
<primary>CTRL-R</primary>
</indexterm>
)
</term><listitem><para><indexterm><primary>Command History</primary></indexterm>Use the CTRL-R key <indexterm><primary>key</primary></indexterm>to perform<indexterm><primary>perform</primary></indexterm> a &ldquo;reverse-i-search&rdquo;. For example, if you wanted to use the command you used the last time you used <emphasis>snort</emphasis><indexterm><primary>snort</primary></indexterm>, you would type:</para><para>
<keycombo>
<keycap>CTRL</keycap>
<keycap>R</keycap>
</keycombo> then type &ldquo;snort&rdquo;.
</para>
<para>What you will see in the console <indexterm><primary>console</primary></indexterm>window <indexterm><primary>window</primary></indexterm>is:</para><screen><![CDATA[(reverse-i-search)`':
]]></screen><para>After you have typed what you are looking for, use the
<keycombo>
<keycap>CTRL</keycap>
<keycap>R</keycap>
</keycombo>
<indexterm>
<primary>CTRL-R</primary>
</indexterm>
key combination<indexterm><primary>key combination</primary></indexterm> to scroll <indexterm><primary>scroll</primary></indexterm>backward through the history.<indexterm><primary>history</primary></indexterm> </para><para>Use
<keycombo>
<keycap>CTRL</keycap>
<keycap>R</keycap>
</keycombo>
<indexterm>
<primary>CTRL-R</primary>
</indexterm>
repeatedly<indexterm><primary>repeatedly</primary></indexterm> to find <indexterm><primary>find</primary></indexterm>every reference <indexterm><primary>reference</primary></indexterm>to the string <indexterm><primary>string</primary></indexterm>you've entered.<indexterm><primary>entered</primary></indexterm> Once you've found <indexterm><primary>found</primary></indexterm>the command you're looking for, use [Enter] to execute it. </para><para>Alternatively,<indexterm><primary>alternatively</primary></indexterm> using the right or left arrow keys<indexterm><primary>arrow keys</primary></indexterm> will place <indexterm><primary>place</primary></indexterm>the command on an actual command-line <indexterm><primary>command-line</primary></indexterm>so you can edit it.</para><para></para></listitem></varlistentry></variablelist></sect1>
<sect1 id="other-Key-combinations"><title>Other Key combinations</title><para></para><para>GNU/Linux shells <indexterm><primary>shells</primary></indexterm>have many shortcut <indexterm><primary>shortcut</primary></indexterm>keys which you can use to speed <indexterm><primary>speed</primary></indexterm>up your work, below is a rough list of some (also see
<keycombo>
<keycap>CTRL</keycap>
<keycap>R</keycap>
</keycombo>
<indexterm>
<primary>CTRL-R</primary>
</indexterm>
in the history <indexterm><primary>history</primary></indexterm>section of the commands, over here, <xref linkend="the-command-line-history">).</para><variablelist><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
</term><listitem><para> the &ldquo;end-of-file&rdquo; (EOF) key combination can be used to quickly log out of any terminal.
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
is also used in programs such as <emphasis>&ldquo;at&rdquo;</emphasis> to signal that you have finished typing your commands (the <acronym>EOF</acronym> command).</para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>Z</keycap>
</keycombo>
<indexterm>
<primary>CTRL-Z</primary>
</indexterm>
</term><listitem><para>key combination<indexterm><primary>key combination</primary></indexterm> is used to stop a process. It can be used to put something in the background temporarily.</para><para>For example, if you were editing a file with <emphasis>vim</emphasis> or <emphasis>emacs</emphasis> just press
<keycombo>
<keycap>CTRL</keycap>
<keycap>Z</keycap>
</keycombo>
<indexterm>
<primary>CTRL-Z</primary>
</indexterm>
to regain control of the terminal do what you want and then type <emphasis>fg</emphasis> <indexterm><primary>fg</primary></indexterm><emphasis> </emphasis>to bring it back. </para><para>For further information please see <xref linkend="controlling-processes">.</para><tip>
<title>If <emphasis>fg</emphasis> doesn't work</title>
<para>If <emphasis>fg</emphasis> doesn't work you may need to type <emphasis>jobs</emphasis> and then <emphasis>fg job_name or fg job_number</emphasis></para>
</tip>
</listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>A</keycap>
</keycombo>
<indexterm>
<primary>CTRL-A</primary>
</indexterm>
&nbsp;and&nbsp;
<keycombo>
<keycap>CTRL</keycap>
<keycap>E</keycap>
</keycombo>
<indexterm>
<primary>CTRL-E</primary>
</indexterm>
</term><listitem><para>These key combinations are used for going to the start and end of the line on the command line. Use
<keycombo>
<keycap>CTRL</keycap>
<keycap>A</keycap>
</keycombo>
<indexterm>
<primary>CTRL-A</primary>
</indexterm>
to jump to the start of the line, and
<keycombo>
<keycap>CTRL</keycap>
<keycap>E</keycap>
</keycombo>
<indexterm>
<primary>CTRL-E</primary>
</indexterm>
to jump to the end of the line.</para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>K</keycap>
</keycombo>
<indexterm>
<primary>CTRL-K</primary>
</indexterm>
</term><listitem><para>This key combination can be used to cut or delete what is currently in front of the cursor.</para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>Y</keycap>
</keycombo>
<indexterm>
<primary>CTRL-Y</primary>
</indexterm>
</term><listitem><para>This key combination can be used to paste the last thing you deleted (using
<keycombo>
<keycap>CTRL</keycap>
<keycap>K</keycap>
</keycombo>
<indexterm>
<primary>CTRL-K</primary>
</indexterm>
or
<keycombo>
<keycap>CTRL</keycap>
<keycap>W</keycap>
</keycombo>
<indexterm>
<primary>CTRL-W</primary>
</indexterm>
). </para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>W</keycap>
</keycombo>
<indexterm>
<primary>CTRL-W</primary>
</indexterm>
</term><listitem><para>This key combination can be used to cut or delete the entire line that has being typed.</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="virtual-terminals"><title>Virtual Terminals and screen</title><para>Using the key combination
<keycombo>
<keycap>ALT</keycap>
<keycap>F*</keycap>
</keycombo>
keys you may change to different virtual terminals. You will have several (usually 6) virtual terminals setup with shells. Number 7 is usually setup with X you need to use
<keycombo>
<keycap>CTRL</keycap>
<keycap>ALT</keycap>
<keycap>F*</keycap>
</keycombo>
<indexterm>
<primary>CTRL-ALT-F*</primary>
</indexterm>
to change to a terminal from within X (X as in the X windowing system).
</para>
<variablelist><varlistentry><term>screen
</term><listitem><para><indexterm><primary>screen</primary></indexterm><indexterm><primary>virtual terminals</primary></indexterm>is a great program that allows <indexterm><primary>allows</primary></indexterm>you to switch <indexterm><primary>switch</primary></indexterm>between multiple virtual terminals<indexterm><primary>virtual terminals</primary></indexterm> on the one physical <indexterm><primary>physical</primary></indexterm>terminal that you are using. Its a command-line <indexterm><primary>command-line</primary></indexterm>based window manager<indexterm><primary>window manager</primary></indexterm>, clearly this isn't that useful if you do have virtual terminals, but its amazingly useful when you log<indexterm><primary>log</primary></indexterm> into machines remotely, using ssh <indexterm><primary>ssh</primary></indexterm>and similar, see <xref linkend="remote-administration">. It works on key-combinations,<indexterm><primary>key-combinations</primary></indexterm> you type</para><screen><![CDATA[screen
]]></screen><para>On the command-line to begin. Now you start with one virtual terminal by default, but using the key combination
<keycombo>
<keycap>CTRL</keycap>
<keycap>A</keycap>
</keycombo>
<indexterm>
<primary>CTRL-A</primary>
</indexterm>
and then hitting &quot;C&quot; you can create another virtual terminal to use. </para><para>Use
<keycombo>
<keycap>CTRL</keycap>
<keycap>N</keycap>
</keycombo>
<indexterm>
<primary>CTRL-N</primary>
</indexterm>
to go to the next virtual terminal and
<keycombo>
<keycap>CTRL</keycap>
<keycap>P</keycap>
</keycombo>
<indexterm>
<primary>CTRL-P</primary>
</indexterm>
to go to the previous virtual terminal. Also try hitting
<keycombo>
<keycap>CTRL</keycap>
<keycap>A</keycap>
</keycombo>
<indexterm>
<primary>CTRL-A</primary>
</indexterm>
to go backwards and forwards between two particular terminals.</para><para><emphasis>screen</emphasis> <indexterm><primary>screen</primary></indexterm>also has various other abilities <indexterm><primary>abilities</primary></indexterm>that you can test <indexterm><primary>test</primary></indexterm>out. The documentation <indexterm><primary>documentation</primary></indexterm>and guides are well written so please feel free to read the manual <indexterm><primary>manual</primary></indexterm>page <indexterm><primary>page</primary></indexterm>or try searching <indexterm><primary>searching</primary></indexterm>the internet.<indexterm><primary>internet</primary></indexterm></para></listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Help"><title>Help</title><para>The help <indexterm><primary>help</primary></indexterm>chapter provides <indexterm><primary>provides</primary></indexterm>information on how you may access the documentation<indexterm><primary>documentation</primary></indexterm> of the GNU/Linux system. There is normally a document <indexterm><primary>document</primary></indexterm>describing every single tool you have installed,<indexterm><primary>installed</primary></indexterm> even if its only brief...</para><variablelist><varlistentry><term>man
</term><listitem><para><indexterm><primary>man</primary></indexterm>This command displays summary <indexterm><primary>summary</primary></indexterm>information <indexterm><primary>information</primary></indexterm>on a program from an online<indexterm><primary>online</primary></indexterm> manual.<indexterm><primary>manual</primary></indexterm> For example typing <emphasis>man man </emphasis>will bring up the manual <indexterm><primary>manual</primary></indexterm>page for man (the manual <indexterm><primary>manual</primary></indexterm>page viewer). Note: q is the quit <indexterm><primary>quit</primary></indexterm>key.</para><para>Command syntax:</para><screen><![CDATA[man program_name
]]></screen><tip>
<title>Also try</title>
<para>Specifying the section of the manual page, sometimes the man page is different for the same tool in different sections, note sections are numbered 1 to 9. Use apropos to find which section number to look in.
</para>
<para>
The syntax to look at a different section is:
<screen>
man section_number tool_name
</screen>
For example:
<screen>
man 2 time
</screen>
This will show you the man page called time in section 2, the equivalent page in section 1 is completely different
</para>
</tip>
</listitem></varlistentry><varlistentry><term>man&nbsp;-K&nbsp;keyword
</term><listitem><para><indexterm><primary>man -K</primary></indexterm>Search the manual <indexterm><primary>manual</primary></indexterm>pages for a string,<indexterm><primary>string</primary></indexterm> as in it will search<indexterm><primary>search</primary></indexterm> all manual <indexterm><primary>manual</primary></indexterm>pages for a particular string within each individual <indexterm><primary>individual</primary></indexterm>man page, it will then prompt <indexterm><primary>prompt</primary></indexterm>whether you would like to view <indexterm><primary>view</primary></indexterm>each page it will find. Use double <indexterm><primary>double</primary></indexterm>quotes &ldquo; and &rdquo; if there are spaces <indexterm><primary>spaces</primary></indexterm>in the string you are typing.</para><caution>
<title>Speed issue</title>
<para> Please be warned that this method is going to be really, really slow. You are searching *all* man pages for a string </para>
</caution>
</listitem></varlistentry><varlistentry><term>man&nbsp;-f&nbsp;command
</term><listitem><para><indexterm><primary>man -f</primary></indexterm>This will list <indexterm><primary>list</primary></indexterm>details <indexterm><primary>details</primary></indexterm>associated <indexterm><primary>associated</primary></indexterm>with the command. The root <indexterm><primary>root</primary></indexterm>user must run <indexterm><primary>run</primary></indexterm><emphasis>makewhatis</emphasis> <indexterm><primary>makewhatis</primary></indexterm>(see below) before this command will work. </para><note>
<title>Equivalent to <emphasis>whatis</emphasis></title>
<para> This command is the same as running <emphasis>whatis</emphasis>
</para>
</note>
</listitem></varlistentry><varlistentry><term>info
</term><listitem><para><indexterm><primary>info</primary></indexterm>Provides a more detailed <indexterm><primary>detailed</primary></indexterm>hyper-text manual <indexterm><primary>manual</primary></indexterm>on a particular command, this only works for some commands.</para><para>Command syntax:</para><screen><![CDATA[info program_name
]]></screen></listitem></varlistentry><varlistentry><term>whatis
</term><listitem><para><indexterm><primary>whatis</primary></indexterm>Displays a one-line description <indexterm><primary>description</primary></indexterm>of what a program <indexterm><primary>program</primary></indexterm>does. The string needs to be an exact <indexterm><primary>exact</primary></indexterm>match, otherwise <emphasis>whatis</emphasis> won't output <indexterm><primary>output</primary></indexterm>anything. Relies on the whatis database (see below).</para><para>Command syntax:</para><screen><![CDATA[whatis program_name
]]></screen></listitem></varlistentry><varlistentry><term>makewhatis
</term><listitem><para><indexterm><primary>makewhatis</primary></indexterm>Make the whatis database for <emphasis>apropos</emphasis>, <emphasis>whatis</emphasis> and<emphasis> man -f.<indexterm><primary>-f</primary></indexterm></emphasis> </para><note>
<title>Root Privileges</title>
<para>This takes some time and you require root privileges to do this.</para>
</note>
</listitem></varlistentry><varlistentry><term>apropos
</term><listitem><para><indexterm><primary>apropos</primary></indexterm>Searches <indexterm><primary>Searches</primary></indexterm>the whatis database for strings,<indexterm><primary>strings</primary></indexterm> similar to <emphasis>whatis</emphasis> except it finds <indexterm><primary>finds</primary></indexterm>and prints <indexterm><primary>prints</primary></indexterm>anything matching <indexterm><primary>matching</primary></indexterm>the string (or any part of the string). Also relies on the whatis database (see above). </para><para>Command syntax:</para><screen><![CDATA[apropos string
]]></screen><note>
<title>Equivalent to...</title>
<para> <emphasis>apropos</emphasis> is the same as doing <emphasis>man -k</emphasis> (lowercase k).</para>
</note>
</listitem></varlistentry></variablelist><note>
<title>Please note</title>
<para>
You need to run <emphasis>makewhatis</emphasis> (as root) so <emphasis>whatis</emphasis>, <emphasis>man -f </emphasis>and <emphasis>apropos </emphasis>will work.
</para>
</note>
<tip>
<title>Also try</title>
<para>
Using a program with the <emphasis>-?</emphasis>,<indexterm><primary>-?</primary></indexterm> <emphasis>--h</emphasis>,<indexterm><primary>--h</primary></indexterm> <emphasis>--help</emphasis><indexterm><primary>--help</primary></indexterm>, and the <emphasis>-h<indexterm><primary>-h</primary></indexterm></emphasis> options, they will display very short summary information on the command usage options.
</para>
</tip>
</chapter>
<chapter id="Directing-input-ouput"><title>Directing Input/Output</title><para></para><para>The directing input/output chapter explains <indexterm><primary>explains</primary></indexterm>how you can use a program and send <indexterm><primary>send</primary></indexterm>its output to a file or to another command that you wish to use. This technique <indexterm><primary>technique</primary></indexterm>is very powerful <indexterm><primary>powerful</primary></indexterm>and there are a number <indexterm><primary>number</primary></indexterm>of ways of doing this.</para><sect1 id="concept-definitions"><title>Concept Definitions</title><para>All three of the following <indexterm><primary>following</primary></indexterm>definitions <indexterm><primary>definitions</primary></indexterm>are called &ldquo; File Streams.&rdquo;<indexterm><primary>File Streams</primary></indexterm><indexterm><primary>Streams</primary></indexterm> They hold information that is either received <indexterm><primary>received</primary></indexterm>from somewhere or sent to somewhere. In a <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>system, the keyboard <indexterm><primary>keyboard</primary></indexterm>input (standard input), information printed to the screen <indexterm><primary>screen</primary></indexterm>(standard output) and error <indexterm><primary>error</primary></indexterm>output (also printed <indexterm><primary>printed</primary></indexterm>to the screen) are treated as separate File Streams.</para><variablelist><varlistentry><term>Standard&nbsp;output
</term><listitem><para>Standard output <indexterm><primary>Standard output</primary></indexterm>is the output from the program printed <indexterm><primary>printed</primary></indexterm>to the screen,<indexterm><primary>screen</primary></indexterm> not including error output <indexterm><primary>Error output</primary></indexterm>(see below).</para></listitem></varlistentry><varlistentry><term>Standard&nbsp;input
</term><listitem><para>Standard input <indexterm><primary>Standard input</primary></indexterm>is the input <indexterm><primary>input</primary></indexterm>from the user. Normally the keyboard <indexterm><primary>keyboard</primary></indexterm>is used as the standard input <indexterm><primary>standard input</primary></indexterm>device in a <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>system.</para></listitem></varlistentry><varlistentry><term>Standard&nbsp;error
</term><listitem><para>Standard error <indexterm><primary>Standard error</primary></indexterm>is error <indexterm><primary>error</primary></indexterm>output from programs.<indexterm><primary>programs</primary></indexterm> This output is also sent to the screen <indexterm><primary>screen</primary></indexterm>and will normally be seen mixed<indexterm><primary>mixed</primary></indexterm> in with standard output.<indexterm><primary>standard output</primary></indexterm> The difference <indexterm><primary>difference</primary></indexterm>between standard output <indexterm><primary>standard output</primary></indexterm>and standard error <indexterm><primary>standard error</primary></indexterm>is that standard error is unbuffered <indexterm><primary>unbuffered</primary></indexterm>(it appears immediately on the screen) and standard error is only printed <indexterm><primary>printed</primary></indexterm>when something goes wrong (it will give you details of what went wrong).</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="usage-input-output"><title>Usage</title><variablelist><varlistentry><term>&gt;
</term><listitem><para><indexterm><primary>></primary></indexterm>The greater <indexterm><primary>greater</primary></indexterm>than symbol <indexterm><primary>symbol</primary></indexterm>is used to send <indexterm><primary>send</primary></indexterm>information somewhere (for example a text file)</para><para>Example:</para><screen><![CDATA[cat file1 file2 > file1_and_2.txt
]]></screen><para>This will concatenate <indexterm><primary>concatenate</primary></indexterm>the files together into one big file named &ldquo;file1_and_2.txt&rdquo;. Note that this will overwrite <indexterm><primary>overwrite</primary></indexterm>any existing <indexterm><primary>existing</primary></indexterm>file.</para></listitem></varlistentry><varlistentry><term>&lt;
</term><listitem><para><indexterm><primary><</primary></indexterm>The less <indexterm><primary>less</primary></indexterm>than symbol will insert <indexterm><primary>insert</primary></indexterm>information from somewhere (a text file) as if you typed it yourself. Often used with commands that are designed <indexterm><primary>designed</primary></indexterm>to get information from standard input <indexterm><primary>standard input</primary></indexterm>only.</para><para>For example (using tr):</para><screen><![CDATA[tr '[A-Z]' '[a-z]' < fileName.txt > fileNameNew.txt
]]></screen><para>The example above would insert <indexterm><primary>insert</primary></indexterm>the contents <indexterm><primary>contents</primary></indexterm>of &ldquo;fileName.txt&rdquo; into the input <indexterm><primary>input</primary></indexterm>of <emphasis>tr</emphasis> <indexterm><primary>tr</primary></indexterm>and output the results <indexterm><primary>results</primary></indexterm>to &ldquo;fileNameNew.txt&rdquo;.</para></listitem></varlistentry><varlistentry><term>&gt;&gt;
</term><listitem><para><indexterm><primary>>></primary></indexterm>The &gt;&gt; symbol <indexterm><primary>symbol</primary></indexterm>appends (adds) information to the end of a file or creates one if the file doesn't exist.<indexterm><primary>exist</primary></indexterm></para></listitem></varlistentry><varlistentry><term>&lt;&lt;
</term><listitem><para><indexterm><primary><<</primary></indexterm>The &lt;&lt; symbol <indexterm><primary>symbol</primary></indexterm>is sometimes used with commands that use standard input<indexterm><primary>standard input</primary></indexterm> to take information. You simply type <emphasis>&lt;&lt; word</emphasis> (where word can be any string) at the end <indexterm><primary>end</primary></indexterm>of the command. However its main use is in shell scripting.<indexterm><primary>shell scripting</primary></indexterm> </para><para>The command takes your input until you type &ldquo;word&rdquo;, which causes the command to terminate <indexterm><primary>terminate</primary></indexterm>and process <indexterm><primary>process</primary></indexterm>the input. </para><para>Using &lt;&lt; is similar to using
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
(EOF key)<emphasis>, </emphasis>except it uses a string <indexterm><primary>string</primary></indexterm>to perform <indexterm><primary>perform</primary></indexterm>the end-of-file function. This design allows it to be used in shell scripts.<indexterm><primary>shell scripts</primary></indexterm></para><para>For example type &quot;cat&quot;<indexterm><primary>cat</primary></indexterm> (with no options...) and it will work on standard input.<indexterm><primary>standard input</primary></indexterm></para><para>To stop <indexterm><primary>stop</primary></indexterm>entering standard input <indexterm><primary>standard input</primary></indexterm>you would normally hit
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
.</para><para>As an alternative <indexterm><primary>alternative</primary></indexterm>you can type &quot;cat &lt;&lt; FINISHED&quot;, then type what you want. </para><para>When you are finished,<indexterm><primary>finished</primary></indexterm> instead of hitting <indexterm><primary>hitting</primary></indexterm>
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
you could type &quot;FINISHED&quot;<indexterm><primary>FINISHED</primary></indexterm> and it will end (the word FINISHED will not be recorded).</para><para></para></listitem></varlistentry><varlistentry><term>2&gt;
</term><listitem><para><indexterm><primary>2></primary></indexterm>Redirects error output.<indexterm><primary>error output</primary></indexterm> For example, to redirect <indexterm><primary>redirect</primary></indexterm>the error output <indexterm><primary>error output</primary></indexterm>to /dev/null<indexterm><primary>/dev/null</primary></indexterm>, so you do not see it, simply append this to the end of another command...</para><para>For example:</para><screen><![CDATA[make some_file 2> /dev/null
]]></screen><para>This will run make on a file and send <indexterm><primary>send</primary></indexterm>all error output to /dev/null</para></listitem></varlistentry><varlistentry><term>|
</term><listitem><para><indexterm><primary>|</primary></indexterm><indexterm><primary>pipe</primary></indexterm>The &ldquo;pipe&rdquo; command allows the output of one command to be sent to the input of another.</para><para>For example:</para><screen><![CDATA[cat file1.txt file2.txt | less
]]></screen><para>Concatenates <indexterm><primary>Concatenates</primary></indexterm>the files together, then runs <emphasis>less</emphasis> on them. If you are only going to look <indexterm><primary>look</primary></indexterm>at a single file, you would simply use <emphasis>less<indexterm><primary>less</primary></indexterm></emphasis> on the file...</para></listitem></varlistentry><varlistentry><term>tee
</term><listitem><para><indexterm><primary>tee</primary></indexterm>Sends output of a program to a file and to standard output.<indexterm><primary>standard output</primary></indexterm> Think of it as a T intersection...it goes two ways.</para><para>For example:</para><screen><![CDATA[ls /home/user | tee my_directories.txt
]]></screen><para>Lists <indexterm><primary>Lists</primary></indexterm>the files (displays the output on the screen) and sends <indexterm><primary>sends</primary></indexterm>the output to a file: &ldquo;my_directories.txt&rdquo;.</para></listitem></varlistentry><varlistentry><term>&amp;&gt;
</term><listitem><para><indexterm><primary>&></primary></indexterm>Redirects standard output <indexterm><primary>standard output</primary></indexterm>and error output <indexterm><primary>error output</primary></indexterm>to a specific <indexterm><primary>specific</primary></indexterm>location.<indexterm><primary>location</primary></indexterm></para><para>For example:</para><screen><![CDATA[make &> /dev/null
]]></screen><para>Sends <indexterm><primary>Sends</primary></indexterm>both error output <indexterm><primary>error output</primary></indexterm>and standard output <indexterm><primary>standard output</primary></indexterm>to /dev/null so you won't see anything...</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="command-substitution"><title>Command Substitution</title><para>Command substitution<indexterm><primary>command substitution</primary></indexterm> is basically another way to do a pipe,<indexterm><primary>pipe</primary></indexterm> you can use pipes and command substitution interchangeably,<indexterm><primary>interchangeably</primary></indexterm> it's up to you which one you find easier...</para><para>Command substitution can be done in two distinct <indexterm><primary>distinct</primary></indexterm>ways.</para><variablelist><varlistentry><term></term>
<listitem><para>&nbsp;</para></listitem></varlistentry><varlistentry><term>Method&nbsp;One&nbsp;(back-quotes)<anchor id="command-substitution-back-quotes"></term>
<listitem><para>&nbsp;</para><para>Simply type:</para><screen><![CDATA[command_1 `command_2 -options`
]]></screen><para>This will execute <indexterm><primary>execute</primary></indexterm>&ldquo;command_2&rdquo; and it's output <indexterm><primary>output</primary></indexterm>will become the input to &ldquo;command_1&rdquo;.</para><tip>
<title>Backquote key</title>
<para>
The back-quote key is usually located at the same place as the tilde, above the [Tab] key.
</para>
</tip>
</listitem></varlistentry><varlistentry><term>Method&nbsp;Two&nbsp;(dollars&nbsp;sign)<anchor id="command-substitution-dollars-sign"></term>
<listitem><para>&nbsp;</para><para>Simply type:</para><screen><![CDATA[command_1 $(command_2)
]]></screen><para>This will execute &ldquo;command_2&rdquo; and it's output will become the input to &ldquo;command_1&rdquo;.</para></listitem></varlistentry><varlistentry><term>Using&nbsp;the&nbsp;pipe&nbsp;instead<anchor id="command-substitution-pipe"></term>
<listitem><para>&nbsp;</para><para>You can of course use pipes <indexterm><primary>pipes</primary></indexterm>to do the same thing, if you don't know what a pipe <indexterm><primary>pipe</primary></indexterm>is, please see <xref linkend="usage-input-output">. For example instead of doing:</para><screen><![CDATA[less $cat file1.txt file2.txt
]]></screen><para>You could do:</para><screen><![CDATA[cat file1.txt file2.txt | less
]]></screen><para>And end up with exactly <indexterm><primary>exactly</primary></indexterm>the same result,<indexterm><primary>result</primary></indexterm> it's up to you which way you find easier.</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="performing-more-than-one-command"><title>Performing more than one command</title><variablelist><varlistentry><term>Executing&nbsp;the&nbsp;second&nbsp;command&nbsp;only&nbsp;if&nbsp;the&nbsp;first&nbsp;is&nbsp;successful<anchor id="execute-command-2-if-1-works"></term>
<listitem><para>&nbsp;</para><para>To do this you would type:</para><screen><![CDATA[command1 && command2
]]></screen><para><indexterm><primary>&&</primary></indexterm>command2<indexterm><primary>command2</primary></indexterm> will be executed if command1 <indexterm><primary>command1</primary></indexterm>successfully completes (if command1 fails <indexterm><primary>fails</primary></indexterm>command2 <indexterm><primary>command2</primary></indexterm>won't be run). This is called a logical <indexterm><primary>logical</primary></indexterm>AND.<indexterm><primary>AND</primary></indexterm></para></listitem></varlistentry><varlistentry><term>Executing&nbsp;the&nbsp;second&nbsp;command&nbsp;only&nbsp;if&nbsp;the&nbsp;first&nbsp;fails<anchor id="execute-command-2-if-1-fails"></term>
<listitem><para>&nbsp;</para><para>To do this you would type:</para><screen><![CDATA[command1 || command2
]]></screen><para><indexterm><primary>||</primary></indexterm>command2 <indexterm><primary>command2</primary></indexterm>will be executed if command1 <indexterm><primary>command1</primary></indexterm>does not successfully complete (if command1 <indexterm><primary>command1</primary></indexterm>is successful <indexterm><primary>successful</primary></indexterm>command2 won't be run). This is called a logical <indexterm><primary>logical</primary></indexterm>OR.<indexterm><primary>OR</primary></indexterm></para></listitem></varlistentry><varlistentry><term>Executing&nbsp;commands&nbsp;sequentially<anchor id="executing-commands-sequentially"></term>
<listitem><para>&nbsp;</para><para>To execute commands sequentially <indexterm><primary>sequentially</primary></indexterm>regardless of the success/failure of the previous <indexterm><primary>previous</primary></indexterm>you simply type:</para><screen><![CDATA[command1; command2
]]></screen><para><indexterm><primary>;</primary></indexterm>command2 <indexterm><primary>command2</primary></indexterm>will execute once command1 <indexterm><primary>command1</primary></indexterm>has completed.</para><tip>
<title>More than two commands</title>
<para>You can continue to use ';' (semicolon) characters to do more and more commands on the one line.</para>
</tip>
</listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Working-with-the-file-system"><title>Working with the file-system</title><para>The working with the file-system <indexterm><primary>file-system</primary></indexterm>chapter explains a number <indexterm><primary>number</primary></indexterm>of commands that you use to move around the file system <indexterm><primary>file system</primary></indexterm>hierarchy <indexterm><primary>hierarchy</primary></indexterm>and manipulate <indexterm><primary>manipulate</primary></indexterm>the files. Also explained are finding <indexterm><primary>finding</primary></indexterm>files and how to mass-rename <indexterm><primary>mass-rename</primary></indexterm>files.</para><sect1 id="using-filesystem"><title>Moving around the filesystem</title><variablelist><varlistentry><term>cd
</term><listitem><para><indexterm><primary>cd</primary></indexterm>Change directory. Use <emphasis>&ldquo; cd ..&rdquo;</emphasis> to go up one directory. </para><para>One dot <indexterm><primary>dot</primary></indexterm>'.' represents <indexterm><primary>represents</primary></indexterm>the current directory <indexterm><primary>current directory</primary></indexterm>while two dots <indexterm><primary>dots</primary></indexterm>'..' represent<indexterm><primary>represent</primary></indexterm> the parent directory.<indexterm><primary>parent directory</primary></indexterm> </para><para><emphasis>&ldquo; cd -&rdquo;</emphasis> will return <indexterm><primary>return</primary></indexterm>you to the previous <indexterm><primary>previous</primary></indexterm>directory (a bit like an &ldquo;undo&rdquo;). </para><para>You can also use <emphasis>cd absolute&nbsp;path</emphasis> or <emphasis>cd relative&nbsp;path</emphasis> (see below):</para><variablelist><varlistentry><term>Absolute&nbsp;paths
</term><listitem><para><indexterm><primary>Absolute path</primary></indexterm>An &ldquo; absolute path&rdquo; is easily recognised <indexterm><primary>recognised</primary></indexterm>from the leading<indexterm><primary>leading</primary></indexterm> forward slash, /. The /<indexterm><primary>/</primary></indexterm> means that you start <indexterm><primary>start</primary></indexterm>at the top level directory and continue down.</para></listitem></varlistentry></variablelist><para>For example to get to /boot/grub<emphasis> </emphasis>you would type:</para><screen><![CDATA[cd /boot/grub
]]></screen><para>This is an absolute path because you start at the top of the hierarchy and go downwards <indexterm><primary>downwards</primary></indexterm>from there (it doesn't matter where in the filesystem <indexterm><primary>filesystem</primary></indexterm>you were when you typed the command).</para><variablelist><varlistentry><term>Relative&nbsp;paths
</term><listitem><para><indexterm><primary>Relative paths</primary></indexterm>A &ldquo; relative path&rdquo; doesn't have a preceding <indexterm><primary>preceding</primary></indexterm>slash. Use a relative path when you start from a directory below the top <indexterm><primary>top</primary></indexterm>level directory structure. This is dependent <indexterm><primary>dependent</primary></indexterm>on where you are in the filesystem.<indexterm><primary>filesystem</primary></indexterm></para><para>For example<emphasis> </emphasis>if you are in root's home <indexterm><primary>home</primary></indexterm>directory and want to get to /root/music, you type:</para><screen><![CDATA[cd music
]]></screen></listitem></varlistentry></variablelist><para>Please note that there is no / using the above<emphasis> cd <indexterm><primary>cd</primary></indexterm></emphasis>command. Using a / would cause <indexterm><primary>cause</primary></indexterm>this to be an absolute <indexterm><primary>absolute</primary></indexterm>path,<indexterm><primary>path</primary></indexterm> working from the top<indexterm><primary>top</primary></indexterm> of the hierarchy downward.</para></listitem></varlistentry><varlistentry><term>ls
</term><listitem><para><indexterm><primary>ls</primary></indexterm>List files and directories.<indexterm><primary>directories</primary></indexterm> Typing &ldquo;ls&rdquo; will list <indexterm><primary>list</primary></indexterm>files and directories, but will not list hidden <indexterm><primary>hidden</primary></indexterm>files or directories<indexterm><primary>directories</primary></indexterm> that start with a leading full stop <indexterm><primary>leading</primary></indexterm> &ldquo;.&rdquo;<indexterm><primary>.</primary></indexterm>.</para><para>Example options:</para><itemizedlist><listitem><para><emphasis>ls -l</emphasis> --- long <indexterm><primary>-l</primary></indexterm><indexterm><primary>long</primary></indexterm>style,<indexterm><primary>style</primary></indexterm> this lists <indexterm><primary>lists</primary></indexterm>permissions, file size,<indexterm><primary>size</primary></indexterm> modification <indexterm><primary>modification</primary></indexterm>date,<indexterm><primary>date</primary></indexterm> ownership.<indexterm><primary>ownership</primary></indexterm></para></listitem><listitem><para><emphasis>ls -a</emphasis> --- <indexterm><primary>-a</primary></indexterm>this means &quot;show all&quot;, this shows <indexterm><primary>shows</primary></indexterm>hidden <indexterm><primary>hidden</primary></indexterm>files, by default <indexterm><primary>default</primary></indexterm>any file or directory <indexterm><primary>directory</primary></indexterm>starting <indexterm><primary>starting</primary></indexterm>with a '.' will not be shown.<indexterm><primary>shown</primary></indexterm></para></listitem><listitem><para><emphasis>ls -d</emphasis> --- <indexterm><primary>-d</primary></indexterm>list directory entires rather than contents <indexterm><primary>contents</primary></indexterm>(see example below)</para></listitem><listitem><para><emphasis>ls -F</emphasis> --- <indexterm><primary>-F</primary></indexterm>append <indexterm><primary>append</primary></indexterm>symbols <indexterm><primary>symbols</primary></indexterm>to particular files, such as * (asterisk) for executable<indexterm><primary>executable</primary></indexterm> files. </para></listitem><listitem><para><emphasis>ls -S </emphasis>--- <indexterm><primary>-S</primary></indexterm>sort <indexterm><primary>sort</primary></indexterm>the output of the command in decending <indexterm><primary>decending</primary></indexterm>order <indexterm><primary>order</primary></indexterm>sorted <indexterm><primary>sorted</primary></indexterm>by size.</para></listitem><listitem><para><emphasis>ls -R</emphasis> --- <indexterm><primary>-R</primary></indexterm>(recursive) to list everything <indexterm><primary>everything</primary></indexterm>in the directories <indexterm><primary>directories</primary></indexterm>below as well as the current directory.</para></listitem></itemizedlist><para>Command syntax, either:</para><screen><![CDATA[ls -options
]]></screen><para>This simply lists everything in the current directory, the options <indexterm><primary>options</primary></indexterm>are not required <indexterm><primary>required</primary></indexterm>(options such as <emphasis>-l</emphasis>, <emphasis>-a</emphasis> et cetera).</para><screen><![CDATA[ls -options string
]]></screen><para>This lists files using a certain string. The string <indexterm><primary>string</primary></indexterm>can contain standard wildcards <indexterm><primary>standard wildcards</primary></indexterm>to list multiple files, to learn<indexterm><primary>learn</primary></indexterm> more about standard wildcards please read <xref linkend="standard-wildcards"></para><para>You can use<emphasis> ls -d</emphasis> to show <indexterm><primary>show</primary></indexterm>directories that match <indexterm><primary>match</primary></indexterm>an exact <indexterm><primary>exact</primary></indexterm>string, or use standard wildcards. Type &ldquo; ls -d */&rdquo; to list all subdirectories <indexterm><primary>subdirectories</primary></indexterm>of the current directory. Depending <indexterm><primary>Depending</primary></indexterm>on the setup <indexterm><primary>setup</primary></indexterm>of your aliases (see <xref linkend="Shell-Tips">) you may simply be able to type<emphasis> lsd <indexterm><primary>lsd</primary></indexterm></emphasis>as the equivalent <indexterm><primary>equivalent</primary></indexterm>to<emphasis> ls -d */</emphasis>.</para><para>Examples <indexterm><primary>Examples</primary></indexterm>for<emphasis> ls -d</emphasis>:</para><screen><![CDATA[ls -d]]><emphasis><![CDATA[ ]]></emphasis><![CDATA[*/
]]></screen><para>Lists all subdirectories <indexterm><primary>subdirectories</primary></indexterm>of current directory.</para><screen><![CDATA[ls -d string*
]]></screen><para>Lists directories that start with &quot;string&quot;.</para><screen><![CDATA[ls -d /usr/*/*/doc
]]></screen><para>Lists all directories <indexterm><primary>directories</primary></indexterm>that are two levels <indexterm><primary>levels</primary></indexterm>below the /usr/ directory and have a directory called &ldquo;doc&rdquo;, this trick <indexterm><primary>trick</primary></indexterm>can come in quite handy sometimes.</para><tip>
<title>You can also use</title>
<para>
Depending on how your aliases (see <xref linkend="Shell-Tips">) are setup you can also use <emphasis>l</emphasis>, <emphasis>la</emphasis> (list all) and <emphasis>ll</emphasis> (list long) to perform the above commands
</para>
</tip>
</listitem></varlistentry><varlistentry><term>pwd
</term><listitem><para><indexterm><primary>pwd</primary></indexterm>Print working directory<indexterm><primary>print working directory</primary></indexterm>. Print <indexterm><primary>Print</primary></indexterm>the absolute <indexterm><primary>absolute</primary></indexterm>(complete) path <indexterm><primary>path</primary></indexterm>to the directory the user is currently in. </para><para>Command syntax:</para><screen><![CDATA[pwd
]]></screen><para>This will tell you the full path <indexterm><primary>path</primary></indexterm>to the directory you are in, for example it may output <indexterm><primary>output</primary></indexterm>&ldquo;/usr/local/bin&rdquo; if you are currently in that directory.</para></listitem></varlistentry><varlistentry><term>tree
</term><listitem><para><indexterm><primary>tree</primary></indexterm>Outputs <indexterm><primary>Outputs</primary></indexterm>an <acronym>ASCII</acronym> <indexterm><primary>ASCII</primary></indexterm>text tree/graph <indexterm><primary>graph</primary></indexterm>starting at a given directory (by default <indexterm><primary>default</primary></indexterm>the current <indexterm><primary>current</primary></indexterm>directory). This command recursively lists <indexterm><primary>lists</primary></indexterm>all files and all directories.<indexterm><primary>directories</primary></indexterm></para><para>In other words, it will list files within the directories <indexterm><primary>directories</primary></indexterm>below the current one, as well as all files in the current directory.</para><para><emphasis>tree</emphasis> has a large number of options, refer <indexterm><primary>refer</primary></indexterm>to the manual <indexterm><primary>manual</primary></indexterm>page <indexterm><primary>page</primary></indexterm>for details.<indexterm><primary>details</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[tree
]]></screen><para>or</para><screen><![CDATA[tree -option(s) /optional/directory/to/list
]]></screen></listitem></varlistentry></variablelist><sect2 id="finding-files"><title>Finding files</title><variablelist><varlistentry><term>find
</term><listitem><para><indexterm><primary>find</primary></indexterm><emphasis>find</emphasis> is a tool which looks <indexterm><primary>looks</primary></indexterm>for files on a filesystem.<indexterm><primary>filesystem</primary></indexterm> <emphasis>find</emphasis> has a large number <indexterm><primary>number</primary></indexterm>of options which can be used to customise <indexterm><primary>customise</primary></indexterm>the search<indexterm><primary>search</primary></indexterm> (refer to the manual/info pages).</para><para>Note that find works with standard wildcards,<indexterm><primary>standard wildcards</primary></indexterm><xref linkend="standard-wildcards">, and can work with regular expressions<indexterm><primary>regular expressions</primary></indexterm>, <xref linkend="regular-expressions">.</para><para>Basic <indexterm><primary>Basic</primary></indexterm>example:</para><screen><![CDATA[find / -name file
]]></screen><para>This would look <indexterm><primary>look</primary></indexterm>for a file named <indexterm><primary>named</primary></indexterm>&ldquo;file&rdquo; and start at the root directory <indexterm><primary>root directory</primary></indexterm>(it will search all directories <indexterm><primary>directories</primary></indexterm>including<indexterm><primary>including</primary></indexterm> those that are mounted <indexterm><primary>mounted</primary></indexterm>filesystems).</para><para>The <emphasis>`-name'<indexterm><primary>-name</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>is case sensitive <indexterm><primary>sensitive</primary></indexterm>you can use the <emphasis>`-iname'</emphasis> option to find something regardless <indexterm><primary>regardless</primary></indexterm>of case.</para><para>Use the <emphasis>'-regex'<indexterm><primary>-regex</primary></indexterm></emphasis> and <emphasis>'-iregex'<indexterm><primary>-iregex</primary></indexterm></emphasis> to find something according to a regular expression (either case sensitive<indexterm><primary>sensitive</primary></indexterm> or case insensitive <indexterm><primary>insensitive</primary></indexterm>respectively).</para><para>The <emphasis>'-exec'<indexterm><primary>-exec</primary></indexterm></emphasis> option is one of the more advanced <indexterm><primary>advanced</primary></indexterm>find <indexterm><primary>find</primary></indexterm>operations.<indexterm><primary>operations</primary></indexterm> It executes a command on the files it finds <indexterm><primary>finds</primary></indexterm>(such as moving <indexterm><primary>moving</primary></indexterm>or removing<indexterm><primary>removing</primary></indexterm> it or anything else...).</para><para>To use the <emphasis>-exec</emphasis> option: use find to find something, then add <indexterm><primary>add</primary></indexterm>the <emphasis>-exec</emphasis> option to the end,<indexterm><primary>end</primary></indexterm> then:</para><screen>
command_to_be_executed <co id="command"> then '{}'<emphasis> </emphasis>(curly brackets) <co id="brackets"> then the arguments (for example a new directory) and finally a ';' <co id="end">.
</screen>
<para>See below for an example of use this command.</para><calloutlist>
<callout arearefs="command">
<para>
This is the tool you want to execute on the files find locates. For example if you wanted to remove everything it finds then you would use <emphasis>-exec rm -f</emphasis>
</para>
</callout>
<callout arearefs="brackets">
<para>
The curly brackets are used in find to represent the current file which has been found. ie. If it found the file shopping.doc then {} would be substituted with shopping.doc. It would then continue to substitute {} for each file it finds. The brackets are normally protected by backslashes (\) or single-quotation marks ('), to stop bash expanding them (trying to interpret them as a special command eg. a wildcard).
</para>
</callout>
<callout arearefs="end">
<para>
This is the symbol used by find to signal the end of the commands. It's usually protected by a backslash (\) or quotes to stop bash from trying to expand it.
</para>
</callout>
</calloutlist>
<screen><![CDATA[find / -name '*.doc' -exec cp '{}' /tmp/ ';'
]]></screen><para>The above command would find <indexterm><primary>find</primary></indexterm>any files with the extension <indexterm><primary>extension</primary></indexterm>'.doc' and copy<indexterm><primary>copy</primary></indexterm> them to your /tmp directory, obviously this command is quite useless, it's just an example of what find can do. Note that the quotation <indexterm><primary>quotation</primary></indexterm>marks are there to stop <indexterm><primary>stop</primary></indexterm>bash <indexterm><primary>bash</primary></indexterm>from trying to interpret<indexterm><primary>interpret</primary></indexterm> the other characters <indexterm><primary>characters</primary></indexterm>as something.</para><para>Excluding <indexterm><primary>Excluding</primary></indexterm>particular folders <indexterm><primary>folders</primary></indexterm>with <emphasis>find</emphasis> can be quite <indexterm><primary>quite</primary></indexterm>confusing, but it may be necessary if you want to search your main disk <indexterm><primary>disk</primary></indexterm>(without searching <indexterm><primary>searching</primary></indexterm>every mounted <indexterm><primary>mounted</primary></indexterm>filesystem). Use the<emphasis> -path <indexterm><primary>-path</primary></indexterm></emphasis> option to exclude <indexterm><primary>exclude</primary></indexterm>the particular folder (note, you cannot have a '/' (forward slash) on the end) and the<emphasis> -prune <indexterm><primary>-prune</primary></indexterm></emphasis> option to exclude <indexterm><primary>exclude</primary></indexterm>the subdirectories.<indexterm><primary>subdirectories</primary></indexterm> An example is below:</para><screen><![CDATA[find / -path '/mnt/win_c' -prune -o -name "string" -print
]]></screen><para><indexterm><primary>-path</primary></indexterm><indexterm><primary>-prune</primary></indexterm><indexterm><primary>-o</primary></indexterm><indexterm><primary>-print</primary></indexterm>This example will search your entire directory tree (everything that is mounted <indexterm><primary>mounted</primary></indexterm>under it) excluding <indexterm><primary>excluding</primary></indexterm>/mnt/win_c and all of the subdirectories <indexterm><primary>subdirectories</primary></indexterm>under /mnt/win_c. When using the <emphasis>-path</emphasis> option you can use wildcards.<indexterm><primary>wildcards</primary></indexterm></para><para>Note that you could add <indexterm><primary>add</primary></indexterm>more<emphasis> -path <indexterm><primary>-path</primary></indexterm>'/directory'</emphasis> statements <indexterm><primary>statements</primary></indexterm>on if you wanted.</para><para><emphasis>find</emphasis> has many, many different <indexterm><primary>different</primary></indexterm>options, refer <indexterm><primary>refer</primary></indexterm>to the manual (and info) page<indexterm><primary>page</primary></indexterm> for more <indexterm><primary>more</primary></indexterm>details.</para></listitem></varlistentry><varlistentry><term>slocate
</term><listitem><para><indexterm><primary>slocate</primary></indexterm><emphasis>slocate</emphasis> outputs <indexterm><primary>outputs</primary></indexterm>a list <indexterm><primary>list</primary></indexterm>of all files on the system that match <indexterm><primary>match</primary></indexterm>the pattern,<indexterm><primary>pattern</primary></indexterm> giving their full path <indexterm><primary>path</primary></indexterm>name (it doesn't have to be an exact <indexterm><primary>exact</primary></indexterm>match, anything which contains the word is shown).</para><note>
<title>Replaces <emphasis>locate</emphasis></title>
<para>Secure locate is a replacement for <emphasis>locate</emphasis>, both have identical syntax. On most distributions locate is an alias to <emphasis>slocate</emphasis>.</para>
</note>
<para>Commmand <indexterm><primary>Commmand</primary></indexterm>syntax:<indexterm><primary>syntax</primary></indexterm></para><screen><![CDATA[slocate string
]]></screen><note>
<title>This won't work unless</title>
<para>
You need to run either <emphasis>updatedb</emphasis> (as root) or <emphasis>slocate -u<indexterm><primary>-u</primary></indexterm> </emphasis>(as root) for slocate to work.
</para>
</note>
</listitem></varlistentry><varlistentry><term><emphasis>whereis</emphasis>
</term><listitem><para>whereis<indexterm><primary><emphasis>whereis</emphasis></primary></indexterm> locates <indexterm><primary>locates</primary></indexterm>the binary,<indexterm><primary>binary</primary></indexterm> source,<indexterm><primary>source</primary></indexterm> and manual page for a particular program, it uses exact <indexterm><primary>exact</primary></indexterm>matches only, if you only know part <indexterm><primary>part</primary></indexterm>of the name use <emphasis>slocate</emphasis><indexterm><primary>slocate</primary></indexterm>.</para><para>Command syntax:</para><screen><![CDATA[whereis program_name
]]></screen></listitem></varlistentry><varlistentry><term>which
</term><listitem><para><indexterm><primary>which</primary></indexterm>Virtually the same as whereis,<indexterm><primary>whereis</primary></indexterm> except it only finds <indexterm><primary>finds</primary></indexterm>the executable<indexterm><primary>executable</primary></indexterm> (the physical <indexterm><primary>physical</primary></indexterm>program). It only looks in the PATH <indexterm><primary>PATH</primary></indexterm>(environment variable) of a users shell.<indexterm><primary>shell</primary></indexterm> </para><para>Use the <emphasis>-a<indexterm><primary>-a</primary></indexterm></emphasis> option to list all occurances <indexterm><primary>occurances</primary></indexterm>of the particular program_name <indexterm><primary>program_name</primary></indexterm>in your path<indexterm><primary>path</primary></indexterm> (so if theres more than one you can see it).</para><para>Command syntax:</para><screen><![CDATA[which program_name
]]></screen></listitem></varlistentry></variablelist></sect2>
</sect1>
<sect1 id="working-files-folders"><title>Working with files and folders</title><variablelist><varlistentry><term>mkdir
</term><listitem><para><indexterm><primary>mkdir</primary></indexterm>Make a directory. Use<emphasis> mkdir -p<indexterm><primary>-p</primary></indexterm></emphasis> to create subdirectories <indexterm><primary>subdirectories</primary></indexterm>automatically.<indexterm><primary>automatically</primary></indexterm></para><note>
<title>Directories are Folders</title>
<para>Directories are sometimes called folders in other operating systems (such as Microsoft Windows)</para>
</note>
<para>Examples:</para><screen><![CDATA[mkdir -p /home/matt/work/maths
]]></screen><para>This would create the directories <indexterm><primary>directories</primary></indexterm>&ldquo;work&rdquo; and &ldquo;maths&rdquo; under matt's home <indexterm><primary>home</primary></indexterm>directory (if matt's home <indexterm><primary>home</primary></indexterm>directory <indexterm><primary>directory</primary></indexterm>didn't exist <indexterm><primary>exist</primary></indexterm>it would create that too).</para><screen><![CDATA[mkdir foo
]]></screen><para>This would create a directory in the current path <indexterm><primary>path</primary></indexterm>named &ldquo;foo&rdquo;.</para></listitem></varlistentry><varlistentry><term>rm
</term><listitem><para><indexterm><primary>rm</primary></indexterm>Remove/delete<indexterm><primary>delete</primary></indexterm><indexterm><primary>remove</primary></indexterm> a file(s) or directories(s). You can use standard wildcards <indexterm><primary>standard wildcards</primary></indexterm>with this command <xref linkend="standard-wildcards">.</para><para>Command syntax:</para><screen><![CDATA[rm -options file_or_folder
]]></screen><para>You can of course use standard wildcards to delete multiple files or multiple<indexterm><primary>multiple</primary></indexterm> directories <indexterm><primary>directories</primary></indexterm>and files.</para><para>Use the<emphasis> -R<indexterm><primary>-R</primary></indexterm></emphasis> or <emphasis>-r<indexterm><primary>-r</primary></indexterm></emphasis> option to remove <indexterm><primary>remove</primary></indexterm>recursively, this removes <indexterm><primary>removes</primary></indexterm>everything <indexterm><primary>everything</primary></indexterm>within subdirectories.<indexterm><primary>subdirectories</primary></indexterm> Also try the <emphasis>-f<indexterm><primary>-f</primary></indexterm></emphasis> option to force <indexterm><primary>force</primary></indexterm>removal (useful when you don't want to be prompted).</para><tip>
<title>Disabling Aliases (per execution)</title>
<para>
On some systems such as <productname>Mandrake</productname> an alias will send <emphasis>rm</emphasis> to <emphasis>rm -i<indexterm><primary>-i</primary></indexterm></emphasis> (prompting you for every file you wish to delete). To override this use: <emphasis>\rm -R directory </emphasis>(using the \ disables the alias for this run only)
</para>
</tip>
</listitem></varlistentry><varlistentry><term>rmdir
</term><listitem><para><indexterm><primary>rmdir</primary></indexterm>Remove an empty <indexterm><primary>empty</primary></indexterm>directory. If you want to remove <indexterm><primary>remove</primary></indexterm>a directory with files in it type &ldquo; rm -R directory&rdquo;, read above for information <indexterm><primary>information</primary></indexterm>on<emphasis> rm -R</emphasis></para><para>Command syntax:</para><screen><![CDATA[rmdir directory
]]></screen><para>This will only remove <indexterm><primary>remove</primary></indexterm>directory if it's empty <indexterm><primary>empty</primary></indexterm>otherwise it will exit <indexterm><primary>exit</primary></indexterm>with an error <indexterm><primary>error</primary></indexterm>message.</para></listitem></varlistentry><varlistentry><term>mv
</term><listitem><para><indexterm><primary>mv</primary></indexterm>Move a file or a directory to a new <indexterm><primary>new</primary></indexterm>location or rename <indexterm><primary>rename</primary></indexterm>a file/directory.</para><para>Rename <indexterm><primary>Rename</primary></indexterm>example: </para><screen><![CDATA[mv filename1 filename2
]]></screen><para>Renames <indexterm><primary>Renames</primary></indexterm>filename1 <indexterm><primary>filename1</primary></indexterm>to filename2.<indexterm><primary>filename2</primary></indexterm></para><para>To move <indexterm><primary>move</primary></indexterm>a file or directory, simply type: </para><screen><![CDATA[mv original_file_or_folder new_location
]]></screen><para>Note that this command can use standard wildcards <indexterm><primary>standard wildcards</primary></indexterm><xref linkend="standard-wildcards"> to move <indexterm><primary>move</primary></indexterm>files (not for renaming).</para><tip>
<title>Move and rename</title>
<para>
Note that you can also move and rename a file in a single command. The difference is with the destination (right hand side) you change the filename to the new name of the file.
</para>
<para>For example typing:</para>
<screen><![CDATA[mv /etc/configuration.txt /home/joe/backupconfig]]></screen>
<para>This would move the file &quot;configuration.txt&quot; to /home/joe/ and rename it &quot;backupconfig&quot;</para>
</tip>
</listitem></varlistentry><varlistentry><term>cp
</term><listitem><para><indexterm><primary>cp</primary></indexterm>Copy a file. Has a number <indexterm><primary>number</primary></indexterm>of useful options, such as<emphasis> -R <indexterm><primary>-R</primary></indexterm></emphasis>(or <emphasis>-r</emphasis>) which <indexterm><primary>which</primary></indexterm>recursively <indexterm><primary>recursively</primary></indexterm>copies <indexterm><primary>copies</primary></indexterm>directories and subdirectories.<indexterm><primary>subdirectories</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[cp -options file_or_files new_location
]]></screen><para>Examples:</para><screen><![CDATA[cp file1 file2
]]></screen><para>Simply copy file1 <indexterm><primary>file1</primary></indexterm>to file2 <indexterm><primary>file2</primary></indexterm>(in the same directory).</para><screen><![CDATA[cp /tmp/file1 ~/file2 /mnt/win_c
]]></screen><para>Where the last <indexterm><primary>last</primary></indexterm>option is the directory to be copied to. The above example copies <indexterm><primary>Copies</primary></indexterm>two files from different areas of the file system to /mnt/win_c</para><screen><![CDATA[cp -R directory_and_or_files new_location
]]></screen><para>This command will copy directories (and all subdirectories) and/or files t<emphasis>o new_location<indexterm><primary>new_location</primary></indexterm></emphasis> </para><para>Note that this command can use standard wildcards <indexterm><primary>standard wildcards</primary></indexterm><xref linkend="standard-wildcards"> to copy <indexterm><primary>copy</primary></indexterm>multiple files.</para><para>You may also like to try the &ldquo;-u&rdquo;<indexterm><primary>-u</primary></indexterm> when moving <indexterm><primary>moving</primary></indexterm>large directories <indexterm><primary>directories</primary></indexterm>around, this copies <indexterm><primary>copies</primary></indexterm>only if the source <indexterm><primary>source</primary></indexterm>file is newer <indexterm><primary>newer</primary></indexterm>than the destination <indexterm><primary>destination</primary></indexterm>to where you are copying <indexterm><primary>copying</primary></indexterm>to, or if the destination file does not exist <indexterm><primary>exist</primary></indexterm>at all.</para></listitem></varlistentry><varlistentry><term>ln
</term><listitem><para><indexterm><primary>ln</primary></indexterm>Create a link <indexterm><primary>link</primary></indexterm>to a file. There are two types <indexterm><primary>types</primary></indexterm>of links:<indexterm><primary>links</primary></indexterm></para><variablelist><varlistentry><term>Hard&nbsp;links
</term><listitem><para><indexterm><primary>hard links</primary></indexterm>Hard links are considered pointers <indexterm><primary>pointers</primary></indexterm>to a file (the number is listed <indexterm><primary>listed</primary></indexterm>by typing<emphasis> ls -l</emphasis>)<emphasis><indexterm><primary>ls</primary></indexterm></emphasis>. Each hard-link <indexterm><primary>hard-link</primary></indexterm>is a reference <indexterm><primary>reference</primary></indexterm>to a file.</para><para>The file itself only goes away when all hard-links <indexterm><primary>hard-links</primary></indexterm>are deleted.<indexterm><primary>deleted</primary></indexterm> If you delete the original <indexterm><primary>original</primary></indexterm>file and there are hard links <indexterm><primary>links</primary></indexterm>to it the original file will remain. </para><para>Example:</para><screen><![CDATA[ln target_name link_name
]]></screen><para>Will create a &ldquo;hard link&rdquo; to target_name <indexterm><primary>target_name</primary></indexterm>called link_name,<indexterm><primary>link_name</primary></indexterm> you need to delete both of these to remove<indexterm><primary>remove</primary></indexterm> the file.</para></listitem></varlistentry><varlistentry><term>Symbolic&nbsp;links
</term><listitem><para><indexterm><primary>Symbolic links</primary></indexterm>Symbolic links are created by typing &ldquo;ln -s&rdquo;.<indexterm><primary>-s</primary></indexterm><emphasis> </emphasis>When you remove <indexterm><primary>remove</primary></indexterm>the original <indexterm><primary>original</primary></indexterm>file the symbolic link <indexterm><primary>symbolic link</primary></indexterm>becomes broken,<indexterm><primary>broken</primary></indexterm> a symbolic link <indexterm><primary>link</primary></indexterm>is similar to a windows <indexterm><primary>windows</primary></indexterm>&ldquo;short-cut&rdquo;. </para><para>The advantage <indexterm><primary>advantage</primary></indexterm>of symbolic <indexterm><primary>symbolic</primary></indexterm>links is that the target can be to something on another file-system, while hard-links <indexterm><primary>hard-links</primary></indexterm>can only exist <indexterm><primary>exist</primary></indexterm>on the same file-system.<indexterm><primary>file-system</primary></indexterm></para><para>For example:</para><screen><![CDATA[ln -s target_name link_name
]]></screen><para>This creates a symbolic link to &ldquo;target_name&rdquo; called &ldquo;link_name&rdquo;, if you delete the original <indexterm><primary>original</primary></indexterm>file the symbolic link won't work (it becomes a broken <indexterm><primary>broken</primary></indexterm>link).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>shred
</term><listitem><para><indexterm><primary>shred</primary></indexterm>Securely remove <indexterm><primary>remove</primary></indexterm>a file by overwriting <indexterm><primary>overwriting</primary></indexterm>it first. Prevents <indexterm><primary>Prevents</primary></indexterm>the data <indexterm><primary>data</primary></indexterm>from being recovered <indexterm><primary>recovered</primary></indexterm>by software <indexterm><primary>software</primary></indexterm>(and even by most hardware), please be very careful <indexterm><primary>careful</primary></indexterm>when using shred as you may never be able <indexterm><primary>able</primary></indexterm>to retrieve<indexterm><primary>retrieve</primary></indexterm> the data <indexterm><primary>data</primary></indexterm>you have run <indexterm><primary>run</primary></indexterm>the application <indexterm><primary>application</primary></indexterm>on.</para><para>For example:</para><screen><![CDATA[shred -n 2 -z -v /dev/hda1
]]></screen><blockquote><para><indexterm><primary>-n</primary></indexterm><indexterm><primary>-z</primary></indexterm><indexterm><primary>-v</primary></indexterm>&ldquo;What this tells shred, is to overwrite <indexterm><primary>overwrite</primary></indexterm>the partition <indexterm><primary>partition</primary></indexterm>2 times with random<indexterm><primary>random</primary></indexterm> data <indexterm><primary>data</primary></indexterm>(- n 2) then finish <indexterm><primary>finish</primary></indexterm>it up by writing <indexterm><primary>writing</primary></indexterm>over it with zeroes <indexterm><primary>zeroes</primary></indexterm>(-z) and show <indexterm><primary>show</primary></indexterm>you its progress (-v). Of course, change <indexterm><primary>change</primary></indexterm>/dev/hda1 to the correct partition <indexterm><primary>partition</primary></indexterm>. Each pass <indexterm><primary>pass</primary></indexterm>can take some time,<indexterm><primary>time</primary></indexterm> which is why I set <indexterm><primary>set</primary></indexterm>it to only do 2 random<indexterm><primary>random</primary></indexterm> passes <indexterm><primary>passes</primary></indexterm>instead of the default <indexterm><primary>default</primary></indexterm>25. You can adjust <indexterm><primary>adjust</primary></indexterm>this number, of course, to your particular level of paranoia<indexterm><primary>paranoia</primary></indexterm> and the amount <indexterm><primary>amount</primary></indexterm>of time you have.</para><para>Since shred writes on such a low-level,<indexterm><primary>low-level</primary></indexterm> it doesn't actually matter what kind of filesystem <indexterm><primary>filesystem</primary></indexterm>is on the partition--everything will be unrecoverable.<indexterm><primary>unrecoverable</primary></indexterm> Once shred is finished,<indexterm><primary>finished</primary></indexterm> you can shutdown the machine <indexterm><primary>machine</primary></indexterm>and sell <indexterm><primary>sell</primary></indexterm>or throw<indexterm><primary>throw</primary></indexterm> away the drive <indexterm><primary>drive</primary></indexterm>with peace <indexterm><primary>peace</primary></indexterm>of mind.<indexterm><primary>mind</primary></indexterm></para><para>...However, even shre dding devices <indexterm><primary>devices</primary></indexterm>is not always completely reliable.<indexterm><primary>reliable</primary></indexterm> For example, most disks <indexterm><primary>disks</primary></indexterm>map <indexterm><primary>map</primary></indexterm>out bad sectors <indexterm><primary>sectors</primary></indexterm>invisibly to the application;<indexterm><primary>application</primary></indexterm> if the bad sectors <indexterm><primary>sectors</primary></indexterm>contain sensitive <indexterm><primary>sensitive</primary></indexterm>data,<indexterm><primary>data</primary></indexterm> `shred' won't be able <indexterm><primary>able</primary></indexterm>to destroy<indexterm><primary>destroy</primary></indexterm> it. [ shred info page <indexterm><primary>page</primary></indexterm>].&rdquo;<footnote><para>This information (as quoted) has come from the &ldquo;Please, For the Love of All That's Recoverable, Shred Your Hard Drive!&rdquo; article, number 18 in the <xref linkend="references"></para></footnote> </para></blockquote><note>
<title>Shredding files doesn't work with all filesystems</title>
<para>
Please note that as mentioned in the shred manual page (please see the manual and preferably info pages for more information). <emphasis>shred </emphasis>does not work correctly<emphasis> </emphasis>on log-structured or journaled filesystems, such as JFS, ReiserFS, XFS, Ext3 and many other modern filesystems
</para>
</note>
<tip>
<title>Alternatives to using shred</title>
<para>shred has its disadvantages when run on a filesystem. First of all since it has to be installed you cannot run shred on your operating systems filesystem, you also cannot use shred on a windows machine easily since you cannot install <emphasis>shred</emphasis> on this machine.</para>
<para>You may like to try alternatives such as the DBAN project that create self-booting floppy disks that can completely erase a machines hard disk.</para>
</tip>
<para>You may also like to see how <emphasis>chattr</emphasis> <indexterm><primary>chattr</primary></indexterm>can assist <indexterm><primary>assist</primary></indexterm>you in shredding <indexterm><primary>shredding</primary></indexterm>files once they are removed (it has similar problems <indexterm><primary>problems</primary></indexterm>to shred,<indexterm><primary>shred</primary></indexterm> only ext2 <indexterm><primary>ext2</primary></indexterm>and ext3<indexterm><primary>ext3</primary></indexterm> style filesystems...), please see <xref linkend="file-permissions">.</para></listitem></varlistentry><varlistentry><term>du
</term><listitem><para><indexterm><primary>du</primary></indexterm>Displays information <indexterm><primary>information</primary></indexterm>about file size. Use<emphasis> du filename </emphasis>to display <indexterm><primary>display</primary></indexterm>the size <indexterm><primary>size</primary></indexterm>of a particular <indexterm><primary>particular</primary></indexterm>file. If you use it on directories <indexterm><primary>directories</primary></indexterm>it will display the information on the size of the files in the directory and each subdirectory.<indexterm><primary>subdirectory</primary></indexterm> </para><para>Options <indexterm><primary>Options</primary></indexterm>for du <indexterm><primary>du</primary></indexterm>(use<emphasis> du -option(s)</emphasis>):</para><itemizedlist><listitem><para><emphasis>-c<indexterm><primary>-c</primary></indexterm> </emphasis>-- this will make <emphasis>du</emphasis> print <indexterm><primary>print</primary></indexterm>a grand <indexterm><primary>grand</primary></indexterm>total <indexterm><primary>total</primary></indexterm>after all arguments <indexterm><primary>arguments</primary></indexterm>have being processed.<indexterm><primary>processed</primary></indexterm></para></listitem><listitem><para><emphasis>-s<indexterm><primary>-s</primary></indexterm> </emphasis>-- summarises <indexterm><primary>summarises</primary></indexterm>for each argument <indexterm><primary>argument</primary></indexterm>(prints the total).</para></listitem><listitem><para><emphasis>-h<indexterm><primary>-h</primary></indexterm></emphasis> -- prints <indexterm><primary>prints</primary></indexterm>things in &ldquo; human readable<indexterm><primary>human readable</primary></indexterm>&rdquo; mode;<indexterm><primary>mode</primary></indexterm> for example printing <indexterm><primary>printing</primary></indexterm>1M (megabyte) rather than 1,024,000 (bytes).</para></listitem></itemizedlist><para>Using the <emphasis>-hs</emphasis> options on a directory will display the total <indexterm><primary>total</primary></indexterm>size of the directory <indexterm><primary>directory</primary></indexterm>and all subdirectories.<indexterm><primary>subdirectories</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[du -options file_directory_or_files
]]></screen><para>Example:</para><screen><![CDATA[du -hs *
]]></screen><para>This command will list <indexterm><primary>list</primary></indexterm>the size of all files in the current directory and it will list the size of subdirectories,<indexterm><primary>subdirectories</primary></indexterm> it will list things in human-readable<indexterm><primary>human-readable</primary></indexterm> sizes <indexterm><primary>sizes</primary></indexterm>using 1024 Kb <indexterm><primary>Kb</primary></indexterm>is a Megabyte,<indexterm><primary>Megabyte</primary></indexterm> M for megabyte,<indexterm><primary>megabyte</primary></indexterm> K for kilobyte <indexterm><primary>kilobyte</primary></indexterm>etc.</para><para></para></listitem></varlistentry><varlistentry><term>file
</term><listitem><para>Attempts <indexterm><primary>Attempts</primary></indexterm>to find <indexterm><primary>find</primary></indexterm>out what type of file it is, for example it may say it's: binary,<indexterm><primary>binary</primary></indexterm> an image <indexterm><primary>image</primary></indexterm>file (well it will say jpeg,<indexterm><primary>jpeg</primary></indexterm> bmp <indexterm><primary>bmp</primary></indexterm>et cetera), ASCII<indexterm><primary>ASCII</primary></indexterm> text,<indexterm><primary>text</primary></indexterm> C header <indexterm><primary>header</primary></indexterm>file and many other kinds of files, it's a very useful utility.<indexterm><primary>utility</primary></indexterm> </para><para>Command syntax:</para><screen><![CDATA[file file_name
]]></screen></listitem></varlistentry><varlistentry><term>stat
</term><listitem><para><indexterm><primary>stat</primary></indexterm>Tells you detailed <indexterm><primary>detailed</primary></indexterm>information <indexterm><primary>information</primary></indexterm>about a file, including <indexterm><primary>including</primary></indexterm>inode number creation/access date. Also has many advanced <indexterm><primary>advanced</primary></indexterm>options and uses. </para><para>For simple use type:</para><screen><![CDATA[stat file
]]></screen></listitem></varlistentry><varlistentry><term>dd
</term><listitem><para><indexterm><primary>dd</primary></indexterm>Copies data <indexterm><primary>data</primary></indexterm>on a very low <indexterm><primary>low</primary></indexterm>level and can be used to create copies <indexterm><primary>copies</primary></indexterm>of disks<indexterm><primary>disks</primary></indexterm> <xref linkend="duplicating-disks"> and many other things (for example CD image <indexterm><primary>image</primary></indexterm>files). </para><para><emphasis>dd</emphasis> can also perform <indexterm><primary>perform</primary></indexterm>conversions on files and vary the block <indexterm><primary>block</primary></indexterm>size used when writing <indexterm><primary>writing</primary></indexterm>the file. </para><para>Command syntax, note the block <indexterm><primary>block</primary></indexterm>size and count <indexterm><primary>count</primary></indexterm>are optional <indexterm><primary>optional</primary></indexterm>and you can use files instead of devices...</para><note>
<title>Please note</title>
<para><emphasis>dd</emphasis> is an advanced and difficult to use command. Its also very powerful, so be careful what you do with it </para>
</note>
<para>Command syntax:</para><para></para><screen><![CDATA[dd if=/dev/xxx of=/dev/xxx bs=xxxx count=x
]]></screen><warning>
<title>Warning</title>
<para>
The command <emphasis>dd</emphasis> is used to work on a very low level. It can be used to overwrite important information such as your master-boot record or various important sections of your hard-disk. Please be careful when using it (especially when working with devices instead of files).
</para>
</warning>
</listitem></varlistentry><varlistentry><term>touch
</term><listitem><para><indexterm><primary>touch</primary></indexterm>This command is used to create empty <indexterm><primary>empty</primary></indexterm>files, simply do<emphasis> touch file_name</emphasis>. It is also used to update <indexterm><primary>update</primary></indexterm>the timestamps <indexterm><primary>timestamps</primary></indexterm>on files.</para><para><emphasis>touch</emphasis> can be used to change <indexterm><primary>change</primary></indexterm>the time and/or date of a file:</para><screen><![CDATA[touch -t]]><indexterm><primary>-t</primary></indexterm><![CDATA[ 05070915 my_report.txt]]><footnote><para>This particular command and explanation has been used (with editing) from the <productname>Linux</productname> Online Classroom, see [4] in the <xref linkend="references"> for further information.</para></footnote><![CDATA[
]]></screen><para>This command would change <indexterm><primary>change</primary></indexterm>the timestamp <indexterm><primary>timestamp</primary></indexterm>on my_report.txt so that it would look <indexterm><primary>look</primary></indexterm>like you created it at 9:15. The first four digits <indexterm><primary>digits</primary></indexterm>stand for May 7th (0507), in MM-DD (American style), and the last <indexterm><primary>last</primary></indexterm>four (0915) the time,<indexterm><primary>time</primary></indexterm> 9:15 in the morning.<indexterm><primary>morning</primary></indexterm> </para><para>Instead of using plain <indexterm><primary>plain</primary></indexterm>numbers to change <indexterm><primary>change</primary></indexterm>the time, you can use options similar to that of the <emphasis>date</emphasis> tool. For example:</para><screen><![CDATA[touch -d '5 May 2000' some_file.txt
]]></screen><para>You can also use <emphasis>--date=</emphasis> instead of <emphasis>-d<indexterm><primary>-d</primary></indexterm><indexterm><primary>--date=</primary></indexterm>. </emphasis>Also have a look at the date command under <xref linkend="date-time-calendars"> for examples <indexterm><primary>examples</primary></indexterm>on using <emphasis>-d</emphasis> and <emphasis>--date=</emphasis> (the syntax <indexterm><primary>syntax</primary></indexterm>for the date <indexterm><primary>date</primary></indexterm>part is exactly <indexterm><primary>exactly</primary></indexterm>the same when using <emphasis>-d</emphasis> or <emphasis>--date</emphasis>).</para></listitem></varlistentry><varlistentry><term>split
</term><listitem><para><indexterm><primary>split</primary></indexterm>Splits <indexterm><primary>Splits</primary></indexterm>files into several <indexterm><primary>several</primary></indexterm>smaller <indexterm><primary>smaller</primary></indexterm>files. </para><para>Use the <emphasis>-b&nbsp;xx</emphasis> <indexterm><primary>-b</primary></indexterm>option <indexterm><primary>option</primary></indexterm>to split <indexterm><primary>split</primary></indexterm>into <emphasis>xx</emphasis> bytes,<indexterm><primary>bytes</primary></indexterm> also try <emphasis>-k</emphasis> <indexterm><primary>-k</primary></indexterm>for kilobytes,<indexterm><primary>kilobytes</primary></indexterm> and <emphasis>-m</emphasis> <indexterm><primary>-m</primary></indexterm>for megabytes.<indexterm><primary>megabytes</primary></indexterm> You can use it to split text files and any other files... you can use <emphasis>cat</emphasis> to re-combine <indexterm><primary>re-combine</primary></indexterm>the files. </para><para>This may be useful if you have to transfer <indexterm><primary>transfer</primary></indexterm>something to floppy <indexterm><primary>floppy</primary></indexterm>disks <indexterm><primary>disks</primary></indexterm>or you wish to divide <indexterm><primary>divide</primary></indexterm>text files into certain sizes.<indexterm><primary>sizes</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[split -options file
]]></screen><para>This will split <indexterm><primary>split</primary></indexterm>the input <indexterm><primary>input</primary></indexterm>file into 1000 lines <indexterm><primary>lines</primary></indexterm>of input each (thats the default...), and output <indexterm><primary>output</primary></indexterm>(using the above example), with the input name file, &ldquo;fileaa&rdquo; (1st part <indexterm><primary>part</primary></indexterm>of file), &ldquo;fileab&rdquo; (2nd part <indexterm><primary>part</primary></indexterm>of file), &ldquo;fileac&rdquo; (3rd part <indexterm><primary>part</primary></indexterm>of file) etc. until the there is no more <indexterm><primary>more</primary></indexterm>of the file left to split.<indexterm><primary>split</primary></indexterm></para></listitem></varlistentry></variablelist></sect1>
<sect1 id="mass-rename"><title>Mass Rename/copy/link Tools</title><para>There are a few different ways to perform mass renaming<indexterm><primary>mass renaming</primary></indexterm> of files in GNU/Linux (yes, mass renaming is possible!). There is also a perl <indexterm><primary>perl</primary></indexterm>script that renames <indexterm><primary>renames</primary></indexterm>the extentions <indexterm><primary>extentions</primary></indexterm>on files, see <xref linkend="Miscellaneous">.</para><para>Below are three ways to perform mass renaming of files, using the commands <emphasis>mmv</emphasis>, <emphasis>rename</emphasis> (a perl <indexterm><primary>perl</primary></indexterm>script) or some bash <indexterm><primary>bash</primary></indexterm>shell scripting.<indexterm><primary>scripting</primary></indexterm></para><variablelist><varlistentry><term></term>
<listitem><para>&nbsp;</para></listitem></varlistentry><varlistentry><term>mmv
</term><listitem><para><indexterm><primary>mmv</primary></indexterm><emphasis>mmv</emphasis> is a mass <indexterm><primary>mass</primary></indexterm>move/copy/renaming tool <indexterm><primary>move</primary></indexterm><indexterm><primary>renaming</primary></indexterm>that uses standard wildcards <indexterm><primary>standard wildcards</primary></indexterm>to perform its functions.<indexterm><primary>functions</primary></indexterm></para><para><emphasis>mmv's</emphasis> manual page is quite difficult to understand, I have only a limited <indexterm><primary>limited</primary></indexterm>understanding <indexterm><primary>ng</primary></indexterm>of this tool. However <emphasis>mmv</emphasis> supports <indexterm><primary>supports</primary></indexterm>some standard <indexterm><primary>standard</primary></indexterm>wildcards.<indexterm><primary>standard wildcards</primary></indexterm><indexterm><primary>wildcards</primary></indexterm></para><para>According to the manual <indexterm><primary>manual</primary></indexterm>the &ldquo;;&rdquo;<indexterm><primary>;</primary></indexterm> wildcard <indexterm><primary>wildcard</primary></indexterm>is useful for matching <indexterm><primary>matching</primary></indexterm>files at any depth <indexterm><primary>depth</primary></indexterm>in the directory tree (ie it will go below the current directory, recursively).</para><para>An example of how to use<emphasis> mmv <indexterm><primary>mmv</primary></indexterm></emphasis>is shown <indexterm><primary>shown</primary></indexterm>below:</para><screen><![CDATA[mmv \*.JPG \#1.jpg
]]></screen><para>The first pattern <indexterm><primary>pattern</primary></indexterm>matches anything with a &ldquo;.JPG&rdquo; and renames <indexterm><primary>renames</primary></indexterm>each file (the &ldquo;#1&rdquo; matches the first wildcard) to &ldquo;.jpg&rdquo;.</para><para>Each time you use a \(wildcard) you can use a #x to get that wildcard. Where x is a positive <indexterm><primary>positive</primary></indexterm>number starting <indexterm><primary>starting</primary></indexterm>at 1.</para><tip>
<title>mmv Homepage</title>
<para>You can find <emphasis>mmv</emphasis> on the web <ulink url="http://linux.maruhn.com/sec/mmv.html">here.</ulink></para>
<para>Also be aware that certain options used with <emphasis>mmv</emphasis> are also applicable to other tools in the suite, these include <emphasis>mcp</emphasis> (mass copy), <emphasis>mad</emphasis> (mass append contents of source file to target name), <emphasis>mln</emphasis> (mass link to a source file).</para>
</tip>
<tip>
<title>Tip:</title>
<para>A <application>Java</application> alternative to <emphasis>mmv</emphasis> which runs on both GNU/Linux and <productname>Windows</productname> is available, <ulink url="http://www.esomaniac.de/">Esomaniac</ulink></para>
</tip>
</listitem></varlistentry><varlistentry><term>rename
</term><listitem><para><indexterm><primary>rename</primary></indexterm><emphasis>rename</emphasis> is a perl <indexterm><primary>perl</primary></indexterm>script which <indexterm><primary>which</primary></indexterm>can be used to mass rename <indexterm><primary>mass rename</primary></indexterm>files according to a regular expression<indexterm><primary>regular expression</primary></indexterm>.</para><para>An example for renaming <indexterm><primary>renaming</primary></indexterm>all &ldquo;.JPG&rdquo; files to &ldquo;.jpg&rdquo; is:</para><screen><![CDATA[rename 's/\.JPG$/.jpg/' *.JPG
]]></screen><note>
<title>Finding rename</title>
<para>You can get rename from various places. I would recommend trying <ulink url="http://search.cpan.org">CPAN Search Site</ulink>, I found the script here <ulink url="http://search.cpan.org/~pederst/rename-1.4/">Rename Script Version 1.4</ulink></para>
</note>
</listitem></varlistentry><varlistentry><term>Bash&nbsp;scripting
</term><listitem><para><indexterm><primary>scripting</primary></indexterm>Bash <indexterm><primary>Bash</primary></indexterm>scripting is one way to rename <indexterm><primary>rename</primary></indexterm>files. You can develop <indexterm><primary>develop</primary></indexterm>a set <indexterm><primary>set</primary></indexterm>of instructions <indexterm><primary>instructions</primary></indexterm>(a script) to rename <indexterm><primary>rename</primary></indexterm>files. Scripts <indexterm><primary>Scripts</primary></indexterm>are useful if you don't have <emphasis>mmv</emphasis> or <emphasis>rename</emphasis>...</para><para>One way to this is shown <indexterm><primary>shown</primary></indexterm>below:</para><screen><![CDATA[for i in *.JPG;
]]><![CDATA[do mv $i `basename $i JPG`jpg;
]]><![CDATA[done
]]></screen><para>Note that the above script <indexterm><primary>script</primary></indexterm>came from a usenet <indexterm><primary>usenet</primary></indexterm>post.<indexterm><primary>post</primary></indexterm> Unfortunately <indexterm><primary>Unfortunately</primary></indexterm>I do not know the author's name.</para><para>The first line <indexterm><primary>line</primary></indexterm>says find everything <indexterm><primary>everything</primary></indexterm>with the &ldquo;.JPG&rdquo; extension <indexterm><primary>extension</primary></indexterm>(capitals only, because the <productname>UNIX</productname> system <indexterm><primary>UNIX</primary></indexterm>is case sensitive).</para><para>The second line uses <emphasis>basename</emphasis> (type man <indexterm><primary>man</primary></indexterm>basename for more details) with the '$i' argument.<indexterm><primary>argument</primary></indexterm> The '$i' is a string <indexterm><primary>string</primary></indexterm>containing the name of the file that matches. The next <indexterm><primary>next</primary></indexterm>portion of the line removes the JPG <indexterm><primary>JPG</primary></indexterm>extension from the end <indexterm><primary>end</primary></indexterm>and adds the jpg <indexterm><primary>jpg</primary></indexterm>extention to each file. The command <emphasis>mv</emphasis> is run <indexterm><primary>run</primary></indexterm>on the output.</para><para>An alternative <indexterm><primary>alternative</primary></indexterm>is:</para><screen><![CDATA[for i in *.JPG;
]]><![CDATA[do mv $i ${i%%.JPG}.jpg;
]]><![CDATA[done
]]></screen><para>The above script renames <indexterm><primary>renames</primary></indexterm>files using a built-in <indexterm><primary>built-in</primary></indexterm>bash <indexterm><primary>bash</primary></indexterm>function. For more information <indexterm><primary>information</primary></indexterm>on bash <indexterm><primary>bash</primary></indexterm>scripting <indexterm><primary>bash scripting</primary></indexterm>you may like to see the <ulink url="http://www.tldp.org/LDP/abs/html/">advanced bash scripting guide</ulink>, authored by Mendel Cooper<indexterm><primary>Mendel Cooper</primary></indexterm><indexterm><primary>advanced bash scripting</primary></indexterm>.</para></listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Finding-information"><title>Finding information about the system</title><para></para><variablelist><varlistentry><term>time
</term><listitem><para>If you are looking <indexterm><primary>looking</primary></indexterm>for how to change <indexterm><primary>change</primary></indexterm>the time please refer <indexterm><primary>refer</primary></indexterm>to <emphasis>date</emphasis> here: <xref linkend="date-time-calendars">. </para><para><emphasis>time </emphasis>is a utility <indexterm><primary>utility</primary></indexterm>to measure <indexterm><primary>measure</primary></indexterm>the amount <indexterm><primary>amount</primary></indexterm>of time it takes a program <indexterm><primary>program</primary></indexterm>to execute.<indexterm><primary>execute</primary></indexterm> It also measures <indexterm><primary>measures</primary></indexterm>CPU <indexterm><primary>CPU</primary></indexterm>usage and displays statistics.<indexterm><primary>statistics</primary></indexterm></para><para>Use<emphasis> time -v<indexterm><primary>-v</primary></indexterm> </emphasis>(verbose mode) to display <indexterm><primary>display</primary></indexterm>even more detailed <indexterm><primary>detailed</primary></indexterm>statistics about the particular<indexterm><primary>particular</primary></indexterm> program.</para><para>Example usage:</para><screen><![CDATA[time program_name options
]]></screen></listitem></varlistentry><varlistentry><term>/proc
</term><listitem><para>The files under the /proc<indexterm><primary>/proc</primary></indexterm> (process information pseudo file-system)<indexterm><primary>process information</primary></indexterm> show <indexterm><primary>show</primary></indexterm>various information about the system. Consider it a window <indexterm><primary>window</primary></indexterm>to the information that the kernel <indexterm><primary>kernel</primary></indexterm>uses. </para><para>For example:</para><screen><![CDATA[cat /proc/cpuinfo
]]></screen><para>Displays information about the <acronym>CPU</acronym>.<indexterm><primary>CPU</primary></indexterm> </para><screen><![CDATA[less /proc/modules]]><emphasis><![CDATA[ ]]></emphasis><![CDATA[
]]></screen><para>Use the above command to view <indexterm><primary>view</primary></indexterm>information about what kernel-modules <indexterm><primary>kernel-modules</primary></indexterm>are loaded <indexterm><primary>loaded</primary></indexterm>on your system.</para></listitem></varlistentry><varlistentry><term>dmesg
</term><listitem><para><indexterm><primary>dmesg</primary></indexterm><emphasis>dmesg</emphasis> can be used to print <indexterm><primary>print</primary></indexterm>(or control) the &ldquo; kernel ring buffer<indexterm><primary>kernel ring buffer</primary></indexterm>&rdquo;. <emphasis>dmesg</emphasis> is generally used to print the contents <indexterm><primary>contents</primary></indexterm>of your bootup <indexterm><primary>bootup</primary></indexterm>messages displayed by the kernel.<indexterm><primary>kernel</primary></indexterm> This is often useful when debugging <indexterm><primary>debugging</primary></indexterm>problems.<indexterm><primary>problems</primary></indexterm></para><para>Simply type:</para><screen><![CDATA[dmesg
]]></screen></listitem></varlistentry><varlistentry><term>df
</term><listitem><para><indexterm><primary>df</primary></indexterm>Displays information about the space <indexterm><primary>space</primary></indexterm>on mounted <indexterm><primary>mounted</primary></indexterm>file-systems. Use the<emphasis> -h <indexterm><primary>-h</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to have <emphasis>df</emphasis> list <indexterm><primary>list</primary></indexterm>the space in a 'human readable' format.<indexterm><primary>format</primary></indexterm> ie. if there are 1024 kilobytes <indexterm><primary>kilobytes</primary></indexterm>left (approximately) then <emphasis>df</emphasis> will say there is 1MB <indexterm><primary>1MB</primary></indexterm>left.</para><para>Command syntax:</para><screen><![CDATA[df -options /dev/hdx
]]></screen><para>The latter part <indexterm><primary>part</primary></indexterm>is optional,<indexterm><primary>optional</primary></indexterm> you can simply use <emphasis>df</emphasis> with or without options <indexterm><primary>options</primary></indexterm>to list space on all file-systems.<indexterm><primary>file-systems</primary></indexterm></para><para></para></listitem></varlistentry><varlistentry><term>who
</term><listitem><para><indexterm><primary>who</primary></indexterm>Displays information on which users are logged <indexterm><primary>logged</primary></indexterm>into the system including the time they logged in. </para><para>Command syntax:</para><screen><![CDATA[who
]]></screen></listitem></varlistentry><varlistentry><term>w
</term><listitem><para><indexterm><primary>w</primary></indexterm>Displays information on who <indexterm><primary>who</primary></indexterm>is logged into the system and what they are doing (ie. the processes <indexterm><primary>processes</primary></indexterm>they are running). It's similar to <emphasis>who</emphasis> but displays slightly different information.</para><para>Command syntax:</para><screen><![CDATA[w
]]></screen></listitem></varlistentry><varlistentry><term>users
</term><listitem><para>Very similar to <emphasis>who</emphasis> except it only prints <indexterm><primary>prints</primary></indexterm>out the user names who <indexterm><primary>who</primary></indexterm>are currently logged in. (Doesn't need or take any options).</para><para>Command syntax:</para><screen><![CDATA[users
]]></screen></listitem></varlistentry><varlistentry><term>last
</term><listitem><para><indexterm><primary>last</primary></indexterm>Displays records <indexterm><primary>records</primary></indexterm>of when various users have logged in or out. This includes <indexterm><primary>includes</primary></indexterm>information on when the computer <indexterm><primary>computer</primary></indexterm>was rebooted.<indexterm><primary>rebooted</primary></indexterm></para><para>To execute this simply type:</para><screen><![CDATA[last
]]></screen></listitem></varlistentry><varlistentry><term>lastlog
</term><listitem><para><indexterm><primary>lastlog</primary></indexterm>Displays a list of users and what day/time they logged <indexterm><primary>logged</primary></indexterm>into the system. </para><para>Simply type:</para><screen><![CDATA[lastlog
]]></screen></listitem></varlistentry><varlistentry><term>whoami
</term><listitem><para><indexterm><primary>whoami</primary></indexterm>Tells the user who they are currently logged in as, this is normally the usename they logged in with but can be changed with commands like su).<indexterm><primary>su</primary></indexterm> <emphasis>whoami</emphasis> does not need or take any options. </para><para>Simply type:</para><screen><![CDATA[whoami
]]></screen></listitem></varlistentry><varlistentry><term>free
</term><listitem><para><indexterm><primary>free</primary></indexterm>Displays memory <indexterm><primary>memory</primary></indexterm>statistics <indexterm><primary>statistics</primary></indexterm>(total, free, used, cached,<indexterm><primary>cached</primary></indexterm> swap). Use the<emphasis> -t <indexterm><primary>-t</primary></indexterm></emphasis> option to display totals <indexterm><primary>totals</primary></indexterm>of everything <indexterm><primary>everything</primary></indexterm>and use the<emphasis> -m <indexterm><primary>-m</primary></indexterm></emphasis>to display memory <indexterm><primary>memory</primary></indexterm>in megabytes.<indexterm><primary>megabytes</primary></indexterm> </para><para>Example:</para><screen><![CDATA[free -tm
]]></screen><para>This will display the memory <indexterm><primary>memory</primary></indexterm>usage including <indexterm><primary>including</primary></indexterm>totals <indexterm><primary>totals</primary></indexterm>in megabytes.<indexterm><primary>megabytes</primary></indexterm></para></listitem></varlistentry><varlistentry><term>uptime
</term><listitem><para><indexterm><primary>uptime</primary></indexterm>Print how long <indexterm><primary>long</primary></indexterm>the computer has been &ldquo;up&rdquo;, how long <indexterm><primary>long</primary></indexterm>the computer has been running.<indexterm><primary>running</primary></indexterm> It also displays the number <indexterm><primary>number</primary></indexterm>of users and the processor <indexterm><primary>processor</primary></indexterm>load (how hard the <acronym>CPU</acronym> has been working...). </para><tip>
<title>The w command</title>
<para>The <emphasis>w</emphasis> command displays the output <indexterm><primary>output</primary></indexterm>of the uptime command when you run this command. You could use the <emphasis>w</emphasis> command instead of uptime.
</para>
</tip>
</listitem></varlistentry><varlistentry><term><emphasis>uname</emphasis>
</term><listitem><para><emphasis>uname<indexterm><primary>uname</primary></indexterm></emphasis> is used to print information <indexterm><primary>information</primary></indexterm>on the system such as OS <indexterm><primary>OS</primary></indexterm>type, kernel version<indexterm><primary>kernel version</primary></indexterm> et cetera.</para><para>Some <emphasis>uname</emphasis> options:</para><itemizedlist><listitem><para><emphasis>-a<indexterm><primary>-a</primary></indexterm></emphasis> --- print all the available <indexterm><primary>available</primary></indexterm>information.</para></listitem><listitem><para><emphasis>-m<indexterm><primary>-m</primary></indexterm></emphasis> --- print only information related to the machine <indexterm><primary>machine</primary></indexterm>itself. </para></listitem><listitem><para><emphasis>-n<indexterm><primary>-n</primary></indexterm></emphasis> --- print only the machine hostname. </para></listitem><listitem><para><emphasis>-r<indexterm><primary>-r</primary></indexterm></emphasis> --- print the release number<indexterm><primary>release number</primary></indexterm> of the current <indexterm><primary>current</primary></indexterm>kernel.<indexterm><primary>kernel</primary></indexterm> </para></listitem><listitem><para><emphasis>-s<indexterm><primary>-s</primary></indexterm></emphasis> --- print the operating <indexterm><primary>operating</primary></indexterm>system name </para></listitem><listitem><para><emphasis>-p<indexterm><primary>-p</primary></indexterm></emphasis> --- print the processor <indexterm><primary>processor</primary></indexterm>type. </para></listitem></itemizedlist><para>Command syntax:</para><screen><![CDATA[uname -options
]]></screen></listitem></varlistentry><varlistentry><term>xargs
</term><listitem><para><indexterm><primary>xargs</primary></indexterm>Note that <emphasis>xargs</emphasis> is an advanced,<indexterm><primary>advanced</primary></indexterm> confusing,<indexterm><primary>confusing</primary></indexterm> yet powerful <indexterm><primary>powerful</primary></indexterm>command. <emphasis>xargs</emphasis> is a command used to run other commands as many times <indexterm><primary>times</primary></indexterm>as necessary, this way it prevents any kind of overload... When you run a command then add a<emphasis> &ldquo;| xargs <indexterm><primary>xargs</primary></indexterm>command2<indexterm><primary>command2</primary></indexterm></emphasis>&rdquo;. The results <indexterm><primary>results</primary></indexterm>of command1 <indexterm><primary>command1</primary></indexterm>will be passed <indexterm><primary>passed</primary></indexterm>to command2, possibly on a line-by-line basis or something similar.<indexterm><primary>command2</primary></indexterm> </para><para>Understanding <emphasis>xargs</emphasis> tends <indexterm><primary>tends</primary></indexterm>to be very difficult and my explanation <indexterm><primary>explanation</primary></indexterm>is not the best. Refer <indexterm><primary>Refer</primary></indexterm>to the examples <indexterm><primary>examples</primary></indexterm>below or try [6] of the <xref linkend="references"> for another <emphasis>xargs</emphasis> tutorial.<indexterm><primary>tutorial</primary></indexterm></para><note>
<title>Alternatives to using xargs</title>
<para>Please note that the below explanation of <emphasis>xargs</emphasis> is not the strongest (at the time of writing I could not find anything better :()).</para>
<para>Alternatives may include writing a simple bash script to do the job which is not the most difficult task in the world.</para>
</note>
<para>Examples:</para><screen><![CDATA[ls | xargs grep work
]]></screen><para>The first command is obvious, it will list <indexterm><primary>list</primary></indexterm>the files in the current directory. For each line <indexterm><primary>line</primary></indexterm>of output of <emphasis>ls</emphasis>, <emphasis>xargs</emphasis> will run <emphasis>grep</emphasis> on that particular line and look <indexterm><primary>look</primary></indexterm>for the string &ldquo;work&rdquo;. The output have the each time <emphasis>grep</emphasis> is executed on a new <indexterm><primary>new</primary></indexterm>line, the output would look like:</para><screen><![CDATA[file_name: results_of_grep
]]></screen><para>If <emphasis>grep</emphasis> didn't find <indexterm><primary>find</primary></indexterm>the word then there would be no output if it had an error <indexterm><primary>error</primary></indexterm>then it will output the error.<indexterm><primary>error</primary></indexterm> Obviously this isn't very useful (you could just do:</para><screen><![CDATA[grep 'word' *
]]></screen><para><emphasis><indexterm><primary>grep</primary></indexterm></emphasis> This is just a simple example...</para><para><emphasis>xargs <indexterm><primary>xargs</primary></indexterm></emphasis>also takes various options:</para><itemizedlist><listitem><para><emphasis>-nx<indexterm><primary>-nx</primary></indexterm></emphasis> --- will group <indexterm><primary>group</primary></indexterm>the first x commands together</para></listitem><listitem><para><emphasis>-lx<indexterm><primary>-lx</primary></indexterm></emphasis> --- xargs <indexterm><primary>xargs</primary></indexterm>will execute <indexterm><primary>execute</primary></indexterm>the command for every x number of lines <indexterm><primary>lines</primary></indexterm>of input<indexterm><primary>input</primary></indexterm></para></listitem><listitem><para><emphasis>-p<indexterm><primary>-p</primary></indexterm></emphasis> --- prompt <indexterm><primary>prompt</primary></indexterm>whether or not to execute this particular string</para></listitem><listitem><para><emphasis>-t<indexterm><primary>-t</primary></indexterm></emphasis> --- (tell) be verbose,<indexterm><primary>verbose</primary></indexterm> echo <indexterm><primary>echo</primary></indexterm>each command before performing <indexterm><primary>performing</primary></indexterm>it</para></listitem><listitem><para><emphasis>-i<indexterm><primary>-i</primary></indexterm></emphasis> --- will use substitution <indexterm><primary>substitution</primary></indexterm>similar to find's -exec <indexterm><primary>-exec</primary></indexterm>option, it will execute certain commands on something.</para></listitem></itemizedlist><para>Example:</para><screen><![CDATA[ls dir1 | xargs -i mv dir1/'{}' dir2/'{}'
]]></screen><para>The {} would be substituted <indexterm><primary>substituted</primary></indexterm>for the current input (in this example the current file/directory) listed <indexterm><primary>listed</primary></indexterm>within the directory.<indexterm><primary>directory</primary></indexterm> The above command would move <indexterm><primary>move</primary></indexterm>every file listed in dir1 <indexterm><primary>dir1</primary></indexterm>to dir2.<indexterm><primary>dir2</primary></indexterm> Obviously this command won't be too useful, it would be easier to go to dir1 <indexterm><primary>dir1</primary></indexterm>and type <emphasis> mv * ../dir2</emphasis></para><para>Here is a more <indexterm><primary>more</primary></indexterm>useful example: </para><screen><![CDATA[\ls *.wav | xargs -i lame -h '{}' '{}'.mp3
]]></screen><para>This would find all wave <indexterm><primary>wave</primary></indexterm>files within the current directory and convert<indexterm><primary>convert</primary></indexterm> them to mp3 <indexterm><primary>mp3</primary></indexterm>files (encoded with lame) and append <indexterm><primary>append</primary></indexterm>a &ldquo;.mp3&rdquo; to the end of the filename, unfortunately it doesn't remove the .wav and so its not too useful...but it works.</para></listitem></varlistentry></variablelist><sect1 id="date-time-calendars"><title>Date/Time/Calendars</title><para>There is one command to change <indexterm><primary>change</primary></indexterm>both the date <indexterm><primary>date</primary></indexterm>and time on a <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>like system, <emphasis>date</emphasis>, there is also a simple calendar <indexterm><primary>calendar</primary></indexterm>utility, <emphasis>cal</emphasis>. If you are looking <indexterm><primary>looking</primary></indexterm>to change <indexterm><primary>change</primary></indexterm>the timestamps <indexterm><primary>timestamps</primary></indexterm>on files please see <xref linkend="Finding-information"></para><variablelist><varlistentry><term>date
</term><listitem><para>Tells you the date (and the time<indexterm><primary>time</primary></indexterm>) and is also used to set <indexterm><primary>set</primary></indexterm>the date/time.</para><para>To set the date, type<emphasis> date MM:DD:YYYY </emphasis>(American style date) where MM is month,<indexterm><primary>month</primary></indexterm> DD <indexterm><primary>DD</primary></indexterm>is the number of days <indexterm><primary>days</primary></indexterm>within the month <indexterm><primary>month</primary></indexterm>and YYYY <indexterm><primary>YYYY</primary></indexterm>is the year.<indexterm><primary>year</primary></indexterm></para><para>For example to set the date to the 1st January 2000 you would type:</para><screen><![CDATA[date 01:01:2000
]]></screen><para>To set the time (where the <emphasis>-s<indexterm><primary>-s</primary></indexterm></emphasis> option is to set a new <indexterm><primary>new</primary></indexterm>time), type:</para><screen><![CDATA[date]]><emphasis><![CDATA[ ]]></emphasis><![CDATA[-s hh:mm:ss
]]></screen><para>Another useful option you can use is <emphasis>--date=&ldquo;string&rdquo;</emphasis> <indexterm><primary>--date=</primary></indexterm>(or <emphasis>-d<indexterm><primary>-d</primary></indexterm></emphasis> <emphasis>&ldquo;string&rdquo;</emphasis>) option to display <indexterm><primary>display</primary></indexterm>a date from x days <indexterm><primary>days</primary></indexterm>ago or in x days <indexterm><primary>days</primary></indexterm>(or x weeks, months,<indexterm><primary>months</primary></indexterm> years <indexterm><primary>years</primary></indexterm>et cetera). See the examples below. </para><para>Examples:</para><screen><![CDATA[date --date="3 months 1 day ago"
]]></screen><para>Will print the date 3 months <indexterm><primary>months</primary></indexterm>and 1 day <indexterm><primary>day</primary></indexterm>ago from the current date. Note that <emphasis>--date=&rdquo;x month x day ago&rdquo;</emphasis> and<emphasis> -d <indexterm><primary>-d</primary></indexterm>&ldquo;x month x day ago&rdquo;</emphasis> are equivalent.<indexterm><primary>equivalent</primary></indexterm></para><screen><![CDATA[date -d "3 days"
]]></screen><para>The above command will print the date 3 days <indexterm><primary>days</primary></indexterm> in the future from now.</para></listitem></varlistentry><varlistentry><term>cal
</term><listitem><para><indexterm><primary>cal</primary></indexterm>Typing <emphasis>cal</emphasis> will give you the calendar <indexterm><primary>calendar</primary></indexterm>of the present <indexterm><primary>present</primary></indexterm>month on your screen,<indexterm><primary>screen</primary></indexterm> in the nice <indexterm><primary>nice</primary></indexterm>standard calendar <indexterm><primary>calendar</primary></indexterm>format. There are various options <indexterm><primary>options</primary></indexterm>to customise <indexterm><primary>customise</primary></indexterm>the calendar,<indexterm><primary>calendar</primary></indexterm> refer <indexterm><primary>refer</primary></indexterm>to the info/man page.<indexterm><primary>page</primary></indexterm></para><para>Example:</para><screen><![CDATA[cal -y year
]]></screen><para><indexterm><primary>-y</primary></indexterm>Will display a calendar <indexterm><primary>calendar</primary></indexterm>for a specific <indexterm><primary>specific</primary></indexterm>year, simply use cal -y <indexterm><primary>-y</primary></indexterm>to print the calendar <indexterm><primary>calendar</primary></indexterm>for the current year.</para><screen><![CDATA[cal 2 2004
]]></screen><para>This will display the calendar <indexterm><primary>calendar</primary></indexterm>for February 2004</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="hard-disk-partition-info"><title>Finding information about partitions</title><para>There are a number of ways to find out information <indexterm><primary>information</primary></indexterm>on your hard disk <indexterm><primary>disk</primary></indexterm>drives, for information on mounted <indexterm><primary>mounted</primary></indexterm>partitions also try<emphasis> df <indexterm><primary>df</primary></indexterm></emphasis>in <xref linkend="Finding-information"></para><para></para><variablelist><varlistentry><term>Using&nbsp;the&nbsp;proc&nbsp;filesystem
</term><listitem><para>You can look <indexterm><primary>look</primary></indexterm>through the information <indexterm><primary>information</primary></indexterm>in the relevant<indexterm><primary>relevant</primary></indexterm> area of the proc <indexterm><primary>/proc</primary></indexterm>filesystem,<indexterm><primary>proc filesystem</primary></indexterm><indexterm><primary>filesystem</primary></indexterm> under the directory <indexterm><primary>directory</primary></indexterm>of either /proc/ide/ or /proc/ide?/hd? where the first question <indexterm><primary>question</primary></indexterm>mark is a number <indexterm><primary>number</primary></indexterm>and the second is a letter <indexterm><primary>letter</primary></indexterm>(starting with 'a'). </para><para>For example:</para><screen><![CDATA[cd /proc/ide0/hda
]]></screen><para>Under this directory there will be various information on the hard drive<indexterm><primary>drive</primary></indexterm> or cdrom <indexterm><primary>cdrom</primary></indexterm>connected.</para></listitem></varlistentry><varlistentry><term>Using&nbsp;fdisk<anchor id="using-fdisk">
</term><listitem><para>Using <emphasis>fdisk</emphasis><indexterm><primary>fdisk</primary></indexterm> with the <emphasis>-l<indexterm><primary>-l</primary></indexterm></emphasis> option will output information on any hard drives <indexterm><primary>drives</primary></indexterm>connected <indexterm><primary>connected</primary></indexterm>to the system and information on their partitions <indexterm><primary>partitions</primary></indexterm>(for example, the type of partition).</para><para>Information relating to using <emphasis>fdisk</emphasis> to partition <indexterm><primary>partition</primary></indexterm>hard disks <indexterm><primary>disks</primary></indexterm>can be found <indexterm><primary>found</primary></indexterm>in your distributions <indexterm><primary>distributions</primary></indexterm>documentation,<indexterm><primary>documentation</primary></indexterm> the <emphasis>fdisk</emphasis> manual <indexterm><primary>manual</primary></indexterm>page or online.<indexterm><primary>online</primary></indexterm></para><note>
<title>Root Access Required</title>
<para> This command needs root access to work </para>
</note>
</listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Controlling-the-system"><title>Controlling the system</title><para>The controlling <indexterm><primary>controlling</primary></indexterm>the system chapter details <indexterm><primary>details</primary></indexterm>commands that you may wish to use to interact <indexterm><primary>interact</primary></indexterm>with devices <indexterm><primary>devices</primary></indexterm>on your system and then details how to control<indexterm><primary>control</primary></indexterm> processes <indexterm><primary>processes</primary></indexterm>and services/daemons.</para><variablelist><varlistentry><term><emphasis>eject</emphasis>
</term><listitem><para><emphasis>eject<indexterm><primary>eject</primary></indexterm></emphasis> simply tells <indexterm><primary>tells</primary></indexterm>a device <indexterm><primary>device</primary></indexterm>to open <indexterm><primary>open</primary></indexterm>(eject) the drive. Useful for cdrom/DVD drives.<indexterm><primary>drives</primary></indexterm></para><para>For example the command below would eject the cdrom-drive <indexterm><primary>cdrom-drive</primary></indexterm>(if your cdrom<indexterm><primary>cdrom</primary></indexterm> is linked <indexterm><primary>linked</primary></indexterm>to /dev/cdrom):</para><screen><![CDATA[eject /dev/cdrom
]]></screen><note>
<title>This won't work unless</title>
<para>
This will only work if the user has permission to mount the partition. Please see the tip in <xref linkend="mounting-and-unmounting"> for more information.
</para>
</note>
<para></para></listitem></varlistentry></variablelist><sect1 id="mounting-and-unmounting"><title>Mounting and Unmounting (Floppy/CDROM/Hard-drive Partitions)</title><tip>
<title>Allowing Users to mount partitions</title>
<para>
By default a <productname>UNIX</productname> system will allow normal users to unmount partitions. However unless given permission by the superuser, users will not be allowed to mount partitions.
</para>
<para>
The commands listed below will not work for normal users unless users have permission to mount that device.
</para>
<para>
If your particular distribution is setup not to allow users to mount partitions its not very hard to change this, simply edit the <emphasis>/etc/fstab</emphasis> file (as root) and:
</para>
<para>
<screen>Replace the word "defaults" with "user" or</screen>
<screen>Add "user" to the end of the options list for the particular partition(s).</screen>
</para>
</tip>
<variablelist><varlistentry><term>mount
</term><listitem><para><indexterm><primary>mount</primary></indexterm>Mount a device.<indexterm><primary>device</primary></indexterm> Attach <indexterm><primary>Attach</primary></indexterm>the device <indexterm><primary>device</primary></indexterm>to the file-system <indexterm><primary>file-system</primary></indexterm>hierarchy <indexterm><primary>hierarchy</primary></indexterm>(the tree <indexterm><primary>tree</primary></indexterm>( / )). This needs to be done so you can access <indexterm><primary>access</primary></indexterm>the drive <indexterm><primary>drive</primary></indexterm>(see below, <xref linkend="mounting-and-unmounting"> for an example).</para></listitem></varlistentry><varlistentry><term>umount
</term><listitem><para><indexterm><primary>umount</primary></indexterm>'Unmount' a device.<indexterm><primary>device</primary></indexterm> The command <emphasis>umount</emphasis> (no 'n') unmount's a device.<indexterm><primary>device</primary></indexterm> It removes <indexterm><primary>removes</primary></indexterm>it from the file-system hierarchy (the tree ( / )). This needs to be done before you remove <indexterm><primary>remove</primary></indexterm>a floppy/CDROM or any other removable<indexterm><primary>removable</primary></indexterm> device <indexterm><primary>device</primary></indexterm>(see below, <xref linkend="mounting-and-unmounting"> for an example).</para></listitem></varlistentry><varlistentry><term>smbmount&nbsp;//wincomp/c&nbsp;/mnt/win
</term><listitem><para><indexterm><primary>smbmount</primary></indexterm>Where &ldquo;win&rdquo; would be the place <indexterm><primary>place</primary></indexterm>you want it mounted <indexterm><primary>mounted</primary></indexterm>and &ldquo;wincomp&rdquo; is the IP address<indexterm><primary>IP address</primary></indexterm> or name of your windows <indexterm><primary>windows</primary></indexterm>computer.</para><note>
<title>Please note</title>
<para>Using ping/smbmount/ssh or other <productname>UNIX</productname> system programs with a computer name rather than IP address will only work if you have the computer listed in your /etc/hosts<indexterm><primary>/etc/hosts</primary></indexterm> file. Here is an example:</para>
<para><screen>
192.168.1.100 new
</screen> This line says that their is a computer called &ldquo;new&rdquo;<indexterm><primary>new</primary></indexterm> with IP address 192.168.1.100<indexterm><primary>192.168.1.100</primary></indexterm>. Now that it exists in the /etc/hosts file I don't have to type the IP address anymore, just the name &ldquo;new&rdquo;.
</para>
</note>
<para><emphasis>smbmount</emphasis> is a tool from the samba <indexterm><primary>samba</primary></indexterm>package, it can mount <indexterm><primary>mount</primary></indexterm>a remote <indexterm><primary>remote</primary></indexterm>windows <indexterm><primary>windows</primary></indexterm>file-system onto your current <indexterm><primary>current</primary></indexterm>computer.</para><para>Un-mounting uses the same syntax <indexterm><primary>syntax</primary></indexterm>as 'umount', as listed above, or you may like to use:</para><screen><![CDATA[smbumount /mountpoint
]]></screen><para><indexterm><primary>smbumount</primary></indexterm>Here are some more examples of how to mount <indexterm><primary>mount</primary></indexterm>a file-system:</para><screen>
mount -t<indexterm><primary>-t</primary></indexterm> ext2 /dev/fd0 /mnt/floppy <co id="vfat">
mount -t iso9660 /dev/hdb /mnt/cdrom <co id="CDROM">
mount -t iso /tmp/image_file /mnt/iso_file/ -o loop <co id="iso">
</screen>
<calloutlist>
<callout arearefs="vfat">
<para>
The windows filesystem is known as vfat<indexterm><primary>vfat</primary></indexterm> (standard on <productname>Windows</productname> 9x) or NFTS<indexterm><primary>NFTS</primary></indexterm> (standard on <productname>Windows</productname> 2000 and XP).
</para>
</callout>
<callout arearefs="CDROM">
<para>
for CDROM's
</para>
</callout>
<callout arearefs="iso">
<para>
This will mount an image file (usually a CD image file) so you can view/change the files (it will appear to be like any other device).
</para>
</callout>
</calloutlist>
<note>
<title>The -t option</title>
<para>
On any system running a newer version of the <productname>Linux</productname> kernel the <emphasis>-t</emphasis> option is not always necessary and can be left out.
</para>
</note>
<para></para><para>Examples of how to unmount <indexterm><primary>unmount</primary></indexterm>a file-system (necessary before you eject/remove disk):</para><screen><![CDATA[umount /mount_point
]]></screen><para>An example unmount point could be &ldquo;/mnt/floppy&rdquo; or &ldquo;/mnt/cdrom&rdquo;</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="shutting-down"><title>Shutting Down/Rebooting the System</title><variablelist><varlistentry><term>shutdown&nbsp;now
</term><listitem><para><indexterm><primary>shutdown</primary></indexterm>Shutdown the computer immediately (don't power down<indexterm><primary>power down</primary></indexterm>). Note that in <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>systems this kind of shutdown <indexterm><primary>shutdown</primary></indexterm>means to go to &ldquo; single-user mode&rdquo;.<indexterm><primary>single-user</primary></indexterm><indexterm><primary>mode</primary></indexterm> Single-user mode is a mode where only the administrator <indexterm><primary>administrator</primary></indexterm>(root) has access<indexterm><primary>access</primary></indexterm> to the computer, this mode <indexterm><primary>mode</primary></indexterm>is designed <indexterm><primary>designed</primary></indexterm>for maintenance <indexterm><primary>maintenance</primary></indexterm>and is often used for repairs.<indexterm><primary>repairs</primary></indexterm></para><para>For example this would take you to single user mode </para><screen><![CDATA[shutdown now
]]></screen></listitem></varlistentry><varlistentry><term>shutdown&nbsp;-h&nbsp;now
</term><listitem><para><indexterm><primary>shutdown -h</primary></indexterm>Shutdown <emphasis>(-h<indexterm><primary>-h</primary></indexterm> = halt) </emphasis>the computer immediately. It begins the shutdown procedure,<indexterm><primary>procedure</primary></indexterm> press
<keycombo>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
<indexterm>
<primary>CTRL-C</primary>
</indexterm>
(break-key) to stop <indexterm><primary>stop</primary></indexterm>it. After the end of the command you can also leave a message <indexterm><primary>message</primary></indexterm>in quotation<indexterm><primary>quotation</primary></indexterm> marks <indexterm><primary>marks</primary></indexterm>which will be broad-casted <indexterm><primary>broad-casted</primary></indexterm>to all users, for example:</para><screen><![CDATA[shutdown -h now "Warning system malfunction, self-destruct imminent"
]]></screen><para>This would halt <indexterm><primary>halt</primary></indexterm>the system and send <indexterm><primary>send</primary></indexterm>the message <indexterm><primary>message</primary></indexterm>to anyone who <indexterm><primary>who</primary></indexterm>is currently logged<indexterm><primary>logged</primary></indexterm> in.</para><tip>
<title>Shutting down at a particular time</title>
<para>You can also put a time that the system should shutdown instead of &ldquo;now&rdquo;. Typing &ldquo;+x minutes<indexterm><primary>minutes</primary></indexterm>&rdquo; (any number <indexterm><primary>number</primary></indexterm>of minutes <indexterm><primary>minutes</primary></indexterm>is appropriate) or you can even set an exact <indexterm><primary>exact</primary></indexterm>time. For example to shutdown <indexterm><primary>shutdown</primary></indexterm>at <indexterm><primary>at</primary></indexterm>11:50 type:
<screen>shutdown -h 11:50</screen>
</para>
</tip>
<note>
<title>Shutdown -h vs poweroff</title>
<para>On some systems, <emphasis>shutdown -h </emphasis>and <emphasis>halt </emphasis>do not actually turn the system's power off. On systems that do not power off with these commands use the <emphasis>poweroff</emphasis><indexterm><primary>poweroff</primary></indexterm> command</para>
</note>
</listitem></varlistentry><varlistentry><term>halt
</term><listitem><para><indexterm><primary>halt</primary></indexterm>The same as <emphasis>shutdown -h now</emphasis> doesn't take any options,<indexterm><primary>options</primary></indexterm> this command simply shuts down immediately.</para></listitem></varlistentry><varlistentry><term>shutdown&nbsp;-r&nbsp;now
</term><listitem><para><indexterm><primary>shutdown -r</primary></indexterm>Shutdown (<emphasis> -r <indexterm><primary>-r</primary></indexterm>= reboot<indexterm><primary>reboot</primary></indexterm></emphasis>) the computer immediately. It begins the reboot procedure,<indexterm><primary>procedure</primary></indexterm> press <indexterm><primary>press</primary></indexterm>
<keycombo>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
<indexterm>
<primary>CTRL-C</primary>
</indexterm>
(break-key) to stop <indexterm><primary>stop</primary></indexterm>it. After the end of the command you can also leave a message <indexterm><primary>message</primary></indexterm>in quotation<indexterm><primary>quotation</primary></indexterm> marks <indexterm><primary>marks</primary></indexterm>which will be broad-casted <indexterm><primary>broad-casted</primary></indexterm>to all users, for example: </para><screen><![CDATA[shutdown -r now "Warning system rebooting, all files will be destroyed"
]]></screen><para>This would reboot the system and send <indexterm><primary>send</primary></indexterm>the message <indexterm><primary>message</primary></indexterm>to anyone who <indexterm><primary>who</primary></indexterm>was logged in.</para><tip>
<title>Rebooting at a particular time</title>
<para>You can also put a time that the system should reboot instead of &ldquo;now&rdquo;. Typing &ldquo;+x minutes<indexterm><primary>minutes</primary></indexterm>&rdquo; (any number of minutes <indexterm><primary>minutes</primary></indexterm>is appropriate) or you can even set <indexterm><primary>set</primary></indexterm>an exact <indexterm><primary>exact</primary></indexterm>time. For example to reboot <indexterm><primary>shutdown</primary></indexterm>at 11:50 type:
<screen>shutdown -r 11:50</screen>
</para>
</tip>
</listitem></varlistentry><varlistentry><term>reboot
</term><listitem><para>The same as <emphasis>shutdown -r now</emphasis>, doesn't take any options, simply reboots <indexterm><primary>reboots</primary></indexterm>the computer immediately. </para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>ALT</keycap>
<keycap>DEL</keycap>
</keycombo>
<indexterm>
<primary>CTRL-ALT-DEL</primary>
</indexterm>
</term><listitem><para> (key-combination) May be used from a terminal <indexterm><primary>terminal</primary></indexterm>to reboot or shutdown,<indexterm><primary>shutdown</primary></indexterm> it depends on your system configuration. Note that this doesn't work from an xterminal.<indexterm><primary>xterminal</primary></indexterm>
<keycombo>
<keycap>CTRL</keycap>
<keycap>ALT</keycap>
<keycap>DEL</keycap>
</keycombo>
<indexterm>
<primary>CTRL-ALT-DEL</primary>
</indexterm>
begins the reboot/shutdown immediately, the user does not have to be logged in.</para><tip>
<title>You can change the behaviour of
<keycombo>
<keycap>CTRL</keycap>
<keycap>ALT</keycap>
<keycap>DEL</keycap>
</keycombo>
<indexterm>
<primary>CTRL-ALT-DEL</primary>
</indexterm>
from rebooting</title>
<para>
To disable
<keycombo>
<keycap>CTRL</keycap>
<keycap>ALT</keycap>
<keycap>DEL</keycap>
</keycombo>
<indexterm>
<primary>CTRL-ALT-DEL</primary>
</indexterm>
from rebooting your computer (or to have it do something different), you can edit the /etc/inittab<indexterm><primary>/etc/inittab</primary></indexterm> file (as root).
</para>
<para>
Here is how it looks on a Mandrake/Mandriva <productname>Linux</productname> system:
<screen>
# Trap
<keycombo>
<keycap>CTRL</keycap>
<keycap>ALT</keycap>
<keycap>DEL</keycap>
</keycombo>
<indexterm>
<primary>CTRL-ALT-DEL</primary>
</indexterm>
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
</screen>
</para>
<para>
Note that the # means a comment (and is not used). If you simply put a # (hash) before the command it would disable it (it would become a comment).
</para>
<para>
You could also change the command it runs for example if you changed the <emphasis>-r</emphasis> to a <emphasis>-h </emphasis>the computer would turn off instead of rebooting, or you could have it do anything you want. It's up to your creativity to make it do something interesting.
</para>
</tip>
</listitem></varlistentry></variablelist></sect1>
<sect1 id="controlling-processes"><title>Controlling Processes</title><para></para><variablelist><varlistentry><term>ps
</term><listitem><para><indexterm><primary>ps</primary></indexterm>Will give you a list <indexterm><primary>list</primary></indexterm>of the processes <indexterm><primary>processes</primary></indexterm>running on your system. With no options, <emphasis>ps</emphasis> will list processes <indexterm><primary>processes</primary></indexterm>that belong to the current user and have a controlling<indexterm><primary>controlling</primary></indexterm> terminal.</para><para>Example options include:</para><itemizedlist><listitem><para><emphasis>-aux</emphasis> --- list all running <indexterm><primary>running</primary></indexterm>processes <indexterm><primary>processes</primary></indexterm>(by all users with some information).</para></listitem><listitem><para><emphasis>-a<indexterm><primary>-a</primary></indexterm></emphasis> --- list all processes from all users.</para></listitem><listitem><para><emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> --- list more information <indexterm><primary>information</primary></indexterm>including user names, %cpu <indexterm><primary>%cpu</primary></indexterm>usage, and %mem <indexterm><primary>%mem</primary></indexterm>usage et cetera.</para></listitem><listitem><para><emphasis>-x<indexterm><primary>-x</primary></indexterm></emphasis> --- list processes <indexterm><primary>processes</primary></indexterm>without controlling <indexterm><primary>controlling</primary></indexterm>terminals.</para></listitem><listitem><para><emphasis>-l<indexterm><primary>-l</primary></indexterm></emphasis> --- display different information including UID <indexterm><primary>UID</primary></indexterm>and nice <indexterm><primary>nice</primary></indexterm>value.<indexterm><primary>value</primary></indexterm></para></listitem><listitem><para><emphasis>--forest<indexterm><primary>--forest</primary></indexterm></emphasis> --- this makes it easier to see the process <indexterm><primary>process</primary></indexterm>hierarchy, which <indexterm><primary>which</primary></indexterm>will give you an indication <indexterm><primary>indication</primary></indexterm>of how the various processes <indexterm><primary>processes</primary></indexterm>on your system interrelate<indexterm><primary>interrelate</primary></indexterm> (although you should also try <emphasis>pstree</emphasis>).</para></listitem></itemizedlist><para>For example to list all running <indexterm><primary>running</primary></indexterm>processes <indexterm><primary>processes</primary></indexterm>with additional <indexterm><primary>additional</primary></indexterm>information, simply type:</para><screen><![CDATA[ps -aux
]]></screen></listitem></varlistentry><varlistentry><term>pstree
</term><listitem><para><indexterm><primary>pstree</primary></indexterm>Displays the processes <indexterm><primary>processes</primary></indexterm>in the form <indexterm><primary>form</primary></indexterm>of a tree <indexterm><primary>tree</primary></indexterm>structure (similar to how <emphasis>tree</emphasis> does it for directories). </para><para>Use the<emphasis> -p <indexterm><primary>-p</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to show <indexterm><primary>show</primary></indexterm>process id's.<indexterm><primary>id's</primary></indexterm></para><para>Example:</para><screen><![CDATA[pstree -p
]]></screen><para>This would list all processes <indexterm><primary>processes</primary></indexterm>and their id's.<indexterm><primary>id's</primary></indexterm></para></listitem></varlistentry><varlistentry><term>pgrep
</term><listitem><para><indexterm><primary>pgrep</primary></indexterm>This command is useful for finding <indexterm><primary>finding</primary></indexterm>the process id <indexterm><primary>process id</primary></indexterm>of a particular<indexterm><primary>particular</primary></indexterm> process when you know part <indexterm><primary>part</primary></indexterm>of its name. </para><para>Use the <emphasis>-l<indexterm><primary>-l</primary></indexterm></emphasis> option to list the name of the process as well and the <emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> option to search <indexterm><primary>search</primary></indexterm>via a particular user(s).</para><para>Normally <emphasis>pgrep</emphasis> will only return <indexterm><primary>return</primary></indexterm>the pid <indexterm><primary>pid</primary></indexterm>number; this way you can use it with other commands.</para><para>Examples:</para><screen><![CDATA[kill $(pgrep mozilla)
]]></screen><para>This would kill <indexterm><primary>kill</primary></indexterm>any process name that starts <indexterm><primary>starts</primary></indexterm>with mozilla.<indexterm><primary>mozilla</primary></indexterm> Note that this is the same as using <emphasis>pkill</emphasis> (see below).</para><para>If you are unfamiliar <indexterm><primary>unfamiliar</primary></indexterm>with the <emphasis>$(&nbsp;)</emphasis> part <indexterm><primary>part</primary></indexterm>of this command, please refer <indexterm><primary>refer</primary></indexterm>to <xref linkend="performing-more-than-one-command">.</para><para>To list processes id's and names type:</para><screen><![CDATA[pgrep -l process_name
]]></screen></listitem></varlistentry><varlistentry><term>top
</term><listitem><para><indexterm><primary>top</primary></indexterm>Displays the 'top' (as in <acronym>CPU</acronym> <indexterm><primary>CPU</primary></indexterm>usage) processes,<indexterm><primary>processes</primary></indexterm> provides <indexterm><primary>provides</primary></indexterm>more detail<indexterm><primary>detail</primary></indexterm> than <emphasis>ps</emphasis>. </para><para><emphasis>top</emphasis> also provides <indexterm><primary>provides</primary></indexterm>an updated <indexterm><primary>updated</primary></indexterm>display, it has many options <indexterm><primary>option</primary></indexterm>that make it fully customisable,<indexterm><primary>customisable</primary></indexterm> refer <indexterm><primary>refer</primary></indexterm>to the manual or info <indexterm><primary>info</primary></indexterm>page <indexterm><primary>page</primary></indexterm>for details. </para></listitem></varlistentry><varlistentry><term>kill
</term><listitem><para>To kill processes <indexterm><primary>processes</primary></indexterm>on your system, you will need their pid's <indexterm><primary>pid's</primary></indexterm>or id's<indexterm><primary>id's</primary></indexterm> . Use <emphasis>ps</emphasis> or <emphasis>pstree</emphasis> to find <indexterm><primary>find</primary></indexterm>out the process id's <indexterm><primary>id's</primary></indexterm>(pid's), or use <emphasis>jobs</emphasis> to find out id's.<indexterm><primary>id's</primary></indexterm></para><tip>
<title>killall and pkill - kill a process by name</title>
<para><emphasis>pkill</emphasis> and <emphasis>killall </emphasis>can be a lot easier to use than <emphasis>kill</emphasis>. <emphasis>pkill</emphasis> allows you to type part of the name of a process to kill it, while <emphasis>killall</emphasis> requires the full process name. See below for more information.</para>
</tip>
<para>Examples:</para><screen><![CDATA[kill pid
]]></screen><para>Simply kill a process (allow it time <indexterm><primary>time</primary></indexterm>to save <indexterm><primary>save</primary></indexterm>it's files and exit)</para><screen><![CDATA[kill %id
]]></screen><para>Same as above, except it uses an id <indexterm><primary>id</primary></indexterm>instead of a pid,<indexterm><primary>pid</primary></indexterm> you need to use a % (percent) when using an id <indexterm><primary>id</primary></indexterm>to kill.</para><screen><![CDATA[kill -kill pid]]><indexterm><primary>-kill</primary></indexterm><![CDATA[
]]></screen><para>Force <indexterm><primary>Force</primary></indexterm>a process to be killed <indexterm><primary>killed</primary></indexterm>(won't allow <indexterm><primary>allow</primary></indexterm>files to be saved <indexterm><primary>saved</primary></indexterm>or updated); only use when necessary because all data <indexterm><primary>data</primary></indexterm>that the program <indexterm><primary>program</primary></indexterm>had will be lost.<indexterm><primary>lost</primary></indexterm></para><para>There are also many other kill options such as kill -HUP<indexterm><primary>-HUP</primary></indexterm><emphasis> </emphasis>(hangup)<emphasis>...</emphasis> refer <indexterm><primary>refer</primary></indexterm>to the manual/info pages <indexterm><primary>pages</primary></indexterm>for more <indexterm><primary>more</primary></indexterm>information.</para></listitem></varlistentry></variablelist><para></para><variablelist><varlistentry><term>killall
</term><listitem><para><indexterm><primary>killall</primary></indexterm>Kill a process by it's name, uses names instead of process <indexterm><primary>process</primary></indexterm>id's<indexterm><primary>id's</primary></indexterm> (pid's). Use<emphasis> -v <indexterm><primary>-v</primary></indexterm></emphasis>to have <emphasis>killall</emphasis> report <indexterm><primary>report</primary></indexterm>whether the kill <indexterm><primary>kill</primary></indexterm>was successful <indexterm><primary>successful</primary></indexterm>or not and <emphasis> -i <indexterm><primary>-i</primary></indexterm></emphasis>for interactive <indexterm><primary>interactive</primary></indexterm>mode (will prompt <indexterm><primary>prompt</primary></indexterm>you before attempting <indexterm><primary>attempting</primary></indexterm>to kill).</para><tip>
<title>pkill - a little like a killall with regular expressions </title>
<para>pkill is another command that allows processes to be killed but does so using regular expressions. See below for more information.</para>
</tip>
<para>For example:</para><screen><![CDATA[killall -iv mozilla
]]></screen><para>Would kill anything named <indexterm><primary>named</primary></indexterm>&ldquo;mozilla&rdquo; and prompt <indexterm><primary>prompt</primary></indexterm>you before each kill and report <indexterm><primary>report</primary></indexterm>whether the kill was successful<indexterm><primary>successful</primary></indexterm> or not. Unfortunately <indexterm><primary>Unfortunately</primary></indexterm>you need to get the name exactly <indexterm><primary>exactly</primary></indexterm>right for <emphasis>killall</emphasis> to work, you would need to use &ldquo;mozilla-bin&rdquo; to kill the mozilla <indexterm><primary>mozilla</primary></indexterm>browser. If you want something where you don't need to know the exact <indexterm><primary>exact</primary></indexterm>name try <emphasis> pkill </emphasis>(below).</para></listitem></varlistentry><varlistentry><term>pkill
</term><listitem><para><indexterm><primary>pkill</primary></indexterm><emphasis>pkill</emphasis> is used to kill processes <indexterm><primary>processes</primary></indexterm>according to an extended <indexterm><primary>extended</primary></indexterm>regular expression.<indexterm><primary>regular expression</primary></indexterm> Use the <emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> option to kill using a user name(s) and process name (for example to only kill a process of a certain user). <emphasis>pkill</emphasis> can also send <indexterm><primary>send</primary></indexterm>specific signals <indexterm><primary>signals</primary></indexterm>to processes.<indexterm><primary>processes</primary></indexterm></para><para>For normal <indexterm><primary>normal</primary></indexterm>usage simply type:</para><screen><![CDATA[pkill process_name
]]></screen><para>Note that the &ldquo;process_name&rdquo; doesn't have to be an exact match...</para><para>Or to kill the &ldquo;process_name&rdquo; of only the users &ldquo;fred&rdquo; and &ldquo;anon&rdquo; type:</para><screen><![CDATA[pkill -u fred anon process_name
]]></screen></listitem></varlistentry><varlistentry><term>skill
</term><listitem><para><indexterm><primary>skill</primary></indexterm><emphasis>skill</emphasis> is used to send <indexterm><primary>send</primary></indexterm>a command/username/tty a particular <indexterm><primary>particular</primary></indexterm>signal.<indexterm><primary>signal</primary></indexterm></para><para><emphasis>skill</emphasis> has a number <indexterm><primary>number</primary></indexterm>of options <indexterm><primary>options</primary></indexterm>available <indexterm><primary>available</primary></indexterm>to ensure correct <indexterm><primary>correct</primary></indexterm>interpretation (otherwise it just guesses what it is), simply type<emphasis> skill <indexterm><primary>skill</primary></indexterm>-option(s)</emphasis></para><itemizedlist><listitem><para><emphasis>-L<indexterm><primary>-L</primary></indexterm></emphasis> --- list <indexterm><primary>list</primary></indexterm>the various signals <indexterm><primary>signals</primary></indexterm>that can be sent</para></listitem><listitem><para><emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> --- specify <indexterm><primary>specify</primary></indexterm>a username; this is obviously followed <indexterm><primary>followed</primary></indexterm>by the user name or a space-seperated <indexterm><primary>space-seperated</primary></indexterm>list of usernames.<indexterm><primary>usernames</primary></indexterm></para></listitem><listitem><para><emphasis>-p<indexterm><primary>-p</primary></indexterm></emphasis> --- process id <indexterm><primary>id</primary></indexterm>(followed by the process id)</para></listitem><listitem><para><emphasis>-c<indexterm><primary>-c</primary></indexterm></emphasis> --- command name (this is the same as <emphasis>killall</emphasis>)</para></listitem><listitem><para><emphasis>-t<indexterm><primary>-t</primary></indexterm></emphasis> --- (tty number)</para></listitem><listitem><para><emphasis>-v<indexterm><primary>-v</primary></indexterm></emphasis> --- verbose <indexterm><primary>verbose</primary></indexterm>mode <indexterm><primary>mode</primary></indexterm></para></listitem><listitem><para><emphasis>-i<indexterm><primary>-i</primary></indexterm></emphasis> --- interactive <indexterm><primary>interactive</primary></indexterm>mode.</para></listitem></itemizedlist><para><emphasis>skill</emphasis> can be used to stop,<indexterm><primary>stop</primary></indexterm> continue, or kill processes <indexterm><primary>processes</primary></indexterm>using the username,<indexterm><primary>username</primary></indexterm> command name or process id (or send <indexterm><primary>send</primary></indexterm>them any variety <indexterm><primary>variety</primary></indexterm>of signals <indexterm><primary>signals</primary></indexterm>you like). </para><para>Useful example:</para><screen><![CDATA[skill -STOP]]><indexterm><primary>-STOP</primary></indexterm><![CDATA[ abusive_user_name
]]></screen><para>The above command will stop <indexterm><primary>stop</primary></indexterm>all of that users processes,<indexterm><primary>processes</primary></indexterm> this will cause<indexterm><primary>cause</primary></indexterm> his screen <indexterm><primary>screen</primary></indexterm>to freeze <indexterm><primary>freeze</primary></indexterm>until you type:</para><screen><![CDATA[skill -CONT]]><indexterm><primary>-CONT</primary></indexterm><![CDATA[ abusive_user_name
]]></screen><para>This would tell <indexterm><primary>tell</primary></indexterm>that all processes <indexterm><primary>processes</primary></indexterm>may continue as before. Note that this would only work if you are root.<indexterm><primary>root</primary></indexterm> Also note you can list more than one user name with the command so it will apply <indexterm><primary>apply</primary></indexterm>to multiple <indexterm><primary>multiple</primary></indexterm>users.</para></listitem></varlistentry><varlistentry><term>
<keycombo>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
<indexterm>
<primary>CTRL-C</primary>
</indexterm>
</term><listitem><para>The break key,<indexterm><primary>break key</primary></indexterm> will kill (break, stop) something that's running<indexterm><primary>running</primary></indexterm> on your terminal.<indexterm><primary>terminal</primary></indexterm></para></listitem></varlistentry><varlistentry><term>jobs
</term><listitem><para><indexterm><primary>jobs</primary></indexterm>Prints <indexterm><primary>Prints</primary></indexterm>currently running <indexterm><primary>running</primary></indexterm>jobs, as in processes <indexterm><primary>processes</primary></indexterm>you have executed within the shell.<indexterm><primary>shell</primary></indexterm></para></listitem></varlistentry><varlistentry><term>bg
</term><listitem><para><indexterm><primary>bg</primary></indexterm>Backgrounds <indexterm><primary>Backgrounds</primary></indexterm>a process. To start <indexterm><primary>start</primary></indexterm>a program in the background <indexterm><primary>background</primary></indexterm>(so it doesn't take over the terminal) use an &ldquo;&amp;&rdquo; (ampersand) sign <indexterm><primary>sign</primary></indexterm>at the end of the command. You usually use
<keycombo>
<keycap>CTRL</keycap>
<keycap>Z</keycap>
</keycombo>
<indexterm>
<primary>CTRL-Z</primary>
</indexterm>
to suspend <indexterm><primary>suspend</primary></indexterm>something you are currently using. You can simply use <emphasis>bg</emphasis> to resume in the background the last job suspended...</para><para>Command syntax:</para><screen><![CDATA[bg job_number
]]></screen><para>or</para><screen><![CDATA[bg job_name
]]></screen></listitem></varlistentry><varlistentry><term>fg
</term><listitem><para><indexterm><primary>fg</primary></indexterm>Bring a process to the foreground,<indexterm><primary>foreground</primary></indexterm> so you can interact <indexterm><primary>interact</primary></indexterm>with it. The process will use your current terminal.<indexterm><primary>terminal</primary></indexterm> Note simply use <emphasis>fg</emphasis> to foreground the last job number suspended... </para><para>You can bring jobs <indexterm><primary>jobs</primary></indexterm>to the foreground <indexterm><primary>foreground</primary></indexterm>by name or by number (use <emphasis>jobs</emphasis> to find the number).</para><para>Command syntax:</para><screen><![CDATA[fg job_number
]]></screen><para>or </para><screen><![CDATA[fg job_name
]]></screen></listitem></varlistentry><varlistentry><term>nice
</term><listitem><para><indexterm><primary>nice</primary></indexterm>Sets <indexterm><primary>Sets</primary></indexterm>the priority <indexterm><primary>priority</primary></indexterm>for a process.<emphasis> nice -20</emphasis> is the maximum <indexterm><primary>maximum</primary></indexterm>priority <indexterm><primary>priority</primary></indexterm>(only administrative <indexterm><primary>administrative</primary></indexterm>users can assign <indexterm><primary>assign</primary></indexterm>negative priorities),<emphasis> nice 20</emphasis> is the minimum <indexterm><primary>minimum</primary></indexterm>priority. You must <indexterm><primary>must</primary></indexterm>be root to give a process a higher <indexterm><primary>higher</primary></indexterm>priority, but you can always lower the priority of your own processes... </para><para>Example:</para><screen><![CDATA[nice -20 make
]]></screen><para>Would execute <indexterm><primary>execute</primary></indexterm><emphasis>make</emphasis> and it would run <indexterm><primary>run</primary></indexterm>at maximum priority.<indexterm><primary>priority</primary></indexterm></para></listitem></varlistentry><varlistentry><term>renice
</term><listitem><para><indexterm><primary>renice</primary></indexterm>Changes the priority of an existing <indexterm><primary>existing</primary></indexterm>command. You may use the options <emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> to change <indexterm><primary>change</primary></indexterm>the priorities <indexterm><primary>priorities</primary></indexterm>of all processes <indexterm><primary>processes</primary></indexterm>for a particular user name and <emphasis>-g<indexterm><primary>-g</primary></indexterm></emphasis> to change <indexterm><primary>change</primary></indexterm>priorities for all processes <indexterm><primary>processes</primary></indexterm>of a particular group.<indexterm><primary>group</primary></indexterm> The default <indexterm><primary>default</primary></indexterm>is to change <indexterm><primary>change</primary></indexterm>via the process id number.</para><para>Example:</para><screen><![CDATA[renice +20 2222
]]></screen><para>This would change <indexterm><primary>change</primary></indexterm>the priority <indexterm><primary>priority</primary></indexterm>of process 2222 to +20 (minimum priority).</para></listitem></varlistentry><varlistentry><term>snice
</term><listitem><para><indexterm><primary>snice</primary></indexterm><emphasis>snice</emphasis> works very similarly to <emphasis>skill</emphasis>, only it changes the priority <indexterm><primary>priority</primary></indexterm>of the process(es). Its function <indexterm><primary>function</primary></indexterm>is similar to that of <emphasis>renice</emphasis>.</para><para>To use options (to ensure correct <indexterm><primary>correct</primary></indexterm>interpretation) you simply type<emphasis> snice -option(s):</emphasis></para><itemizedlist><listitem><para><emphasis>-u</emphasis> --- specify <indexterm><primary>specify</primary></indexterm>a username; this is obviously followed <indexterm><primary>followed</primary></indexterm>by the user name or a space-seperated <indexterm><primary>space-seperated</primary></indexterm>list of usernames.<indexterm><primary>usernames</primary></indexterm></para></listitem><listitem><para><emphasis>-p</emphasis> --- process id <indexterm><primary>id</primary></indexterm>(followed by the process id)</para></listitem><listitem><para><emphasis>-c</emphasis> --- command name (this is the same as <emphasis>killall</emphasis>)</para></listitem><listitem><para><emphasis>-t</emphasis> --- tty number</para></listitem><listitem><para><emphasis>-v</emphasis> --- verbose <indexterm><primary>verbose</primary></indexterm>mode <indexterm><primary>mode</primary></indexterm></para></listitem><listitem><para><emphasis>-i<indexterm><primary>-i</primary></indexterm></emphasis> --- interactive <indexterm><primary>interactive</primary></indexterm>mode.</para></listitem></itemizedlist><para>Example:</para><screen><![CDATA[snice -10 -u root
]]></screen><para>This would increase <indexterm><primary>increase</primary></indexterm>the priority <indexterm><primary>priority</primary></indexterm>of all root's processes.<indexterm><primary>processes</primary></indexterm></para><para></para></listitem></varlistentry></variablelist></sect1>
<sect1 id="controlling-services"><title>Controlling services</title><variablelist><varlistentry><term>Concept&nbsp;Definitions<anchor id="services-concept"></term>
<listitem><para>&nbsp;</para><para>UNIX <indexterm><primary>UNIX</primary></indexterm>systems use scripts <indexterm><primary>scripts</primary></indexterm>to control <indexterm><primary>control</primary></indexterm>&ldquo;daemons&rdquo; which provide <indexterm><primary>provide</primary></indexterm>&ldquo;services&rdquo; (for example your sound <indexterm><primary>sound</primary></indexterm>output) to run a <productname>UNIX</productname> system. <productname>UNIX</productname> systems consist of a variety <indexterm><primary>variety</primary></indexterm>of services <indexterm><primary>services</primary></indexterm>(daemons).</para><para>A &ldquo;daemon&rdquo; is a system process which runs in the background <indexterm><primary>background</primary></indexterm>(zero interaction) performing<indexterm><primary>performing</primary></indexterm> a particular task.<indexterm><primary>task</primary></indexterm></para><para>Daemons <indexterm><primary>Daemons</primary></indexterm>normally have a &ldquo;d&rdquo; on the end of their name and either listen <indexterm><primary>listen</primary></indexterm>for certain events <indexterm><primary>events</primary></indexterm>or perform<indexterm><primary>perform</primary></indexterm> a system task,<indexterm><primary>task</primary></indexterm> for example <emphasis>sshd</emphasis> listens <indexterm><primary>listens</primary></indexterm>for secure shell requests to the particular <indexterm><primary>particular</primary></indexterm>machine <indexterm><primary>machine</primary></indexterm>and handles<indexterm><primary>handles</primary></indexterm> them when they occur.</para><para>Daemons usually perform critical <indexterm><primary>critical</primary></indexterm>system tasks <indexterm><primary>tasks</primary></indexterm>such as control <indexterm><primary>control</primary></indexterm>swap-space, memory <indexterm><primary>memory</primary></indexterm>management <indexterm><primary>management</primary></indexterm>and various other tasks.<indexterm><primary>tasks</primary></indexterm></para></listitem></varlistentry><varlistentry><term>service
</term><listitem><para><indexterm><primary>service</primary></indexterm><emphasis>service</emphasis> is a shell script available <indexterm><primary>available</primary></indexterm>on Mandrake/Mandriva<indexterm><primary>Mandriva</primary></indexterm><indexterm><primary>Mandrake</primary></indexterm> and Redhat <indexterm><primary>Redhat</primary></indexterm>systems which allows <indexterm><primary>allows</primary></indexterm>you to perform various tasks <indexterm><primary>tasks</primary></indexterm>on services.<indexterm><primary>services</primary></indexterm> </para><itemizedlist><listitem><para>Use the <emphasis>-s<indexterm><primary>-s</primary></indexterm></emphasis> option to print <indexterm><primary>print</primary></indexterm>the status <indexterm><primary>status</primary></indexterm>of all services <indexterm><primary>services</primary></indexterm>available <indexterm><primary>available</primary></indexterm></para></listitem><listitem><para>Use the <emphasis>-f<indexterm><primary>-f</primary></indexterm></emphasis> option followed <indexterm><primary>followed</primary></indexterm>by a service <indexterm><primary>service</primary></indexterm>name to restart <indexterm><primary>restart</primary></indexterm>that particular service. </para></listitem><listitem><para>Use the <emphasis>-R<indexterm><primary>-R</primary></indexterm></emphasis> option to restart <indexterm><primary>restart</primary></indexterm>all services <indexterm><primary>services</primary></indexterm>(note that this will kill <indexterm><primary>kill</primary></indexterm>any current services running,<indexterm><primary>running</primary></indexterm> including the X windows system).</para></listitem></itemizedlist><para>For example to restart <indexterm><primary>restart</primary></indexterm>the daemon <indexterm><primary>daemon</primary></indexterm><emphasis> sshd <indexterm><primary>sshd</primary></indexterm></emphasis>you would type:</para><screen><![CDATA[service -f sshd
]]></screen></listitem></varlistentry><varlistentry><term>Using&nbsp;the&nbsp;script&nbsp;directly
</term><listitem><para>You may also execute the shell script directly from <emphasis>/etc/init.d</emphasis><indexterm><primary>/etc/init.d</primary></indexterm>. Simply go to that directory <indexterm><primary>directory</primary></indexterm>then type <emphasis>./script_name</emphasis>.</para><para>Executing the script <indexterm><primary>script</primary></indexterm>should return <indexterm><primary>return</primary></indexterm>the options it can take, by default <indexterm><primary>default</primary></indexterm>they will be:</para><itemizedlist><listitem><para>restart <indexterm><primary>restart</primary></indexterm>--- this will make the service <indexterm><primary>service</primary></indexterm>stop <indexterm><primary>stop</primary></indexterm>and then start again.</para></listitem><listitem><para>start --- this option <indexterm><primary>option</primary></indexterm>will start a service (assuming its not running).</para></listitem><listitem><para>stop --- this option will stop a service (assuming its running).</para></listitem><listitem><para>status <indexterm><primary>status</primary></indexterm>--- this option will tell <indexterm><primary>tell</primary></indexterm>you about the service<indexterm><primary>service</primary></indexterm></para></listitem></itemizedlist></listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Managing-users"><title>Managing users</title><variablelist><varlistentry><term>su&nbsp;username
</term><listitem><para><indexterm><primary>su</primary></indexterm>(Switch User), change <indexterm><primary>change</primary></indexterm>to a different <indexterm><primary>different</primary></indexterm>user. </para><para>Use <emphasis>su&nbsp;-</emphasis> to switch <indexterm><primary>switch</primary></indexterm>to root or<emphasis> su username</emphasis>, to switch <indexterm><primary>switch</primary></indexterm>to a different <indexterm><primary>different</primary></indexterm>username. </para><tip>
<title>Using sudo<indexterm><primary>sudo</primary></indexterm></title>
<para> Its often considered better practice to use the <emphasis>sudo </emphasis>command rather than switch to the root user</para>
<para> The <emphasis>sudo</emphasis> command allows you to perform actions as root but logs the actions you take (so you can trace anything that was done to the system by yourself or others). <emphasis>sudo</emphasis> has a very good manual page which provides plenty of information about it.</para>
<para> You use sudo similar to how you execute a normal command with sudo prepended to it, for example:</para>
<para><screen> sudo rpm -U myrpm.i386.rpm </screen></para>
<para> This would allow you to install a rpm even if you have the correct sudo access </para>
</tip>
<para>Note that if you want to return <indexterm><primary>return</primary></indexterm>to your original <indexterm><primary>original</primary></indexterm>user you don't use <emphasis>su</emphasis> again, type <emphasis>exit</emphasis> or press <indexterm><primary>press</primary></indexterm>
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
.</para><para>Simply typing <emphasis>su</emphasis> will give you some root <indexterm><primary>root</primary></indexterm>privileges,<indexterm><primary>privileges</primary></indexterm> but there are minor <indexterm><primary>minor</primary></indexterm>complications relating to environment <indexterm><primary>environment</primary></indexterm>variables. It's generally considered better practice <indexterm><primary>practice</primary></indexterm>to use <emphasis>su&nbsp;- </emphasis>because it has no restrictions.<indexterm><primary>restrictions</primary></indexterm></para><para></para></listitem></varlistentry><varlistentry><term>root
</term><listitem><para>The superuser.<indexterm><primary>superuser</primary></indexterm> This user has power <indexterm><primary>power</primary></indexterm>over everything <indexterm><primary>everything</primary></indexterm>and all, and can do anything with the system (including destroy <indexterm><primary>destroy</primary></indexterm>it, and of course fix <indexterm><primary>fix</primary></indexterm>it :)). This user is used to perform most administration <indexterm><primary>administration</primary></indexterm>functions <indexterm><primary>functions</primary></indexterm>on the system.</para></listitem></varlistentry></variablelist><sect1 id="users-and-groups"><title>Users/Groups</title><para></para><para>All user information <indexterm><primary>information</primary></indexterm>is normally listed in the &ldquo;/etc/passwd&rdquo;<indexterm><primary>/etc/passwd</primary></indexterm> file and the group <indexterm><primary>group</primary></indexterm>information in the &ldquo;/etc/groups&rdquo;<indexterm><primary>/etc/groups</primary></indexterm> file.</para><para>If you need to edit <indexterm><primary>edit</primary></indexterm>either file it is recommended <indexterm><primary>recommended</primary></indexterm>that you use <emphasis>vipw</emphasis> to edit the password file and <emphasis>vigr</emphasis> to edit the group <indexterm><primary>group</primary></indexterm>file. These particular <indexterm><primary>particular</primary></indexterm>commands take care of any processing <indexterm><primary>processing</primary></indexterm>and locking <indexterm><primary>locking</primary></indexterm>of the files before and after editing <indexterm><primary>editing</primary></indexterm>them.</para><para>There is a lot of information about adding/removing/controlling users and groups,<indexterm><primary>groups</primary></indexterm> this information is only the minimal <indexterm><primary>minimal</primary></indexterm>information required.</para><variablelist><varlistentry><term>chsh
</term><listitem><para><indexterm><primary>chsh</primary></indexterm>Used to change <indexterm><primary>change</primary></indexterm>your login <indexterm><primary>login</primary></indexterm>shell. </para><para>To list <indexterm><primary>list</primary></indexterm>the shells <indexterm><primary>shells</primary></indexterm>available <indexterm><primary>available</primary></indexterm>type:</para><screen><![CDATA[chsh --list-shells
]]></screen><para>Simply type<emphasis> chsh <indexterm><primary>chsh</primary></indexterm></emphasis>then [Enter], then type the name of the shell you would like to use every time <indexterm><primary>time</primary></indexterm>you login.<indexterm><primary>login</primary></indexterm></para></listitem></varlistentry><varlistentry><term>chfn
</term><listitem><para><indexterm><primary>chfn</primary></indexterm>Change <indexterm><primary>Change</primary></indexterm>finger <indexterm><primary>finger</primary></indexterm>information. </para><para>The information <indexterm><primary>information</primary></indexterm>this command changes is reflected <indexterm><primary>reflected</primary></indexterm>in the /etc/passwd file, use this utility <indexterm><primary>utility</primary></indexterm>to update <indexterm><primary>update</primary></indexterm>your real name, office <indexterm><primary>office</primary></indexterm>and home <indexterm><primary>home</primary></indexterm>phone numbers<indexterm><primary>numbers</primary></indexterm> (if they exist). </para><para>Use the <emphasis>-f</emphasis> option to change a users full name. Use this tool as either <emphasis>chfn</emphasis> or<emphasis> chfn user_name </emphasis>(usable by root only).</para><para>Command syntax:</para><screen><![CDATA[chfn user_name
]]></screen></listitem></varlistentry><varlistentry><term>passwd
</term><listitem><para><indexterm><primary>passwd</primary></indexterm>Changes the password of a user. You will need to be root if you want to change <indexterm><primary>change</primary></indexterm>other users passwords.<indexterm><primary>passwords</primary></indexterm></para><para>Simply type<emphasis> passwd <indexterm><primary>passwd</primary></indexterm></emphasis>to change <indexterm><primary>change</primary></indexterm>your own password or to change <indexterm><primary>change</primary></indexterm>another users password <indexterm><primary>password</primary></indexterm>type:</para><screen><![CDATA[passwd username
]]></screen></listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Text-related-tools"><title>Text Related Tools</title><para>The text <indexterm><primary>text</primary></indexterm>related tools chapter is the largest in this guide,<indexterm><primary>guide</primary></indexterm> most of the time on a GNU/Linux machine <indexterm><primary>machine</primary></indexterm>you will spend <indexterm><primary>spend</primary></indexterm>time interacting with text. This chapter briefly covers text editors <indexterm><primary>editors</primary></indexterm>and goes into more <indexterm><primary>more</primary></indexterm>depth <indexterm><primary>depth</primary></indexterm>on viewing<indexterm><primary>viewing</primary></indexterm> text, using tools to manipulate <indexterm><primary>manipulate</primary></indexterm>text, finding text within files and changing text formats <indexterm><primary>formats</primary></indexterm>between windows <indexterm><primary>windows</primary></indexterm>based systems and GNU/Linux based systems.</para><sect1 id="text-editors"><title>Text Editors</title><variablelist><varlistentry><term>vi
</term><listitem><para><indexterm><primary>vi</primary></indexterm>A traditional <indexterm><primary>traditional</primary></indexterm>UNIX <indexterm><primary>UNIX</primary></indexterm>system text editor,<indexterm><primary>editor</primary></indexterm> should be on any <productname>UNIX</productname> system. It requires learning <indexterm><primary>learning</primary></indexterm>a few key <indexterm><primary>key</primary></indexterm>combinations, but is very powerful,<indexterm><primary>powerful</primary></indexterm> and it is also quite <indexterm><primary>quite</primary></indexterm>small. vi <indexterm><primary>vi</primary></indexterm>is well known for its minimal <indexterm><primary>minimal</primary></indexterm>use of resources.<indexterm><primary>resources</primary></indexterm></para><note>
<title>vim</title>
<para> <emphasis>vim</emphasis> - vi improved. A newer version of the vulnerable <emphasis>vi </emphasis>editor. Many systems use <emphasis>vim</emphasis> rather than <emphasis>vi</emphasis>.
</para>
</note>
</listitem></varlistentry><varlistentry><term>emacs
</term><listitem><para><indexterm><primary>emacs</primary></indexterm>More than just a text editor.<indexterm><primary>editor</primary></indexterm> This text editor <indexterm><primary>editor</primary></indexterm>has a steep <indexterm><primary>steep</primary></indexterm>learning <indexterm><primary>learning</primary></indexterm>curve but is also very powerful,<indexterm><primary>powerful</primary></indexterm> it is both advanced <indexterm><primary>advanced</primary></indexterm>and quite <indexterm><primary>quite</primary></indexterm>large. <emphasis>emacs</emphasis> <indexterm><primary>Emacs</primary></indexterm>can do anything, surf <indexterm><primary>surf</primary></indexterm>the internet,<indexterm><primary>internet</primary></indexterm> chat,<indexterm><primary>chat</primary></indexterm> play <indexterm><primary>play</primary></indexterm>games and many other tasks.<indexterm><primary>tasks</primary></indexterm></para></listitem></varlistentry><varlistentry><term>Others
</term><listitem><para>There are too many different text editors <indexterm><primary>editors</primary></indexterm>to list here. Have a look on the internet,<indexterm><primary>internet</primary></indexterm> either search <indexterm><primary>search</primary></indexterm>for them using any search engine or you will find many of them at <ulink url="http://sourceforge.net/">Sourceforge</ulink><indexterm><primary>Sourceforge</primary></indexterm> or <ulink url="http://freshmeat.net/">Freshmeat.</ulink><indexterm><primary>Freshmeat</primary></indexterm></para></listitem></varlistentry></variablelist></sect1>
<sect1 id="text-viewing-tools"><title>Text Viewing Tools </title><variablelist><varlistentry><term>head
</term><listitem><para><indexterm><primary>head</primary></indexterm>With no options it shows <indexterm><primary>shows</primary></indexterm>the first ten lines of a text file. </para><para>Use<emphasis> head -n <indexterm><primary>-n</primary></indexterm>x </emphasis>(where &ldquo;x&rdquo; is a number) to display <indexterm><primary>display</primary></indexterm>the first x<emphasis> </emphasis>lines. </para><para>Try <emphasis> head -F <indexterm><primary>-F</primary></indexterm></emphasis>to use a continually updated <indexterm><primary>updated</primary></indexterm>version <indexterm><primary>version</primary></indexterm>of <emphasis>head</emphasis> (if the file changes it will be reloaded <indexterm><primary>reloaded</primary></indexterm>and displayed), please note that using this option <indexterm><primary>option</primary></indexterm>will run <indexterm><primary>run</primary></indexterm><emphasis>head</emphasis> is a continuous <indexterm><primary>continuous</primary></indexterm>loop so you'll need to use
<keycombo>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
<indexterm>
<primary>CTRL-C</primary>
</indexterm>
to exit.<indexterm><primary>exit</primary></indexterm></para><para>For example:</para><screen><![CDATA[head -n 20 somelog.txt
]]></screen><para>Will display the top 20 entries <indexterm><primary>entries</primary></indexterm>of the file &ldquo;somelog.txt&rdquo;.</para></listitem></varlistentry><varlistentry><term>tail
</term><listitem><para><indexterm><primary>tail</primary></indexterm>With no options it shows <indexterm><primary>shows</primary></indexterm>the last <indexterm><primary>last</primary></indexterm>ten lines of a file. </para><para>Use<emphasis> tail -n <indexterm><primary>-n</primary></indexterm>x </emphasis>(where &ldquo;x&rdquo; is a number) to display the last <emphasis>x </emphasis>lines. </para><para>Try<emphasis> tail -F <indexterm><primary>-F</primary></indexterm></emphasis>to use a continually updated <indexterm><primary>updated</primary></indexterm>version <indexterm><primary>version</primary></indexterm>of <emphasis>tail</emphasis> (if the file changes it will be reloaded <indexterm><primary>reloaded</primary></indexterm>and displayed), please note that using this option will run <emphasis>tail</emphasis> is a continuous <indexterm><primary>continuous</primary></indexterm>loop so you'll need to use
<keycombo>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
<indexterm>
<primary>CTRL-C</primary>
</indexterm>
to exit.<indexterm><primary>exit</primary></indexterm></para><para>For example:</para><screen><![CDATA[tail -n 20 somelog.txt
]]></screen><para>Will display <indexterm><primary>display</primary></indexterm>the last 20 entries <indexterm><primary>entries</primary></indexterm>of the file &ldquo;somelog.txt&rdquo;.</para></listitem></varlistentry><varlistentry><term>less
</term><listitem><para><indexterm><primary>less</primary></indexterm>Views text, can scroll <indexterm><primary>scroll</primary></indexterm>backwards and forwards.<indexterm><primary>forwards</primary></indexterm> Has many different options which are all described <indexterm><primary>described</primary></indexterm>in the manual <indexterm><primary>manual</primary></indexterm>page.<indexterm><primary>page</primary></indexterm> </para><para>When <emphasis>less</emphasis> is already running,<indexterm><primary>running</primary></indexterm> use :n<indexterm><primary>:n</primary></indexterm> and :p<indexterm><primary>:p</primary></indexterm> (type a colon <indexterm><primary>colon</primary></indexterm>then the character) to move <indexterm><primary>move</primary></indexterm>to the next <indexterm><primary>next</primary></indexterm>and previous <indexterm><primary>previous</primary></indexterm>files (when there are multiple <indexterm><primary>multiple</primary></indexterm>open <indexterm><primary>open</primary></indexterm>files).</para><para>Command syntax:</para><screen><![CDATA[less filename.txt
]]></screen><para>Or using a tool (in this example <emphasis>cat</emphasis>):</para><screen><![CDATA[cat file.txt | less
]]></screen></listitem></varlistentry><varlistentry><term>more
</term><listitem><para>Displays text, one page full at a time,<indexterm><primary>time</primary></indexterm> more limited than <emphasis>less</emphasis>. In this case <emphasis>less</emphasis> is better than <emphasis>more</emphasis>.</para><screen><![CDATA[more filename.txt
]]></screen><para>Or using a tool (is this example cat):</para><screen><![CDATA[cat file.txt | more
]]></screen></listitem></varlistentry><varlistentry><term>cat<anchor id="cat">
</term><listitem><para>Combines <indexterm><primary>Combines</primary></indexterm>(concatenates) multiple <indexterm><primary>multiple</primary></indexterm>documents <indexterm><primary>documents</primary></indexterm>into one document.<indexterm><primary>document</primary></indexterm> Can be used on individual <indexterm><primary>individual</primary></indexterm>files as well.</para><para>Some useful options:<indexterm><primary>options</primary></indexterm></para><itemizedlist><listitem><para><emphasis>-b</emphasis><indexterm><primary>-b</primary></indexterm> --- number <indexterm><primary>number</primary></indexterm>all non-blank <indexterm><primary>non-blank</primary></indexterm>lines</para></listitem><listitem><para><emphasis>-n<indexterm><primary>-n</primary></indexterm></emphasis> --- number all lines. </para></listitem></itemizedlist><para>Also try using <emphasis>nl</emphasis> to number lines (it can do more complex <indexterm><primary>complex</primary></indexterm>numbering), you will find it under this section,<indexterm><primary>section</primary></indexterm> <xref linkend="text-manipulation-tools"></para><para>Example:</para><screen><![CDATA[cat filepart1 filepart2 filepart3 > wholefile.txt
]]></screen><para>This will combine <indexterm><primary>combine</primary></indexterm>(concatenate) filepart1,<indexterm><primary>filepart1</primary></indexterm> filepart2 <indexterm><primary>filepart2</primary></indexterm>and filepart3 <indexterm><primary>filepart3</primary></indexterm>into the single file &ldquo;wholefile.txt&rdquo;.</para></listitem></varlistentry><varlistentry><term>tac
</term><listitem><para><indexterm><primary>tac</primary></indexterm>Combines (concatenates) multiple <indexterm><primary>multiple</primary></indexterm>documents <indexterm><primary>documents</primary></indexterm>into one document <indexterm><primary>document</primary></indexterm>and outputs<indexterm><primary>outputs</primary></indexterm> them in reverse order.<indexterm><primary>reverse</primary></indexterm> Can also be used on individual <indexterm><primary>individual</primary></indexterm>files. Notice that <emphasis>tac</emphasis> is <emphasis>cat</emphasis> written backwards. </para><para>Example:</para><screen><![CDATA[tac filepart1 filepart2 filepart3 > wholefile.txt
]]></screen><para>This will combine <indexterm><primary>combine</primary></indexterm>(concatenate) filepart1,<indexterm><primary>filepart1</primary></indexterm> filepart2 <indexterm><primary>filepart2</primary></indexterm>and filepart3 <indexterm><primary>filepart3</primary></indexterm>into the single file but have each of the files written in reverse.<indexterm><primary>reverse</primary></indexterm></para></listitem></varlistentry><varlistentry><term>z*&nbsp;commands
</term><listitem><para><indexterm><primary>z* commands</primary></indexterm>Many commands can be prefixed <indexterm><primary>prefixed</primary></indexterm>with a &ldquo;z&rdquo; to read/work within a gzip <indexterm><primary>gzip</primary></indexterm>compressed<indexterm><primary>compressed</primary></indexterm> file. </para><para>Some examples <indexterm><primary>examples</primary></indexterm>are <emphasis>zcat, zless,<indexterm><primary>zless</primary></indexterm> zmore,<indexterm><primary>zmore</primary></indexterm> zgrep,<indexterm><primary>zgrep</primary></indexterm> zcmp,<indexterm><primary>zcmp</primary></indexterm> zdiff<indexterm><primary>zdiff</primary></indexterm></emphasis>. </para><para>There are many utilities <indexterm><primary>utilities</primary></indexterm>for working with text within compressed files without trying to manually de-compress them somewhere first...most begin with a &ldquo;z&rdquo;. You will find some of them mentioned over here, <xref linkend="compression">.</para></listitem></varlistentry><varlistentry><term>bz*&nbsp;commands
</term><listitem><para><indexterm><primary>bz* commands</primary></indexterm>There are also a few commands that prefixed <indexterm><primary>prefixed</primary></indexterm>with a &ldquo;bz&rdquo; to read/work within a file compressed <indexterm><primary>compressed</primary></indexterm>with bzip2.<indexterm><primary>bzip2</primary></indexterm> </para><para>The tools are <emphasis>bzcat, bzless,<indexterm><primary>bzless</primary></indexterm> bzgrep<indexterm><primary>bzgrep</primary></indexterm>.</emphasis> You will find some of them mentioned over here, <xref linkend="compression">.</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="text-information-tools"><title>Text Information Tools</title><para></para><variablelist><varlistentry><term>wc
</term><listitem><para><indexterm><primary>wc</primary></indexterm>Word count, count how many words you have in a text <indexterm><primary>text</primary></indexterm>document. Can also be used to count <indexterm><primary>count</primary></indexterm>the lines or bytes <indexterm><primary>bytes</primary></indexterm>within the file. </para><para>Use the options<emphasis> -w <indexterm><primary>-w</primary></indexterm></emphasis>for words, <emphasis>-l<indexterm><primary>-l</primary></indexterm> </emphasis>for lines <indexterm><primary>lines</primary></indexterm>and <emphasis>-c<indexterm><primary>-c</primary></indexterm> </emphasis>for bytes.<indexterm><primary>bytes</primary></indexterm> Or simply run <emphasis>wc</emphasis> with no options to get all three.</para><para>Command syntax:</para><screen><![CDATA[wc -option file.txt
]]></screen></listitem></varlistentry><varlistentry><term>style
</term><listitem><para><indexterm><primary>style</primary></indexterm>To run various readability <indexterm><primary>readability</primary></indexterm>tests on a particular <indexterm><primary>particular</primary></indexterm>text file. Will output <indexterm><primary>output</primary></indexterm>scores <indexterm><primary>scores</primary></indexterm>on a number of different <indexterm><primary>different</primary></indexterm>readability <indexterm><primary>readability</primary></indexterm>tests (with no options).</para><para>Command syntax: </para><screen><![CDATA[style -options text_file
]]></screen><note>
<title>Find style in the diction package</title>
<para>This command is part of the diction package and does not appear to be used too often these days</para>
</note>
</listitem></varlistentry><varlistentry><term>cmp
</term><listitem><para><indexterm><primary>cmp</primary></indexterm>Determines whether or not two files differ, works on any type of file. Very similar to <emphasis>diff</emphasis> only it compares <indexterm><primary>compares</primary></indexterm>on the binary <indexterm><primary>binary</primary></indexterm>level instead of just the text.</para></listitem></varlistentry><varlistentry><term>diff
</term><listitem><para><indexterm><primary>diff</primary></indexterm>Compares two text files and output a difference <indexterm><primary>difference</primary></indexterm>report (sometimes called a &quot;diff&quot;<indexterm><primary>diff</primary></indexterm>) containing the text that differs between two files. </para><para>Can be used to create a 'patch' file (which can be used by <emphasis>patch</emphasis>). </para><para>Example:</para><screen><![CDATA[diff file1.txt file2.txt
]]></screen><para><emphasis>diff</emphasis> will output <indexterm><primary>output</primary></indexterm>a '&gt;' (followed by the line) for each line <indexterm><primary>line</primary></indexterm>that isn't in the first file but is in the second file, and it will output a '&lt;' (followed by the line) for each line that is in the first file but not in the second file.</para></listitem></varlistentry><varlistentry><term>sdiff
</term><listitem><para><indexterm><primary>sdiff</primary></indexterm>Instead of giving a difference <indexterm><primary>difference</primary></indexterm>report, it outputs <indexterm><primary>outputs</primary></indexterm>the files in two columns,<indexterm><primary>columns</primary></indexterm> side by side, separated <indexterm><primary>separated</primary></indexterm>by spaces.<indexterm><primary>spaces</primary></indexterm></para></listitem></varlistentry><varlistentry><term>diff3
</term><listitem><para><indexterm><primary>diff3</primary></indexterm>Same as <emphasis>diff</emphasis> except for three files.</para></listitem></varlistentry><varlistentry><term></term>
<listitem><para>&nbsp;</para></listitem></varlistentry><varlistentry><term>comm
</term><listitem><para><indexterm><primary>comm</primary></indexterm>Compares two files, line-by-line <indexterm><primary>line-by-line</primary></indexterm>and prints <indexterm><primary>prints</primary></indexterm>lines that are unique <indexterm><primary>unique</primary></indexterm>to file1 <indexterm><primary>file1</primary></indexterm>(1st column), unique to file2<indexterm><primary>file2</primary></indexterm> (2nd column) and common <indexterm><primary>common</primary></indexterm>to both files (3rd column). </para><para>Use <emphasis>comm</emphasis> with the -1, -2, or -3 to suppress <indexterm><primary>suppress</primary></indexterm>the printing <indexterm><primary>printing</primary></indexterm>of those particular lines. Simply run <indexterm><primary>run</primary></indexterm><emphasis>comm</emphasis> to have all three listed <indexterm><primary>listed</primary></indexterm>(ie. unique <indexterm><primary>unique</primary></indexterm>to files 1 and 2 and common <indexterm><primary>common</primary></indexterm>to both).</para><para>Command syntax:</para><screen><![CDATA[comm file1 file2
]]></screen></listitem></varlistentry><varlistentry><term>look
</term><listitem><para><indexterm><primary>look</primary></indexterm>To output a list of words in the system dictionary that begin with a given string <indexterm><primary>string</primary></indexterm>-- this is useful for finding <indexterm><primary>finding</primary></indexterm>words that begin with a particular phrase <indexterm><primary>phrase</primary></indexterm>or prefix.<indexterm><primary>prefix</primary></indexterm> </para><para>Give the string as an argument;<indexterm><primary>argument</primary></indexterm> it is not case sensitive.<indexterm><primary>sensitive</primary></indexterm> </para><para>Command syntax:</para><screen><![CDATA[look string
]]></screen></listitem></varlistentry></variablelist></sect1>
<sect1 id="text-manipulation-tools"><title>Text manipulation tools</title><tip>
<title>Also see</title>
<para>Also see <emphasis>tac</emphasis>, and <emphasis>cat</emphasis> over in this section, <xref linkend="text-viewing-tools">, as they can perform text manipulation too</para>
</tip>
<variablelist><varlistentry><term>sort
</term><listitem><para><indexterm><primary>sort</primary></indexterm>Sorting <indexterm><primary>Sorting</primary></indexterm>text with no options <indexterm><primary>options</primary></indexterm>the sort is alphabetical.<indexterm><primary>alphabetical</primary></indexterm> Can be run on text files to sort <indexterm><primary>sort</primary></indexterm>them alphabetically <indexterm><primary>alphabetically</primary></indexterm>(note it also concatenates<indexterm><primary>concatenates</primary></indexterm> files), can also be used with a pipe <indexterm><primary>pipe</primary></indexterm>'|' to sort <indexterm><primary>sort</primary></indexterm>the output of a command. </para><para>Use<emphasis> sort -r<indexterm><primary>-r</primary></indexterm></emphasis> to reverse <indexterm><primary>reverse</primary></indexterm>the sort <indexterm><primary>sort</primary></indexterm>output, use the<emphasis> -g <indexterm><primary>-g</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to sort <indexterm><primary>sort</primary></indexterm>'numerically' (ie read the entire number,<indexterm><primary>number</primary></indexterm> not just the first digit).</para><para>Examples:</para><screen><![CDATA[cat shoppinglist.txt | sort
]]></screen><para>The above command would run <emphasis>cat</emphasis> on the shopping <indexterm><primary>shopping</primary></indexterm>list <indexterm><primary>list</primary></indexterm>then sort the results <indexterm><primary>results</primary></indexterm>and display them in alphabetical order.<indexterm><primary>order</primary></indexterm></para><screen><![CDATA[sort -r shoppinglist.txt
]]></screen><para>The above command would run <emphasis>sort</emphasis> on a file and <emphasis>sort</emphasis> the file in reverse <indexterm><primary>reverse</primary></indexterm>alphabetical <indexterm><primary>alphabetical</primary></indexterm>order. </para><para>Advanced sort commands: </para><para><emphasis>sort</emphasis> is a powerful <indexterm><primary>powerful</primary></indexterm>utility,<indexterm><primary>utility</primary></indexterm> here are some of the more <indexterm><primary>more</primary></indexterm>hard to learn <indexterm><primary>learn</primary></indexterm>(and lesser<indexterm><primary>lesser</primary></indexterm> used) commands. Use the <emphasis>-t<indexterm><primary>-t</primary></indexterm></emphasis> option to use a particular symbol <indexterm><primary>symbol</primary></indexterm>as the separator <indexterm><primary>separator</primary></indexterm>then use the <emphasis>-k</emphasis> option to specify <indexterm><primary>specify</primary></indexterm>which column <indexterm><primary>column</primary></indexterm>you would like to sort by, where column 1 is the first column <indexterm><primary>column</primary></indexterm><emphasis>before</emphasis> the separator.<indexterm><primary>separator</primary></indexterm> Also use the <emphasis>-g<indexterm><primary>-g</primary></indexterm></emphasis> option if numeric <indexterm><primary>numeric</primary></indexterm>sorting is not working correctly (without the -g <indexterm><primary>-g</primary></indexterm>option sort just looks <indexterm><primary>looks</primary></indexterm>at the first digit <indexterm><primary>digit</primary></indexterm>of the number). Here is a complex <indexterm><primary>complex</primary></indexterm>example:</para><screen><![CDATA[sort -t : -k 4 -k 1 -g /etc/passwd | more ]]><indexterm><primary>-k</primary></indexterm><![CDATA[
]]></screen><para>This will sort the &ldquo;/etc/passwd&rdquo;<indexterm><primary>/etc/passwd</primary></indexterm> file, using the colon <indexterm><primary>colon</primary></indexterm>':' as the separator.<indexterm><primary>separator</primary></indexterm> It will sort via the 4th column <indexterm><primary>column</primary></indexterm>(GID section, in the file) and then sort within that sort using the first (name) to resolve any ties.<indexterm><primary>ties</primary></indexterm> The <emphasis>-g</emphasis> is there so it sorts via full <indexterm><primary>full</primary></indexterm>numbers, otherwise it will have 4000 before 50 (it will just look at the first digit...).</para><para></para></listitem></varlistentry><varlistentry><term>join
</term><listitem><para><indexterm><primary>join</primary></indexterm>Will put two lines together assuming they share at least <indexterm><primary>least</primary></indexterm>one common<indexterm><primary>common</primary></indexterm> value <indexterm><primary>value</primary></indexterm>on the relevant <indexterm><primary>relevant</primary></indexterm>line. It won't print <indexterm><primary>print</primary></indexterm>lines if they don't have a common value. </para><para>Command syntax:</para><screen><![CDATA[join file1 file2
]]></screen></listitem></varlistentry><varlistentry><term>cut
</term><listitem><para><indexterm><primary>cut</primary></indexterm>Prints <indexterm><primary>Prints</primary></indexterm>selected <indexterm><primary>selected</primary></indexterm>parts of lines (of a text file), or, in other words, removes <indexterm><primary>removes</primary></indexterm>certain sections <indexterm><primary>sections</primary></indexterm>of a line. You may wish to remove <indexterm><primary>remove</primary></indexterm>things according to tabs <indexterm><primary>tabs</primary></indexterm>or commas,<indexterm><primary>commas</primary></indexterm> or anything else you can think of... </para><para>Options for <emphasis>cut:</emphasis></para><itemizedlist><listitem><para>-d <indexterm><primary>-d</primary></indexterm>--- allows <indexterm><primary>allows</primary></indexterm>you to specify another delimiter,<indexterm><primary>delimiter</primary></indexterm> for example ':' is often used with /etc/passwd:</para><screen><![CDATA[cut -d ':' (and probably some more options here) /etc/passwd
]]></screen></listitem><listitem><para><emphasis>-f <indexterm><primary>-f</primary></indexterm></emphasis>--- this option works with the text by columns,<indexterm><primary>columns</primary></indexterm> separated <indexterm><primary>separated</primary></indexterm>according to the delimiter.<indexterm><primary>delimiter</primary></indexterm> For example if your file had lines <indexterm><primary>lines</primary></indexterm>like &ldquo;result,somethingelse,somethingelse&rdquo; and you only wanted result <indexterm><primary>result</primary></indexterm>you would use:</para><screen><![CDATA[cut -d ',' -f 1 /etc/passwd
]]></screen><para>This would get you only the usernames <indexterm><primary>usernames</primary></indexterm>in /etc/passwd</para></listitem><listitem><para>&ldquo;,&rdquo; (commas) --- used to separate <indexterm><primary>separate</primary></indexterm>numbers, these allow <indexterm><primary>allow</primary></indexterm>you to cut <indexterm><primary>cut</primary></indexterm>particular<indexterm><primary>particular</primary></indexterm> columns.<indexterm><primary>columns</primary></indexterm> For example:</para><screen><![CDATA[cut -d ':' -f 1,7 /etc/passwd
]]></screen><para>This would only show <indexterm><primary>show</primary></indexterm>the username <indexterm><primary>username</primary></indexterm>and the shell <indexterm><primary>shell</primary></indexterm>that each person <indexterm><primary>person</primary></indexterm>is setup<indexterm><primary>setup</primary></indexterm> for in /etc/passwd.</para></listitem><listitem><para>&ldquo;-&rdquo; (hyphen) --- used to show <indexterm><primary>show</primary></indexterm>from line x to line y, for example 1-4, (would be from lines 1 to line <indexterm><primary>line</primary></indexterm>4).</para><screen><![CDATA[cut -c 1-50 file1.txt
]]></screen><para>This would cut (display) characters <indexterm><primary>characters</primary></indexterm>(columns) 1 to 50 of each line (and anything else on that line <indexterm><primary>line</primary></indexterm>is ignored)</para></listitem><listitem><para>-x <indexterm><primary>-x</primary></indexterm>--- where x is a number, to cut <indexterm><primary>cut</primary></indexterm>from line 1 to &ldquo;x&rdquo;</para></listitem><listitem><para>x- --- where x is a number, to cut <indexterm><primary>cut</primary></indexterm>from &ldquo;x&rdquo; to the end.<indexterm><primary>end</primary></indexterm></para><screen><![CDATA[cut -5, 20-, 8 file2.txt
]]></screen><para>This would display (&ldquo;cut&rdquo;) characters <indexterm><primary>characters</primary></indexterm>(columns) 1 to 5, 8 and from 20 to the end.</para></listitem></itemizedlist></listitem></varlistentry><varlistentry><term>ispell/aspell
</term><listitem><para><indexterm><primary>aspell</primary></indexterm><indexterm><primary>ispell</primary></indexterm>To spell <indexterm><primary>spell</primary></indexterm>check a file interactively, prompts <indexterm><primary>prompts</primary></indexterm>for you to replace<indexterm><primary>replace</primary></indexterm> word or continue. <emphasis>aspell</emphasis> is said to be better at suggesting <indexterm><primary>suggesting</primary></indexterm>replacement words, but its probably<indexterm><primary>probably</primary></indexterm> best to find <indexterm><primary>find</primary></indexterm>out for yourself.</para><para><emphasis>aspell</emphasis> example:</para><screen><![CDATA[aspell -c FILE.txt
]]></screen><para>This will run <emphasis>aspell</emphasis> on a particular file called &ldquo;FILE.txt&rdquo;, <emphasis>aspell</emphasis> will run interactively and prompt <indexterm><primary>prompt</primary></indexterm>for user input.</para><para><emphasis>ispell</emphasis> example:</para><screen><![CDATA[ispell FILE.txt
]]></screen><para>This will run <emphasis>ispell</emphasis> on a particular file called &ldquo;FILE.txt&rdquo; <emphasis>ispell</emphasis> will run interactively and prompt <indexterm><primary>prompt</primary></indexterm>for user input.</para></listitem></varlistentry><varlistentry><term>chcase
</term><listitem><para><indexterm><primary>chcase</primary></indexterm>Is used to change the uppercase <indexterm><primary>uppercase</primary></indexterm>letters in a file name to lowercase<indexterm><primary>lowercase</primary></indexterm> (or vice versa).</para><para>You could also use <emphasis>tr<indexterm><primary>tr</primary></indexterm></emphasis> to do the same thing... </para><screen><![CDATA[cat fileName.txt | tr '[A-Z]' '[a-z]' > newFileName.txt
]]></screen><para>The above would convert <indexterm><primary>convert</primary></indexterm>uppercase to lowercase using the file &ldquo;fileName.txt&rdquo; as input <indexterm><primary>input</primary></indexterm>and outputting the results <indexterm><primary>results</primary></indexterm>to &ldquo;newFileName.txt&rdquo;.</para><screen><![CDATA[cat fileName.txt | tr '[a-z]' '[A-Z]' > newFileName.txt
]]></screen><para>The above would convert lowercase to uppercase using the file &ldquo;fileName.txt&rdquo; as input <indexterm><primary>input</primary></indexterm>and outputting the results <indexterm><primary>results</primary></indexterm>to &ldquo;newFileName.txt&rdquo;.</para><para><emphasis>chcase</emphasis> (a perl <indexterm><primary>perl</primary></indexterm>script) can be found <indexterm><primary>found</primary></indexterm>at the <ulink url="http://www.blemished.net/chcase.html">chcase homepage.</ulink><indexterm><primary>chcase homepage</primary></indexterm></para><para></para></listitem></varlistentry><varlistentry><term>fmt
</term><listitem><para><indexterm><primary>fmt</primary></indexterm>(format) a simple text formatter. Use<emphasis> fmt <indexterm><primary>fmt</primary></indexterm></emphasis>with the <emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> option to output text with &quot;uniform spacing&quot;, where the space <indexterm><primary>space</primary></indexterm>between words is reduced to one space character <indexterm><primary>character</primary></indexterm>and the space between sentences <indexterm><primary>sentences</primary></indexterm>is reduced to two space characters. </para><para>Example:</para><screen><![CDATA[fmt -u myessay.txt
]]></screen><para>Will make sure the amount <indexterm><primary>amount</primary></indexterm>of space between sentences <indexterm><primary>sentences</primary></indexterm>is two spaces and the amount <indexterm><primary>amount</primary></indexterm>of space between words is one space.</para></listitem></varlistentry><varlistentry><term>paste
</term><listitem><para><indexterm><primary>paste</primary></indexterm>Puts lines from two files together, either lines of each file side by side (normally separated <indexterm><primary>separated</primary></indexterm>by a tab-stop <indexterm><primary>tab-stop</primary></indexterm>but you can have any symbols(s) you like...) or it can have words from each file (the first file then the second file) side by side.</para><para>To obtain a list <indexterm><primary>list</primary></indexterm>of lines side by side, the first lines from the first file on the left side separated <indexterm><primary>separated</primary></indexterm>by a tab-stop <indexterm><primary>tab-stop</primary></indexterm>then the first lines from the second file. You would type:</para><screen><![CDATA[paste file1.txt file2.txt
]]></screen><para>To have the list displayed in serial,<indexterm><primary>serial</primary></indexterm> first line from first file, [Tab], second line from first file, then third and fourth until the end of the first file type:</para><screen><![CDATA[paste --serial file1.txt file2.txt
]]></screen><tip>
<title>This command is very simple to understand if you make yourself an example</title>
<para>Its much easier if you create an example for yourself. With just a couple of lines, I used "first line first file" and "first line second file" et cetera for a quick example.</para>
</tip>
</listitem></varlistentry><varlistentry><term>expand
</term><listitem><para><indexterm><primary>expand</primary></indexterm>Will convert tabs to spaces <indexterm><primary>spaces</primary></indexterm>and output it. Use the option<emphasis> -t <indexterm><primary>-t</primary></indexterm>num</emphasis> to specify <indexterm><primary>specify</primary></indexterm>the size <indexterm><primary>size</primary></indexterm>of a &ldquo;tapstop&rdquo;, the number of characters <indexterm><primary>characters</primary></indexterm>between each tab.<indexterm><primary>tab</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[expand file_name.txt
]]></screen></listitem></varlistentry></variablelist><para></para><variablelist><varlistentry><term>unexpand
</term><listitem><para><indexterm><primary>unexpand</primary></indexterm>Will convert spaces to tabs <indexterm><primary>tabs</primary></indexterm>and output it.</para><para>Command syntax:</para><screen><![CDATA[unexpand file_name.txt
]]></screen></listitem></varlistentry><varlistentry><term>uniq
</term><listitem><para><indexterm><primary>uniq</primary></indexterm>Eliminates duplicate <indexterm><primary>duplicate</primary></indexterm>entries from a file and it sometimes greatly <indexterm><primary>greatly</primary></indexterm>simplifies the display. </para><para><emphasis>uniq</emphasis> options: </para><itemizedlist><listitem><para><emphasis>-c <indexterm><primary>-c</primary></indexterm></emphasis> --- count <indexterm><primary>count</primary></indexterm>the number of occurances <indexterm><primary>occurances</primary></indexterm>of each duplicate<emphasis> </emphasis></para></listitem><listitem><para><emphasis>-u <indexterm><primary>-u</primary></indexterm></emphasis>--- list only unique <indexterm><primary>unique</primary></indexterm>entries </para></listitem><listitem><para><emphasis>-d <indexterm><primary>-d</primary></indexterm></emphasis>--- list only duplicate entries</para></listitem></itemizedlist><para>For example:</para><screen><![CDATA[uniq -cd phone_list.txt
]]></screen><para>This would display <indexterm><primary>display</primary></indexterm>any duplicate entries only and a count <indexterm><primary>count</primary></indexterm>of the number of times <indexterm><primary>times</primary></indexterm>that entry <indexterm><primary>entry</primary></indexterm>has appeared.</para></listitem></varlistentry><varlistentry><term>tr
</term><listitem><para><indexterm><primary>tr</primary></indexterm>(translation). A filter <indexterm><primary>filter</primary></indexterm>useful to replace all instances <indexterm><primary>instances</primary></indexterm>of characters <indexterm><primary>characters</primary></indexterm>in a text file or &quot;squeeze&quot;<indexterm><primary>squeeze</primary></indexterm> the whitespace<indexterm><primary>whitespace</primary></indexterm>.</para><para>Example:</para><screen><![CDATA[cat some_file | tr '3' '5' > new_file
]]></screen><para>This will run the <emphasis>cat</emphasis> program <indexterm><primary>program</primary></indexterm>on some file, the output of this command will be sent to the <emphasis>tr</emphasis> command, <emphasis>tr</emphasis> will replace all the instances <indexterm><primary>instances</primary></indexterm>of 3 with 5, like a search <indexterm><primary>search</primary></indexterm>and replace. You can also do other things such as:</para><screen><![CDATA[cat some_file | tr '[A-Z]' '[a-z]' > new_file
]]></screen><para>This will run <emphasis>cat</emphasis> on some_file <indexterm><primary>some_file</primary></indexterm>and convert any capital <indexterm><primary>capital</primary></indexterm>letters to lowercase letters (you could use this to change the case of file names too...).</para><tip>
<title>Alternatives</title>
<para>
You can also do a search and replace with a one line <application>Perl</application> command, read about it at the end of this section.
</para>
</tip>
</listitem></varlistentry><varlistentry><term>nl
</term><listitem><para><indexterm><primary>nl</primary></indexterm>The number lines <indexterm><primary>number lines</primary></indexterm>tool, it's default <indexterm><primary>default</primary></indexterm>action is to write <indexterm><primary>write</primary></indexterm>it's input (either the file names given as an argument,<indexterm><primary>argument</primary></indexterm> or the standard <indexterm><primary>standard</primary></indexterm>input) to the standard output. </para><para>Line <indexterm><primary>Line</primary></indexterm>numbers are added to every line and the text is indented.<indexterm><primary>indented</primary></indexterm> </para><para>This command can do take some more <indexterm><primary>more</primary></indexterm>advanced <indexterm><primary>advanced</primary></indexterm>numbering <indexterm><primary>numbering</primary></indexterm>options, simply read the info <indexterm><primary>info</primary></indexterm>page <indexterm><primary>page</primary></indexterm>on it. </para><para>These advanced <indexterm><primary>advanced</primary></indexterm>options mainly relate to customisation <indexterm><primary>customisation</primary></indexterm>of the numbering,<indexterm><primary>numbering</primary></indexterm> including <indexterm><primary>including</primary></indexterm>different forms <indexterm><primary>forms</primary></indexterm>of separation <indexterm><primary>separation</primary></indexterm>for sections/pages/footers etc.</para><para>Also try <emphasis> cat -n<indexterm><primary>cat</primary></indexterm><indexterm><primary>-n</primary></indexterm></emphasis> (number all lines) or<emphasis> cat -b<indexterm><primary>-b</primary></indexterm></emphasis> (number all non-blank <indexterm><primary>non-blank</primary></indexterm>lines). For more <indexterm><primary>more</primary></indexterm>info <indexterm><primary>info</primary></indexterm>on <emphasis>cat</emphasis> check <indexterm><primary>check</primary></indexterm>under this section:<indexterm><primary>section</primary></indexterm> <xref linkend="text-viewing-tools"> </para><para>There are two ways you can use <emphasis>nl</emphasis>:</para><screen><![CDATA[nl some_text_file.txt
]]></screen><para>The above command would add <indexterm><primary>add</primary></indexterm>numbers to each line of some_text_file.<indexterm><primary>some_text_file</primary></indexterm> You could use <emphasis>nl</emphasis> to number the output of something as shown <indexterm><primary>shown</primary></indexterm>in the example below;</para><screen><![CDATA[grep some_string some_file | nl
]]></screen></listitem></varlistentry><varlistentry><term>Perl&nbsp;search&nbsp;and&nbsp;replace&nbsp;text
</term><listitem><para><indexterm><primary>search and replace text</primary></indexterm>To search and replace text in a file is to use the following <indexterm><primary>following</primary></indexterm>one-line <indexterm><primary>one-line</primary></indexterm>Perl<indexterm><primary>perl</primary></indexterm> command<footnote><para>This information has been taken from the <productname>Linux</productname> Cookbook (without editing). See [3] in the <xref linkend="references"> for further information.</para></footnote>:</para><screen><![CDATA[$ perl -pi -e "s/oldstring/newstring/g;" filespec [RET]
]]></screen><para>In this example, &ldquo;oldstring&rdquo;<indexterm><primary>oldstring</primary></indexterm><emphasis> </emphasis>is the string <indexterm><primary>string</primary></indexterm>to search, &ldquo;newstring<emphasis>&rdquo;<indexterm><primary>newstring</primary></indexterm></emphasis> is the string to replace it with, and &ldquo;filespe<emphasis>c</emphasis>&rdquo;<indexterm><primary>filespec</primary></indexterm> is the name of the file or files to work on. You can use this for more than one file. </para><para>Example: To replace <indexterm><primary>replace</primary></indexterm>the string &ldquo;helpless&rdquo; with the string &ldquo;helpful&rdquo; in all files in the current <indexterm><primary>current</primary></indexterm>directory,<indexterm><primary>directory</primary></indexterm> type: </para><screen><![CDATA[$ perl -pi -e "s/helpless/helpful/g;" * [RET]
]]></screen><para>Also try using <emphasis>tr<indexterm><primary>tr</primary></indexterm></emphasis> to do the same thing (see further above in this section).</para></listitem></varlistentry></variablelist><tip>
<title>If these tools are too primitive</title>
<para>If these text tools are too simple for your purposes then you are probably looking at doing some programming or scripting.</para>
<para>If you would like more information on bash scripting then please see the <ulink url="http://www.tldp.org/LDP/abs/html/">advanced bash scripting guide</ulink><indexterm><primary>advanced bash scripting guide</primary></indexterm>, authored by Mendel Cooper<indexterm><primary>Mendel Cooper</primary></indexterm>.</para>
<para>sed and awk are traditional <productname>UNIX</productname> system tools for working with text, this guide does not provide an explanation of them. sed works on a line-by-line basis performing substitution and awk can perform a similar task or assist by working on a file and printing out certain information (its a programming language).</para>
<para>You will normally find them installed on your GNU/Linux system and will find many tutorials all over the internet, feel free to look them up if you ever have to perform many similar operations on a text file.</para>
</tip>
</sect1>
<sect1 id="text-filter-tools"><title>Text Conversion/Filter Tools</title><variablelist><varlistentry><term>Filters&nbsp;(UNIX&nbsp;System/dos&nbsp;formats)<anchor id="text-filters-unix-dos">
</term><listitem><para>The following <indexterm><primary>following</primary></indexterm>filters <indexterm><primary>filters</primary></indexterm>allow you to change <indexterm><primary>change</primary></indexterm>text from Dos-style <indexterm><primary>Dos-style</primary></indexterm>to <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>system style <indexterm><primary>style</primary></indexterm>and vice-versa,<indexterm><primary>vice-versa</primary></indexterm> or convert a file to other formats.<indexterm><primary>formats</primary></indexterm> Also note that many modern text editors can do this for you...</para><variablelist><varlistentry><term>Why&nbsp;use&nbsp;filters?
</term><listitem><para>Because <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>systems and Microsoft <indexterm><primary>Microsoft</primary></indexterm>use two different standards<indexterm><primary>standards</primary></indexterm> to represent <indexterm><primary>represent</primary></indexterm>the end-of-line <indexterm><primary>end-of-line</primary></indexterm>in an <acronym>ASCII</acronym> <indexterm><primary>ASCII</primary></indexterm>text file. </para><para>This can sometimes causes <indexterm><primary>causes</primary></indexterm>problems <indexterm><primary>problems</primary></indexterm>in editors <indexterm><primary>editors</primary></indexterm>or viewers <indexterm><primary>viewers</primary></indexterm>which aren't familiar<indexterm><primary>familiar</primary></indexterm> with the other operating <indexterm><primary>operating</primary></indexterm>systems end-of-line style. The following <indexterm><primary>following</primary></indexterm>tools allow you to get around this difference.<indexterm><primary>difference</primary></indexterm></para></listitem></varlistentry><varlistentry><term>Whats&nbsp;the&nbsp;difference?
</term><listitem><para>The difference <indexterm><primary>difference</primary></indexterm>is very simple, on a <productname>Windows</productname> <indexterm><primary>Windows</primary></indexterm>text file, a newline <indexterm><primary>newline</primary></indexterm>is signalled <indexterm><primary>signalled</primary></indexterm>by a carriage <indexterm><primary>carriage</primary></indexterm>return <indexterm><primary>return</primary></indexterm>followed by a newline, '\r\n' in <acronym>ASCII</acronym>.<indexterm><primary>ASCII</primary></indexterm></para><para>On a <productname>UNIX</productname> system a newline <indexterm><primary>newline</primary></indexterm>is simply a newline, '\n' in <acronym>ASCII</acronym>.<indexterm><primary>ASCII</primary></indexterm></para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>dos2unix
</term><listitem><para><indexterm><primary>dos2unix</primary></indexterm>This converts <indexterm><primary>converts</primary></indexterm>Microsoft-style end-of-line <indexterm><primary>end-of-line</primary></indexterm>characters to <productname>UNIX</productname> system style end-of-line characters. </para><para>Simply type:</para><screen><![CDATA[dos2unix file.txt
]]></screen></listitem></varlistentry><varlistentry><term>fromdos
</term><listitem><para><indexterm><primary>fromdos</primary></indexterm>This does the same as<emphasis> dos2unix <indexterm><primary>dos2unix</primary></indexterm></emphasis>(above). </para><para>Simply type:</para><screen><![CDATA[fromdos file.txt
]]></screen><para><emphasis>fromdos</emphasis> can be obtained from <ulink url="http://www.thefreecountry.com/tofrodos/">the from/to dos website.</ulink><indexterm><primary>from/to dos website</primary></indexterm></para></listitem></varlistentry><varlistentry><term>unix2dos
</term><listitem><para><indexterm><primary>unix2dos</primary></indexterm>This converts <productname>UNIX</productname> system style end-of-line characters to Microsoft-style end-of-line <indexterm><primary>end-of-line</primary></indexterm>characters. </para><para>Simply type:</para><screen><![CDATA[unix2dos file.txt
]]></screen></listitem></varlistentry><varlistentry><term>todos
</term><listitem><para><indexterm><primary>todos</primary></indexterm>This does the same as <emphasis>unix2dos</emphasis> (above). </para><para>Simply type:</para><screen><![CDATA[todos file.txt
]]></screen><para><emphasis>todos</emphasis> can be obtained from <ulink url="http://www.thefreecountry.com/tofrodos/">the from/to dos website.</ulink><indexterm><primary>from/to dos website</primary></indexterm></para></listitem></varlistentry><varlistentry><term>antiword
</term><listitem><para><indexterm><primary>antiword</primary></indexterm>This filter <indexterm><primary>filter</primary></indexterm>converts <indexterm><primary>converts</primary></indexterm>Microsoft word documents into plain <indexterm><primary>plain</primary></indexterm>ASCII text <indexterm><primary>text</primary></indexterm>documents.<indexterm><primary>documents</primary></indexterm> </para><para>Simply type:</para><screen><![CDATA[antiword file.doc
]]></screen><para>You can get <emphasis>antiword</emphasis> from <ulink url="http://www.winfield.demon.nl/">the antiword homepage.</ulink><indexterm><primary>antiword homepage</primary></indexterm></para></listitem></varlistentry><varlistentry><term>recode
</term><listitem><para><indexterm><primary>recode</primary></indexterm>Converts text files between various formats <indexterm><primary>formats</primary></indexterm>including HTML <indexterm><primary>HTML</primary></indexterm>and dozens of different <indexterm><primary>different</primary></indexterm>forms of text encodings.<indexterm><primary>encodings</primary></indexterm> </para><para>Use<emphasis> recode -l<indexterm><primary>-l</primary></indexterm></emphasis> for a full <indexterm><primary>full</primary></indexterm>listing.<indexterm><primary>listing</primary></indexterm> It can also be used to convert text to and from <productname>Windows</productname> <indexterm><primary>Windows</primary></indexterm>and <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>system formats <indexterm><primary>formats</primary></indexterm>(so you don't get the weird symbols). </para><caution>
<title> Warning </title>
<para>
By default recode overwrites the input file, use '<' to use recode as a filter only (and to not overwrite the file).
</para>
</caution>
<variablelist><varlistentry><term>Examples:</term>
<listitem><para>&nbsp;</para></listitem></varlistentry></variablelist><para>UNIX system text to <productname>Windows</productname> text:</para><screen><![CDATA[recode ..pc file_name
]]></screen><para>Windows text to <productname>UNIX</productname> system text:</para><screen><![CDATA[recode ..pc/ file_name
]]></screen><para>UNIX system text to <productname>Windows</productname> text without overwriting <indexterm><primary>overwriting</primary></indexterm>the original <indexterm><primary>original</primary></indexterm>file (and creating a new <indexterm><primary>new</primary></indexterm>output file):</para><screen><![CDATA[recode ..pc < file_name > recoded_file
]]></screen></listitem></varlistentry><varlistentry><term>tr
</term><listitem><para><indexterm><primary>tr</primary></indexterm>(Windows to <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>system style conversion <indexterm><primary>conversion</primary></indexterm>only). While <emphasis>tr</emphasis> is not specifically <indexterm><primary>specifically</primary></indexterm>designed to convert files from Windows-format <indexterm><primary>Windows-format</primary></indexterm>to UNIX<indexterm><primary>UNIX</primary></indexterm> system format <indexterm><primary>format</primary></indexterm>by doing:</para><screen><![CDATA[tr -d '\r' < inputFile.txt > outputFile.txt
]]></screen><para>The -d <indexterm><primary>-d</primary></indexterm>switch means to simply delete <indexterm><primary>delete</primary></indexterm>any occurances <indexterm><primary>occurances</primary></indexterm>of the string. Since we are looking <indexterm><primary>looking</primary></indexterm>for '\r'<indexterm><primary>\r</primary></indexterm>, carriage returns <indexterm><primary>carriage returns</primary></indexterm>it will remove <indexterm><primary>remove</primary></indexterm>any it finds,<indexterm><primary>finds</primary></indexterm> making the file a UNIX<indexterm><primary>UNIX</primary></indexterm> system text file. You can read more about <emphasis>tr</emphasis> over here, <xref linkend="text-manipulation-tools">.</para></listitem></varlistentry></variablelist><sect2 id="text-conversion-tools"><title>Conversion tools</title><variablelist><varlistentry><term>enscript
</term><listitem><para><indexterm><primary>enscript</primary></indexterm>Converts text files to postscript,<indexterm><primary>postscript</primary></indexterm> rtf,<indexterm><primary>rtf</primary></indexterm> HTML <indexterm><primary>HTML</primary></indexterm>(use <emphasis>ghostview</emphasis> to view <indexterm><primary>view</primary></indexterm>the postscript <indexterm><primary>postscript</primary></indexterm>file). <emphasis>enscript</emphasis> has a large number of options <indexterm><primary>options</primary></indexterm>which can be used to customise <indexterm><primary>customise</primary></indexterm>the output.</para><para>Examples:<footnote><para>These examples are based off information from the enscript manual page, see [12] in the <xref linkend="references"> for further information. </para></footnote></para><screen><![CDATA[enscript --language=html input_file.txt -o output_file.html
]]></screen><para>This will take some file and output it as a html <indexterm><primary>html</primary></indexterm>file.</para><screen><![CDATA[enscript --help-highlight
]]></screen><para>Display help on using the highlight <indexterm><primary>highlight</primary></indexterm>feature (list all different types <indexterm><primary>types</primary></indexterm>of highlighting <indexterm><primary>highlighting</primary></indexterm>available)</para><screen><![CDATA[enscript --help-highlight
]]></screen><para>Highlight <indexterm><primary>lang</primary></indexterm>(pretty print), example:</para><screen><![CDATA[enscript -E --color --language=html --toc --output=foo.html *.h *.c
]]></screen><para>Add <indexterm><primary>Add</primary></indexterm>all the files with a .h <indexterm><primary>.h</primary></indexterm>and a .c (C source <indexterm><primary>source</primary></indexterm>and header <indexterm><primary>header</primary></indexterm>files) into a file called foo.html, use colour <indexterm><primary>colour</primary></indexterm>and add <indexterm><primary>add</primary></indexterm>a table <indexterm><primary>table</primary></indexterm>of contents<indexterm><primary>contents</primary></indexterm></para><para>For further options refer to the well written manual page <indexterm><primary>page</primary></indexterm>of enscript.<indexterm><primary>enscript</primary></indexterm></para></listitem></varlistentry><varlistentry><term>figlet
</term><listitem><para><indexterm><primary>figlet</primary></indexterm>Used to create <acronym>ASCII</acronym> <indexterm><primary>ASCII</primary></indexterm>&ldquo;art&rdquo;. Figlet can create several <indexterm><primary>several</primary></indexterm>different forms (fonts) of <acronym>ASCII</acronym> <indexterm><primary>ASCII</primary></indexterm>art,<indexterm><primary>art</primary></indexterm> its one of the more <indexterm><primary>more</primary></indexterm>unusual <indexterm><primary>unusual</primary></indexterm>programs <indexterm><primary>programs</primary></indexterm>around.</para></listitem></varlistentry></variablelist></sect2>
</sect1>
<sect1 id="finding-text-within-files"><title>Finding Text Within Files</title><variablelist><varlistentry><term>grep
</term><listitem><para><indexterm><primary>grep</primary></indexterm>Looks for text within files. For example:</para><screen><![CDATA[]]><emphasis><![CDATA[grep this_word this_file.txt]]></emphasis><![CDATA[
]]></screen><para>Example options:</para><itemizedlist><listitem><para><emphasis>-v<indexterm><primary>-v</primary></indexterm></emphasis> --- this option is used to display lines <indexterm><primary>lines</primary></indexterm>which do not contain the string.</para></listitem><listitem><para><emphasis>-n<indexterm><primary>-n</primary></indexterm></emphasis> --- this option displays the line <indexterm><primary>line</primary></indexterm>numbers</para></listitem><listitem><para><emphasis>-w<indexterm><primary>-w</primary></indexterm></emphasis> --- this option makes grep <indexterm><primary>grep</primary></indexterm>match the whole word </para></listitem><listitem><para><emphasis>-A x </emphasis>or<emphasis> -B </emphasis>x<indexterm><primary>-A</primary></indexterm><indexterm><primary>-B</primary></indexterm> (where x is a number) --- display <indexterm><primary>display</primary></indexterm>&ldquo;x&rdquo; lines After or Before the section <indexterm><primary>section</primary></indexterm>where the particular <indexterm><primary>particular</primary></indexterm>word is found.<indexterm><primary>found</primary></indexterm> </para></listitem><listitem><para><emphasis>-r<indexterm><primary>-r</primary></indexterm></emphasis> or <emphasis>rgrep</emphasis> --- search for text <indexterm><primary>text</primary></indexterm>within files recursively. </para></listitem></itemizedlist><para>This command uses regular expressions<indexterm><primary>regular expressions</primary></indexterm>, for more information <indexterm><primary>information</primary></indexterm>please see, <xref linkend="regular-expressions">.</para><para>For example, this command would look <indexterm><primary>look</primary></indexterm>in the file &ldquo;rpmlist.txt&rdquo; for anything starting <indexterm><primary>starting</primary></indexterm>with &ldquo;rpm&rdquo;:</para><screen><![CDATA[grep rpm rpmlist.txt
]]></screen><para>Or you could use it like this, to search through the output <indexterm><primary>output</primary></indexterm>of another file:</para><screen><![CDATA[rpm -qa | grep ogg]]><indexterm><primary>-q</primary></indexterm><![CDATA[]]><indexterm><primary>-a</primary></indexterm><![CDATA[
]]></screen><para>The first command lists <indexterm><primary>lists</primary></indexterm>all RPM's installed <indexterm><primary>installed</primary></indexterm>on your system, the second finds<indexterm><primary>finds</primary></indexterm> any containing the string &ldquo;ogg&rdquo; and outputs <indexterm><primary>outputs</primary></indexterm>them.</para></listitem></varlistentry><varlistentry><term>rgrep
</term><listitem><para><indexterm><primary>rgrep</primary></indexterm>A &quot;recursive&quot;<indexterm><primary>recursive</primary></indexterm> version <indexterm><primary>version</primary></indexterm>of <emphasis>grep</emphasis> (this is a different <indexterm><primary>different</primary></indexterm>program to <emphasis>grep</emphasis>). This will search all the files in the current directory <indexterm><primary>directory</primary></indexterm>and all it's subdirectories and print <indexterm><primary>print</primary></indexterm>the names of the files and the matching <indexterm><primary>matching</primary></indexterm>line. Follows <indexterm><primary>Follows</primary></indexterm>similar syntax <indexterm><primary>syntax</primary></indexterm>to <emphasis>grep</emphasis> (see above). You could also use <emphasis>grep</emphasis> with the <emphasis>-r</emphasis> option <indexterm><primary>option</primary></indexterm>to achieve the same affect.<indexterm><primary>affect</primary></indexterm></para></listitem></varlistentry><varlistentry><term>fgrep
</term><listitem><para><indexterm><primary>fgrep</primary></indexterm>This version <indexterm><primary>version</primary></indexterm>of <emphasis>grep</emphasis> calls <indexterm><primary>calls</primary></indexterm><emphasis>grep</emphasis> with the <emphasis>-F</emphasis> option. This will look for literal <indexterm><primary>literal</primary></indexterm>strings only, it won't use or expand <indexterm><primary>expand</primary></indexterm>any kind of regular <indexterm><primary>regular</primary></indexterm>expression.</para><para>For example you could type:</para><screen><![CDATA[fgrep 'a$*b?' file.txt
]]></screen><para>And <emphasis>fgrep</emphasis> would look for the string &ldquo;a$*b?&rdquo; in the file &ldquo;file.txt&rdquo;.</para></listitem></varlistentry></variablelist><tip>
<title>Other Versions</title>
<para>
There are various versions of grep which are designed to do different things try searching for them on the internet or within your distribution.
</para>
</tip>
</sect1>
</chapter>
<chapter id="Mathematical-tools"><title>Mathematical tools</title><para></para><note>
<title>num-utils homepage</title>
<para>
The &ldquo;num-utils&rdquo; homepage, <ulink url="http://suso.suso.org/programs/num-utils/">Num Utils,</ulink> contains a variety of command line programs that could be useful when performing maths on your GNU/Linux machine.
</para>
</note>
<variablelist><varlistentry><term>units
</term><listitem><para><indexterm><primary>units</primary></indexterm>Convert <indexterm><primary>Convert</primary></indexterm>units of measurement <indexterm><primary>measurement</primary></indexterm>between different scales.<indexterm><primary>scales</primary></indexterm> For example, centimeters <indexterm><primary>centimeters</primary></indexterm>to inches,<indexterm><primary>inches</primary></indexterm> litres <indexterm><primary>litres</primary></indexterm>to gallons.<indexterm><primary>gallons</primary></indexterm></para><para>Simply run <indexterm><primary>run</primary></indexterm>the program,<indexterm><primary>program</primary></indexterm> I recommend <indexterm><primary>recommend</primary></indexterm>running <indexterm><primary>running</primary></indexterm>it as follows:<indexterm><primary>follows</primary></indexterm></para><screen><![CDATA[units --verbose]]><indexterm><primary>--verbose</primary></indexterm><![CDATA[
]]></screen><para>This will run the program and it will tell <indexterm><primary>tell</primary></indexterm>you exactly <indexterm><primary>exactly</primary></indexterm>what it is doing.</para><para>Example: you enter <indexterm><primary>enter</primary></indexterm>&ldquo;60 meters<indexterm><primary>meters</primary></indexterm>&rdquo; then you want it worked out in &ldquo;kilometers&rdquo;. The first line will tell <indexterm><primary>tell</primary></indexterm>you what this evaluates <indexterm><primary>evaluates</primary></indexterm>to.</para><para>If you wanted the conversion <indexterm><primary>conversion</primary></indexterm>rate for &ldquo;meters&rdquo; to &ldquo;kilometers&rdquo; read the second line of the output <indexterm><primary>output</primary></indexterm>(which will tell <indexterm><primary>tell</primary></indexterm>you meters/1000).</para><note>
<title>To exit</title>
<para>Press <indexterm><primary>press</primary></indexterm>
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
(end-of-file key) when you are finished <indexterm><primary>finished</primary></indexterm>using <emphasis>units</emphasis>.</para>
</note>
</listitem></varlistentry><varlistentry><term>python
</term><listitem><para><indexterm><primary>python</primary></indexterm>Python <indexterm><primary>Python</primary></indexterm>is a very powerful,<indexterm><primary>powerful</primary></indexterm> easy to learn,<indexterm><primary>learn</primary></indexterm> general <indexterm><primary>general</primary></indexterm>purpose, interpreted<indexterm><primary>interpreted</primary></indexterm> programming <indexterm><primary>programming</primary></indexterm>language. And it makes a great <indexterm><primary>great</primary></indexterm>calculator! If you don't have a calculator <indexterm><primary>calculator</primary></indexterm>installed<indexterm><primary>installed</primary></indexterm> then simply type <emphasis>python</emphasis>, then hit <indexterm><primary>hit</primary></indexterm>[Enter]. </para><para>This will execute <indexterm><primary>execute</primary></indexterm>the <acronym>Python</acronym> <indexterm><primary>Python</primary></indexterm>interpreter in interactive <indexterm><primary>interactive</primary></indexterm>mode. Type your sums <indexterm><primary>sums</primary></indexterm>just like you would use a calculator.<indexterm><primary>calculator</primary></indexterm> Note that if you want to work out fractions <indexterm><primary>fractions</primary></indexterm>make sure you use a decimal<indexterm><primary>decimal</primary></indexterm> point and a zero <indexterm><primary>zero</primary></indexterm>to obtain the correct <indexterm><primary>correct</primary></indexterm>answer (otherwise it will use integer<indexterm><primary>integer</primary></indexterm> division).</para><para>To start <indexterm><primary>start</primary></indexterm>python in interactive <indexterm><primary>interactive</primary></indexterm>mode, simply type:</para><screen><![CDATA[python
]]></screen><para>Once python <indexterm><primary>python</primary></indexterm>is started <indexterm><primary>started</primary></indexterm>you can use it to add <indexterm><primary>add</primary></indexterm>up sums <indexterm><primary>sums</primary></indexterm>or maybe do some python programming.<indexterm><primary>programming</primary></indexterm></para><para>Use
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
(end-of-file key) to exit <indexterm><primary>exit</primary></indexterm>the <acronym>Python</acronym> <indexterm><primary>Python</primary></indexterm>interpreter.</para></listitem></varlistentry><varlistentry><term>numgrep
</term><listitem><para><indexterm><primary>numgrep</primary></indexterm>A little bit <indexterm><primary>bit</primary></indexterm>like grep <indexterm><primary>grep</primary></indexterm>only this is designed <indexterm><primary>designed</primary></indexterm>for numbers <indexterm><primary>numbers</primary></indexterm>only. </para><para>Use '/' (forward slashes) to contain each expression.<indexterm><primary>expression</primary></indexterm> </para><para>Use m&lt;n&gt; to find <indexterm><primary>find</primary></indexterm>multiples of the number <indexterm><primary>number</primary></indexterm>n and use f&lt;n&gt; to find factors<indexterm><primary>factors</primary></indexterm> of the number n. </para><para>Use commas <indexterm><primary>commas</primary></indexterm>to seperate expressions <indexterm><primary>expressions</primary></indexterm>and .. (two dots) to represent <indexterm><primary>represent</primary></indexterm>a range.<indexterm><primary>range</primary></indexterm> </para><para>For example, to input <indexterm><primary>input</primary></indexterm>from standard <indexterm><primary>standard</primary></indexterm>input <indexterm><primary>input</primary></indexterm><indexterm><primary>standard input</primary></indexterm>you could simply type:</para><screen><![CDATA[numgrep
]]></screen><para>To input from a file and look <indexterm><primary>look</primary></indexterm>for numbers <indexterm><primary>numbers</primary></indexterm>between 1 and 1000 you could type:</para><screen><![CDATA[numgrep /1..1000/ file_name
]]></screen><note>
<title>This tool comes from the num-utils package</title>
<para>
Please note that this tool is part of the num-utils package.
</para>
</note>
</listitem></varlistentry></variablelist><para></para></chapter>
<chapter id="Network-commands"><title>Network Commands</title><para>The network <indexterm><primary>network</primary></indexterm>commands chapter explains <indexterm><primary>explains</primary></indexterm>various tools which can be useful when networking <indexterm><primary>networking</primary></indexterm>with other computers <indexterm><primary>computers</primary></indexterm>both within the network <indexterm><primary>network</primary></indexterm>and accross the internet,<indexterm><primary>internet</primary></indexterm> obtaining more <indexterm><primary>more</primary></indexterm>information <indexterm><primary>information</primary></indexterm>about other computers. This chapter also includes <indexterm><primary>includes</primary></indexterm>information on tools for network <indexterm><primary>network</primary></indexterm>configuration, file transfer <indexterm><primary>transfer</primary></indexterm>and working with remote machines.<indexterm><primary>remote machines</primary></indexterm></para><variablelist><varlistentry><term>netstat
</term><listitem><para><indexterm><primary>netstat</primary></indexterm>Displays contents <indexterm><primary>contents</primary></indexterm>of /proc/net files.<indexterm><primary>/proc/net</primary></indexterm> It works with the <productname>Linux</productname> Network Subsystem,<indexterm><primary>Subsystem</primary></indexterm> it will tell <indexterm><primary>tell</primary></indexterm>you what the status<indexterm><primary>status</primary></indexterm> of ports <indexterm><primary>ports</primary></indexterm>are ie. open,<indexterm><primary>open</primary></indexterm> closed,<indexterm><primary>closed</primary></indexterm> waiting,<indexterm><primary>waiting</primary></indexterm> masquerade <indexterm><primary>masquerade</primary></indexterm>connections. It will also display various other things. It has many different options.<indexterm><primary>options</primary></indexterm></para></listitem></varlistentry><varlistentry><term>tcpdump
</term><listitem><para><indexterm><primary>tcpdump</primary></indexterm>This is a sniffer,<indexterm><primary>sniffer</primary></indexterm> a program that captures <indexterm><primary>captures</primary></indexterm>packets off <indexterm><primary>off</primary></indexterm>a network<indexterm><primary>network</primary></indexterm> interface <indexterm><primary>interface</primary></indexterm>and interprets <indexterm><primary>interprets</primary></indexterm>them for you. It understands all basic <indexterm><primary>basic</primary></indexterm>internet <indexterm><primary>Internet</primary></indexterm>protocols,<indexterm><primary>protocols</primary></indexterm> and can be used to save <indexterm><primary>save</primary></indexterm>entire packets <indexterm><primary>packets</primary></indexterm>for later inspection.<indexterm><primary>inspection</primary></indexterm></para></listitem></varlistentry><varlistentry><term>ping
</term><listitem><para>The ping <indexterm><primary>ping</primary></indexterm>command (named after the sound <indexterm><primary>sound</primary></indexterm>of an active sonar system) sends <indexterm><primary>sends</primary></indexterm>echo requests <indexterm><primary>requests</primary></indexterm>to the host <indexterm><primary>host</primary></indexterm>you specify <indexterm><primary>specify</primary></indexterm>on the command line, and lists<indexterm><primary>lists</primary></indexterm> the responses <indexterm><primary>responses</primary></indexterm>received their round <indexterm><primary>round</primary></indexterm>trip time.</para><para>You simply use ping as:</para><screen><![CDATA[ping ip_or_host_name
]]></screen><para>Note to stop <indexterm><primary>stop</primary></indexterm>ping (otherwise it goes forever) use
<keycombo>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
<indexterm>
<primary>CTRL-C</primary>
</indexterm>
(break).</para><note>
<title>Please note</title>
<para>Using ping/smbmount/ssh or other <productname>UNIX</productname> system programs with a computer name rather than IP address will only work if you have the computer listed <indexterm><primary>listed</primary></indexterm>in your /etc/hosts<indexterm><primary>/etc/hosts</primary></indexterm> file. Here is an example:</para>
<para><screen>
192.168.1.100 new
</screen> This line says that their is a computer called &ldquo;new&rdquo;<indexterm><primary>new</primary></indexterm> with IP address 192.168.1.100<indexterm><primary>192.168.1.100</primary></indexterm>. Now that it exists in the /etc/hosts file I don't have to type the IP address anymore, just the name &ldquo;new&rdquo;.
</para>
</note>
</listitem></varlistentry><varlistentry><term>hostname
</term><listitem><para><indexterm><primary>hostname</primary></indexterm>Tells the user the host <indexterm><primary>host</primary></indexterm>name of the computer they are logged <indexterm><primary>logged</primary></indexterm>into. Note: may be called <emphasis>host.<indexterm><primary>host</primary></indexterm></emphasis></para></listitem></varlistentry><varlistentry><term>traceroute
</term><listitem><para><indexterm><primary>traceroute</primary></indexterm><emphasis>traceroute</emphasis> will show <indexterm><primary>show</primary></indexterm>the route <indexterm><primary>route</primary></indexterm>of a packet.<indexterm><primary>packet</primary></indexterm> It attempts <indexterm><primary>attempts</primary></indexterm>to list <indexterm><primary>list</primary></indexterm>the series <indexterm><primary>series</primary></indexterm>of hosts <indexterm><primary>hosts</primary></indexterm>through which <indexterm><primary>which</primary></indexterm>your packets <indexterm><primary>packets</primary></indexterm>travel<indexterm><primary>travel</primary></indexterm> on their way to a given destination.<indexterm><primary>destination</primary></indexterm> Also have a look at <emphasis>xtraceroute</emphasis> (one of several <indexterm><primary>several</primary></indexterm>graphical <indexterm><primary>graphical</primary></indexterm>equivalents of this program). </para><para>Command syntax:</para><screen><![CDATA[traceroute machine_name_or_ip
]]></screen></listitem></varlistentry><varlistentry><term>tracepath
</term><listitem><para><indexterm><primary>tracepath</primary></indexterm><emphasis>tracepath</emphasis> performs <indexterm><primary>performs</primary></indexterm>a very simlar function <indexterm><primary>function</primary></indexterm>to <emphasis>traceroute</emphasis> the main difference <indexterm><primary>difference</primary></indexterm>is that <emphasis>tracepath</emphasis> doesn't take complicated <indexterm><primary>complicated</primary></indexterm>options.</para><para>Command syntax:</para><screen><![CDATA[tracepath machine_name_or_ip
]]></screen></listitem></varlistentry><varlistentry><term>findsmb
</term><listitem><para><indexterm><primary>findsmb</primary></indexterm><emphasis>findsmb</emphasis> is used to list info <indexterm><primary>info</primary></indexterm>about machines <indexterm><primary>machines</primary></indexterm>that respond <indexterm><primary>respond</primary></indexterm>to SMB <indexterm><primary>SMB</primary></indexterm>name queries <indexterm><primary>queries</primary></indexterm>(for example windows <indexterm><primary>windows</primary></indexterm>based machines <indexterm><primary>machines</primary></indexterm>sharing <indexterm><primary>sharing</primary></indexterm>their hard disk's). </para><para>Command syntax:</para><screen><![CDATA[findsmb
]]></screen><para>This would find all machines <indexterm><primary>machines</primary></indexterm>possible,<indexterm><primary>possible</primary></indexterm> you may need to specify a particular<indexterm><primary>particular</primary></indexterm> subnet to query those machines only...</para></listitem></varlistentry><varlistentry><term>nmap
</term><listitem><para><indexterm><primary>nmap</primary></indexterm>&ldquo; network <indexterm><primary>network</primary></indexterm>exploration tool and security <indexterm><primary>security</primary></indexterm>scanner<indexterm><primary>scanner</primary></indexterm>&rdquo;. <emphasis>nmap</emphasis> is a very advanced <indexterm><primary>advanced</primary></indexterm>network tool used to query <indexterm><primary>query</primary></indexterm>machines (local or remote) as to whether they are up and what ports <indexterm><primary>ports</primary></indexterm>are open <indexterm><primary>open</primary></indexterm>on these machines.<indexterm><primary>machines</primary></indexterm> </para><para>A simple usage example:</para><screen><![CDATA[nmap machine_name
]]></screen><para>This would query your own machine <indexterm><primary>machine</primary></indexterm>as to what ports <indexterm><primary>ports</primary></indexterm>it keeps open.<indexterm><primary>open</primary></indexterm> <emphasis>nmap</emphasis> is a very powerful <indexterm><primary>powerful</primary></indexterm>tool, documentation <indexterm><primary>documentation</primary></indexterm>is available <indexterm><primary>available</primary></indexterm>on the <ulink url="http://www.insecure.org/nmap/">nmap site</ulink><indexterm><primary>nmap site</primary></indexterm> as well as the information in the manual <indexterm><primary>manual</primary></indexterm>page.<indexterm><primary>page</primary></indexterm></para></listitem></varlistentry></variablelist><sect1 id="network-configuration"><title>Network Configuration </title><para></para><variablelist><varlistentry><term>ifconfig
</term><listitem><para><indexterm><primary>ifconfig</primary></indexterm>This command is used to configure <indexterm><primary>configure</primary></indexterm>network <indexterm><primary>network</primary></indexterm>interfaces<indexterm><primary>interfaces</primary></indexterm>, or to display their current configuration.<indexterm><primary>configuration</primary></indexterm> In addition <indexterm><primary>addition</primary></indexterm>to activating and deactivating <indexterm><primary>deactivating</primary></indexterm>interfaces <indexterm><primary>interfaces</primary></indexterm>with the &ldquo;up&rdquo; and &ldquo;down&rdquo; settings,<indexterm><primary>settings</primary></indexterm> this command is necessary for setting <indexterm><primary>setting</primary></indexterm>an interface's address<indexterm><primary>address</primary></indexterm> information <indexterm><primary>information</primary></indexterm>if you don't have the <emphasis>ifcfg</emphasis> script.<indexterm><primary>script</primary></indexterm></para><para>Use <emphasis>ifconfig</emphasis> as either:</para><screen><![CDATA[ifconfig
]]></screen><para>This will simply list all information on all network <indexterm><primary>network</primary></indexterm>devices currently up.</para><screen><![CDATA[ifconfig eth0 down
]]></screen><para>This will take eth0 (assuming the device <indexterm><primary>device</primary></indexterm>exists) down, it won't be able<indexterm><primary>able</primary></indexterm> to receive <indexterm><primary>receive</primary></indexterm>or send <indexterm><primary>send</primary></indexterm>anything until you put the device back &ldquo;up&rdquo; again.</para><para>Clearly there are a lot more options for this tool, you will need to read the manual/info page to learn <indexterm><primary>learn</primary></indexterm>more <indexterm><primary>more</primary></indexterm>about them. </para><para></para></listitem></varlistentry><varlistentry><term>ifup
</term><listitem><para><indexterm><primary>ifup</primary></indexterm>Use <emphasis> ifup device-name </emphasis>to bring an interface <indexterm><primary>interface</primary></indexterm>up by following a script (which will contain your default networking <indexterm><primary>networking</primary></indexterm>settings). Simply type<emphasis> ifup <indexterm><primary>ifup</primary></indexterm></emphasis>and you will get help on using the script.</para><para>For example typing:</para><screen><![CDATA[ifup eth0
]]></screen><para>Will bring eth0 <indexterm><primary>eth0</primary></indexterm>up if it is currently down.</para></listitem></varlistentry><varlistentry><term>ifdown
</term><listitem><para><indexterm><primary>ifdown</primary></indexterm>Use<emphasis> ifdown device-name </emphasis>to bring an interface <indexterm><primary>interface</primary></indexterm>down using a script (which will contain your default network settings). Simply type<emphasis> ifdown <indexterm><primary>ifdown</primary></indexterm></emphasis>and you will get help <indexterm><primary>help</primary></indexterm>on using the script.</para><para>For example typing:</para><screen><![CDATA[ifdown eth0
]]></screen><para>Will bring eth0 <indexterm><primary>eth0</primary></indexterm>down if it is currently up.</para></listitem></varlistentry><varlistentry><term>ifcfg
</term><listitem><para><indexterm><primary>ifcfg</primary></indexterm>Use <emphasis>ifcfg</emphasis> to configure <indexterm><primary>configure</primary></indexterm>a particular interface.<indexterm><primary>interface</primary></indexterm> Simply type ifcfg <indexterm><primary>ifcfg</primary></indexterm>to get help <indexterm><primary>help</primary></indexterm>on using this script.</para><para>For example, to change <indexterm><primary>change</primary></indexterm>eth0 <indexterm><primary>eth0</primary></indexterm>from 192.168.0.1 <indexterm><primary>192.168.0.1</primary></indexterm>to 192.168.0.2 <indexterm><primary>192.168.0.2</primary></indexterm>you could do:</para><screen><![CDATA[ifcfg eth0 del 192.168.0.1
]]><![CDATA[ifcfg eth0 add 192.168.0.2
]]></screen><para>The first command takes eth0 <indexterm><primary>eth0</primary></indexterm>down and removes <indexterm><primary>removes</primary></indexterm>that stored <indexterm><primary>stored</primary></indexterm>IP address<indexterm><primary>IP address</primary></indexterm> and the second one brings it back up with the new <indexterm><primary>new</primary></indexterm>address.</para></listitem></varlistentry><varlistentry><term>route
</term><listitem><para><indexterm><primary>route</primary></indexterm>The <emphasis>route</emphasis> command is the tool used to display <indexterm><primary>display</primary></indexterm>or modify <indexterm><primary>modify</primary></indexterm>the routing <indexterm><primary>routing</primary></indexterm>table.<indexterm><primary>table</primary></indexterm> To add <indexterm><primary>add</primary></indexterm>a gateway <indexterm><primary>gateway</primary></indexterm>as the default <indexterm><primary>default</primary></indexterm>you would type:</para><screen><![CDATA[route add default gw some_computer
]]></screen></listitem></varlistentry></variablelist></sect1>
<sect1 id="internet-specific-commands"><title>Internet Specific Commands</title><para>Note that should DNS <indexterm><primary>DNS</primary></indexterm>not be configured correctly <indexterm><primary>correctly</primary></indexterm>on your machine,<indexterm><primary>machine</primary></indexterm> you need to edit <indexterm><primary>edit</primary></indexterm>&ldquo;/etc/resolv.conf&rdquo;<indexterm><primary>/etc/resolv.conf</primary></indexterm> to make things work...</para><variablelist><varlistentry><term>host
</term><listitem><para><indexterm><primary>host</primary></indexterm>Performs a simple lookup <indexterm><primary>lookup</primary></indexterm>of an internet <indexterm><primary>internet</primary></indexterm>address (using the Domain Name System, DNS). Simply type:</para><screen><![CDATA[host ip_address
]]></screen><para>or</para><screen><![CDATA[host domain_name
]]></screen></listitem></varlistentry><varlistentry><term>dig
</term><listitem><para><indexterm><primary>dig</primary></indexterm>The &quot;domain information groper&quot;<indexterm><primary>domain information groper</primary></indexterm> tool. More advanced <indexterm><primary>advanced</primary></indexterm>then <emphasis>host</emphasis>... If you give a hostname <indexterm><primary>hostname</primary></indexterm>as an argument <indexterm><primary>argument</primary></indexterm>to output <indexterm><primary>output</primary></indexterm>information about that host,<indexterm><primary>host</primary></indexterm> including <indexterm><primary>including</primary></indexterm>it's IP address, hostname and various other information. </para><para>For example, to look up information about &ldquo;www.amazon.com&rdquo; type:</para><screen><![CDATA[dig www.amazon.com
]]></screen><para>To find the host name for a given IP address (ie a reverse <indexterm><primary>reverse</primary></indexterm>lookup), use <emphasis>dig</emphasis> with the <emphasis>`-x'<indexterm><primary>-x</primary></indexterm></emphasis> option.<indexterm><primary>option</primary></indexterm></para><screen><![CDATA[dig -x 100.42.30.95
]]></screen><para>This will look up the address <indexterm><primary>address</primary></indexterm>(which may or may not exist) and returns <indexterm><primary>returns</primary></indexterm>the address of the host,<indexterm><primary>host</primary></indexterm> for example if that was the address of &ldquo;http://slashdot.org&rdquo;<indexterm><primary>http://slashdot.org</primary></indexterm> then it would return <indexterm><primary>return</primary></indexterm>&ldquo;http://slashdot.org&rdquo;.</para><para><emphasis>dig</emphasis> takes a huge <indexterm><primary>huge</primary></indexterm>number <indexterm><primary>number</primary></indexterm>of options <indexterm><primary>options</primary></indexterm>(at the point of being too many), refer<indexterm><primary>refer</primary></indexterm> to the manual page for more information.<indexterm><primary>information</primary></indexterm></para><para></para></listitem></varlistentry><varlistentry><term>whois
</term><listitem><para><indexterm><primary>whois</primary></indexterm>(now <acronym>BW</acronym> whois) is used to look up the contact <indexterm><primary>contact</primary></indexterm>information from the &ldquo;whois&rdquo; databases,<indexterm><primary>databases</primary></indexterm> the servers <indexterm><primary>servers</primary></indexterm>are only likely to hold major <indexterm><primary>major</primary></indexterm>sites. Note that contact information is likely to be hidden <indexterm><primary>hidden</primary></indexterm>or restricted <indexterm><primary>restricted</primary></indexterm>as it is often abused by crackers <indexterm><primary>crackers</primary></indexterm>and others looking <indexterm><primary>looking</primary></indexterm>for a way to cause <indexterm><primary>cause</primary></indexterm>malicious damage <indexterm><primary>damage</primary></indexterm>to organisation's.</para></listitem></varlistentry><varlistentry><term>wget
</term><listitem><para><indexterm><primary>wget</primary></indexterm>(GNU Web get) used to download <indexterm><primary>download</primary></indexterm>files from the World Wide Web.</para><para>To archive <indexterm><primary>archive</primary></indexterm>a single web-site, use the <emphasis>-m<indexterm><primary>-m</primary></indexterm></emphasis> or <emphasis>--mirror<indexterm><primary>--mirror</primary></indexterm></emphasis> (mirror) option.</para><para>Use<emphasis> </emphasis>the<emphasis> -nc <indexterm><primary>-n</primary></indexterm></emphasis>(no clobber) option to stop <indexterm><primary>stop</primary></indexterm><emphasis>wget</emphasis> from overwriting <indexterm><primary>overwriting</primary></indexterm>a file if you already have it.</para><para>Use the <emphasis>-c<indexterm><primary>-c</primary></indexterm></emphasis> or <emphasis>--continue</emphasis> option to continue a file that was unfinished <indexterm><primary>unfinished</primary></indexterm>by wget or another program.<indexterm><primary>program</primary></indexterm></para><para>Simple usage <indexterm><primary>usage</primary></indexterm>example:</para><screen><![CDATA[wget url_for_file
]]></screen><para>This would simply get a file from a site.<indexterm><primary>site</primary></indexterm> </para><para><emphasis>wget</emphasis> can also retrieve <indexterm><primary>retrieve</primary></indexterm>multiple files using standard wildcards,<indexterm><primary>standard wildcards</primary></indexterm> the same as the type used in bash,<indexterm><primary>bash</primary></indexterm> like *, [ ], ?. Simply use <emphasis>wget</emphasis> as per normal <indexterm><primary>normal</primary></indexterm>but use single quotation <indexterm><primary>quotation</primary></indexterm>marks (' ') on the URL <indexterm><primary>URL</primary></indexterm>to prevent<indexterm><primary>prevent</primary></indexterm> bash <indexterm><primary>bash</primary></indexterm>from expanding <indexterm><primary>expanding</primary></indexterm>the wildcards.<indexterm><primary>wildcards</primary></indexterm> There are complications if you are retrieving from a http site (see below...).</para><para>Advanced usage <indexterm><primary>usage</primary></indexterm>example, (used from <emphasis>wget</emphasis> manual page):</para><screen><![CDATA[wget --spider --force-html -i bookmarks.html
]]></screen><para>This will parse <indexterm><primary>parse</primary></indexterm>the file bookmarks.html <indexterm><primary>bookmarks.html</primary></indexterm>and check <indexterm><primary>check</primary></indexterm>that all the links <indexterm><primary>links</primary></indexterm>exist.<indexterm><primary>exist</primary></indexterm></para><para>Advanced usage:<indexterm><primary>usage</primary></indexterm> this is how you can download <indexterm><primary>download</primary></indexterm>multiple files using http <indexterm><primary>http</primary></indexterm>(using a wildcard...).</para><para>Notes: http <indexterm><primary>http</primary></indexterm>doesn't support <indexterm><primary>support</primary></indexterm>downloading <indexterm><primary>downloading</primary></indexterm>using standard wildcards,<indexterm><primary>standard wildcards</primary></indexterm> ftp <indexterm><primary>ftp</primary></indexterm>does so you may use wildcards with ftp and it will work fine. A work-around <indexterm><primary>work-around</primary></indexterm>for this http limitation is shown <indexterm><primary>shown</primary></indexterm>below:</para><screen><![CDATA[wget -r -l1 --no-parent -A.gif http://www.website.com]]><footnote><para>This way around the wildcard limitation has been adopted (with a tiny amount of editing) from <ulink url="http://www.lns.cornell.edu/public/COMP/info/wget/wget_7.html">wget manual page</ulink>, see [9] in the <xref linkend="references"> for further information.</para></footnote><![CDATA[
]]></screen><para>This will download (recursively), to a depth <indexterm><primary>depth</primary></indexterm>of one, in other words in the current <indexterm><primary>current</primary></indexterm>directory <indexterm><primary>directory</primary></indexterm>and not below that. This command will ignore references <indexterm><primary>references</primary></indexterm>to the parent <indexterm><primary>parent</primary></indexterm>directory,<indexterm><primary>directory</primary></indexterm> and downloads<indexterm><primary>downloads</primary></indexterm> anything that ends in &ldquo;.gif&rdquo;. If you wanted to download say, anything that ends <indexterm><primary>ends</primary></indexterm>with &ldquo;.pdf&rdquo; as well than add <indexterm><primary>add</primary></indexterm>a <emphasis>-A.pdf</emphasis> <indexterm><primary>-A</primary></indexterm>before the website <indexterm><primary>website</primary></indexterm>address. Simply change <indexterm><primary>change</primary></indexterm>the website <indexterm><primary>website</primary></indexterm>address and the type of file being downloaded<indexterm><primary>downloaded</primary></indexterm> to download something else. Note that doing <emphasis>-A.gif</emphasis> is the same as doing <emphasis>-A &ldquo;*.gif</emphasis>&rdquo; (double quotes <indexterm><primary>quotes</primary></indexterm>only, single quotes <indexterm><primary>quotes</primary></indexterm>will not work).</para><para><emphasis>wget</emphasis> has many more options refer to the examples section of the manual page,<indexterm><primary>page</primary></indexterm> this tool is very well documented.</para><note>
<title>Alternative website downloaders</title>
<para>You may like to try alternatives like httrack<indexterm><primary>httrack</primary></indexterm>. A full <acronym>GUI</acronym> website downloader written in python and available for GNU/Linux </para>
</note>
</listitem></varlistentry><varlistentry><term>curl
</term><listitem><para><indexterm><primary>curl</primary></indexterm><emphasis>curl</emphasis> is another remote <indexterm><primary>remote</primary></indexterm>downloader.<indexterm><primary>downloader</primary></indexterm> This remote <indexterm><primary>remote</primary></indexterm>downloader <indexterm><primary>downloader</primary></indexterm>is designed <indexterm><primary>designed</primary></indexterm>to work without user interaction and supports <indexterm><primary>supports</primary></indexterm>a variety <indexterm><primary>variety</primary></indexterm>of protocols,<indexterm><primary>protocols</primary></indexterm> can upload/download and has a large number of tricks/work-arounds for various things. It can access <indexterm><primary>access</primary></indexterm>dictionary <indexterm><primary>dictionary</primary></indexterm>servers <indexterm><primary>servers</primary></indexterm>(dict), ldap <indexterm><primary>ldap</primary></indexterm>servers, ftp, http,<indexterm><primary>http</primary></indexterm> gopher,<indexterm><primary>gopher</primary></indexterm> see the manual <indexterm><primary>manual</primary></indexterm>page for full <indexterm><primary>full</primary></indexterm>details.<indexterm><primary>details</primary></indexterm> </para><para>To access <indexterm><primary>access</primary></indexterm>the full <indexterm><primary>full</primary></indexterm>manual (which is huge) for this command type:</para><screen><![CDATA[curl -M]]><indexterm><primary>-M</primary></indexterm><![CDATA[
]]></screen><para>For general <indexterm><primary>general</primary></indexterm>usage you can use it like <emphasis>wget</emphasis>. You can also login <indexterm><primary>login</primary></indexterm>using a user name by using the <emphasis>-u<indexterm><primary>-u</primary></indexterm></emphasis> option and typing your username <indexterm><primary>username</primary></indexterm>and password like this:</para><screen><![CDATA[curl -u username:password http://www.placetodownload/file
]]></screen><para>To upload <indexterm><primary>upload</primary></indexterm>using ftp <indexterm><primary>ftp</primary></indexterm>you the <emphasis>-T<indexterm><primary>-T</primary></indexterm></emphasis> option:<indexterm><primary>option</primary></indexterm></para><screen><![CDATA[curl -T file_name ftp://ftp.uploadsite.com
]]></screen><para>To continue a file use the <emphasis>-C<indexterm><primary>-C</primary></indexterm></emphasis> option:</para><screen><![CDATA[curl -C - -o file http://www.site.com
]]></screen></listitem></varlistentry></variablelist></sect1>
<sect1 id="remote-administration"><title>Remote Administration Related</title><variablelist><varlistentry><term>ssh
</term><listitem><para><indexterm><primary>ssh</primary></indexterm>Secure shell,<indexterm><primary>secure shell</primary></indexterm> remotely <indexterm><primary>remotely</primary></indexterm>login <indexterm><primary>login</primary></indexterm>on a machine running <indexterm><primary>running</primary></indexterm>the <emphasis>sshd</emphasis> daemon.<indexterm><primary>daemon</primary></indexterm> Once you are logged <indexterm><primary>logged</primary></indexterm>in you have a secure shell and are able <indexterm><primary>able</primary></indexterm>to execute<indexterm><primary>execute</primary></indexterm> various commands on that computer <indexterm><primary>computer</primary></indexterm>such as copy <indexterm><primary>copy</primary></indexterm>files, reboot the computer, just like it was your own GNU/Linux PC.<indexterm><primary>PC</primary></indexterm></para><para>Or you can use <emphasis>ssh</emphasis> with a full hostname <indexterm><primary>hostname</primary></indexterm>to connect <indexterm><primary>connect</primary></indexterm>to a remote <indexterm><primary>remote</primary></indexterm>machine (as in across the internet). </para><para>Examples:</para><screen><![CDATA[ssh hostname
]]></screen><para>Connect to a remote <indexterm><primary>remote</primary></indexterm>system with your current username, you will obviously need the password of the user on the other machine.</para><screen><![CDATA[ssh username@hostname
]]></screen><para>Connect to a remote <indexterm><primary>remote</primary></indexterm>system with your a different <indexterm><primary>different</primary></indexterm>username, you will obviously need the password <indexterm><primary>password</primary></indexterm>of the user on the other machine.</para></listitem></varlistentry><varlistentry><term>scp
</term><listitem><para><indexterm><primary>scp</primary></indexterm>Secure copy,<indexterm><primary>secure copy</primary></indexterm> part <indexterm><primary>part</primary></indexterm>of the ssh <indexterm><primary>ssh</primary></indexterm>package.<indexterm><primary>package</primary></indexterm> Allows you to copy files from one computer to another computer, use<emphasis> -r<indexterm><primary>-r</primary></indexterm> </emphasis>to copy recursively (copy entire directories <indexterm><primary>directories</primary></indexterm>and subdirectories).</para><para><emphasis>scp</emphasis>'s syntax <indexterm><primary>syntax</primary></indexterm>is always</para><screen><![CDATA[scp machineToBeCopiedFrom machineToBeCopiedTo
]]></screen><para>Where either machine can be a local <indexterm><primary>local</primary></indexterm>directory (on the current filesystem<indexterm><primary>filesystem</primary></indexterm> /) or a remote <indexterm><primary>remote</primary></indexterm>machine. Remote machines are usually <emphasis>machinesFullName:/directory</emphasis> (if you omit <indexterm><primary>omit</primary></indexterm>the directory part it will just assume the home <indexterm><primary>home</primary></indexterm>directory of the username you are logging <indexterm><primary>logging</primary></indexterm>in with).</para><para>The example below copies <indexterm><primary>copies</primary></indexterm>all files from the current directory (not including<indexterm><primary>including</primary></indexterm> any directories), the command will login <indexterm><primary>login</primary></indexterm>to &ldquo;new&rdquo; using the username of the person <indexterm><primary>person</primary></indexterm>currently logged in on the local <indexterm><primary>local</primary></indexterm>computer, the files will be copied to the root <indexterm><primary>root</primary></indexterm>directory of the remote <indexterm><primary>remote</primary></indexterm>computer called &ldquo;new&rdquo; (which is probably <indexterm><primary>probably</primary></indexterm>on the LAN):</para><screen><![CDATA[scp * new:/
]]></screen><para>You could also copy files from another computer to another computer. Let's say you are on a computer called &ldquo;p100&rdquo;. And you want to copy files (and directories) from &ldquo;hp166&rdquo; (in the /tmp directory and anything below that) to &ldquo;new&rdquo; and put the files in new's temporary <indexterm><primary>temporary</primary></indexterm>directory. You could do:</para><screen><![CDATA[scp -r hp166:/tmp new:/tmp
]]></screen><para>Assuming you were logged in as &ldquo;fred&rdquo; you would need passwords <indexterm><primary>passwords</primary></indexterm>for user &ldquo;fred&rdquo; on the computers hp166 and new.<indexterm><primary>new</primary></indexterm> Add <indexterm><primary>Add</primary></indexterm>an <emphasis>user_name@</emphasis> before the computer name to login <indexterm><primary>login</primary></indexterm>under a different user name. </para><para>For example to perform <indexterm><primary>perform</primary></indexterm>the above command with user &ldquo;root&rdquo; on hp166 <indexterm><primary>hp166</primary></indexterm>and &ldquo;anon&rdquo; on new <indexterm><primary>new</primary></indexterm>you would type:</para><screen><![CDATA[scp -r root@hp166:/tmp anon@new:/tmp
]]></screen><para>To copy from a remote <indexterm><primary>remote</primary></indexterm>machine to a local <indexterm><primary>local</primary></indexterm>computer <indexterm><primary>computer</primary></indexterm>you simply do things in reverse:<indexterm><primary>reverse</primary></indexterm></para><screen><![CDATA[scp remoteMachine:/mystuff/* .
]]></screen><para>This will copy files on the remote <indexterm><primary>remote</primary></indexterm>machine in the directory &ldquo;mystuff&rdquo; to your local <indexterm><primary>local</primary></indexterm>computer.</para><note>
<title>Remote Machines</title>
<para>Please note that when working with a remote machine you need to have a : (colon) after the machine name even if you want the files in their home directory. Otherwise the command will fail.</para>
</note>
<para></para></listitem></varlistentry><varlistentry><term>sftp
</term><listitem><para><indexterm><primary>sftp</primary></indexterm>Secure ftp,<indexterm><primary>secure ftp</primary></indexterm> another part <indexterm><primary>part</primary></indexterm>of the ssh <indexterm><primary>ssh</primary></indexterm>package.<indexterm><primary>package</primary></indexterm> This command is similar to ftp but uses an encrypted <indexterm><primary>encrypted</primary></indexterm>tunnel <indexterm><primary>tunnel</primary></indexterm>to connect to an ftp server <indexterm><primary>server</primary></indexterm>and is therefore more <indexterm><primary>more</primary></indexterm>secure <indexterm><primary>secure</primary></indexterm>than just plain <indexterm><primary>plain</primary></indexterm><emphasis>ftp</emphasis>.</para><para>The command usage is very similar to <emphasis>ftp</emphasis> (the command-line tool), <emphasis>sftp</emphasis> (once running) uses commands such as<emphasis> help <indexterm><primary>help</primary></indexterm></emphasis>(for help), <emphasis>put</emphasis> (send files to the server), <emphasis>get</emphasis> (download files from the server) and various others, refer <indexterm><primary>refer</primary></indexterm>to the manual page and internal <indexterm><primary>internal</primary></indexterm>documentation <indexterm><primary>documentation</primary></indexterm>for further details.</para><tip>
<title>Graphical programs</title>
<para>Sometimes its easier to manage files with a GUI, many of these programs do have good <acronym>GUI</acronym> equivalents, try searching the internet or sites like <ulink url="http://sourceforge.net">Sourceforge</ulink><indexterm><primary>Sourceforge</primary></indexterm> or <ulink url="http://freshmeat.net">Freshmeat.</ulink><indexterm><primary>Freshmeat.</primary></indexterm></para>
</tip>
</listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Security"><title>Security</title><para>The security <indexterm><primary>security</primary></indexterm>chapter is designed <indexterm><primary>designed</primary></indexterm>to give the user a very basic <indexterm><primary>basic</primary></indexterm>level <indexterm><primary>level</primary></indexterm>of understanding of security <indexterm><primary>security</primary></indexterm>within the GNU/Linux operating <indexterm><primary>operating</primary></indexterm>system. This chapter also has information <indexterm><primary>information</primary></indexterm>on the <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>system style file permissions<indexterm><primary>permissions</primary></indexterm> used on most GNU/Linux machines.<indexterm><primary>machines</primary></indexterm> </para><para>More comprehensive <indexterm><primary>comprehensive</primary></indexterm>guides can be found <indexterm><primary>found</primary></indexterm>at the <ulink url="http://www.tldp.org">Linux Documentation Project</ulink><indexterm><primary>Linux Documentation Project</primary></indexterm>, such as the <ulink url="http://www.tldp.org/HOWTO/Security-HOWTO/">Linux Security howto</ulink><indexterm><primary>Linux Security howto</primary></indexterm> authored <indexterm><primary>authored</primary></indexterm>by Kevin Fenzi <indexterm><primary>Kevin Fenzi</primary></indexterm>and Dave Wreski.<indexterm><primary>Dave Wreski</primary></indexterm> </para><para>There are also sites <indexterm><primary>sites</primary></indexterm>such as <ulink url="http://www.linuxsecurity.com">Linux Security</ulink>.<indexterm><primary>Linux Security</primary></indexterm> If your looking <indexterm><primary>looking</primary></indexterm>for a program <indexterm><primary>program</primary></indexterm>to assist <indexterm><primary>assist</primary></indexterm>in locking <indexterm><primary>locking</primary></indexterm>down your operating system you may want to check <indexterm><primary>check</primary></indexterm><ulink url="http://www.bastille-linux.org">Bastille Linux</ulink><indexterm><primary>Bastille Linux</primary></indexterm> that runs on <acronym>RPM</acronym> <indexterm><primary>RPM</primary></indexterm>based distributions <indexterm><primary>distributions</primary></indexterm>(Redhat/Mandriva/SuSE).</para><variablelist><varlistentry><term>Changing&nbsp;root's&nbsp;password
</term><listitem><para><indexterm><primary>root's password</primary></indexterm>This trick <indexterm><primary>trick</primary></indexterm>works well if you have forgotten <indexterm><primary>forgotten</primary></indexterm>your superuser <indexterm><primary>superuser</primary></indexterm>password, type<emphasis> linux single</emphasis> at a LILO/Grub prompt.<indexterm><primary>prompt</primary></indexterm> Then <emphasis>passwd</emphasis> once the system has started <indexterm><primary>started</primary></indexterm>and you are at a console.<indexterm><primary>console</primary></indexterm> </para><variablelist><varlistentry><term>Grub:
</term><listitem><para>If you are using grub <indexterm><primary>grub</primary></indexterm>go to the relevant <indexterm><primary>relevant</primary></indexterm>line (the one with the kernel<indexterm><primary>kernel</primary></indexterm> and various options) then press <indexterm><primary>press</primary></indexterm>'e' for edit <indexterm><primary>edit</primary></indexterm>and add <indexterm><primary>add</primary></indexterm>&ldquo;single&rdquo; on to the end <indexterm><primary>end</primary></indexterm>of the lines <indexterm><primary>section</primary></indexterm>that boot <indexterm><primary>boots</primary></indexterm>the kernel.<indexterm><primary>kernel</primary></indexterm> Then hit <indexterm><primary>hit</primary></indexterm>[Enter] and press <indexterm><primary>press</primary></indexterm>'b' (to boot). </para></listitem></varlistentry><varlistentry><term>Lilo:
</term><listitem><para>If you are using lilo <indexterm><primary>lilo</primary></indexterm>press escape <indexterm><primary>escape</primary></indexterm>and type &ldquo; linux <indexterm><primary>linux</primary></indexterm>single&rdquo; and then hit <indexterm><primary>hit</primary></indexterm>[Enter] to boot.<indexterm><primary>boot</primary></indexterm></para></listitem></varlistentry></variablelist><caution>
<title>Security Warning</title>
<para>
This is also a basic security hazard if you have others using your computer and security is a concern, you may like to add a password to your LILO or Grub prompt to stop this from being done.
</para>
</caution>
</listitem></varlistentry></variablelist><para></para><variablelist><varlistentry><term>umask
</term><listitem><para>The umask <indexterm><primary>umask</primary></indexterm>is a value <indexterm><primary>value</primary></indexterm>set <indexterm><primary>set</primary></indexterm>by the shell.<indexterm><primary>shell</primary></indexterm> It controls <indexterm><primary>controls</primary></indexterm>the default <indexterm><primary>default</primary></indexterm>permissions of any file created during that shell<indexterm><primary>shell</primary></indexterm> session.<indexterm><primary>session</primary></indexterm> This information is inherited from the shell's parent <indexterm><primary>parent</primary></indexterm>and is normally set in some configuration <indexterm><primary>configuration</primary></indexterm>file by the root user (in my case /etc/profile<indexterm><primary>/etc/profile</primary></indexterm>).</para><para>umask has an unusual way of doing things ...to set the umask you must describe<indexterm><primary>describe</primary></indexterm> file permissions <indexterm><primary>file permissions</primary></indexterm>by saying what will be disabled.<indexterm><primary>disabled</primary></indexterm> </para><para>You can do this by doing 777 minus <indexterm><primary>minus</primary></indexterm>the file permissions you want. Note that <emphasis>umask</emphasis> works with numbers <indexterm><primary>numbers</primary></indexterm>only, for an explanation <indexterm><primary>explanation</primary></indexterm> please see, <xref linkend="file-permissions"></para><para>For example:</para><para>You want the default during a particular shell session <indexterm><primary>default</primary></indexterm>to be equivalent <indexterm><primary>equivalent</primary></indexterm>to<emphasis> chmod <indexterm><primary>chmod</primary></indexterm>750</emphasis> (user has r/w/x, group <indexterm><primary>group</primary></indexterm>has r/x and other has no permissions), then the command you would use would be:</para><screen><![CDATA[umask 027
]]></screen></listitem></varlistentry></variablelist><sect1 id="some-basic-security-tools"><title>Some basic Security Tools</title><para></para><variablelist><varlistentry><term>md5sum
</term><listitem><para><indexterm><primary>md5sum</primary></indexterm>Compute an md5 <indexterm><primary>md5</primary></indexterm>checksum (128-bit) for file &ldquo;file_name&rdquo; to verify <indexterm><primary>verify</primary></indexterm>it's integrity.<indexterm><primary>integrity</primary></indexterm> You normally use the &ldquo; md5sum -c&rdquo; <indexterm><primary>-c</primary></indexterm>option <indexterm><primary>option</primary></indexterm>to check <indexterm><primary>check</primary></indexterm>against a given file (often with a &ldquo;.asc&rdquo; extention) to check <indexterm><primary>check</primary></indexterm>whether the various files are correct,<indexterm><primary>correct</primary></indexterm> this comes in handy <indexterm><primary>handy</primary></indexterm>when downloading <indexterm><primary>downloading</primary></indexterm>isos as the checking <indexterm><primary>checking</primary></indexterm>is automated <indexterm><primary>automated</primary></indexterm>for you.</para><para>Command syntax:</para><screen><![CDATA[md5sum file_name
]]></screen></listitem></varlistentry><varlistentry><term>mkpasswd&nbsp;-l&nbsp;10
</term><listitem><para>This command will make a random <indexterm><primary>random</primary></indexterm>password of length <indexterm><primary>length</primary></indexterm>ten characters.<indexterm><primary>characters</primary></indexterm> This password <indexterm><primary>password</primary></indexterm>generator <indexterm><primary>generator</primary></indexterm>creates passwords <indexterm><primary>passwords</primary></indexterm>that are designed <indexterm><primary>designed</primary></indexterm>to be hard to guess. There are similar alternatives <indexterm><primary>alternatives</primary></indexterm>to this program scattered <indexterm><primary>scattered</primary></indexterm>around the internet.<indexterm><primary>internet</primary></indexterm></para></listitem></varlistentry></variablelist></sect1>
<sect1 id="file-permissions"><title>File Permissions</title><para>Use <emphasis> ls <indexterm><primary>ls</primary></indexterm>-l </emphasis><indexterm><primary>-l</primary></indexterm>to see the permissions of files (list-long). They will appear like this, note that I have added spaces <indexterm><primary>spaces</primary></indexterm>between permissions to make it easier to read:</para><para>Where: r <indexterm><primary>r</primary></indexterm>= read, w <indexterm><primary>w</primary></indexterm>= write,<indexterm><primary>write</primary></indexterm> x = execute <indexterm><primary>execute</primary></indexterm></para><screen>
- rwx rw- r-- 1 <co id="links"> newuser newuser
type<co id="type">owner<co id="owner">group<co id="group">others<co id="others">
</screen>
<calloutlist>
<callout arearefs="links">
<para>
This number is the number of hard links (pointers) to this file. You can use <emphasis>ln </emphasis>to create another hard-link to the file.
</para>
</callout>
<callout arearefs="type">
<para>
This is the type of file. '-' means a regular file, 'd' would mean a directory, 'l' would mean a link. There are also other types such as 'c' for character device and 'b' for block device (found in the /dev/ directory).
</para>
</callout>
<callout arearefs="owner">
<para>
These are the permissions for the owner of the file (the user who created the file).
</para>
</callout>
<callout arearefs="group">
<para>
These are the permissions for the group, any users who belong is the same group as the user who created the file will have these permissions.
</para>
</callout>
<callout arearefs="others">
<para>
These are the permissions for everyone else. Any user who is outside the group will have these permissions to the file.
</para>
</callout>
</calloutlist>
<para>The two names at the end are the username <indexterm><primary>username</primary></indexterm>and group <indexterm><primary>group</primary></indexterm>respectively.<indexterm><primary>respectively</primary></indexterm></para><variablelist><varlistentry><term>chmod
</term><listitem><para><indexterm><primary>chmod</primary></indexterm>Change <indexterm><primary>Change</primary></indexterm>file access <indexterm><primary>file access</primary></indexterm>permissions for a file(s).</para><para>There are two methods <indexterm><primary>methods</primary></indexterm>to change <indexterm><primary>change</primary></indexterm>permissions using <emphasis>chmod</emphasis>; letters <indexterm><primary>letters</primary></indexterm>or numbers.<indexterm><primary>numbers</primary></indexterm></para><variablelist><varlistentry><term>Letters&nbsp;Method:
</term><listitem><para>use a + or - (plus or minus <indexterm><primary>minus</primary></indexterm>sign) to add <indexterm><primary>add</primary></indexterm>or remove <indexterm><primary>remove</primary></indexterm>permissions for a file respectively. Use an equals <indexterm><primary>equals</primary></indexterm>sign =, to specify <indexterm><primary>specify</primary></indexterm>new <indexterm><primary>new</primary></indexterm>permissions and remove <indexterm><primary>remove</primary></indexterm>the old <indexterm><primary>old</primary></indexterm>ones for the particular <indexterm><primary>particular</primary></indexterm>type of user(s). </para><para>You can use<emphasis> chmod <indexterm><primary>chmod</primary></indexterm>letter</emphasis> where the letters <indexterm><primary>letters</primary></indexterm>are:</para><para><emphasis>a</emphasis> (all (everyone))<emphasis>, u</emphasis> (user)<emphasis>,</emphasis> <emphasis>g</emphasis> (group) and <emphasis>o</emphasis> (other).</para></listitem></varlistentry></variablelist><para>Examples:</para><screen><![CDATA[chmod u+rw somefile
]]></screen><para>This would give the user read and write <indexterm><primary>write</primary></indexterm>permission.</para><screen><![CDATA[chmod o-rwx somefile
]]></screen><para>This will remove <indexterm><primary>remove</primary></indexterm>read/write/execute permissions from other users (doesn't include <indexterm><primary>include</primary></indexterm>users within your group).</para><screen><![CDATA[chmod a+r]]><emphasis><![CDATA[ ]]></emphasis><![CDATA[somefile
]]></screen><para>This will give everyone <indexterm><primary>everyone</primary></indexterm>read permission <indexterm><primary>permission</primary></indexterm>for the file.</para><screen><![CDATA[chmod a=rx somefile
]]></screen><para>This would give everyone execute and read permission to the file, if anyone had write <indexterm><primary>write</primary></indexterm>permission it would be removed.</para><variablelist><varlistentry><term>Numbers&nbsp;Method:
</term><listitem><para>you can also use numbers <indexterm><primary>numbers</primary></indexterm>(instead of letters) to change <indexterm><primary>change</primary></indexterm>file permissions. Where:</para><para>r <indexterm><primary>r</primary></indexterm>(read) = 4 w <indexterm><primary>w</primary></indexterm>(write) = 2 x (execute) = 1 </para></listitem></varlistentry></variablelist><para>Numbers <indexterm><primary>Numbers</primary></indexterm>can be added together so you can specify read/write/execute permissions; read+write = 6, read+execute = 5, read+write+execute = 7</para><para>Examples:</para><screen><![CDATA[chmod 777 somefile
]]></screen><para>This would give everyone read/write/execute permission on &ldquo;this_file&rdquo;. The first number <indexterm><primary>number</primary></indexterm>is user, second is group <indexterm><primary>group</primary></indexterm>and third is everyone else (other).</para><screen><![CDATA[chmod 521 somefile
]]></screen><para>This would give the user read and execute <indexterm><primary>execute</primary></indexterm>permission, and the group <indexterm><primary>group</primary></indexterm>write<indexterm><primary>write</primary></indexterm> permission <indexterm><primary>permission</primary></indexterm>(but not read permission!) and everyone else execute <indexterm><primary>execute</primary></indexterm>permission. (Note that it's just an example, settings like that don't really make sense...).</para></listitem></varlistentry><varlistentry><term>chown
</term><listitem><para><indexterm><primary>chown</primary></indexterm>Changes the ownership <indexterm><primary>ownership</primary></indexterm>rights <indexterm><primary>rights</primary></indexterm>of a file (hence the name 'chown' - change owner<indexterm><primary>change owner</primary></indexterm>). This program can only be used by root. </para><para>Use the<emphasis> -R <indexterm><primary>-R</primary></indexterm></emphasis> option to change <indexterm><primary>change</primary></indexterm>things recursively,<indexterm><primary>recursively</primary></indexterm> in other words, all matching <indexterm><primary>matching</primary></indexterm>files including <indexterm><primary>including</primary></indexterm>those in subdirectories.<indexterm><primary>subdirectories</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[chown owner:group the_file_name
]]></screen></listitem></varlistentry><varlistentry><term>sticky&nbsp;bit
</term><listitem><para><indexterm><primary>bit</primary></indexterm>Only the person <indexterm><primary>person</primary></indexterm>who <indexterm><primary>who</primary></indexterm>created the file within a directory may delete<indexterm><primary>delete</primary></indexterm> it, even if other people <indexterm><primary>people</primary></indexterm>have write <indexterm><primary>write</primary></indexterm>permission. You can turn <indexterm><primary>turn</primary></indexterm>it on by typing: </para><screen><![CDATA[chmod 1700]]><emphasis><![CDATA[ ]]></emphasis><![CDATA[somedirectory (where 1 = sticky bit)
]]></screen><para>or (where <emphasis>t</emphasis> represents <indexterm><primary>represents</primary></indexterm>the sticky <indexterm><primary>sticky</primary></indexterm>bit)</para><screen><![CDATA[chmod +t somedirectory
]]></screen><para>To turn <indexterm><primary>turn</primary></indexterm>it off <indexterm><primary>off</primary></indexterm>you would need to type:</para><screen><![CDATA[chmod 0700 somefile (where the zero would mean no sticky bit)
]]></screen><para>or (where <emphasis>t </emphasis> represents <indexterm><primary>represents</primary></indexterm>the sticky <indexterm><primary>sticky</primary></indexterm>bit)</para><screen><![CDATA[chmod -t somefile]]><indexterm><primary>-t</primary></indexterm><![CDATA[
]]></screen><para>Note that the permissions <indexterm><primary>permissions</primary></indexterm>aren't relevant <indexterm><primary>relevant</primary></indexterm>in the numbers <indexterm><primary>numbers</primary></indexterm>example, only the first number (1 = on, 0 = off).</para><para>An example of a sticky <indexterm><primary>sticky</primary></indexterm>directory is usually /tmp</para></listitem></varlistentry><varlistentry><term>suid
</term><listitem><para>Allow SUID/SGID (switch user ID/switch group <indexterm><primary>group</primary></indexterm>ID) access.<indexterm><primary>access</primary></indexterm> You would normally use <emphasis>chmod</emphasis> to turn <indexterm><primary>turn</primary></indexterm>this on or off <indexterm><primary>off</primary></indexterm>for a particular file, suid <indexterm><primary>suid</primary></indexterm>is generally considered a security <indexterm><primary>security</primary></indexterm>hazard so be careful <indexterm><primary>careful</primary></indexterm>when using this. </para><para>Example:</para><screen><![CDATA[chmod u+s file_name
]]></screen><para>This will give everyone permission to execute <indexterm><primary>execute</primary></indexterm>the file with the permissions of the user who set the +s switch.<indexterm><primary>switch</primary></indexterm> </para><caution>
<title>
Security Hazard
</title>
<para>
This is obviously a security hazard. You should avoid using the suid flag unless necessary.
</para>
</caution>
</listitem></varlistentry></variablelist><para></para><variablelist><varlistentry><term>chattr
</term><listitem><para><emphasis><indexterm><primary>chattr</primary></indexterm></emphasis>Change file system attributes (works on ext2fs and possibly others...). Use the <emphasis>-R</emphasis> option to change <indexterm><primary>change</primary></indexterm>files recursively,<emphasis> chattr </emphasis>has a large number <indexterm><primary>number</primary></indexterm>of attributes <indexterm><primary>attributes</primary></indexterm>which can be set <indexterm><primary>set</primary></indexterm>on a file, read the manual<indexterm><primary>manual</primary></indexterm> page <indexterm><primary>page</primary></indexterm>for further information.</para><para>Example:</para><screen><![CDATA[chattr +i /sbin/lilo.conf]]><footnote><para>This example and tiny parts of the explanation have been taken from the <productname>Linux</productname> Online Classroom, see [4] in the <xref linkend="references"> for further information. </para></footnote><![CDATA[
]]></screen><para>This sets <indexterm><primary>sets</primary></indexterm>the 'immutable' flag <indexterm><primary>flag</primary></indexterm>on a file. Use a '+' to add <indexterm><primary>add</primary></indexterm>attributes <indexterm><primary>attributes</primary></indexterm>and a '-' to take them away. The +i will prevent <indexterm><primary>prevent</primary></indexterm>any changes (accidental or otherwise) to the &ldquo;lilo.conf&rdquo; file. If you wish to modify <indexterm><primary>modify</primary></indexterm>the lilo.conf file you will need to unset <indexterm><primary>unset</primary></indexterm>the immutable<indexterm><primary>immutable</primary></indexterm> flag:<indexterm><primary>flag</primary></indexterm><emphasis> chattr -i</emphasis>.<indexterm><primary>-i</primary></indexterm> Note some flags <indexterm><primary>flags</primary></indexterm>can only be used by root;<indexterm><primary>root</primary></indexterm> <emphasis>-i</emphasis>, <emphasis>-a</emphasis> and probably <indexterm><primary>probably</primary></indexterm>many others.</para><para>Note there are many different <indexterm><primary>different</primary></indexterm>attributes <indexterm><primary>attributes</primary></indexterm>that chattr can change,<indexterm><primary>change</primary></indexterm> here are a few more which may be useful:</para><itemizedlist><listitem><para>A<indexterm><primary>A</primary></indexterm> (no Access time) --- if a file or directory has this attribute set, whenever it is accessed,<indexterm><primary>accessed</primary></indexterm> either for reading <indexterm><primary>reading</primary></indexterm>of for writing,<indexterm><primary>writing</primary></indexterm> it's last <indexterm><primary>last</primary></indexterm>access time<indexterm><primary>access time</primary></indexterm> will not be updated.<indexterm><primary>updated</primary></indexterm> This can be useful, for example, on files or directories <indexterm><primary>directories</primary></indexterm>which are very often accessed <indexterm><primary>accessed</primary></indexterm>for reading, especially since this parameter is the only one which changes on an inode <indexterm><primary>inode</primary></indexterm>when it's opened.<indexterm><primary>opened</primary></indexterm></para></listitem><listitem><para>a<indexterm><primary>a</primary></indexterm> (append only) --- if a file has this attribute <indexterm><primary>attribute</primary></indexterm>set and is open for writing, the only operation possible will be to append <indexterm><primary>append</primary></indexterm>data <indexterm><primary>data</primary></indexterm>to it's previous contents. For a directory, this means that you can only add <indexterm><primary>add</primary></indexterm>files to it, but not rename <indexterm><primary>rename</primary></indexterm>or delete any existing <indexterm><primary>existing</primary></indexterm>file. Only root can set or clear this attribute.</para></listitem><listitem><para>s<indexterm><primary>s</primary></indexterm> (secure deletion) --- when such a file or directory with this attribute<indexterm><primary>attribute</primary></indexterm> set is deleted,<indexterm><primary>deleted</primary></indexterm> the blocks <indexterm><primary>blocks</primary></indexterm>it was occupying <indexterm><primary>occupying</primary></indexterm>on disk <indexterm><primary>disk</primary></indexterm>are written back with zeroes <indexterm><primary>zeroes</primary></indexterm>(similar to using <emphasis>shred</emphasis>). Note that this does work on the ext2,<indexterm><primary>ext2</primary></indexterm> and ext3 <indexterm><primary>ext3</primary></indexterm>filesystems but is unlikely to work on others (please see the documentation <indexterm><primary>documentation</primary></indexterm>for the filesystem <indexterm><primary>filesystem</primary></indexterm>you are using). You may also like to see <emphasis>shred</emphasis><indexterm><primary>shred</primary></indexterm>, please see <xref linkend="Working-with-the-file-system"></para></listitem></itemizedlist></listitem></varlistentry><varlistentry><term>lsattr
</term><listitem><para><indexterm><primary>lsattr</primary></indexterm>(list attributes). This will list <indexterm><primary>list</primary></indexterm>if whether a file has any special <indexterm><primary>special</primary></indexterm>attributes (as set by chattr). Use the <emphasis>-R</emphasis> option to list recursively <indexterm><primary>recursively</primary></indexterm>and try using the <emphasis>-d<indexterm><primary>-d</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to list directories <indexterm><primary>directories</primary></indexterm>like other files rather than listing <indexterm><primary>listing</primary></indexterm>their contents.<indexterm><primary>contents</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[lsattr
]]></screen><para>This will list files in the current <indexterm><primary>current</primary></indexterm>directory, you may also like to specify<indexterm><primary>specify</primary></indexterm> a directory or a file:</para><screen><![CDATA[lsattr /directory/or/file
]]></screen></listitem></varlistentry></variablelist></sect1>
</chapter>
<chapter id="Backing-up-files"><title>Archiving Files</title><para>The archiving <indexterm><primary>archiving</primary></indexterm>files chapter provides <indexterm><primary>provides</primary></indexterm>some basic <indexterm><primary>basic</primary></indexterm>information <indexterm><primary>information</primary></indexterm>on the simple programs <indexterm><primary>programs</primary></indexterm>that you can use to archive <indexterm><primary>archive</primary></indexterm>files. You will often see these programs <indexterm><primary>programs</primary></indexterm>used when you try to install <indexterm><primary>install</primary></indexterm>programs without using a package management<indexterm><primary>package management</primary></indexterm> tool.</para><note>
<title>This is not a backup guide</title>
<para>Please note that while <emphasis>tar</emphasis> is useful for regular purposes, and possibly combined with bash sciprting or similar it can become useful, it is not a great program for performing real backups of data.</para>
<para>You should try searching the internet if you are looking for backup programs on GNU/Linux or try <ulink url="http://sourceforge.net">Sourceforge</ulink><indexterm><primary>Sourceforge</primary></indexterm> or <ulink url="http://freshmeat.net">Freshmeat</ulink><indexterm><primary>Freshmeat</primary></indexterm> for programs that you can use. You may also like to see rsync<indexterm><primary>rsync</primary></indexterm>, <xref linkend="rsync">.</para>
</note>
<sect1 id="tar"><title>tar (tape archiver)</title><para>Type <emphasis>tar</emphasis> then <emphasis>-option(s)</emphasis></para><para>Options list:<indexterm><primary>list</primary></indexterm></para><itemizedlist><listitem><para>-c<indexterm><primary>-c</primary></indexterm> --- create.</para></listitem><listitem><para>-v<indexterm><primary>-v</primary></indexterm> --- verbose,<indexterm><primary>verbose</primary></indexterm> give more output,<indexterm><primary>output</primary></indexterm> show <indexterm><primary>show</primary></indexterm>what files are being worked with (extracted or added).</para></listitem><listitem><para>-f<indexterm><primary>-f</primary></indexterm> --- file (create or extract <indexterm><primary>extract</primary></indexterm>from file) - should always be the last option otherwise the command will not work. </para></listitem><listitem><para>-z<indexterm><primary>-z</primary></indexterm> --- put the file though gzip <indexterm><primary>gzip</primary></indexterm>or use gunzip <indexterm><primary>gunzip</primary></indexterm>on the file first.</para></listitem><listitem><para>-x<indexterm><primary>-x</primary></indexterm> --- extract the files from the tarball.<indexterm><primary>tarball</primary></indexterm></para></listitem><listitem><para>-p<indexterm><primary>-p</primary></indexterm> --- preserves <indexterm><primary>preserves</primary></indexterm>dates,<indexterm><primary>dates</primary></indexterm> permissions of the original <indexterm><primary>original</primary></indexterm>files.</para></listitem><listitem><para>-j<indexterm><primary>-jj</primary></indexterm> --- send <indexterm><primary>send</primary></indexterm>archive through bzip2.<indexterm><primary>bzip2</primary></indexterm></para></listitem><listitem><para>--exclude=pattern<indexterm><primary>exclude=pattern</primary></indexterm> --- this will stop <indexterm><primary>stop</primary></indexterm>certain files from being archived <indexterm><primary>archived</primary></indexterm>(using a standard wild-card<indexterm><primary>standard wild-card</primary></indexterm> pattern) or a single file name.</para></listitem></itemizedlist><variablelist><varlistentry><term>tar&nbsp;examples</term>
<listitem><para>&nbsp;</para><screen><![CDATA[tar -cvpf name_of_file.tar files_to_be_backed_up
]]></screen><para>This would create a tape <indexterm><primary>tape</primary></indexterm>archive (no compressing).</para><screen><![CDATA[tar -zxvpf my_tar_file.tar.gz
]]></screen><para>This would extract files (verbosely) from a gzipped <indexterm><primary>gzipped</primary></indexterm>tape <indexterm><primary>tape</primary></indexterm>archive.</para></listitem></varlistentry></variablelist></sect1>
<sect1 id="rsync"><title>rsync</title><para></para><variablelist><varlistentry><term>rsync
</term><listitem><para><indexterm><primary>rsync</primary></indexterm><emphasis>rsync</emphasis> is a replacement <indexterm><primary>replacement</primary></indexterm>for the old <indexterm><primary>old</primary></indexterm><emphasis>rcp<indexterm><primary>rcp</primary></indexterm></emphasis> (remote-copy) command. It can use <emphasis>ssh</emphasis> for encryption <indexterm><primary>encryption</primary></indexterm>and is a very flexible <indexterm><primary>flexible</primary></indexterm>tool, it can copy from local <indexterm><primary>local</primary></indexterm>machine<indexterm><primary>machine</primary></indexterm> to local machine, from local to remote <indexterm><primary>remote</primary></indexterm>(and vice-versa), and to and from rsync <indexterm><primary>rsync</primary></indexterm>servers.<indexterm><primary>servers</primary></indexterm> </para><para><emphasis>rsync</emphasis> uses an advanced <indexterm><primary>advanced</primary></indexterm>differencing algorithm,<indexterm><primary>algorithm</primary></indexterm> so when to copies <indexterm><primary>copies</primary></indexterm>or syncs <indexterm><primary>syncs</primary></indexterm>something it will (a) only copy new/changed files and (b) if the files have being changed it will copy the differences <indexterm><primary>differences</primary></indexterm>between the files (not the entire file). Using this method <indexterm><primary>method</primary></indexterm><emphasis>rsync</emphasis> saves <indexterm><primary>saves</primary></indexterm>time <indexterm><primary>time</primary></indexterm>and bandwidth.<indexterm><primary>bandwidth</primary></indexterm> </para><para><emphasis>rsync</emphasis> also has advanced <indexterm><primary>advanced</primary></indexterm>exclusion options <indexterm><primary>options</primary></indexterm>similar to <acronym>GNU</acronym> tar.<indexterm><primary>tar</primary></indexterm> <emphasis>rsync</emphasis> has a well written manual page,<indexterm><primary>page</primary></indexterm> for further information <indexterm><primary>information</primary></indexterm>read the <emphasis>rsync</emphasis> documentation <indexterm><primary>documentation</primary></indexterm>online or type:</para><screen><![CDATA[man rsync
]]></screen><para>If you wish to visit <indexterm><primary>visit</primary></indexterm>the rsync <indexterm><primary>rsync</primary></indexterm>site you will find <indexterm><primary>find</primary></indexterm>it over <ulink url="http://www.samba.org/rsync/">here</ulink><indexterm><primary>rsync site</primary></indexterm></para></listitem></varlistentry></variablelist></sect1>
<sect1 id="compression"><title>Compression</title><para>There are two main compression <indexterm><primary>compression</primary></indexterm>utilities <indexterm><primary>utilities</primary></indexterm>used in GNU/Linux. It's normal <indexterm><primary>normal</primary></indexterm>to first &ldquo;tar&rdquo; a bunch <indexterm><primary>bunch</primary></indexterm>of files (using the <emphasis>tar</emphasis> program of course) and then compress <indexterm><primary>compress</primary></indexterm>them with either <emphasis>bzip2</emphasis> or <emphasis>gzip</emphasis>. Of course either of these tools could be used without tar,<indexterm><primary>tar</primary></indexterm> although they are not designed <indexterm><primary>designed</primary></indexterm>to work on more <indexterm><primary>more</primary></indexterm>than one file (they use the <productname>UNIX</productname> <indexterm><primary>UNIX</primary></indexterm>tools philosophy,<indexterm><primary>philosophy</primary></indexterm> let <indexterm><primary>let</primary></indexterm><emphasis>tar</emphasis> group the files, they will do the compression...this simplifies their program). It's normal <indexterm><primary>normal</primary></indexterm>to use <emphasis>tar</emphasis> and then use these tools on them, or use <emphasis>tar</emphasis> with the correct <indexterm><primary>correct</primary></indexterm>options to use these compression <indexterm><primary>compression</primary></indexterm>programs.<indexterm><primary>programs</primary></indexterm></para><variablelist><varlistentry><term>GNU&nbsp;zip&nbsp;(gzip)
</term><listitem><para>gzip <indexterm><primary>gzip</primary></indexterm>is the <acronym>GNU</acronym> <indexterm><primary>GNU</primary></indexterm>zip <indexterm><primary>zip</primary></indexterm>compression program <indexterm><primary>program</primary></indexterm>and probably <indexterm><primary>probably</primary></indexterm>the most common <indexterm><primary>common</primary></indexterm>compression format <indexterm><primary>format</primary></indexterm>on UNIX-like <indexterm><primary>UNIX-like</primary></indexterm>operating systems.</para><screen><![CDATA[gzip your_tar_file.tar
]]></screen><para>This will compress <indexterm><primary>compress</primary></indexterm>a tar <indexterm><primary>tar</primary></indexterm>archive <indexterm><primary>archive</primary></indexterm>with <acronym>GNU</acronym> <indexterm><primary>GNU</primary></indexterm>zip,<indexterm><primary>zip</primary></indexterm> usually with a .gz <indexterm><primary>.gz</primary></indexterm>extension. Gzip <indexterm><primary>Gzip</primary></indexterm>can compress <indexterm><primary>compress</primary></indexterm>any type of file, it doesn't have to be a tar <indexterm><primary>tar</primary></indexterm>archive.</para><screen><![CDATA[gunzip your_file.gz
]]></screen><para>This will decompress <indexterm><primary>decompress</primary></indexterm>a gzipped <indexterm><primary>gzipped</primary></indexterm>file, and leave the contents <indexterm><primary>contents</primary></indexterm>in the current<indexterm><primary>current</primary></indexterm> directory.<indexterm><primary>directory</primary></indexterm></para></listitem></varlistentry><varlistentry><term>bzip2
</term><listitem><para>bzip2 <indexterm><primary>bzip2</primary></indexterm>is a newer <indexterm><primary>newer</primary></indexterm>compression program taht offers superior <indexterm><primary>superior</primary></indexterm>compression to gzip <indexterm><primary>gzip</primary></indexterm>at the cost <indexterm><primary>cost</primary></indexterm>of more processor <indexterm><primary>processor</primary></indexterm>time.</para><screen><![CDATA[bzip2 your_tar_file.tar
]]></screen><para>This will compress <indexterm><primary>compress</primary></indexterm>a tar <indexterm><primary>tar</primary></indexterm>archive with the bzip2 <indexterm><primary>bzip2</primary></indexterm>compression program, usually with a .bz <indexterm><primary>.bz</primary></indexterm>extension. bzip2 <indexterm><primary>bzip2</primary></indexterm>can compress <indexterm><primary>compress</primary></indexterm>any type of file, it doesn't have to be a tar <indexterm><primary>tar</primary></indexterm>archive. </para><screen><![CDATA[bunzip2 your_file.tar.bz2
]]></screen><para>This will decompress <indexterm><primary>decompress</primary></indexterm>a file compressed <indexterm><primary>compressed</primary></indexterm>by bzip2,<indexterm><primary>bzip2</primary></indexterm> and leave the contents<indexterm><primary>contents</primary></indexterm> in the current directory. </para></listitem></varlistentry><varlistentry><term>zipinfo
</term><listitem><para><indexterm><primary>zipinfo</primary></indexterm>Use <emphasis>zipinfo</emphasis> to find detailed <indexterm><primary>detailed</primary></indexterm>information about a zip <indexterm><primary>zip</primary></indexterm>archive (the ones usually generally used by ms-dos <indexterm><primary>ms-dos</primary></indexterm>and windows,<indexterm><primary>windows</primary></indexterm> for example winzip). </para><para>Command syntax:</para><screen><![CDATA[zipinfo zip_file.zip
]]></screen></listitem></varlistentry><varlistentry><term>zipgrep
</term><listitem><para><indexterm><primary>zipgrep</primary></indexterm>Will run <indexterm><primary>run</primary></indexterm><emphasis>grep</emphasis> to look <indexterm><primary>look</primary></indexterm>for files within a zip <indexterm><primary>zip</primary></indexterm>file (ms-dos style,<indexterm><primary>style</primary></indexterm> for example winzip) without manually <indexterm><primary>manually</primary></indexterm>decompressing the file first.</para><para>Command syntax:</para><screen><![CDATA[zipgrep pattern zip_file.zip
]]></screen></listitem></varlistentry><varlistentry><term>bzip2recover
</term><listitem><para><indexterm><primary>bzip2recover</primary></indexterm>Used to recover <indexterm><primary>recover</primary></indexterm>files from a damaged <indexterm><primary>damaged</primary></indexterm>bzip2 archive.<indexterm><primary>archive</primary></indexterm> It simply extracts out all the working blocks <indexterm><primary>blocks</primary></indexterm>as there own bzip2 <indexterm><primary>bzip2</primary></indexterm>archives,<indexterm><primary>archives</primary></indexterm> you can than use<emphasis> bzip2 -t </emphasis><indexterm><primary>-t</primary></indexterm>on each file to test <indexterm><primary>test</primary></indexterm>the integrity <indexterm><primary>integrity</primary></indexterm>of them and extract <indexterm><primary>extract</primary></indexterm>the working files.</para></listitem></varlistentry><varlistentry><term>bzme
</term><listitem><para><indexterm><primary>bzme</primary></indexterm>Will convert <indexterm><primary>convert</primary></indexterm>a file that is zipped <indexterm><primary>zipped</primary></indexterm>or gzipped <indexterm><primary>gzipped</primary></indexterm>to a file compressed<indexterm><primary>compressed</primary></indexterm> using <emphasis>bzip2</emphasis>. </para><para>Command syntax:</para><screen><![CDATA[bzme filename
]]></screen></listitem></varlistentry></variablelist><tip>
<title>Tip</title>
<para>
Both gzip and bzip2 supply tools to work within compressed files for example listing the files within the archive, running <emphasis>less</emphasis> on them, using <emphasis>grep</emphasis> to find files within the archive et cetera.
</para>
<para>
For gzip the commands are prefixed with z, <emphasis>zcat, zless, zgrep</emphasis>.
</para>
<para>
For bzip2 the commands are prefixed with bz, <emphasis>bzcat, bzless, bzgrep</emphasis>.
</para>
</tip>
</sect1>
</chapter>
<chapter id="Graphics-tools"><title>Graphics tools (command line based)</title><para>The graphics <indexterm><primary>graphics</primary></indexterm>tools chapter explains <indexterm><primary>explains</primary></indexterm>some image <indexterm><primary>image</primary></indexterm>programs <indexterm><primary>programs</primary></indexterm>that can be called from the command-line.<indexterm><primary>command-line</primary></indexterm> While I have found <indexterm><primary>found</primary></indexterm>image programs <indexterm><primary>programs</primary></indexterm>that can be used from the command-line,<indexterm><primary>command-line</primary></indexterm> zgv <indexterm><primary>zgv</primary></indexterm>is the only one I've ever heard of, I did not find them very useful. All the tools listed <indexterm><primary>listed</primary></indexterm>use the X windowing <indexterm><primary>windowing</primary></indexterm>system to work and simply run<indexterm><primary>run</primary></indexterm> from the command line (so they can be scripted/automated if necessary).</para><variablelist><varlistentry><term>montage
</term><listitem><para><indexterm><primary>montage</primary></indexterm>Creates a 'montage', an image created of many other images,<indexterm><primary>images</primary></indexterm> arranged<indexterm><primary>arranged</primary></indexterm> in a random <indexterm><primary>random</primary></indexterm>fashion. </para><para>Command syntax:</para><screen><![CDATA[montage r34.jpg r32.jpg skylines* skyline_images.miff
]]></screen><para>The above would create a &ldquo;montage&rdquo; of images (it would tile <indexterm><primary>tile</primary></indexterm>a certain number <indexterm><primary>number</primary></indexterm>of images) into a composite <indexterm><primary>composite</primary></indexterm>image called &ldquo;skyline_images.miff&rdquo;, you could always use <emphasis> display <indexterm><primary>display</primary></indexterm></emphasis>to view <indexterm><primary>view</primary></indexterm>the image. </para><note>
<title>Note</title>
<para>
Note that the images are converted to the same size (scaled) so they can be tiled together.
</para>
</note>
</listitem></varlistentry><varlistentry><term>convert
</term><listitem><para>To convert the file format <indexterm><primary>format</primary></indexterm>of an image to another image format. <emphasis>convert</emphasis> is used to change <indexterm><primary>change</primary></indexterm>a files format,<indexterm><primary>format</primary></indexterm> for example from a jpeg <indexterm><primary>jpeg</primary></indexterm>to a bitmap <indexterm><primary>bitmap</primary></indexterm>or one of many other formats.<indexterm><primary>formats</primary></indexterm><emphasis> convert </emphasis>can also manipulate <indexterm><primary>manipulate</primary></indexterm>the images as well (see the man <indexterm><primary>man</primary></indexterm>page <indexterm><primary>page</primary></indexterm>or the ImageMagick<indexterm><primary>ImageMagick</primary></indexterm> site).</para><para>Example from Jpeg <indexterm><primary>Jpeg</primary></indexterm>to PNG <indexterm><primary>PNG</primary></indexterm>format:</para><screen><![CDATA[convert JPEG: thisfile.jpg PNG: thisfile.png
]]></screen></listitem></varlistentry><varlistentry><term>import
</term><listitem><para><indexterm><primary>import</primary></indexterm>Captures screen-shots <indexterm><primary>screen-shots</primary></indexterm>from the X server <indexterm><primary>server</primary></indexterm>and saves <indexterm><primary>saves</primary></indexterm>them to a file. A screen-dump <indexterm><primary>screen-dump</primary></indexterm>of what X is doing.</para><para>Command syntax:</para><screen><![CDATA[import file_name
]]></screen></listitem></varlistentry><varlistentry><term>display
</term><listitem><para><emphasis>display</emphasis> is used to display (output) images on the screen.<indexterm><primary>screen</primary></indexterm> Once open <indexterm><primary>open</primary></indexterm>you are can also perform <indexterm><primary>perform</primary></indexterm>editing <indexterm><primary>editing</primary></indexterm>functions and are able <indexterm><primary>able</primary></indexterm>to read/write images.<indexterm><primary>images</primary></indexterm> It has various interesting options <indexterm><primary>options</primary></indexterm>such as the ability <indexterm><primary>ability</primary></indexterm>to display <indexterm><primary>display</primary></indexterm>images as a slide <indexterm><primary>slide</primary></indexterm>show <indexterm><primary>show</primary></indexterm>and the ability <indexterm><primary>ability</primary></indexterm>to capture <indexterm><primary>capture</primary></indexterm>screenshots of a single window<indexterm><primary>window</primary></indexterm> on-screen.<indexterm><primary>on-screen</primary></indexterm> </para><para>Command syntax (for displaying an image):</para><screen><![CDATA[display image_name
]]></screen><para>To display a slide <indexterm><primary>slide</primary></indexterm>show <indexterm><primary>show</primary></indexterm>of images, open <indexterm><primary>open</primary></indexterm>the images you want possibly <indexterm><primary>possibly</primary></indexterm>using a wildcard, for example:</para><screen><![CDATA[display *.jpg
]]></screen><para>And then click <indexterm><primary>click</primary></indexterm>on the image to bring up the menu <indexterm><primary>menu</primary></indexterm>and then look under the miscellaneous <indexterm><primary>miscellaneous</primary></indexterm>menu <indexterm><primary>menu</primary></indexterm>for the slide <indexterm><primary>slide</primary></indexterm>show <indexterm><primary>show</primary></indexterm>option.</para><caution>
<title>Speed Warning</title>
<para>
Be careful when opening multiple large sized images (especially on a slow machine) and putting the slide show on a small delay between image changes. Your processor will be overloaded and it will take a significant amount of time to be able to close ImageMagick.
</para>
</caution>
</listitem></varlistentry><varlistentry><term>identify
</term><listitem><para>Will identify <indexterm><primary>identify</primary></indexterm>the type of image <indexterm><primary>image</primary></indexterm>as well as it's size,<indexterm><primary>size</primary></indexterm> colour <indexterm><primary>colour</primary></indexterm>depth and various other information. Use the<emphasis> -verbose <indexterm><primary>-verbose</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to show <indexterm><primary>show</primary></indexterm>detailed <indexterm><primary>detailed</primary></indexterm>information on the particular <indexterm><primary>particular</primary></indexterm>file(s). </para><para>Command syntax:</para><screen><![CDATA[identify image_name
]]></screen></listitem></varlistentry><varlistentry><term>mogrify
</term><listitem><para><indexterm><primary>mogrify</primary></indexterm><emphasis>mogrify</emphasis> is another ImageMagick <indexterm><primary>ImageMagick</primary></indexterm>command which is used to transform <indexterm><primary>transform</primary></indexterm>images in a number of different ways, including <indexterm><primary>including</primary></indexterm>scaling,<indexterm><primary>scaling</primary></indexterm> rotation <indexterm><primary>rotation</primary></indexterm>and various other effects.<indexterm><primary>effects</primary></indexterm> This command can work on a single file or in batch.<indexterm><primary>batch</primary></indexterm></para><para>For example, to convert a large number <indexterm><primary>number</primary></indexterm>of tiff <indexterm><primary>tiff</primary></indexterm>files to jpeg <indexterm><primary>jpeg</primary></indexterm>files you could type:</para><screen><![CDATA[mogrify -format jpeg *.tiff]]><indexterm><primary>-format</primary></indexterm><![CDATA[
]]></screen><para>This command has the power <indexterm><primary>power</primary></indexterm>to do a number of things in batch <indexterm><primary>batch</primary></indexterm>including making thumbnails <indexterm><primary>thumbnails</primary></indexterm>of sets <indexterm><primary>sets</primary></indexterm>of images.</para><para>For this you could type:<footnote><para>This example has come been used from (unedited) &ldquo;CLI for noobies: import, display, mogrify&rdquo;, see [16] in the <xref linkend="references"> for further information.</para></footnote></para><screen><![CDATA[mogrify -geometry]]><indexterm><primary>-geometry</primary></indexterm><![CDATA[ 120x120 *.jpg
]]></screen></listitem></varlistentry><varlistentry><term>showrgb
</term><listitem><para><indexterm><primary>showrgb</primary></indexterm><emphasis>showrgb</emphasis> is used to uncompile <indexterm><primary>uncompile</primary></indexterm>an rgb <indexterm><primary>rgb</primary></indexterm>colour-name database.<indexterm><primary>database</primary></indexterm> The default <indexterm><primary>default</primary></indexterm>is the one that X was built <indexterm><primary>built</primary></indexterm>with. This database <indexterm><primary>database</primary></indexterm>can be used to find <indexterm><primary>find</primary></indexterm>the correct <indexterm><primary>correct</primary></indexterm>colour <indexterm><primary>colour</primary></indexterm>combination for a particular colour <indexterm><primary>colour</primary></indexterm>(well it can be used as a rough <indexterm><primary>rough</primary></indexterm>guide <indexterm><primary>guide</primary></indexterm>anyway). </para><para>To list <indexterm><primary>list</primary></indexterm>the colours <indexterm><primary>colours</primary></indexterm>from the X database,<indexterm><primary>database</primary></indexterm> simply type:</para><screen><![CDATA[showrgb
]]></screen></listitem></varlistentry></variablelist><note>
<title>Please note:</title>
<para>
All tools listed, excluding <emphasis>showrgb</emphasis> are part of the ImageMagick package. Type <emphasis>man ImageMagick </emphasis>for a full list of available commands. Or see the ImageMagick site <ulink url="http://www.imagemagick.org">ImageMagick</ulink><indexterm><primary>ImageMagick</primary></indexterm> for further information.
</para>
</note>
</chapter>
<chapter id="Working-with-MS-DOS"><title>Working with MS-DOS files</title><para>Use the mtools <indexterm><primary>mtools</primary></indexterm>programs <indexterm><primary>programs</primary></indexterm>to work with ms-dos <indexterm><primary>ms-dos</primary></indexterm>based files, execute <indexterm><primary>execute</primary></indexterm><emphasis>mtools</emphasis> for a full <indexterm><primary>full</primary></indexterm>listing <indexterm><primary>listing</primary></indexterm>of available <indexterm><primary>available</primary></indexterm>m* tools. There are a lot of files within the mtools <indexterm><primary>mtools</primary></indexterm>package <indexterm><primary>package</primary></indexterm>for working with ms-dos<indexterm><primary>ms-dos</primary></indexterm> disks,<indexterm><primary>disks</primary></indexterm> also try the info <indexterm><primary>info</primary></indexterm>documentation <indexterm><primary>documentation</primary></indexterm>of mtools <indexterm><primary>mtools</primary></indexterm>for more <indexterm><primary>more</primary></indexterm>details.<indexterm><primary>details</primary></indexterm></para><note>
<title>The use of slashes</title>
<para>
Note that with mtools commands you can use the slashes on the a: part either way (ie. backslash (windows-style) or forward slash (UNIX system style)).
</para>
</note>
<variablelist><varlistentry><term>mformat
</term><listitem><para><indexterm><primary>mformat</primary></indexterm>Formats <indexterm><primary>Formats</primary></indexterm>an unmounted <indexterm><primary>unmounted</primary></indexterm>disk as an ms-dos <indexterm><primary>ms-dos</primary></indexterm>floppy disk.<indexterm><primary>disk</primary></indexterm> Usage <indexterm><primary>Usage</primary></indexterm>is similar to the ms-dos <indexterm><primary>ms-dos</primary></indexterm>format <indexterm><primary>format</primary></indexterm>utility,<indexterm><primary>utility</primary></indexterm> to format <indexterm><primary>format</primary></indexterm>the first floppy<indexterm><primary>floppy</primary></indexterm> disk <indexterm><primary>disk</primary></indexterm>you can type:</para><screen><![CDATA[mformat a:
]]></screen></listitem></varlistentry><varlistentry><term>mcopy
</term><listitem><para><indexterm><primary>mcopy</primary></indexterm>Copies files from an ms-dos <indexterm><primary>ms-dos</primary></indexterm>disk when it's not mounted.<indexterm><primary>mounted</primary></indexterm> Similar to the ms-dos <indexterm><primary>ms-dos</primary></indexterm>copy command except it's more advanced.<indexterm><primary>advanced</primary></indexterm> </para><para>Command syntax:</para><screen><![CDATA[mcopy a:/file_or_files /destination/directory
]]></screen></listitem></varlistentry><varlistentry><term>mmount
</term><listitem><para><indexterm><primary>mmount</primary></indexterm>Mount an ms-dos <indexterm><primary>ms-dos</primary></indexterm>disk, without using the normal <indexterm><primary>normal</primary></indexterm>UNIX system mount.</para><para>For example:</para><screen><![CDATA[mmount a: /mnt/floppy
]]></screen><para>This will mount <indexterm><primary>mount</primary></indexterm>the floppy under /mnt/floppy (this option may or may not be necessary, it depends on your /etc/fstab setup).</para></listitem></varlistentry><varlistentry><term>mbadblocks
</term><listitem><para><indexterm><primary>mbadblocks</primary></indexterm>Scans <indexterm><primary>Scans</primary></indexterm>an ms-dos <indexterm><primary>ms-dos</primary></indexterm>(fat formatted <indexterm><primary>formatted</primary></indexterm>disk) for bad blocks,<indexterm><primary>blocks</primary></indexterm> it marks<indexterm><primary>marks</primary></indexterm> any unused bad blocks <indexterm><primary>blocks</primary></indexterm>as &ldquo;bad&rdquo; so they won't be used. </para><para>Example:</para><screen><![CDATA[mbadblocks a:
]]></screen></listitem></varlistentry><varlistentry><term>dosfsck
</term><listitem><para><indexterm><primary>dosfsck</primary></indexterm>This program <indexterm><primary>program</primary></indexterm>is used to check <indexterm><primary>check</primary></indexterm>and repair <indexterm><primary>repair</primary></indexterm>ms-dos based filesystems.<indexterm><primary>filesystems</primary></indexterm> Use the <emphasis>-a<indexterm><primary>-a</primary></indexterm></emphasis> option to automatically <indexterm><primary>automatically</primary></indexterm>repair <indexterm><primary>repair</primary></indexterm>the filesystem <indexterm><primary>filesystem</primary></indexterm>(ie don't ask the user questions), the <emphasis>-t<indexterm><primary>-t</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to mark <indexterm><primary>mark</primary></indexterm>un-readable <indexterm><primary>un-readable</primary></indexterm>clusters <indexterm><primary>clusters</primary></indexterm>as bad and the <emphasis>-v</emphasis> option to be more <indexterm><primary>more</primary></indexterm>verbose <indexterm><primary>verbose</primary></indexterm>(print more information).</para><para>Example:</para><screen><![CDATA[dosfsck -at /dev/fd0
]]></screen><para>This would check <indexterm><primary>check</primary></indexterm>your floppy disk <indexterm><primary>disk</primary></indexterm>for any errors <indexterm><primary>errors</primary></indexterm>(and bad sectors) and repair<indexterm><primary>repair</primary></indexterm> them automatically.<indexterm><primary>automatically</primary></indexterm></para></listitem></varlistentry></variablelist></chapter>
<chapter id="Scheduling"><title>Scheduling Commands to run in the background</title><para>There are two main tools used to perform <indexterm><primary>perform</primary></indexterm>scheduled <indexterm><primary>scheduled</primary></indexterm>tasks, <emphasis>at</emphasis> and <emphasis>cron</emphasis>. You may also like to try <ulink url="http://anacron.sourceforge.net">anacron</ulink><indexterm><primary>anacron</primary></indexterm> if your computer <indexterm><primary>computer</primary></indexterm>does not run continuously, as cron <indexterm><primary>cron</primary></indexterm>will only work if your computer is left on (anacron can catch <indexterm><primary>catch</primary></indexterm>up with the scheduled <indexterm><primary>scheduled</primary></indexterm>tasks the next time the computer is on...).</para><variablelist><varlistentry><term>at
</term><listitem><para><indexterm><primary>at</primary></indexterm>'at' executes a command once on a particular <indexterm><primary>particular</primary></indexterm>day,<indexterm><primary>day</primary></indexterm> at <indexterm><primary>at</primary></indexterm>a particular time.<indexterm><primary>time</primary></indexterm> <emphasis>at</emphasis> will add <indexterm><primary>add</primary></indexterm>a particular command to be executed.</para><para>Examples:</para><screen><![CDATA[at 21:30
]]></screen><para>You then type the commands you want executed then press <indexterm><primary>press</primary></indexterm>the end-of-file<indexterm><primary>end-of-file</primary></indexterm> key <indexterm><primary>character</primary></indexterm>(normally
<keycombo>
<keycap>CTRL</keycap>
<keycap>D</keycap>
</keycombo>
<indexterm>
<primary>CTRL-D</primary>
</indexterm>
). Also try:</para><screen><![CDATA[at now + time
]]></screen><para>This will run at the current time + the hours/mins/seconds you specify<indexterm><primary>specify</primary></indexterm> (use<emphasis> at <indexterm><primary>at</primary></indexterm>now + 1 hour <indexterm><primary>hour</primary></indexterm></emphasis>to have command(s) run in 1 hour from now...)</para><para>You can also use the <emphasis>-f<indexterm><primary>-f</primary></indexterm></emphasis> option to have at <indexterm><primary>at</primary></indexterm>execute a particular <indexterm><primary>particular</primary></indexterm>file (a shell <indexterm><primary>shell</primary></indexterm>script).</para><screen><![CDATA[at -f shell_script now + 1 hour
]]></screen><para>This would run the shell <indexterm><primary>shell</primary></indexterm>script 1 hour <indexterm><primary>hour</primary></indexterm>from now.</para></listitem></varlistentry><varlistentry><term>atq
</term><listitem><para><indexterm><primary>atq</primary></indexterm>Will list jobs currently in queue <indexterm><primary>queue</primary></indexterm>for the user who executed it, if root<indexterm><primary>root</primary></indexterm> executes at <indexterm><primary>at</primary></indexterm>it will list <indexterm><primary>list</primary></indexterm>all jobs <indexterm><primary>jobs</primary></indexterm>in queue <indexterm><primary>queue</primary></indexterm>for the at <indexterm><primary>at</primary></indexterm>daemon. Doesn't need or take any options.<indexterm><primary>options</primary></indexterm></para></listitem></varlistentry><varlistentry><term>atrm
</term><listitem><para><indexterm><primary>atrm</primary></indexterm>Will remove <indexterm><primary>remove</primary></indexterm>a job <indexterm><primary>job</primary></indexterm>from the 'at' queue.<indexterm><primary>queue</primary></indexterm></para><para>Command syntax:</para><screen><![CDATA[atrm job_no
]]></screen><para>Will delete <indexterm><primary>delete</primary></indexterm>the job <indexterm><primary>job</primary></indexterm>&ldquo;job_no&rdquo; (use <emphasis>atq</emphasis> to find out the number <indexterm><primary>number</primary></indexterm>of the job)</para></listitem></varlistentry><varlistentry><term><emphasis>cron</emphasis>
</term><listitem><para><emphasis>cron<indexterm><primary>cron</primary></indexterm></emphasis> can be used to schedule <indexterm><primary>schedule</primary></indexterm>a particular <indexterm><primary>particular</primary></indexterm>function <indexterm><primary>function</primary></indexterm>to occur every minute,<indexterm><primary>minute</primary></indexterm> hour,<indexterm><primary>hour</primary></indexterm> day,<indexterm><primary>day</primary></indexterm> week, or month.<indexterm><primary>month</primary></indexterm> </para><para>It's normal <indexterm><primary>normal</primary></indexterm>to use the crontab <indexterm><primary>crontab</primary></indexterm>to perform the editing <indexterm><primary>editing</primary></indexterm>functions as this automates <indexterm><primary>automates</primary></indexterm>the process <indexterm><primary>process</primary></indexterm>for the cron <indexterm><primary>cron</primary></indexterm>daemon <indexterm><primary>daemon</primary></indexterm>and makes it easier for normal<indexterm><primary>normal</primary></indexterm> users to use cron.<indexterm><primary>cron</primary></indexterm></para><tip>
<title>Anacron</title>
<para><emphasis>anacron</emphasis> is another tool designed for systems which are not always on, such as home computers</para>
<para>While <emphasis>cron </emphasis>will not run if the computer is off, <emphasis>anacron </emphasis>will simply run the command when the computer is next on (it catches up with things).</para>
</tip>
<para></para></listitem></varlistentry><varlistentry><term>crontab
</term><listitem><para><indexterm><primary>crontab</primary></indexterm><emphasis>crontab</emphasis> is used to edit,<indexterm><primary>edit</primary></indexterm> read and remove <indexterm><primary>remove</primary></indexterm>the files which the cron <indexterm><primary>cron</primary></indexterm>daemon <indexterm><primary>daemon</primary></indexterm>reads.<indexterm><primary>reads</primary></indexterm> </para><para>Options <indexterm><primary>Options</primary></indexterm>for crontab <indexterm><primary>crontab</primary></indexterm>(use<emphasis> crontab <indexterm><primary>crontab</primary></indexterm>-option(s)</emphasis>):</para><itemizedlist><listitem><para><emphasis>-e<indexterm><primary>-e</primary></indexterm></emphasis> --- to edit the file.</para></listitem><listitem><para><emphasis>-l<indexterm><primary>-l</primary></indexterm> </emphasis>--- to list the contents <indexterm><primary>contents</primary></indexterm>of the file.</para></listitem><listitem><para><emphasis>-u <indexterm><primary>-u</primary></indexterm>username </emphasis>--- use the <emphasis>-u</emphasis> with a username <indexterm><primary>username</primary></indexterm>argument <indexterm><primary>argument</primary></indexterm>to work with another users crontab <indexterm><primary>crontab</primary></indexterm>file.</para></listitem></itemizedlist><para>When using <emphasis> crontab -e <indexterm><primary>-e</primary></indexterm></emphasis>you have a number of fields <indexterm><primary>fields</primary></indexterm>(6) what they mean is listed <indexterm><primary>listed</primary></indexterm>below:</para><para><informaltable>
<tgroup cols="2" colsep="1" rowsep="1">
<colspec colname="col0" align="center">
<colspec colname="col1" align="center">
<tbody>
<row>
<entry align="center" valign="top"><para>Field</para></entry>
<entry align="center" valign="top"><para>Allowed Values</para></entry>
</row>
<row>
<entry align="center" valign="top"><para>minute</para></entry>
<entry align="center" valign="top"><para>0-59</para></entry>
</row>
<row>
<entry align="center" valign="top"><para>hour</para></entry>
<entry align="center" valign="top"><para>0-23</para></entry>
</row>
<row>
<entry align="center" valign="top"><para>day of month</para></entry>
<entry align="center" valign="top"><para>1-31</para></entry>
</row>
<row>
<entry align="center" valign="top"><para>month</para></entry>
<entry align="center" valign="top"><para>1-12 (or names, see below)</para></entry>
</row>
<row>
<entry align="center" valign="top"><para>day of week</para></entry>
<entry align="center" valign="top"><para>0-7 (0 or 7 is Sun, or use three letter names)</para></entry>
</row>
</tbody>
</tgroup></informaltable>
</para><para>There are also a number of shortcut <indexterm><primary>shortcut</primary></indexterm>methods for common <indexterm><primary>common</primary></indexterm>tasks, including:<indexterm><primary>including</primary></indexterm><footnote><para>This information has come from (without editing) a post on the LinuxChix techtalk mailing list, please see [16] in the <xref linkend="references"> for further information.</para></footnote></para><itemizedlist><listitem><para><emphasis>@reboot</emphasis> --- run <indexterm><primary>run</primary></indexterm>command at <indexterm><primary>at</primary></indexterm>reboot </para></listitem><listitem><para><emphasis>@yearly</emphasis> --- same as 0 0 1 1 * </para></listitem><listitem><para><emphasis>@annually</emphasis> --- same as @yearly </para></listitem><listitem><para><emphasis>@monthly</emphasis> --- same as 0 0 1 * * </para></listitem><listitem><para><emphasis>@weekly</emphasis> --- same as 0 0 * * 0 </para></listitem><listitem><para><emphasis>@daily</emphasis> --- same as 0 0 * * * </para></listitem><listitem><para><emphasis>@midnight</emphasis> --- same as @daily </para></listitem><listitem><para><emphasis>@hourly</emphasis> --- same as 0 * * * * </para></listitem></itemizedlist><para><footnote><para>This information comes from the cron manual page with small additions (no changes to original content), refer to [13] in the <xref linkend="references"> for further information.</para></footnote></para><para>Note that * (asterisk) is used to mean anything (similar to the wildcard). For example if you leave the day <indexterm><primary>day</primary></indexterm>part (the 5th place) with an asterisk<indexterm><primary>asterisk</primary></indexterm> it would mean everyday.<indexterm><primary>everyday</primary></indexterm></para><para>Lists <indexterm><primary>Lists</primary></indexterm>are allowed.<indexterm><primary>allowed</primary></indexterm> A list is a set <indexterm><primary>set</primary></indexterm>of numbers <indexterm><primary>numbers</primary></indexterm>(or ranges) separated <indexterm><primary>separated</primary></indexterm>by commas.<indexterm><primary>commas</primary></indexterm> Examples:<indexterm><primary>Examples</primary></indexterm> ``1,2,5,9'', ``0-4,8-12&rdquo;.</para><para>Step <indexterm><primary>Step</primary></indexterm>values <indexterm><primary>values</primary></indexterm>can be used in conjunction <indexterm><primary>conjunction</primary></indexterm>with ranges.<indexterm><primary>ranges</primary></indexterm> Following <indexterm><primary>Following</primary></indexterm>a range <indexterm><primary>range</primary></indexterm>with ``/&lt;number&gt;'' specifies <indexterm><primary>specifies</primary></indexterm>skips of the number's value<indexterm><primary>value</primary></indexterm> through the range. For example, ``0-23/2'' can be used in the hours <indexterm><primary>hours</primary></indexterm>field <indexterm><primary>field</primary></indexterm>to specify <indexterm><primary>specify</primary></indexterm>command execution <indexterm><primary>execution</primary></indexterm>every other hour <indexterm><primary>hour</primary></indexterm>(the alternative <indexterm><primary>alternative</primary></indexterm>in the V7 <indexterm><primary>V7</primary></indexterm>standard is ``0,2,4,6,8,10,12,14,16,18,20,22''). Steps <indexterm><primary>Steps</primary></indexterm>are also permitted <indexterm><primary>permitted</primary></indexterm>after an asterisk,<indexterm><primary>asterisk</primary></indexterm> so if you want to say ``every two hours'', just use ``*/2''.</para><para>When writing <indexterm><primary>writing</primary></indexterm>a crontab <indexterm><primary>crontab</primary></indexterm>entry <indexterm><primary>entry</primary></indexterm>you simply type in six <indexterm><primary>six</primary></indexterm>fields separated <indexterm><primary>separated</primary></indexterm>by spaces,<indexterm><primary>spaces</primary></indexterm> the first five <indexterm><primary>five</primary></indexterm>are those listed in the table <indexterm><primary>table</primary></indexterm>(using numbers <indexterm><primary>numbers</primary></indexterm>or letters <indexterm><primary>letters</primary></indexterm>and numbers <indexterm><primary>numbers</primary></indexterm>as appropriate), the 6th field <indexterm><primary>field</primary></indexterm>is the command to be executed and any options, cron <indexterm><primary>cron</primary></indexterm>will read everything <indexterm><primary>everything</primary></indexterm>up until the newline.<indexterm><primary>newline</primary></indexterm></para><para>Example:</para><screen><![CDATA[5 4 * * sun echo "run at 5 after 4 every sunday"
]]></screen><para>This would run the echo <indexterm><primary>echo</primary></indexterm>command with the string <indexterm><primary>string</primary></indexterm>shown at 4:05 every Sunday.</para></listitem></varlistentry></variablelist><para></para></chapter>
<chapter id="Miscellaneous"><title>Miscellaneous</title><para>The miscellaneous <indexterm><primary>miscellaneous</primary></indexterm>chapter contains commands that don't really fit into the other sections <indexterm><primary>sections</primary></indexterm>of this guide.</para><variablelist><varlistentry><term>renaming&nbsp;extensions
</term><listitem><para><indexterm><primary>renaming extensions</primary></indexterm>To rename <indexterm><primary>rename</primary></indexterm>all of the files in the current <indexterm><primary>current</primary></indexterm>directory<indexterm><primary>directory</primary></indexterm> with a '.htm' extension <indexterm><primary>extension</primary></indexterm>to '.html', type:</para><screen><![CDATA[$ chcase -x 's/htm/html/' '*.htm']]><indexterm><primary>-x</primary></indexterm><![CDATA[
]]></screen><para>You can get a copy <indexterm><primary>copy</primary></indexterm>of <emphasis>the chcase <indexterm><primary>chcase</primary></indexterm></emphasis> perl <indexterm><primary>perl</primary></indexterm>script<emphasis> <ulink url="http://www.blemished.net/chcase.html">here.</ulink></emphasis></para><para>For more <indexterm><primary>more</primary></indexterm>complex <indexterm><primary>complex</primary></indexterm>renaming <indexterm><primary>renaming</primary></indexterm>you should read <xref linkend="mass-rename"></para></listitem></varlistentry><varlistentry><term>rel<footnote><para>This information comes from the <productname>Linux</productname> Cookbook (without editing). See [3] in the <xref linkend="references"> for further information.</para></footnote>
</term><listitem><para>Use rel <indexterm><primary>rel</primary></indexterm>to analyze <indexterm><primary>analyze</primary></indexterm>text files for relevance <indexterm><primary>relevance</primary></indexterm>to a given set of keywords.<indexterm><primary>keywords</primary></indexterm> It outputs <indexterm><primary>outputs</primary></indexterm>the names of those files that are relevant <indexterm><primary>relevant</primary></indexterm>to the given keywords, ranked <indexterm><primary>ranked</primary></indexterm>in order <indexterm><primary>order</primary></indexterm>of relevance;<indexterm><primary>relevance</primary></indexterm> if a file does not meet the criteria,<indexterm><primary>criteria</primary></indexterm> it is not outputted in the relevance <indexterm><primary>relevance</primary></indexterm>listing.</para></listitem></varlistentry><varlistentry><term>units&nbsp;man&nbsp;page
</term><listitem><para><indexterm><primary>units man page</primary></indexterm>There is a man page, part of the <productname>Linux</productname> Programmers <indexterm><primary>Programmers</primary></indexterm>Manual called &ldquo;units&rdquo;. It displays various information <indexterm><primary>information</primary></indexterm>on the various scientific <indexterm><primary>scientific</primary></indexterm>measurements<indexterm><primary>measurements</primary></indexterm> (such as mega,<indexterm><primary>mega</primary></indexterm> giga <indexterm><primary>giga</primary></indexterm>et cetera). This manual <indexterm><primary>manual</primary></indexterm>page <indexterm><primary>page</primary></indexterm>also has a short discussion about the argument <indexterm><primary>argument</primary></indexterm>over which<indexterm><primary>which</primary></indexterm> standard <indexterm><primary>standard</primary></indexterm>should be used to measure <indexterm><primary>measure</primary></indexterm>data (ie. the kibibyte <indexterm><primary>kibibyte</primary></indexterm>vs kilobyte). </para><para>To access <indexterm><primary>access</primary></indexterm>this man page type:</para><screen><![CDATA[man 7 units
]]></screen></listitem></varlistentry><varlistentry><term>fortune
</term><listitem><para><indexterm><primary>fortune</primary></indexterm><emphasis>fortune</emphasis> is a tool which will print <indexterm><primary>print</primary></indexterm>a random,<indexterm><primary>random</primary></indexterm> hopefully interesting quote <indexterm><primary>quote</primary></indexterm>or entertaining short piece <indexterm><primary>piece</primary></indexterm>of writing.<indexterm><primary>writing</primary></indexterm> There are options <indexterm><primary>options</primary></indexterm>to customise <indexterm><primary>customise</primary></indexterm>which area the epigrams <indexterm><primary>epigrams</primary></indexterm>should come from. Just type <emphasis>fortune</emphasis> to get a random <indexterm><primary>random</primary></indexterm>epigram <indexterm><primary>epigram</primary></indexterm>from any section.<indexterm><primary>section</primary></indexterm> </para><para>Simply type:</para><screen><![CDATA[fortune
]]></screen></listitem></varlistentry></variablelist></chapter>
<chapter id="Mini-guides"><title>Mini-Guides</title><para>The mini-guides <indexterm><primary>mini-guides</primary></indexterm>chapter is a section <indexterm><primary>section</primary></indexterm>of the document <indexterm><primary>document</primary></indexterm>that describes <indexterm><primary>describes</primary></indexterm>certain concepts <indexterm><primary>concepts</primary></indexterm>in more depth <indexterm><primary>depth</primary></indexterm>than the usual command descriptions.<indexterm><primary>descriptions</primary></indexterm> The information <indexterm><primary>information</primary></indexterm>listed is fairly specific <indexterm><primary>specific</primary></indexterm>as I have tried to avoid <indexterm><primary>avoid</primary></indexterm>the duplication <indexterm><primary>duplication</primary></indexterm>of too much information that is already online.<indexterm><primary>online</primary></indexterm></para><sect1 id="RPM"><title>RPM: Redhat Package Management System</title><para></para><variablelist><varlistentry><term>Checking
</term><listitem><para><indexterm><primary>Checking</primary></indexterm> Installed <indexterm><primary>Installed</primary></indexterm>RPM's</para></listitem></varlistentry></variablelist><para>Use the <emphasis> rpm <indexterm><primary>rpm</primary></indexterm>-V<indexterm><primary>-V</primary></indexterm></emphasis> option <indexterm><primary>option</primary></indexterm>to check <indexterm><primary>check</primary></indexterm>whether or not a package <indexterm><primary>package</primary></indexterm>has been modified.<indexterm><primary>modified</primary></indexterm> </para><para>For example:</para><screen><![CDATA[rpm -V textutils
]]></screen><para>If none <indexterm><primary>none</primary></indexterm>of the files from the textutils <indexterm><primary>textutils</primary></indexterm>package <indexterm><primary>package</primary></indexterm>have changed then rpm <indexterm><primary>rpm</primary></indexterm>will exit <indexterm><primary>exit</primary></indexterm>without outputting any data.<indexterm><primary>data</primary></indexterm> If, on the other hand,<indexterm><primary>hand</primary></indexterm> the program <indexterm><primary>program</primary></indexterm>has changed, you may see something like this:</para><screen><![CDATA[U.5....T /bin/cat
]]></screen><para>This isn't as cryptic <indexterm><primary>cryptic</primary></indexterm>as it appears. The line <indexterm><primary>line</primary></indexterm>returned <indexterm><primary>returned</primary></indexterm>from <emphasis> rpm <indexterm><primary>rpm</primary></indexterm>-V<indexterm><primary>-V</primary></indexterm></emphasis> contains any number <indexterm><primary>number</primary></indexterm>of eight characters <indexterm><primary>characters</primary></indexterm>plus the full <indexterm><primary>full</primary></indexterm>path <indexterm><primary>path</primary></indexterm>to the file. Here are the characters <indexterm><primary>characters</primary></indexterm>and their meaning:<footnote><para>Note that the list under section 24.1.2 comes from the <acronym>RPM</acronym> manual page, see [11] in the <xref linkend="references"> for further details.</para></footnote></para><itemizedlist><listitem><para>S --- File size differs</para></listitem><listitem><para>M --- Mode differs (includes permissions <indexterm><primary>permissions</primary></indexterm>and file type)</para></listitem><listitem><para>5 --- MD5 <indexterm><primary>MD5</primary></indexterm>sum <indexterm><primary>sum</primary></indexterm>differs</para></listitem><listitem><para>D --- Device <indexterm><primary>Device</primary></indexterm>major/minor number mis-match<indexterm><primary>mis-match</primary></indexterm></para></listitem><listitem><para>L --- ReadLink(2) path <indexterm><primary>path</primary></indexterm>mis-match</para></listitem><listitem><para>U --- User ownership <indexterm><primary>ownership</primary></indexterm>differs</para></listitem><listitem><para>G --- Group <indexterm><primary>Group</primary></indexterm>ownership <indexterm><primary>ownership</primary></indexterm>differs</para></listitem><listitem><para>T --- mTime <indexterm><primary>mTime</primary></indexterm>differs</para></listitem></itemizedlist><tip>
<title>Mandriva<indexterm><primary>Mandriva</primary></indexterm> Users Note</title>
<para>
Mandriva <productname>Linux</productname> uses a customised version of <acronym>RPM</acronym> called urpmi<indexterm><primary>urpmi</primary></indexterm> (It consists of the urpm*<indexterm><primary>urpm*</primary></indexterm> commands, urpmi to install, urpme<indexterm><primary>urpme</primary></indexterm> to remove and urpmf<indexterm><primary>urpmf</primary></indexterm> and urpmq<indexterm><primary>urpmq</primary></indexterm> to query).
</para>
<para>
This customised version has advantages over standard RPM, including automatic-dependency solving and Debian apt-get<indexterm><primary>apt-get</primary></indexterm> style functions (ability to download programs over the internet and have all dependencies resolved automatically).
</para>
<para>
The urpm* commands are all described in detail in Mandriva's documentation and various sources online.
</para>
</tip>
</sect1>
<sect1 id="checking-the-hard-disk"><title>Checking the Hard Disk for errors</title><para>Checking <indexterm><primary>Checking</primary></indexterm>the hard disk <indexterm><primary>disk</primary></indexterm>for errors <indexterm><primary>errors</primary></indexterm>on your primary <indexterm><primary>primary</primary></indexterm>drive is very, very rarely required <indexterm><primary>required</primary></indexterm>in GNU/Linux, most checking <indexterm><primary>checking</primary></indexterm>is automated <indexterm><primary>automated</primary></indexterm>on start-up <indexterm><primary>start-up</primary></indexterm>if it is required.<indexterm><primary>required</primary></indexterm> If you do need to check <indexterm><primary>check</primary></indexterm>the hard disk for errors you will first need to unmount <indexterm><primary>unmount</primary></indexterm>it. Then use the file system checker, <emphasis>fsck</emphasis>.</para><screen><![CDATA[fsck.file_system_type
]]></screen><para>If you had an ext3 <indexterm><primary>ext3</primary></indexterm>file-system then it would be:</para><screen><![CDATA[fsck.ext3
]]></screen><tip>
<title>Also try </title>
<para>
You can also try using:
<screen>
fsck -t file_system_type<indexterm><primary>-t</primary></indexterm>
</screen>
</para>
</tip>
</sect1>
<sect1 id="duplicating-disks"><title>Duplicating disks</title><para>This simple technique <indexterm><primary>technique</primary></indexterm>shows you how you would duplicate <indexterm><primary>duplicate</primary></indexterm>floppy disks <indexterm><primary>disks</primary></indexterm>in a GNU/Linux system using dd.<indexterm><primary>dd</primary></indexterm> This technique <indexterm><primary>technique</primary></indexterm>is not as useful as it used to be but can still be used for creating an image <indexterm><primary>image</primary></indexterm>of a cd <indexterm><primary>cd</primary></indexterm>(although that is best done through the cd burning <indexterm><primary>burning</primary></indexterm>program).</para><para>This information <indexterm><primary>information</primary></indexterm>has been taken from the <productname>Linux</productname> Online Classroom,<indexterm><primary>Linux Online Classroom</primary></indexterm> see [4] in the <xref linkend="references"> for further details.<indexterm><primary>details</primary></indexterm></para><screen><![CDATA[$ dd if=/dev/fd0 of=floppy-image
]]><![CDATA[$ dd if=floppy-image of=/dev/fd0
]]></screen><para>The first dd <indexterm><primary>dd</primary></indexterm>makes an exact <indexterm><primary>exact</primary></indexterm>image of the floppy <indexterm><primary>floppy</primary></indexterm>to the file floppy-image,<indexterm><primary>floppy-image</primary></indexterm> the second one writes the image to the floppy. (The user has presumably switched <indexterm><primary>switched</primary></indexterm>the floppy before the second command. Otherwise the command pair is of doubtful usefulness).</para><para>Similar techinques <indexterm><primary>techinques</primary></indexterm>can be used when creating bootdisks,<indexterm><primary>bootdisks</primary></indexterm> you simply use dd<indexterm><primary>dd</primary></indexterm> to transfer <indexterm><primary>transfer</primary></indexterm>the image to the floppy disk.</para></sect1>
<sect1 id="wildcards"><title>Wildcards</title><para>Wildcards are useful in many ways for a GNU/Linux system and for various other uses. Commands can use wildcards <indexterm><primary>wildcards</primary></indexterm>to perform <indexterm><primary>perform</primary></indexterm>actions on more <indexterm><primary>more</primary></indexterm>than one file at a time,<indexterm><primary>time</primary></indexterm> or to find <indexterm><primary>find</primary></indexterm>part of a phrase <indexterm><primary>phrase</primary></indexterm>in a text <indexterm><primary>text</primary></indexterm>file. There are many uses for wildcards, there are two different <indexterm><primary>different</primary></indexterm>major <indexterm><primary>major</primary></indexterm>ways that wildcards are used, they are globbing <indexterm><primary>globbing</primary></indexterm>patterns/standard wildcards that are often used by the shell.<indexterm><primary>shell</primary></indexterm> The alternative <indexterm><primary>alternative</primary></indexterm>is regular expressions, popular <indexterm><primary>popular</primary></indexterm>with many other commands and popular <indexterm><primary>popular</primary></indexterm>for use with text searching <indexterm><primary>searching</primary></indexterm>and manipulation.<indexterm><primary>manipulation</primary></indexterm></para><tip>
<title> Tip </title>
<para>
If you have a file with wildcard expressions in it then you can use single quotes to stop bash expanding them or use backslashes (escape characters), or both.
</para>
<para>
For example if you wanted to create a file called 'fo*' (fo and asterisk) you would have to do it like this (note that you shouldn't create files with names like this, this is just an example):
<screen>
touch 'fo*'
</screen>
</para>
</tip>
<para>Note that parts <indexterm><primary>parts</primary></indexterm>of both subsections <indexterm><primary>subsections</primary></indexterm>on wildcards are based (at least <indexterm><primary>least</primary></indexterm>in part) off <indexterm><primary>off</primary></indexterm>the grep <indexterm><primary>grep</primary></indexterm>manual <indexterm><primary>manual</primary></indexterm>and info <indexterm><primary>info</primary></indexterm>pages. Please see the <xref linkend="references"> for further information.</para><sect2 id="standard-wildcards"><title>Standard Wildcards (globbing patterns)</title><para>Standard wildcards<indexterm><primary>standard wildcards</primary></indexterm> (also known as globbing patterns<indexterm><primary>globbing patterns</primary></indexterm>) are used by various command-line utilities <indexterm><primary>utilities</primary></indexterm>to work with multiple <indexterm><primary>multiple</primary></indexterm>files. For more information on standard wildcards (globbing patterns) refer <indexterm><primary>refer</primary></indexterm>to the manual page <indexterm><primary>page</primary></indexterm>by typing:</para><screen><![CDATA[man 7 glob
]]></screen><note>
<title>Can be used by</title>
<para>
Standard wildcards are used by nearly any command (including mv, cp, rm and many others).
</para>
</note>
<variablelist><varlistentry><term>?&nbsp;(question&nbsp;mark)<indexterm><primary>?</primary></indexterm>
</term><listitem><para>this can represent <indexterm><primary>represent</primary></indexterm>any <emphasis>single </emphasis>character. If you specified <indexterm><primary>specified</primary></indexterm>something at the command line like &quot;hd?&quot; GNU/Linux would look <indexterm><primary>look</primary></indexterm>for hda,<indexterm><primary>hda</primary></indexterm> hdb,<indexterm><primary>hdb</primary></indexterm> hdc <indexterm><primary>hdc</primary></indexterm>and every other letter/number between a-z,<indexterm><primary>a-z</primary></indexterm> 0-9.</para></listitem></varlistentry><varlistentry><term>*&nbsp;(asterisk)<indexterm><primary>*</primary></indexterm>
</term><listitem><para>this can represent <indexterm><primary>represent</primary></indexterm>any number of characters <indexterm><primary>characters</primary></indexterm>(including zero,<indexterm><primary>zero</primary></indexterm> in other words, zero <indexterm><primary>zero</primary></indexterm>or more characters). If you specified <indexterm><primary>specified</primary></indexterm>a &quot;cd*&quot; it would use &quot;cda&quot;, &quot;cdrom&quot;<indexterm><primary>cdrom</primary></indexterm>, &quot;cdrecord&quot;<indexterm><primary>cdrecord</primary></indexterm> and <emphasis>anything</emphasis> that starts <indexterm><primary>starts</primary></indexterm>with &ldquo;cd&rdquo; also including <indexterm><primary>including</primary></indexterm>&ldquo;cd&rdquo; itself. &quot;m*l&quot; could by mill, mull,<indexterm><primary>mull</primary></indexterm> ml, and anything that starts with an m and ends<indexterm><primary>ends</primary></indexterm> with an l.</para></listitem></varlistentry><varlistentry><term>[&nbsp;]&nbsp;(square&nbsp;brackets)<indexterm><primary>[ ]</primary></indexterm>
</term><listitem><para>specifies <indexterm><primary>specifies</primary></indexterm>a range.<indexterm><primary>range</primary></indexterm> If you did m[a,o,u]m it can become: mam, mum,<indexterm><primary>mum</primary></indexterm> mom <indexterm><primary>mom</primary></indexterm>if you did: m[a-d]m it can become anything that starts and ends <indexterm><primary>ends</primary></indexterm>with m and has any character <indexterm><primary>character</primary></indexterm>a to d inbetween. For example, these would work: mam, mbm,<indexterm><primary>mbm</primary></indexterm> mcm,<indexterm><primary>mcm</primary></indexterm> mdm.<indexterm><primary>mdm</primary></indexterm> This kind of wildcard specifies <indexterm><primary>specifies</primary></indexterm>an &ldquo;or&rdquo; relationship <indexterm><primary>relationship</primary></indexterm>(you only need one to match).</para></listitem></varlistentry><varlistentry><term>{&nbsp;}&nbsp;(curly&nbsp;brackets)<indexterm><primary>{ }</primary></indexterm>
</term><listitem><para>terms <indexterm><primary>terms</primary></indexterm>are separated <indexterm><primary>separated</primary></indexterm>by commas <indexterm><primary>commas</primary></indexterm>and each term <indexterm><primary>term</primary></indexterm>must be the name of something or a wildcard. This wildcard will copy anything that matches either wildcard(s), or exact<indexterm><primary>exact</primary></indexterm> name(s) (an &ldquo;or&rdquo; relationship,<indexterm><primary>relationship</primary></indexterm> one or the other).</para><para>For example, this would be valid:<indexterm><primary>valid</primary></indexterm></para><screen><![CDATA[cp {*.doc,*.pdf} ~
]]></screen><para>This will copy anything ending <indexterm><primary>ending</primary></indexterm>with .doc <indexterm><primary>.doc</primary></indexterm>or .pdf <indexterm><primary>.pdf</primary></indexterm>to the users home <indexterm><primary>home</primary></indexterm>directory.<indexterm><primary>directory</primary></indexterm> Note that spaces <indexterm><primary>spaces</primary></indexterm>are not allowed <indexterm><primary>allowed</primary></indexterm>after the commas <indexterm><primary>commas</primary></indexterm>(or anywhere else).</para></listitem></varlistentry><varlistentry><term>[!]
</term><listitem><para><indexterm><primary>[!]</primary></indexterm>This construct is similar to the [&nbsp;] construct, except rather than matching <indexterm><primary>matching</primary></indexterm>any characters <indexterm><primary>characters</primary></indexterm>inside <indexterm><primary>inside</primary></indexterm>the brackets,<indexterm><primary>brackets</primary></indexterm> it'll match <indexterm><primary>match</primary></indexterm>any character,<indexterm><primary>character</primary></indexterm> as long <indexterm><primary>long</primary></indexterm>as it is not listed <indexterm><primary>listed</primary></indexterm>between the [ and ]. This is a logical <indexterm><primary>logical</primary></indexterm>NOT.<indexterm><primary>NOT</primary></indexterm> For example<emphasis> rm <indexterm><primary>rm</primary></indexterm>myfile[!9]</emphasis> will remove <indexterm><primary>remove</primary></indexterm>all myfiles* (ie. myfiles1,<indexterm><primary>myfiles1</primary></indexterm> myfiles2 <indexterm><primary>myfiles2</primary></indexterm>etc) but won't remove <indexterm><primary>remove</primary></indexterm>a file with the number 9 anywhere within it's name.</para></listitem></varlistentry><varlistentry><term>\&nbsp;(backslash)<indexterm><primary>\</primary></indexterm>
</term><listitem><para>is used as an &quot;escape&quot; character,<indexterm><primary>escape character</primary></indexterm> i.e. to protect <indexterm><primary>protect</primary></indexterm>a subsequent <indexterm><primary>subsequent</primary></indexterm>special character.<indexterm><primary>special character</primary></indexterm> Thus, &quot;\\&rdquo; searches <indexterm><primary>searches</primary></indexterm>for a backslash.<indexterm><primary>backslash</primary></indexterm> Note you may need to use quotation <indexterm><primary>quotation</primary></indexterm>marks and backslash(es).</para></listitem></varlistentry></variablelist></sect2>
<sect2 id="regular-expressions"><title>Regular Expressions</title><para>Regular expressions are a type of globbing pattern <indexterm><primary>globbing pattern</primary></indexterm>used when working with text. They are used for any form <indexterm><primary>form</primary></indexterm>of manipulation <indexterm><primary>manipulation</primary></indexterm>of multiple <indexterm><primary>multiple</primary></indexterm>parts <indexterm><primary>parts</primary></indexterm>of text <indexterm><primary>text</primary></indexterm>and by various programming <indexterm><primary>programming</primary></indexterm>languages that work with text. For more information <indexterm><primary>information</primary></indexterm>on regular expressions refer <indexterm><primary>refer</primary></indexterm>to the manual page or try an online tutorial, for example IBM Developerworks<indexterm><primary>IBM Developerworks</primary></indexterm> <ulink url="https://www6.software.ibm.com/developerworks/education/l-regexp/index.html">using regular expressions</ulink>. For the manual <indexterm><primary>manual</primary></indexterm>page <indexterm><primary>page</primary></indexterm>type:</para><para>Type:</para><screen><![CDATA[man 7 regex
]]></screen><note>
<title>Regular expressions can be used by</title>
<para>
Regular Expressions are used by <emphasis>grep</emphasis> (and can be used) by <emphasis>find </emphasis>and many other programs.
</para>
</note>
<tip>
<title>Tip</title>
<para>If your regular expressions don't seem to be working then you probably need to use single quotation marks over the sentence and then use backslashes on every single special character.
</para>
</tip>
<variablelist><varlistentry><term>.&nbsp;(dot)<indexterm><primary>.</primary></indexterm>
</term><listitem><para>will match <indexterm><primary>match</primary></indexterm><emphasis>any single character</emphasis>, equivalent <indexterm><primary>equivalent</primary></indexterm>to ? (question mark) in standard wildcard<indexterm><primary>standard wildcard</primary></indexterm> expressions.<indexterm><primary>expressions</primary></indexterm> Thus, &quot;m.a&quot; matches &quot;mpa&quot; and &quot;mea&quot; but not &quot;ma&quot; or &quot;mppa&quot;. </para></listitem></varlistentry><varlistentry><term>\&nbsp;(backslash)<indexterm><primary>\</primary></indexterm>
</term><listitem><para>is used as an &quot;escape&quot; character,<indexterm><primary>escape character</primary></indexterm> i.e. to protect <indexterm><primary>protect</primary></indexterm>a subsequent <indexterm><primary>subsequent</primary></indexterm>special character.<indexterm><primary>specialcharacter</primary></indexterm> Thus, &quot;\\&quot; searches <indexterm><primary>searches</primary></indexterm>for a backslash.<indexterm><primary>backslash</primary></indexterm> Note you may need to use quotation <indexterm><primary>quotation</primary></indexterm>marks and backslash(es).</para></listitem></varlistentry><varlistentry><term>.*&nbsp;(dot&nbsp;and&nbsp;asterisk)<indexterm><primary>.*</primary></indexterm>
</term><listitem><para>is used to match <indexterm><primary>match</primary></indexterm>any string,<indexterm><primary>string</primary></indexterm> equivalent <indexterm><primary>equivalent</primary></indexterm>to * in standard wildcards.</para></listitem></varlistentry><varlistentry><term>*&nbsp;(asterisk)<indexterm><primary>*</primary></indexterm>
</term><listitem><para>the proceeding <indexterm><primary>proceeding</primary></indexterm>item is to be matched <indexterm><primary>matched</primary></indexterm><emphasis> zero <indexterm><primary>zero</primary></indexterm>or more<indexterm><primary>more</primary></indexterm></emphasis> times.<indexterm><primary>times</primary></indexterm> ie. n* will match <indexterm><primary>match</primary></indexterm>n, nn,<indexterm><primary>nn</primary></indexterm> nnnn,<indexterm><primary>nnnn</primary></indexterm> nnnnnnn <indexterm><primary>nnnnnnn</primary></indexterm>but not na or any other character.<indexterm><primary>character</primary></indexterm></para></listitem></varlistentry><varlistentry><term>^&nbsp;(caret)<indexterm><primary>^</primary></indexterm>
</term><listitem><para>means &quot;the beginning <indexterm><primary>beginning</primary></indexterm>of the line&quot;. So &quot;^a&quot; means find a line <indexterm><primary>line</primary></indexterm>starting <indexterm><primary>starting</primary></indexterm>with an &quot;a&quot;.</para></listitem></varlistentry><varlistentry><term>$&nbsp;(dollar&nbsp;sign)<indexterm><primary>$</primary></indexterm>
</term><listitem><para>means &quot;the end <indexterm><primary>end</primary></indexterm>of the line&quot;. So &quot;a$&quot; means find a line ending with an &quot;a&quot;.</para><para>For example, this command searches <indexterm><primary>searches</primary></indexterm>the file myfile <indexterm><primary>myfile</primary></indexterm>for lines <indexterm><primary>lines</primary></indexterm>starting with an &quot;s&quot; and ending <indexterm><primary>ending</primary></indexterm>with an &quot;n&quot;, and prints <indexterm><primary>prints</primary></indexterm>them to the standard output <indexterm><primary>standard output</primary></indexterm>(screen):</para><screen><![CDATA[cat myfile | grep '^s.*n$'
]]></screen></listitem></varlistentry><varlistentry><term>[&nbsp;]&nbsp;(square&nbsp;brackets)<indexterm><primary>[ ]</primary></indexterm>
</term><listitem><para>specifies <indexterm><primary>specifies</primary></indexterm>a range.<indexterm><primary>range</primary></indexterm> If you did m[a,o,u]m it can become: mam, mum,<indexterm><primary>mum</primary></indexterm> mom <indexterm><primary>mom</primary></indexterm>if you did: m[a-d]m it can become anything that starts <indexterm><primary>starts</primary></indexterm>and ends <indexterm><primary>ends</primary></indexterm>with m and has any character <indexterm><primary>character</primary></indexterm>a to d inbetween. For example, these would work: mam, mbm,<indexterm><primary>mbm</primary></indexterm> mcm,<indexterm><primary>mcm</primary></indexterm> mdm.<indexterm><primary>mdm</primary></indexterm> This kind of wildcard specifies <indexterm><primary>specifies</primary></indexterm>an &ldquo;or&rdquo; relationship <indexterm><primary>relationship</primary></indexterm>(you only need one to match).</para></listitem></varlistentry><varlistentry><term>|
</term><listitem><para><indexterm><primary>|</primary></indexterm>This wildcard <indexterm><primary>wildcard</primary></indexterm>makes a logical <indexterm><primary>logical</primary></indexterm>OR <indexterm><primary>OR</primary></indexterm>relationship <indexterm><primary>relationship</primary></indexterm>between wildcards.<indexterm><primary>wildcards</primary></indexterm> This way you can search <indexterm><primary>search</primary></indexterm>for something or something else (possibly using two different regular expressions). You may need to add <indexterm><primary>add</primary></indexterm>a '\' (backslash) before this command to work, because the shell may attempt<indexterm><primary>attempt</primary></indexterm> to interpret <indexterm><primary>interpret</primary></indexterm>this as a pipe.<indexterm><primary>pipe</primary></indexterm></para></listitem></varlistentry><varlistentry><term>[^]
</term><listitem><para><indexterm><primary>[^]</primary></indexterm>This is the equivalent <indexterm><primary>equivalent</primary></indexterm>of [!]<indexterm><primary>[!]</primary></indexterm> in standard wildcards.<indexterm><primary>standard wildcards</primary></indexterm> This performs <indexterm><primary>performs</primary></indexterm>a logical <indexterm><primary>logical</primary></indexterm>&ldquo;not&rdquo;. This will match <indexterm><primary>match</primary></indexterm>anything that is not listed within those square <indexterm><primary>square</primary></indexterm>brackets. For example,<emphasis> rm <indexterm><primary>rm</primary></indexterm>myfile[^9]</emphasis> will remove <indexterm><primary>remove</primary></indexterm>all myfiles* (ie. myfiles1,<indexterm><primary>myfiles1</primary></indexterm> myfiles2 <indexterm><primary>myfiles2</primary></indexterm>etc) but won't remove <indexterm><primary>remove</primary></indexterm>a file with the number <indexterm><primary>number</primary></indexterm>9 anywhere within it's name.</para></listitem></varlistentry></variablelist></sect2>
<sect2 id="useful-posix-characters"><title>Useful&nbsp;categories&nbsp;of&nbsp;characters&nbsp;(as&nbsp;defined&nbsp;by&nbsp;the&nbsp;POSIX&nbsp;standard)</title><para>This information has been taken from the grep <indexterm><primary>grep</primary></indexterm>info <indexterm><primary>info</primary></indexterm>page <indexterm><primary>page</primary></indexterm>with a tiny <indexterm><primary>tiny</primary></indexterm>amount<indexterm><primary>amount</primary></indexterm> of editing,<indexterm><primary>editing</primary></indexterm> see [10] in the <xref linkend="references"> for further information.</para><itemizedlist><listitem><para>[:upper:] uppercase <indexterm><primary>uppercase</primary></indexterm>letters</para></listitem><listitem><para>[:lower:] lowercase <indexterm><primary>lowercase</primary></indexterm>letters </para></listitem><listitem><para>[:alpha:] alphabetic <indexterm><primary>alphabetic</primary></indexterm>(letters) meaning upper+lower (both uppercase and lowercase letters)</para></listitem><listitem><para>[:digit:] numbers <indexterm><primary>numbers</primary></indexterm>in decimal,<indexterm><primary>decimal</primary></indexterm> 0 to 9 </para></listitem><listitem><para>[:alnum:] alphanumeric <indexterm><primary>alphanumeric</primary></indexterm>meaning alpha+digits (any uppercase or lowercase letters <indexterm><primary>letters</primary></indexterm>or any decimal <indexterm><primary>decimal</primary></indexterm>digits)</para></listitem><listitem><para>[:space:] whitespace <indexterm><primary>whitespace</primary></indexterm>meaning spaces,<indexterm><primary>spaces</primary></indexterm> tabs,<indexterm><primary>tabs</primary></indexterm> newlines <indexterm><primary>newlines</primary></indexterm>and similar</para></listitem><listitem><para>[:graph:] graphically printable <indexterm><primary>graphically printable</primary></indexterm>characters excluding <indexterm><primary>excluding</primary></indexterm>space</para></listitem><listitem><para>[:print:] printable <indexterm><primary>printable</primary></indexterm>characters including <indexterm><primary>including</primary></indexterm>space<indexterm><primary>space</primary></indexterm></para></listitem><listitem><para>[:punct:] punctuation <indexterm><primary>punctuation</primary></indexterm>characters meaning graphical <indexterm><primary>graphical</primary></indexterm>characters minus <indexterm><primary>minus</primary></indexterm>alpha<indexterm><primary>alpha</primary></indexterm> and digits<indexterm><primary>digits</primary></indexterm></para></listitem><listitem><para>[:cntrl:] control <indexterm><primary>control</primary></indexterm>characters meaning non-printable characters<indexterm><primary>characters</primary></indexterm></para></listitem><listitem><para>[:xdigit:] characters <indexterm><primary>characters</primary></indexterm>that are hexadecimal <indexterm><primary>hexadecimal</primary></indexterm>digits. </para></listitem></itemizedlist><note>
<title>These are used with</title>
<para>
The above commands will work with most tools which work with text (for example: <emphasis>tr</emphasis>).
</para>
</note>
<para>For example (advanced example)<emphasis>,</emphasis> this command scans <indexterm><primary>scans</primary></indexterm>the output <indexterm><primary>output</primary></indexterm>of the dir <indexterm><primary>dir</primary></indexterm>command, and prints <indexterm><primary>prints</primary></indexterm>lines <indexterm><primary>lines</primary></indexterm>containing a capital <indexterm><primary>capital</primary></indexterm>letter followed <indexterm><primary>followed</primary></indexterm>by a digit:<indexterm><primary>digit</primary></indexterm> </para><screen><![CDATA[ls -l | grep '[[:upper:]][[:digit:]]'
]]></screen><para>The command greps for [upper_case_letter][any_digit], meaning any uppercase<indexterm><primary>uppercase</primary></indexterm> letter <indexterm><primary>letter</primary></indexterm>followed by any digit.<indexterm><primary>digit</primary></indexterm> If you remove the [&nbsp;] (square brackets) in the middle <indexterm><primary>middle</primary></indexterm>it would look for an uppercase letter or a digit, because it would become [upper_case_letter&nbsp;any_digit]</para></sect2>
</sect1>
</chapter>
&appendix;
&bibliography;
&index;
</book>