ACC SHELL

Path : /usr/share/doc/manual/opensuse-manuals_en/manual/
File Upload :
Current File : //usr/share/doc/manual/opensuse-manuals_en/manual/cha.new.bash.html

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 7. Shell Basics</title><link rel="stylesheet" href="susebooks.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><link rel="home" href="index.html" title="Documentation"><link rel="up" href="part.basics.html" title="Part II. Basics"><link rel="prev" href="cha.new.html" title="Chapter 6. Basic Concepts"><link rel="next" href="part.trouble.html" title="Part III. Help and Troubleshooting"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header" border="0" class="bctable"><tr><td width="80%"><div class="breadcrumbs"><p><a href="index.html"> Documentation</a><span class="breadcrumbs-sep"> &gt; </span><a href="book.opensuse.startup.html">Start-Up</a><span class="breadcrumbs-sep"> &gt; </span><a href="part.basics.html">Basics</a><span class="breadcrumbs-sep"> &gt; </span><strong><a accesskey="p" title="Chapter 6. Basic Concepts" href="cha.new.html"><span>&#9664;</span></a> </strong></p></div></td></tr></table></div><div class="chapter" title="Chapter 7. Shell Basics"><div class="titlepage"><div><div><h2 class="title"><a name="cha.new.bash"></a>Chapter 7. Shell Basics<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#cha.new.bash">¶</a></span></h2></div></div></div><div class="toc"><p><b>Contents</b></p><dl><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.start">7.1. Starting a Shell</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.commands">7.2. Entering Commands</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.fildir">7.3. Working with Files and Directories</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.root">7.4. Becoming Root</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.perm">7.5. Modifying File Permissions</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.feat">7.6. Useful Features of the Shell</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.edit">7.7. Editing Texts</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.search">7.8. Searching for Files or Contents</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.view">7.9. Viewing Text Files</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.redir">7.10. Redirection and Pipes</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.new.bash.jobs">7.11. Starting Programs and Handling Processes</a></span></dt><dt><span class="sect1"><a href="cha.new.bash.html#sec.shell.commands">7.12. Important Linux Commands</a></span></dt></dl></div><a class="indexterm" name="id358290"></a><p>
  When working with Linux these days, you can communicate with the system
  almost without ever requiring a command line interpreter (the shell).
  After booting your Linux system, you are usually directed to a graphical
  user interface that guides you through the login process and the following
  interactions with the operating system. The graphical user interface in
  Linux (the X Window System or X11) is initially configured during
  installation. Both KDE and GNOME desktop (and other window managers you
  can install) use it for interaction with the user.
 </p><p>
  Nevertheless, it is useful to have some basic knowledge of working with a
  shell because you might encounter situations where the graphical user
  interface is not available. For example, if some problem with the X Window
  System occurs. If you are not familiar with a shell, you might feel a bit
  uncomfortable at first when entering commands, but the more you get used
  to it, the more you will realize that the command line is often the
  quickest and easiest way to perform some daily tasks.
 </p><p>
  For UNIX or Linux several shells are available which differ slightly in
  behavior and in the commands they accept. The default shell in
  openSUSE® is Bash (GNU Bourne-Again Shell).
 </p><p>
  The following sections will guide you through your first steps with the
  Bash shell and will show you how to complete some basic tasks via the
  command line. If you are interested in learning more or rather feel like a
  shell <span class="quote">&#8220;<span class="quote">power user</span>&#8221;</span> already, refer to
  Chapter <i>Bash and Bash Scripts</i> (&#8593;Reference).
 </p><div class="sect1" title="7.1. Starting a Shell"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.start"></a>7.1. Starting a Shell<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.start">¶</a></span></h2></div></div></div><a class="indexterm" name="id358345"></a><p>
   Basically, there are two different ways to start a shell from the
   graphical user interface which usually shows after you have booted your
   computer:
  </p><div class="itemizedlist"><ul class="itemizedlist" type="bullet"><li class="listitem" style="list-style-type: disc"><p>
     you can leave the graphical user interface or
    </p></li><li class="listitem" style="list-style-type: disc"><p>
     you can start a terminal window <span class="emphasis"><em>within</em></span> the
     graphical user interface.
    </p></li></ul></div><p>
   While the first option is always available, you can only make use of the
   second option when you are already logged in to a desktop such as KDE or
   GNOME. Whichever way you choose, there is always a way back and you can
   switch back and forth between the shell and the graphical user interface.
  </p><p>
   If you want to give it a try, press <span class="keycap">Ctrl</span>+<span class="keycap">Alt</span>+<span class="keycap">F2</span> to leave the graphical user interface. The graphical user
   interface disappears and you are taken to a shell which prompts you to
   log in. Type your username and press <span class="keycap">Enter</span>. Then
   type your password and press <span class="keycap">Enter</span>. The prompt now
   changes and shows some useful information as in the following example:
  </p><pre class="screen"> <a name="co.prompt.user"></a><img src="callouts/1.png" alt="1" border="0">   <a name="co.prompt.hostname"></a><img src="callouts/2.png" alt="2" border="0">   <a name="co.prompt.path"></a><img src="callouts/3.png" alt="3" border="0">
tux@linux:~&gt;</pre><a class="indexterm" name="id358446"></a><div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><p><a href="#co.prompt.user"><img src="callouts/1.png" alt="1" border="0"></a> </p></td><td valign="top" align="left"><p>
     Your login.
    </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.prompt.hostname"><img src="callouts/2.png" alt="2" border="0"></a> </p></td><td valign="top" align="left"><p>
     The hostname of your computer.
    </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.prompt.path"><img src="callouts/3.png" alt="3" border="0"></a> </p></td><td valign="top" align="left"><p>
     Path to the current directory. Directly after login, the current
     directory usually is your home directory, indicated by the
     <code class="literal">~</code> symbol (tilde) .
    </p></td></tr></table></div><p>
   When you are logged in at a remote computer the information provided by
   the prompt always shows you which system you are currently working on.
  </p><p>
   <a class="indexterm" name="id358502"></a> When the cursor is located behind this prompt, you can pass
   commands directly to your computer system. For example, you can now enter
   <span class="command"><strong>ls <code class="option">-l</code></strong></span> to list the contents of the
   current directory in a detailed format. If this is enough for your first
   encounter with the shell and you want to go back to the graphical user
   interface, you should log out from your shell session first. To do so,
   type <span class="command"><strong>exit</strong></span> and press <span class="keycap">Enter</span>.
   Then press <span class="keycap">Alt</span>+<span class="keycap">F7</span> to switch back to the graphical user interface. You will find
   your desktop and the applications running on it unchanged.
  </p><p>
   When you are already logged in to the GNOME or the KDE desktop and want
   to start a terminal window within the desktop, press <span class="keycap">Alt</span>+<span class="keycap">F2</span> and enter
   <span class="command"><strong>konsole</strong></span> (for KDE) or <span class="command"><strong>gnome-terminal</strong></span>
   (for GNOME). This opens a terminal window on your desktop. As you are
   already logged in to your desktop, the prompt shows information about
   your system as described above. You can now enter commands and execute
   tasks just like in any shell which runs parallel to your desktop. To
   switch to another application on the desktop just click on the
   corresponding application window or select it from the taskbar of your
   panel. To close the terminal window press <span class="keycap">Alt</span>+<span class="keycap">F4</span>.
  </p></div><div class="sect1" title="7.2. Entering Commands"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.commands"></a>7.2. Entering Commands<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.commands">¶</a></span></h2></div></div></div><a class="indexterm" name="id358591"></a><p>
   As soon as the prompt appears on the shell it is ready to receive and
   execute commands. A command can consist of several elements. The first
   element is the actual command, followed by parameters or options. You can
   type a command and edit it by using the following keys:
   <span class="keycap">&#8592;</span>, <span class="keycap">&#8594;</span>,
   <span class="keycap">Home</span>, <span class="keycap">End</span>,
   <span class="keycap">&lt;&#8212;</span> (Backspace), <span class="keycap">Del</span>,
   and <span class="keycap">Space</span>. You can correct typing errors or add
   options. The command is not executed until you press
   <span class="keycap">Enter</span>.
  </p><div class="important"><table border="0" cellpadding="3" cellspacing="0" width="100%" summary="Important: No News Is Good News"><tr class="head"><td width="32"><img alt="[Important]" src="admon/important.png"></td><th align="left">No News Is Good News</th></tr><tr><td colspan="2" align="left" valign="top"><p>
    The shell is not verbose: in contrast to some graphical user interfaces,
    it usually does not provide confirmation messages when commands have
    been executed. Messages only appear in case of problems or errors
    &#8212;or if you explicitly ask for them by executing a command with a
    certain option.
   </p><p>
    Also keep this in mind for commands to delete objects. Before entering a
    command like <span class="command"><strong>rm</strong></span> (without any option) for removing a
    file, you should know if you really want to get rid of the object: it
    will be deleted irretrievably, without confirmation.
   </p></td></tr></table></div><div class="sect2" title="7.2.1. Using Commands without Options"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.commands.simple"></a>7.2.1. Using Commands without Options<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.commands.simple">¶</a></span></h3></div></div></div><p>
    In <a class="xref" href="cha.new.html#sec.new.users.accperm.ugo" title="6.3.1. Permissions for User, Group and Others">Section 6.3.1, &#8220;Permissions for User, Group and Others&#8221;</a> you already got to know
    one of the most basic commands: <span class="command"><strong>ls</strong></span>, <a class="indexterm" name="id358689"></a> which used to list the contents of a directory. This
    command can be used with or without options. Entering the plain
    <span class="command"><strong>ls</strong></span> command shows the contents of the current
    directory:
   </p><pre class="screen">tux@knox:~&gt; ls
bin Desktop Documents public_html tux.txt
tux@knox:~&gt;</pre><p>
    As you already learned in <a class="xref" href="cha.new.html#sec.new.fs.concept" title="6.2.1. Key Features">Section 6.2.1, &#8220;Key Features&#8221;</a> files in
    Linux may have a file extension or a suffix, such as
    <code class="literal">.txt</code>, but do not need to have one. This makes it
    difficult to differentiate between files and folders in this output of
    the <span class="command"><strong>ls</strong></span>. By default, the colors in the Bash shell give
    you a hint: directories are usually shown in blue, files in black.
   </p></div><div class="sect2" title="7.2.2. Using Commands with Options"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.commands.options"></a>7.2.2. Using Commands with Options<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.commands.options">¶</a></span></h3></div></div></div><p>
    <a class="indexterm" name="id358739"></a> A better way to get more details about the contents of a
    directory is using the <span class="command"><strong>ls</strong></span> command with a string of
    options. Options modify the way a command works so that you can get it
    to carry out specific tasks. Options are separated from the command with
    a blank and are usually prefixed with a hyphen. The <span class="command"><strong>ls
    <code class="option">-l</code></strong></span> command shows the contents of the same
    directory in full detail (long listing format):
   </p><pre class="screen">tux@knox:~&gt; ls -l
drwxr-xr-x 1 tux users     48 2006-06-23 16:08 bin
drwx---r-- 1 tux users  53279 2006-06-21 13:16 Desktop
drwx------ 1 tux users    280 2006-06-23 16:08 Documents
drwxr-xr-x 1 tux users  70733 2006-06-21 09:35 public_html
-rw-r--r-- 1 tux users  47896 2006-06-21 09:46 tux.txt
tux@knox:~&gt;</pre><p>
    This output shows the following information about each object:
   </p><pre class="screen">drwxr-xr-x<a name="co.ls_l.perm"></a><img src="callouts/1.png" alt="1" border="0"> 1<a name="co.ls_l.a"></a><img src="callouts/2.png" alt="2" border="0"> tux<a name="co.ls_l.user"></a><img src="callouts/3.png" alt="3" border="0"> users<a name="co.ls_l.group"></a><img src="callouts/4.png" alt="4" border="0"> 48<a name="co.ls_l.size"></a><img src="callouts/5.png" alt="5" border="0"> 2006-06-23 16:08<a name="co.ls_l.date"></a><img src="callouts/6.png" alt="6" border="0"> bin<a name="co.ls_l.name"></a><img src="callouts/7.png" alt="7" border="0"> </pre><div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.perm"><img src="callouts/1.png" alt="1" border="0"></a> </p></td><td valign="top" align="left"><p>
      Type of object and access permissions. For further information, refer
      to <a class="xref" href="cha.new.html#sec.new.users.accperm.ugo" title="6.3.1. Permissions for User, Group and Others">Section 6.3.1, &#8220;Permissions for User, Group and Others&#8221;</a>.
     </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.a"><img src="callouts/2.png" alt="2" border="0"></a> </p></td><td valign="top" align="left"><p>
      Number of hard links to this file.
     </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.user"><img src="callouts/3.png" alt="3" border="0"></a> </p></td><td valign="top" align="left"><p>
      Owner of the file or directory. For further information, refer to
      <a class="xref" href="cha.new.html#sec.new.users.accperm.ugo" title="6.3.1. Permissions for User, Group and Others">Section 6.3.1, &#8220;Permissions for User, Group and Others&#8221;</a>.
     </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.group"><img src="callouts/4.png" alt="4" border="0"></a> </p></td><td valign="top" align="left"><p>
      Group assigned to the file or directory. For further information,
      refer to <a class="xref" href="cha.new.html#sec.new.users.accperm.ugo" title="6.3.1. Permissions for User, Group and Others">Section 6.3.1, &#8220;Permissions for User, Group and Others&#8221;</a>.
     </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.size"><img src="callouts/5.png" alt="5" border="0"></a> </p></td><td valign="top" align="left"><p>
      File size in bytes.
     </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.date"><img src="callouts/6.png" alt="6" border="0"></a> </p></td><td valign="top" align="left"><p>
      Date and time of the last change.
     </p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co.ls_l.name"><img src="callouts/7.png" alt="7" border="0"></a> </p></td><td valign="top" align="left"><p>
      Name of the object.
     </p></td></tr></table></div><p>
    Usually, you can combine several options by prefixing only the first
    option with a hyphen and then write the others consecutively without a
    blank. For example, if you want to see all files in a directory in long
    listing format, you can combine the two options <code class="option">-l</code> and
    <code class="option">-a</code> (show all files) for the <span class="command"><strong>ls</strong></span>
    command. Executing <span class="command"><strong>ls <code class="option">-la</code></strong></span> shows also
    hidden files in the directory, indicated by a dot in front (for example,
    <code class="literal">.hiddenfile</code>).
   </p><p>
    The list of contents you get with <span class="command"><strong>ls</strong></span> is sorted
    alphabetically by filenames. But like in a graphical file manager, you
    can also sort the output of <span class="command"><strong>ls <code class="option">-l</code></strong></span>
    according to various criteria such as date, file extension or file size:
   </p><div class="itemizedlist"><ul class="itemizedlist" type="bullet"><li class="listitem" style="list-style-type: disc"><p>
      For date and time, use <span class="command"><strong>ls <code class="option">-lt</code></strong></span>
      (displays newest first).
     </p></li><li class="listitem" style="list-style-type: disc"><p>
      For extensions, use <span class="command"><strong>ls <code class="option">-lx</code></strong></span>
      (displays files with no extension first).
     </p></li><li class="listitem" style="list-style-type: disc"><p>
      For file size, use <span class="command"><strong>ls <code class="option">-lS</code></strong></span>
      (displays largest first).
     </p></li></ul></div><p>
    To revert the order of sorting, add <code class="option">-r</code> as an option to
    your <span class="command"><strong>ls</strong></span> command. For example, <span class="command"><strong>ls
    <code class="option">-lr</code></strong></span> gives you the contents list sorted in
    reverse alphabetical order, <span class="command"><strong>ls <code class="option">-ltr</code></strong></span>
    shows the oldest files first. There are lots of other useful options for
    <span class="command"><strong>ls</strong></span>. In the following section you will learn how to
    investigate them.
   </p></div><div class="sect2" title="7.2.3. Getting Help"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.commands.help"></a>7.2.3. Getting Help<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.commands.help">¶</a></span></h3></div></div></div><p>
    Nobody is expected to know all options of all commands by heart. If you
    remember the command name but are not sure about the options or the
    syntax of the command, choose one of the following possibilities:
   </p><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong><code class="option">--help</code></strong></span> option <a class="indexterm" name="id359056"></a><a class="indexterm" name="id359064"></a>
     </span></dt><dd><p>
       If you only want to look up the options of a certain command, try
       entering the command followed by a space and <code class="option">--help</code>.
       This <code class="option">--help</code> option exists for many commands. For
       example, <span class="command"><strong>ls <code class="option">--help</code></strong></span> displays all
       the options for the <span class="command"><strong>ls</strong></span> command. <a class="indexterm" name="id359099"></a>
      </p></dd><dt><span class="term">Manual Pages<a class="indexterm" name="id359119"></a><a class="indexterm" name="id359128"></a><a class="indexterm" name="id359136"></a>
     </span></dt><dd><p>
       To learn more about the various commands, you can also use the manual
       pages. Manual pages also give a short description of what the command
       does. They can be accessed with <span class="command"><strong>man</strong></span> followed by
       the name of the command, for example, <span class="command"><strong>man ls</strong></span>.
      </p><p>
       The man pages are displayed directly in the shell. To navigate them,
       move up and down with <span class="keycap">Page &#8593;</span> and
       <span class="keycap">Page &#8595;</span>. Move between the beginning and the end
       of a document with <span class="keycap">Home</span> and
       <span class="keycap">End</span>. End this viewing mode by pressing
       <span class="keycap">Q</span>. Learn more about the <span class="command"><strong>man</strong></span>
       command itself with <span class="command"><strong>man man</strong></span>.
      </p></dd><dt><span class="term">Info Pages<a class="indexterm" name="id359201"></a><a class="indexterm" name="id359210"></a><a class="indexterm" name="id359218"></a>
     </span></dt><dd><p>
       Info pages usually provide even more information about commands. To
       view the info page for a certain command, enter
       <span class="command"><strong>info</strong></span> followed by the name of the command (for
       example, <span class="command"><strong>info ls</strong></span>). You can browse an info page
       with a viewer directly in the shell and display the different
       sections, called <span class="quote">&#8220;<span class="quote">nodes.</span>&#8221;</span> Use
       <span class="keycap">Space</span> to move forward and
       <span class="keycap">&lt;&#8212;</span> to move backwards. Within a node, you
       can also browse with <span class="keycap">Page &#8593;</span> and
       <span class="keycap">Page &#8595;</span> but only
       <span class="keycap">Space</span> and <span class="keycap">&lt;&#8212;</span> will
       take you also to the previous or subsequent node. Like for the man
       pages, press <span class="keycap">Q</span> to end the viewing mode.
      </p></dd></dl></div><p>
    Note that man pages and info pages do not exist for all commands.
    Sometimes both are available (usually for key commands), sometimes only
    a man page or an info page exists, and sometimes neither of them are
    available.
   </p></div><div class="sect2" title="7.2.4. Bash Shortcut Keys"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.commands.shortcuts"></a>7.2.4. Bash Shortcut Keys<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.commands.shortcuts">¶</a></span></h3></div></div></div><a class="indexterm" name="id359298"></a><p>
    After having entered several commands, your shell will begin to fill up
    with all sorts of commands and the corresponding outputs. In the
    following table, find some useful shortcut keys for navigating and
    editing in the shell.
   </p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th>
        <p>
         Shortcut Key
        </p>
       </th><th>
        <p>
         Function
        </p>
       </th></tr></thead><tbody><tr><td>
        <p>
         <span class="keycap">Ctrl</span>+<span class="keycap">L</span>
        </p>
       </td><td>
        <p>
         Clears the screen and moves the current line to the top of the
         page.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">Ctrl</span>+<span class="keycap">C</span>
        </p>
       </td><td>
        <p>
         Aborts the command which is currently being executed.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">Shift</span>+<span class="keycap">Page &#8593;</span>
        </p>
       </td><td>
        <p>
         Scrolls upwards.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">Shift</span>+<span class="keycap">Page &#8595;</span>
        </p>
       </td><td>
        <p>
         Scrolls downwards.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">Ctrl</span>+<span class="keycap">U</span>
        </p>
       </td><td>
        <p>
         Deletes from cursor position to start of line.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">Ctrl</span>+<span class="keycap">K</span>
        </p>
       </td><td>
        <p>
         Deletes from cursor position to the end of line.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">Ctrl</span>+<span class="keycap">D</span>
        </p>
       </td><td>
        <p>
         Closes the shell session.
        </p>
       </td></tr><tr><td>
        <p>
         <span class="keycap">&#8593;</span>, <span class="keycap">&#8595;</span>
        </p>
       </td><td>
        <p>
         Browses in the history of executed commands.
        </p>
       </td></tr></tbody></table></div></div></div><div class="sect1" title="7.3. Working with Files and Directories"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.fildir"></a>7.3. Working with Files and Directories<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.fildir">¶</a></span></h2></div></div></div><a class="indexterm" name="id359609"></a><a class="indexterm" name="id359617"></a><a class="indexterm" name="id359626"></a><p>
   To address a certain file or directory, you must specify the path leading
   to that directory or file. As you may know from MS DOS or Mac OS already,
   there are two ways to specify a path:
  </p><div class="variablelist"><dl><dt><span class="term">Absolute Path<a class="indexterm" name="id359644"></a>
    </span></dt><dd><p>
      Enter the entire path from the root directory to the relevant file or
      directory.
     </p></dd><dt><span class="term">Relative Path<a class="indexterm" name="id359670"></a>
    </span></dt><dd><p>
      Enter a path to the relevant file or directory by using the current
      directory as a starting point. This implies to give the levels you
      have to move up or down in the file system tree to reach the target
      directory of file, starting from the current directory.
     </p></dd></dl></div><p>
   Paths contain filenames, directories or both, separated by slashes.
   Absolute paths always start with a slash. Relative paths do not have a
   slash at the beginning, but can have one or two dots.
  </p><p>
   When entering commands, you can choose either way to specify a path,
   depending on your preferences or the amount of typing, both will lead to
   the same result. To change directories, use the <span class="command"><strong>cd</strong></span>
   command and specify the path to the directory.
  </p><div class="note"><table border="0" cellpadding="3" cellspacing="0" width="100%" summary="Note: Handling Blanks in Filenames or Directory Names"><tr class="head"><td width="32"><img alt="[Note]" src="admon/note.png"></td><th align="left">Handling Blanks in Filenames or Directory Names</th></tr><tr><td colspan="2" align="left" valign="top"><p>
    If a filename or the name of a directory contains a space, either escape
    the space using a back slash (<code class="literal">\</code>) in front of the
    blank or enclose the filename in single

    quotes. Otherwise Bash interprets a filename like <code class="filename">My
    Documents</code> as the names of two files or directories,
    <code class="filename">My</code> and <code class="filename">Documents</code> in this case.

   </p></td></tr></table></div><p>
   When specifying paths, the following <span class="quote">&#8220;<span class="quote">shortcuts</span>&#8221;</span> can save
   you a lot of typing:
  </p><div class="itemizedlist"><ul class="itemizedlist" type="bullet"><li class="listitem" style="list-style-type: disc"><p>
     The tilde symbol (<code class="literal">~</code>) is a shortcut for home
     directories. For example, to list the contents of your home directory,
     use <span class="command"><strong>ls</strong></span> <code class="option">~</code>. To list the contents of
     another user's home directory, enter <span class="command"><strong>ls
     <code class="option">~<em class="replaceable"><code>username</code></em> </code></strong></span> (or
     course, this will only work if you have permission to view the
     contents, see <a class="xref" href="cha.new.html#sec.new.users.accperm" title="6.3. File Access Permissions">Section 6.3, &#8220;File Access Permissions&#8221;</a>). For example,
     entering <span class="command"><strong>ls ~tux</strong></span> would list the contents of the home
     directory of a user named
     <code class="systemitem">tux</code>. You can use the
     tilde symbol as shortcut for home directories also if you are working
     in a network environment where your home directory may not be called
     <code class="filename">/home</code> but can be mapped to any directory in the
     file system.
    </p><p>
     From anywhere in the file system, you can reach your home directory by
     entering <span class="command"><strong>cd <code class="option">~</code></strong></span> or by simply entering
     <span class="command"><strong>cd</strong></span> without any options.
    </p></li><li class="listitem" style="list-style-type: disc"><p>
     When using relative paths, refer to the current directory with a dot
     (<code class="literal">.</code>). This is mainly useful for commands such as
     <span class="command"><strong>cp</strong></span> or <span class="command"><strong>mv</strong></span> by which you can copy or
     move files and directories.
    </p></li><li class="listitem" style="list-style-type: disc"><p>
     The next higher level in the tree is represented by two dots
     (<code class="literal">..</code>). In order to switch to the parent directory of
     your current directory, enter <span class="command"><strong>cd ..</strong></span>, to go up two
     levels from the current directory enter <span class="command"><strong>cd ../..</strong></span>
     etc.
    </p></li></ul></div><p>
   To apply your knowledge, find some examples below. They address basic
   tasks you may want to execute with files or folders using Bash.
  </p><div class="sect2" title="7.3.1. Examples for Working with Files and Directories"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.fildir.ex"></a>7.3.1. Examples for Working with Files and Directories<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.fildir.ex">¶</a></span></h3></div></div></div><p>
    Suppose you want to copy a file located somewhere in your home directory
    to a subdirectory of <code class="filename">/tmp</code> that you need to create
    first.
   </p><div class="procedure" title="Procedure 7.1. Creating and Changing Directories"><a name="id359881"></a><p class="title"><b>Procedure 7.1. Creating and Changing Directories</b></p><p>
     From your home directory create a subdirectory in
     <code class="filename">/tmp</code>:
    </p><ol class="procedure" type="1"><li><p>
      Enter
     </p><pre class="screen">mkdir  /tmp/test</pre><p>
      <span class="command"><strong>mkdir</strong></span> stands for <span class="quote">&#8220;<span class="quote">make directory</span>&#8221;</span>.
      This command creates a new directory named <code class="filename">test</code>
      in the <code class="filename">/tmp</code> directory. In this case, you are
      using an absolute path to create the <code class="filename">test</code>
      directory.
     </p></li><li><p>
      To check what happened, now enter
     </p><pre class="screen">ls -l /tmp</pre><p>
      The new directory <code class="filename">test</code> should appear in the list
      of contents of the <code class="filename">/tmp</code> directory.
     </p></li><li><p>
      Switch to the newly created directory with
     </p><pre class="screen">cd /tmp/test</pre></li></ol></div><div class="procedure" title="Procedure 7.2. Creating and Copying Files"><a name="id359972"></a><p class="title"><b>Procedure 7.2. Creating and Copying Files</b></p><p>
     Now create a new file in a subdirectory of your home directory and copy
     it to <code class="filename">/tmp/test</code>. Use a relative path for this
     task.
    </p><div class="important"><table border="0" cellpadding="3" cellspacing="0" width="100%" summary="Important: Overwriting of Existing Files"><tr class="head"><td width="32"><img alt="[Important]" src="admon/important.png"></td><th align="left">Overwriting of Existing Files</th></tr><tr><td colspan="2" align="left" valign="top"><p>
      Before copying, moving or renaming a file, check if your target
      directory already contains a file with the same name. If yes, consider
      changing one of the filenames or use <span class="command"><strong>cp</strong></span> or
      <span class="command"><strong>mv</strong></span> with options like <code class="option">-i</code>, which
      will prompt before overwriting an existing file. Otherwise Bash will
      overwrite the existing file without confirmation.
     </p></td></tr></table></div><ol class="procedure" type="1"><li><p>
      To list the contents of your home directory, enter
     </p><pre class="screen">ls -l ~</pre><p>
      It should contain a subdirectory called <code class="filename">Documents</code>
      by default. If not, create this subdirectory with the
      <span class="command"><strong>mkdir</strong></span> command you already know:
     </p><pre class="screen">mkdir ~/Documents</pre></li><li><p>
      To create a new, empty file named <code class="filename">myfile.txt</code> in
      the <code class="filename">Documents</code> directory, enter
     </p><pre class="screen">touch ~/Documents/myfile.txt</pre><p>
      Usually, the <span class="command"><strong>touch</strong></span> command updates the modification
      and access date for an existing file. If you use
      <span class="command"><strong>touch</strong></span> with a filename which does not exist in your
      target directory, it creates a new file.
     </p></li><li><p>
      Enter
     </p><pre class="screen">ls -l ~/Documents</pre><p>
      The new file should appear in the list of contents.
     </p></li><li><p>
      To copy the newly created file, enter
     </p><pre class="screen">cp ~/Documents/myfile.txt .</pre><p>
      Do not forget the dot at the end.
     </p><p>
      This command tells Bash to go to your home directory and to copy
      <code class="filename"> myfile.txt</code> from the
      <code class="filename">Documents</code> subdirectory to the current directory,
      <code class="filename">/tmp/test</code>, without changing the name of the file.
     </p></li><li><p>
      Check the result by entering
     </p><pre class="screen">ls -l</pre><p>
      The file <code class="filename">myfile.txt </code> should appear in the list of
      contents for <code class="filename">/tmp/test</code>.
     </p></li></ol></div><div class="procedure" title="Procedure 7.3. Renaming and Removing Files or Directories"><a name="id360154"></a><p class="title"><b>Procedure 7.3. Renaming and Removing Files or Directories</b></p><p>
     Now suppose you want to rename <code class="filename">myfile.txt </code> into
     <code class="filename">tuxfile.txt</code>. Finally you decide to remove the
     renamed file and the <code class="filename">test</code> subdirectory.
    </p><ol class="procedure" type="1"><li><p>
      To rename the file, enter
     </p><pre class="screen">mv myfile.txt tuxfile.txt</pre></li><li><p>
      To check what happened, enter
     </p><pre class="screen">ls -l</pre><p>
      Instead of <code class="filename">myfile.txt</code>,
      <code class="filename">tuxfile.txt</code> should appear in the list of
      contents.
     </p><p>
      <span class="command"><strong>mv</strong></span> stands for <code class="literal">move</code> and is used
      with two options: the first option specifies the source, the second
      option specifies the target of the operation. You can use
      <span class="command"><strong>mv</strong></span> either
     </p><div class="itemizedlist"><ul class="itemizedlist" type="bullet"><li class="listitem" style="list-style-type: disc"><p>
        to rename a file or a directory,
       </p></li><li class="listitem" style="list-style-type: disc"><p>
        to move a file or directory to a new location or
       </p></li><li class="listitem" style="list-style-type: disc"><p>
        to do both in one step.
       </p></li></ul></div></li><li><p>
      Coming to the conclusion that you do not need the file any longer, you
      can delete it by entering
     </p><pre class="screen">rm tuxfile.txt </pre><p>
      Bash deletes the file without any confirmation.
     </p></li><li><p>
      Move up one level with <span class="command"><strong>cd ..</strong></span> and check with
     </p><pre class="screen">ls -l test</pre><p>
      if the <code class="filename">test</code> directory is empty now.
     </p></li><li><p>
      If yes, you can remove the <code class="filename">test</code> directory by
      entering
     </p><pre class="screen">rmdir test</pre></li></ol></div></div></div><div class="sect1" title="7.4. Becoming Root"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.root"></a>7.4. Becoming Root<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.root">¶</a></span></h2></div></div></div><a class="indexterm" name="id360335"></a><p>
   As you learned in<a class="xref" href="cha.new.html#sec.new.users" title="6.1. User Concept">Section 6.1, &#8220;User Concept&#8221;</a>, some tasks in Linux
   require <code class="systemitem">root</code> permissions, otherwise they cannot be executed.
  </p><div class="sect2" title="7.4.1. Using su"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.root.su"></a>7.4.1. Using <span class="command"><strong>su</strong></span><span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.root.su">¶</a></span></h3></div></div></div><p>
    In order to temporarily become <code class="systemitem">root</code> in a shell, proceed as
    follows:
   </p><div class="procedure"><ol class="procedure" type="1"><li><p>
      Enter <span class="command"><strong>su</strong></span>. You are prompted for the <code class="systemitem">root</code>
      password.
     </p></li><li><p>
      Enter the password. If you mistyped the <code class="systemitem">root</code> password, the shell
      displays a message. In this case, you have to re-enter
      <span class="command"><strong>su</strong></span> before retyping the password. If your password
      is correct, a hash symbol <code class="literal">#</code> appears at the end of
      the prompt, signaling that you are acting as <code class="systemitem">root</code> now.
     </p></li><li><p>
      Execute your task. For example, transfer ownership of a file to a new
      user which only <code class="systemitem">root</code> is allowed to do:
     </p><pre class="screen">chown wilber kde_quick.xml</pre></li><li><p>
      After having completed your tasks as <code class="systemitem">root</code>, switch back to your
      normal user account. To do so, enter
     </p><pre class="screen">exit</pre><p>
      The hash symbol disappears and you are acting as <span class="quote">&#8220;<span class="quote">normal</span>&#8221;</span>
      user again.
     </p></li></ol></div></div><div class="sect2" title="7.4.2. Using sudo"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.root.sudo"></a>7.4.2. Using <span class="command"><strong>sudo</strong></span><span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.root.sudo">¶</a></span></h3></div></div></div><p>
    Alternatively, you can also use <span class="command"><strong>sudo</strong></span> (superuser
    <span class="quote">&#8220;<span class="quote">do</span>&#8221;</span>) to execute some tasks which normally are for
    <code class="systemitem">root</code>s only. With sudo, administrators can grant certain users
    <code class="systemitem">root</code> privileges for some commands. Depending on the system
    configuration, users can then run <code class="systemitem">root</code> commands by entering their
    normal password only. Due to a timestamp function, users are only
    granted a <span class="quote">&#8220;<span class="quote">ticket</span>&#8221;</span> for a restricted period of time after
    having entered their password. The ticket usually expires after a few
    minutes. In openSUSE, sudo requires the <code class="systemitem">root</code> password by default
    (if not configured otherwise by your system administrator).
   </p><p>
    For users, sudo is convenient as it prevents you from switching accounts
    twice (to <code class="systemitem">root</code> and back again). To change the ownership of a file
    using sudo, only one command is necessary instead of three:
   </p><pre class="screen">sudo chown wilber kde_quick.xml</pre><p>
    After you have entered the password which you are prompted for, the
    command is executed. If you enter a second <code class="systemitem">root</code> command shortly
    after that, you are not prompted for the password again, because your
    ticket is still valid. After a certain amount of time, the ticket
    automatically expires and the password is required again. This also
    prevents unauthorized persons from gaining <code class="systemitem">root</code> privileges in case
    a user forgets to switch back to his normal user account again and
    leaves a <code class="systemitem">root</code> shell open.
   </p></div></div><div class="sect1" title="7.5. Modifying File Permissions"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.perm"></a>7.5. Modifying File Permissions<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.perm">¶</a></span></h2></div></div></div><a class="indexterm" name="id360592"></a><p>
   In Linux, objects such as files or folder or processes generally belong
   to the user who created or initiated them. The group which is associated
   with a file or a folder depends on the primary group the user belongs to
   when creating the object. When you create a new file or directory,
   initial access permissions for this object are set according to a
   predefined scheme. For further details refer to
   <a class="xref" href="cha.new.html#sec.new.users.accperm" title="6.3. File Access Permissions">Section 6.3, &#8220;File Access Permissions&#8221;</a>.
  </p><p>
   As the owner of a file or directory (and, of course, as
   <code class="systemitem">root</code>), you can change the
   access permissions to this object.
  </p><p>
   To change object attributes like access permissions of a file or folder,
   use the <span class="command"><strong>chmod</strong></span> command <a class="indexterm" name="id360631"></a> followed by the following parameters:
  </p><div class="itemizedlist"><ul class="itemizedlist" type="bullet"><li class="listitem" style="list-style-type: disc"><p>
     the users for which to change the permissions,
    </p></li><li class="listitem" style="list-style-type: disc"><p>
     the type of access permission you want to remove, set or add and
    </p></li><li class="listitem" style="list-style-type: disc"><p>
     the files or folders for which you want to change permissions separated
     by spaces.
    </p></li></ul></div><p>
   The users for which you can change file access permissions fall into the
   following categories: the owner of the file (user, <code class="literal">u</code>),
   the group that own the file (group, <code class="literal">g</code>) and the other
   users (others, <code class="literal">o</code>). You can add, remove or set one or
   more of the following permissions: read, write or execute.
  </p><p>
   As <code class="systemitem">root</code>, you can also change the ownership of a file: with the
   command <span class="command"><strong>chown</strong></span> <a class="indexterm" name="id360706"></a> (change owner) you can transfer ownership to a new user.
  </p><div class="sect2" title="7.5.1. Examples for Changing Access Permissions and Ownership"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.perm.ex"></a>7.5.1. Examples for Changing Access Permissions and Ownership<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.perm.ex">¶</a></span></h3></div></div></div><p>
    The following example shows the output of an <span class="command"><strong>ls
    <code class="option">-l</code></strong></span> command in a shell.
   </p><div class="example"><a name="ex.new.bash.accperm.ugo"></a><p class="title"><b>Example 7.1. Access Permissions For Files and Folders</b><span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#ex.new.bash.accperm.ugo">¶</a></span></p><div class="example-contents"><pre class="screen">-rw-r----- 1 tux users      0 2006-06-23 16:08 checklist.txt
-rw-r--r-- 1 tux users  53279 2006-06-21 13:16 gnome_quick.xml
-rw-rw---- 1 tux users      0 2006-06-23 16:08 index.htm
-rw-r--r-- 1 tux users  70733 2006-06-21 09:35 kde-start.xml
-rw-r--r-- 1 tux users  47896 2006-06-21 09:46 kde_quick.xml
drwxr-xr-x 2 tux users     48 2006-06-23 16:09 local
-r-xr-xr-x 1 tux users 624398 2006-06-23 15:43 tux.jpg</pre></div></div><br class="example-break"><p>
    In the example above, user <code class="systemitem">tux</code> owns
    the file <code class="filename">kde-start.xml</code> and has read and write
    access to the file but cannot execute it. The
    <code class="systemitem">users</code> group can read the file but cannot write
    or execute it. The same holds true for the other users as shown by the
    third block of characters.
   </p><div class="procedure" title="Procedure 7.4. Changing Access Permissions"><a name="id360774"></a><p class="title"><b>Procedure 7.4. Changing Access Permissions</b></p><p>
     Suppose you are <code class="systemitem">tux</code> and want to
     modify the access permissions to your files:
    </p><ol class="procedure" type="1"><li><p>
      If you want to grant the <code class="systemitem">users</code> group also
      write access to <code class="filename">kde-start.xml</code>, enter
     </p><pre class="screen">chmod g+w kde-start.xml</pre></li><li><p>
      To grant the <code class="systemitem">users</code> group and other users
      write access to <code class="filename">kde-start.xml</code>, enter
     </p><pre class="screen">chmod go+w kde-start.xml</pre></li><li><p>
      To remove write access for all users, enter
     </p><pre class="screen">chmod -w kde-start.xml</pre><p>
      If you do not specify any kind of users, the changes apply to all
      users&#8212; the owner of the file, the owning group and the others.
      Now even the owner <code class="systemitem">tux</code> does not
      have write access to the file without first reestablishing write
      permissions.
     </p></li><li><p>
      To prohibit the <code class="systemitem">users</code>group and others to
      change into the directory <code class="filename">local</code>, enter
     </p><pre class="screen">chmod go-x local</pre></li><li><p>
      To grant others write permissions for two files, for
      <code class="filename">kde_quick.xml</code> and
      <code class="filename">gnome_quick.xml</code>, enter
     </p><pre class="screen">chmod o+w  kde_quick.xml gnome_quick.xml</pre></li></ol></div><div class="procedure" title="Procedure 7.5. Changing Ownership"><a name="id360898"></a><p class="title"><b>Procedure 7.5. Changing Ownership</b></p><p>
     Suppose you are <code class="systemitem">tux</code> and want to
     transfer the ownership of the file <code class="filename">kde_quick.xml</code>
     to an other user, named <code class="systemitem">wilber</code>. In
     this case, proceed as follows:
    </p><ol class="procedure" type="1"><li><p>
      Enter the username and password for <code class="systemitem">root</code>.
     </p></li><li><p>
      Enter
     </p><pre class="screen">chown wilber kde_quick.xml</pre></li><li><p>
      Check what happened with
     </p><pre class="screen">ls -l kde_quick.xml</pre><p>
      You should get the following output:
     </p><pre class="screen">-rw-r--r-- 1 wilber users  47896 2006-06-21 09:46 kde_quick.xml</pre></li><li><p>
      If the ownership is set according to your wishes, switch back to your
      normal user account.
     </p></li></ol></div></div></div><div class="sect1" title="7.6. Useful Features of the Shell"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.feat"></a>7.6. Useful Features of the Shell<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.feat">¶</a></span></h2></div></div></div><a class="indexterm" name="id360993"></a><p>
   As you probably noticed in the examples above, entering commands in Bash
   can include a lot of typing. In the following, get to know some features
   of the Bash that can make your work a lot easier and save a lot of
   typing.
  </p><div class="variablelist"><dl><dt><span class="term">History <a class="indexterm" name="id361016"></a><a class="indexterm" name="id361025"></a>
    </span></dt><dd><p>
      By default, Bash <span class="quote">&#8220;<span class="quote">remembers</span>&#8221;</span> commands you have entered.
      This feature is called <span class="emphasis"><em>history</em></span>. You can browse
      through commands that have been entered before, select one you want to
      repeat and then execute it again. To do so, press
      <span class="keycap">&#8593;</span> repeatedly until the desired command
      appears at the prompt. To move forward through the list of previously
      entered commands, press <span class="keycap">&#8595;</span>. For easier
      repetition of a certain command from Bash history, just type the first
      letter of the command you want to repeat and press
      <span class="keycap">Page &#8593;</span>.
     </p><p>
      You can now edit the selected command (for example, change the name of
      a file or a path), before you execute the command by pressing
      <span class="keycap">Enter</span>. To edit the command line, just move the
      cursor to the desired position using the arrow keys and start typing.
     </p><p>
      You can also search for a certain command in the history. Press
      <span class="keycap">Ctrl</span>+<span class="keycap">R</span>
      to start an incremental search function. showing the following prompt:
     </p><pre class="screen"> (reverse-i-search)`': </pre><p>
      Just type one or several letters from the command you are searching
      for. Each character you enter narrows down the search. The
      corresponding search result is shown on the right side of the colon
      whereas your input appears on the left of the colon. To accept a
      search result, press <span class="keycap">Esc</span>. The prompt now
      changes to its normal appearance and shows the command you chose. You
      can now edit the command or directly execute it by pressing
      <span class="keycap">Enter</span>.
     </p></dd><dt><span class="term">Completion<a class="indexterm" name="id361123"></a><a class="indexterm" name="id361131"></a>
    </span></dt><dd><p>
      Completing a filename or directory name to its full length after
      typing its first letters is another helpful feature of Bash. To do so,
      type the first letters then press <span class="keycap">&#8594;|</span>
      (Tabulator). If the filename or path can be uniquely identified, it is
      completed at once and the cursor moves to the end of the filename. You
      can then enter the next option of the command, if necessary. If the
      filename or path cannot be uniquely identified (because there are
      several filenames starting with the same letters), the filename or
      path is only completed up to the point where it becomes ambiguous
      again. You can then obtain a list of them by pressing
      <span class="keycap">&#8594;|</span> a second time. After this, you can enter the
      next letters of the file or path then try completion again by pressing
      <span class="keycap">&#8594;|</span>. When completing filenames and paths
      with the help of <span class="keycap">&#8594;|</span>, you can
      simultaneously check whether the file or path you want to enter really
      exists (and you can be sure of getting the spelling right).
     </p></dd><dt><span class="term">Wild Cards <a class="indexterm" name="id361183"></a><a class="indexterm" name="id361192"></a>
    </span></dt><dd><p>
      You can replace one or more characters in a filename with a wild card
      for pathname expansion. Wild cards are characters that can stand for
      other characters. There are three different types of these in Bash:
     </p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td>
          <p>
           Wild Card
          </p>
         </td><td>
          <p>
           Function
          </p>
         </td></tr><tr><td>
          <p>
           <code class="literal">?</code>
          </p>
         </td><td>
          <p>
           Matches exactly one arbitrary character
          </p>
         </td></tr><tr><td>
          <p>
           <code class="literal">*</code>
          </p>
         </td><td>
          <p>
           Matches any number of characters
          </p>
         </td></tr><tr><td>
          <p>
           <code class="literal">[<em class="replaceable"><code>set</code></em>]</code>
          </p>
         </td><td>
          <p>
           Matches one of the characters from the group specified inside the
           square brackets, which is represented here by the string
           <em class="replaceable"><code>set</code></em>.
          </p>
         </td></tr></tbody></table></div></dd></dl></div><div class="sect2" title="7.6.1. Examples For Using History, Completion and Wildcards"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.feat.ex"></a>7.6.1. Examples For Using History, Completion and Wildcards<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.feat.ex">¶</a></span></h3></div></div></div><p>
    The following examples illustrate how to make use of these convenient
    features of Bash.
   </p><div class="procedure" title="Procedure 7.6. Using History and Completion"><a name="id361337"></a><p class="title"><b>Procedure 7.6. Using History and Completion</b></p><p>
     If you already did the example <a class="xref" href="cha.new.bash.html#sec.new.bash.fildir.ex" title="7.3.1. Examples for Working with Files and Directories">Section 7.3.1, &#8220;Examples for Working with Files and Directories&#8221;</a>
     your shell buffer should be filled with commands which you can retrieve
     using the history function.
    </p><ol class="procedure" type="1"><li><p>
      Press <span class="keycap">&#8593;</span> repeatedly until <span class="command"><strong>cd ~</strong></span>
      appears.
     </p></li><li><p>
      Press <span class="keycap">Enter</span> to execute the command and to switch
      to your home directory.
     </p><p>
      By default, your home directory contains two subdirectories starting
      with the same letter, <code class="filename">Documents</code> and
      <code class="filename">Desktop</code>.
     </p></li><li><p>
      Enter <span class="command"><strong>cd D</strong></span> and press <span class="keycap">&#8594;|</span>.
     </p><p>
      Nothing happens since Bash cannot identify to which one of the
      subdirectories you want to change.
     </p></li><li><p>
      Press <span class="keycap">&#8594;|</span> again to see the list of possible
      choices:
     </p><pre class="screen">tux@knox:~&gt; cd D Desktop/   Documents/ tux@knox:~&gt; cd D</pre></li><li><p>
      The prompt still shows your initial input. Type the next character of
      the subdirectory you want to go to and press <span class="keycap">&#8594;|</span>
      again.
     </p><p>
      Bash now completes the path.
     </p></li><li><p>
      You can now execute the command with <span class="keycap">Enter</span>.
     </p></li></ol></div><div class="procedure" title="Procedure 7.7. Using Wildcards"><a name="id361475"></a><p class="title"><b>Procedure 7.7. Using Wildcards</b></p><p>
     Now suppose that your home directory contains a number of files with
     various file extensions. It also holds several versions of one file
     which you saved under different filenames
     <code class="filename">myfile1.txt</code>, <code class="filename">myfile2.txt</code> etc.
     You want to search for certain files according to their properties.
    </p><ol class="procedure" type="1"><li><p>
      First, create some test files in your home directory:
     </p><ol type="a" class="substeps"><li><p>
        Use the <span class="command"><strong>touch</strong></span> command to create several (empty)
        files with different file extensions, for example
        <code class="filename">.pdf</code>, <code class="filename">.xml</code> and
        <code class="filename">.jpg</code>.
       </p><p>
        You can do this consecutively (do not forget to use the Bash history
        function) or with only one <span class="command"><strong>touch</strong></span> command: simply
        add several filenames separated by a space.
       </p></li><li><p>
        Create at least two files that have the same file extension, for
        example <code class="filename">.html</code>.
       </p></li><li><p>
        To create several <span class="quote">&#8220;<span class="quote">versions</span>&#8221;</span> of one file, enter
       </p><pre class="screen">touch myfile{1..5}.txt</pre><p>
        This command creates five consecutively numbered files:
       </p><pre class="screen">myfile1.txt,&#8230;,myfile5.txt</pre></li><li><p>
        List the contents of your home directory. It should look similar to
        this:
       </p><pre class="screen">-rw-r--r-- 1 tux users   0 2006-07-14 13:34 foo.xml
-rw-r--r-- 1 tux users   0 2006-07-14 13:47 home.html
-rw-r--r-- 1 tux users   0 2006-07-14 13:47 index.html
-rw-r--r-- 1 tux users   0 2006-07-14 13:47 toc.html
-rw-r--r-- 1 tux users   0 2006-07-14 13:34 manual.pdf
-rw-r--r-- 1 tux users   0 2006-07-14 13:49 myfile1.txt
-rw-r--r-- 1 tux users   0 2006-07-14 13:49 myfile2.txt
-rw-r--r-- 1 tux users   0 2006-07-14 13:49 myfile3.txt
-rw-r--r-- 1 tux users   0 2006-07-14 13:49 myfile4.txt
-rw-r--r-- 1 tux users   0 2006-07-14 13:49 myfile5.txt
-rw-r--r-- 1 tux users   0 2006-07-14 13:32 tux.png
       </pre></li></ol></li><li><p>
      With the help of wild cards, select certain subsets of the files
      according to various criteria:
     </p><ol type="a" class="substeps"><li><p>
        To list all files with the <code class="filename">.html</code> extension,
        enter
       </p><pre class="screen"> ls -l *.html</pre></li><li><p>
        To list all <span class="quote">&#8220;<span class="quote">versions</span>&#8221;</span> of
        <code class="filename">myfile.txt</code>, enter
       </p><pre class="screen">ls -l myfile?.txt</pre><p>
        Note that you can only use the <code class="literal">?</code> wild card here
        because the numbering of the files is single-digit. As soon as you
        have a file named <code class="filename">myfile10.txt</code> you must to use
        the <code class="literal">*</code> wild card to view all versions of
        <code class="filename">myfile.txt</code> (or add another question mark, so
        your string looks like <span class="command"><strong>myfile??.txt</strong></span>).
       </p></li><li><p>
        To remove, for example, version 1-3 and version 5 of
        <code class="filename">myfile.txt</code>, enter
       </p><pre class="screen">rm myfile[1-3,5].txt</pre></li><li><p>
        Check the result with
       </p><pre class="screen">ls -l</pre><p>
        Of all <code class="filename">myfile.txt</code> versions only
        <code class="filename">myfile4.txt</code> should be left.
       </p></li></ol></li></ol></div><p>
    You can also combine several wild cards in one command. In the example
    above, <span class="command"><strong>rm myfile[1-3,5].*</strong></span> would lead to the same
    result as <span class="command"><strong>rm myfile[1-3,5].txt</strong></span> because there are only
    files with the extension <code class="filename">.txt</code> available.
   </p><div class="note"><table border="0" cellpadding="3" cellspacing="0" width="100%" summary="Note: Using Wildcards in rm Commands"><tr class="head"><td width="32"><img alt="[Note]" src="admon/note.png"></td><th align="left">Using Wildcards in rm Commands</th></tr><tr><td colspan="2" align="left" valign="top"><p>
     Wildcards in a <span class="command"><strong>rm </strong></span> command can be very useful but
     also dangerous: you might delete more files from your directory than
     intended. To see which files would be affected by the
     <span class="command"><strong>rm</strong></span>, run your wildcard string with
     <span class="command"><strong>ls</strong></span> instead of <span class="command"><strong>rm</strong></span> first.
    </p></td></tr></table></div></div></div><div class="sect1" title="7.7. Editing Texts"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.edit"></a>7.7. Editing Texts<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.edit">¶</a></span></h2></div></div></div><a class="indexterm" name="id361780"></a><a class="indexterm" name="id361789"></a><a class="indexterm" name="id361794"></a><p>
   In order to edit files from the command line, you will need to know the
   vi editor. vi is a default editor which can be found on nearly every
   UNIX/Linux system. It can run several operating modes in which the keys
   you press have different functions. This does not make it very easy for
   beginners, but you should know at least the most basic operations with
   vi. There may be situations where no other editor than vi is available.
  </p><p>
   Basically, vi makes use of three operating modes:
  </p><div class="variablelist"><dl><dt><span class="term"><span class="emphasis"><em>command</em></span> mode</span></dt><dd><p>
      In this mode, vi accepts certain key combinations as commands. Simple
      tasks such as searching words or deleting a line can be executed.
     </p></dd><dt><span class="term"><span class="emphasis"><em>insert</em></span> mode</span></dt><dd><p>
      In this mode, you can write normal text.
     </p></dd><dt><span class="term"><span class="emphasis"><em>extended</em></span> mode</span></dt><dd><p>
      In this mode, also known as colon mode (as you have to enter a colon
      to switch to this mode), vi can execute also more complex tasks such
      as searching and replacing text.
     </p></dd></dl></div><p>
   In the following (very simple) example, you will learn how to open and
   edit a file with vi, how to save your changes and quit vi.
  </p><div class="sect2" title="7.7.1. Example: Editing with vi"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.edit.ex"></a>7.7.1. Example: Editing with vi<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.edit.ex">¶</a></span></h3></div></div></div><div class="procedure"><div class="note"><table border="0" cellpadding="3" cellspacing="0" width="100%" summary="Note: Display of Keys"><tr class="head"><td width="32"><img alt="[Note]" src="admon/note.png"></td><th align="left">Display of Keys</th></tr><tr><td colspan="2" align="left" valign="top"><p>
      In the following, find several commands that you can enter in vi by
      just pressing keys. These appear in uppercase as on a keyboard. If you
      need to enter a key in uppercase, this is stated explicitly by showing
      a key combination including the <span class="keycap">Shift</span> key.
     </p></td></tr></table></div><ol class="procedure" type="1"><li><p>
      To create and open a new file with vi, enter
     </p><pre class="screen">vi textfile.txt</pre><p>
      By default, vi opens in <span class="emphasis"><em>command</em></span> mode in which you
      cannot enter text.
     </p></li><li><p>
      Press <span class="keycap">I</span> to switch to insert mode. The bottom line
      changes and indicates that you now can insert text.
     </p></li><li><p>
      Write some sentences. If you want to insert a new line, first press
      <span class="keycap">Esc</span> to switch back to command mode.
      Press <span class="keycap">O</span> to insert a new line and to switch to insert
      mode again.
     </p></li><li><p>
      In the insert mode, you can edit the text with the arrow keys and with
      <span class="keycap">Del</span>.
     </p></li><li><p>
      To leave vi, press <span class="keycap">Esc</span> to switch to command
      mode again. Then press <span class="keycap">:</span> which takes you to the
      extended mode. The bottom line now shows a colon.
     </p></li><li><p>
      To leave vi and save your changes, type <span class="command"><strong>wq</strong></span>
      (<code class="literal">w</code> for <code class="literal">write</code>;
      <code class="literal">q</code> for <code class="literal">quit</code>) and press
      <span class="keycap">Enter</span>. If you want to save the file under
      a different name, type <span class="command"><strong>w
      <em class="replaceable"><code>filename</code></em></strong></span> and press
      <span class="keycap">Enter</span>.
     </p><p>
      To leave vi without saving, type <span class="command"><strong>q!</strong></span> instead and
      press <span class="keycap">Enter</span>.
     </p></li></ol></div></div></div><div class="sect1" title="7.8. Searching for Files or Contents"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.search"></a>7.8. Searching for Files or Contents<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.search">¶</a></span></h2></div></div></div><a class="indexterm" name="id362067"></a><a class="indexterm" name="id362076"></a><p>
   Bash offers you several commands to search for files and to search for
   the contents of files:
  </p><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>locate</strong></span><a class="indexterm" name="id362098"></a>
    </span></dt><dd><p>
      This utility is only available if you have installed the
      <code class="systemitem">findutils-locate</code>
      package. With this command you can find out in which directory a
      specified file is located. If desired, use wild cards to specify
      filenames. The program is very quick, because it uses a database
      specifically created for the purpose (rather than searching through
      the entire file system). This very fact, however, also results in a
      major drawback: locate is unable to find any files created after the
      latest update of its database. The database can be generated by
      <code class="systemitem">root</code> running
      <span class="command"><strong>updatedb</strong></span>.
     </p></dd><dt><span class="term"><span class="command"><strong>find</strong></span><a class="indexterm" name="id362144"></a>
    </span></dt><dd><p>
      With <span class="command"><strong>find</strong></span>, search for a file in a given directory.
      The first argument specifies the directory in which to start the
      search. The option <code class="option">-name</code> must be followed by a search
      string, which may also include wild cards. Unlike
      <span class="command"><strong>locate</strong></span>, which uses a database,
      <span class="command"><strong>find</strong></span> scans the actual directory.
     </p></dd><dt><span class="term"><span class="command"><strong>grep</strong></span><a class="indexterm" name="id362187"></a>
    </span></dt><dd><p>
      The <span class="command"><strong>grep</strong></span> command finds a specific search string in
      the specified text files. If the search string is found, the command
      displays the line in which <code class="literal">searchstring</code> was found,
      along with the filename. If desired, use wild cards to specify
      filenames.
     </p></dd></dl></div><div class="sect2" title="7.8.1. Examples for Searching"><div class="titlepage"><div><div><h3 class="title"><a name="id362218"></a>7.8.1. Examples for Searching<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#id362218">¶</a></span></h3></div></div></div><div class="procedure"><p>
     The KDE and GNOME desktops store user-specific application data in
     hidden directories, for example <code class="filename">.kde</code> and
     <code class="filename">.gnome</code>.
    </p><ol class="procedure" type="1"><li><p>
      To locate these directories on your computer, enter
     </p><pre class="screen">locate .kde</pre><p>
      if you have installed KDE desktop or
     </p><pre class="screen">locate .gnome</pre><p>
      if you have installed GNOME desktop.
     </p><p>
      You will see that <span class="command"><strong>locate</strong></span> displays all file names in
      the database that contain the string <code class="literal">.kde</code> or
      <code class="literal">.gnome</code> anywhere. To learn how to modify this
      behavior refer to the man page of <span class="command"><strong>locate</strong></span>.
     </p></li><li><p>
      To search your home directory for all occurrences of filenames that
      contain the file extension <code class="filename">.txt</code>, use
     </p><pre class="screen">find ~ -name '*.txt' -print</pre></li><li><p>
      To search a directory (in this case, your home directory) for all
      occurrences of files which contain, for example, the word
      <code class="literal">music</code>, enter
     </p><pre class="screen">grep music ~/*</pre><p>
      Note that grep is case-sensitive&#8212; unless you use it with the
      <code class="option">-i</code> option. With the command above you will not find
      any files containing <code class="literal">Music</code>.
     </p><p>
      If you want to use a search string which consists of more than one
      word, enclose the string in double quotation marks, for example:
     </p><pre class="screen">grep "music is great" ~/*</pre></li></ol></div></div></div><div class="sect1" title="7.9. Viewing Text Files"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.view"></a>7.9. Viewing Text Files<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.view">¶</a></span></h2></div></div></div><a class="indexterm" name="id362353"></a><p>
   When searching for the contents of a file with <span class="command"><strong>grep</strong></span>,
   the output gives you the line in which the
   <code class="literal">searchstring</code> was found along with the filename. Often
   this contextual information is still not enough information to decide
   whether you want to open and edit this file. Bash offers you several
   commands to have a quick look at the contents of a text file directly in
   the shell, without opening an editor.
  </p><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>head</strong></span><a class="indexterm" name="id362385"></a><a class="indexterm" name="id362390"></a>
    </span></dt><dd><p>
      With <span class="command"><strong>head</strong></span> you can view the first lines of a text
      file. If you do not specify the command any further,
      <span class="command"><strong>head</strong></span> shows the first 10 lines of a text file.
     </p></dd><dt><span class="term"><span class="command"><strong>tail</strong></span><a class="indexterm" name="id362421"></a><a class="indexterm" name="id362425"></a>
    </span></dt><dd><p>
      The <span class="command"><strong>tail</strong></span> command is the counterpart of
      <span class="command"><strong>head</strong></span>. If you use <span class="command"><strong>tail</strong></span> without
      any further options it displays the last 10 lines of a text file. This
      can be very useful to view log files of your system, where the most
      recent messages or log entries are usually found at the end of the
      file.
     </p></dd><dt><span class="term"><span class="command"><strong>less</strong></span><a class="indexterm" name="id362461"></a><a class="indexterm" name="id362466"></a>
    </span></dt><dd><p>
      With <span class="command"><strong>less</strong></span>, display the whole contents of a text
      file. To move up and down half a page use <span class="keycap">Page &#8593;</span>
      and <span class="keycap">Page &#8595;</span>. Use <span class="keycap">Space</span> to
      scroll down one page. <span class="keycap">Home</span> takes you to the
      beginning, and <span class="keycap">End</span> to the end of the document. To
      end the viewing mode, press <span class="keycap">Q</span>.
     </p></dd><dt><span class="term"><span class="command"><strong>more</strong></span><a class="indexterm" name="id362520"></a><a class="indexterm" name="id362525"></a>
    </span></dt><dd><p>
      Instead of <code class="literal">less</code>, you can also use the older program
      <code class="literal">more</code>. It has basically the same
      function&#8212;however, it is less convenient because it does not
      allow you to scroll backwards. Use <span class="keycap">Space</span> to move
      forward. When you reach the end of the document, the viewer closes
      automatically.
     </p></dd><dt><span class="term"><span class="command"><strong>cat</strong></span><a class="indexterm" name="id362561"></a><a class="indexterm" name="id362566"></a>
    </span></dt><dd><p>
      The <span class="command"><strong>cat</strong></span> command displays the contents of a file,
      printing the entire contents to the screen without interruption. As
      <span class="command"><strong>cat</strong></span> does not allow you to scroll it is not very
      useful as viewer but it is rather often used in combination with other
      commands.
     </p></dd></dl></div></div><div class="sect1" title="7.10. Redirection and Pipes"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.redir"></a>7.10. Redirection and Pipes<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.redir">¶</a></span></h2></div></div></div><a class="indexterm" name="id362602"></a><a class="indexterm" name="id362611"></a><a class="indexterm" name="id362619"></a><a class="indexterm" name="id362628"></a><a class="indexterm" name="id362636"></a><a class="indexterm" name="id362645"></a><p>
   Sometimes it would be useful if you could write the output of a command
   to a file for further editing or if you could combine several commands,
   using the output of one command as the input for the next one. The shell
   offers this function by means of redirection or pipes.
  </p><p>
   Normally, the standard output in the shell is your screen (or an open
   shell window) and the standard input is the keyboard. With the help of
   certain symbols you can redirect the input or the output to another
   object, such as a file or another command.
  </p><div class="variablelist"><dl><dt><span class="term">Redirection</span></dt><dd><p>
      With <code class="literal">&gt;</code> you can forward the output of a command
      to a file (output redirection), with <code class="literal">&lt;</code> you can
      use a file as input for a command (input redirection).
     </p></dd><dt><span class="term">Pipe</span></dt><dd><p>
      By means of a pipe symbol <code class="literal">|</code> you can also redirect
      the output: with a pipe, you can combine several commands, using the
      output of one command as input for the next command. In contrast to
      the other redirection symbols &gt; and &lt;, the use of the pipe is
      not constrained to files.
     </p></dd></dl></div><div class="sect2" title="7.10.1. Examples for Redirection and Pipe"><div class="titlepage"><div><div><h3 class="title"><a name="sec.new.bash.redir.ex"></a>7.10.1. Examples for Redirection and Pipe<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.redir.ex">¶</a></span></h3></div></div></div><div class="procedure"><ol class="procedure" type="1"><li><p>
      To write the output of a command like <span class="command"><strong>ls</strong></span> to a file,
      enter
     </p><pre class="screen">ls -l &gt; filelist.txt</pre><p>
      This creates a file named <code class="filename">filelist.txt</code> that
      contains the list of contents of your current directory as generated
      by the <span class="command"><strong>ls</strong></span> command.
     </p><p>
      However, if a file named <code class="filename">filelist.txt</code> already
      exists, this command overwrites the existing file. To prevent this,
      use <code class="literal">&gt;&gt;</code> instead of &gt;. Entering
     </p><pre class="screen">ls -l &gt;&gt; filelist.txt </pre><p>
      simply appends the output of the <span class="command"><strong>ls</strong></span> command to an
      already existing file named <code class="filename">filelist.txt</code>. If the
      file does not exist, it is created.
     </p></li><li><p>
      Redirections also works the other way round. Instead of using the
      standard input from the keyboard for a command, you can use a file as
      input:
     </p><pre class="screen">sort &lt; filelist.txt</pre><p>
      This will force the <span class="command"><strong>sort</strong></span> command to get its input
      from the contents of <code class="filename">filelist.txt</code>. The result is
      shown on the screen. Of course, you can also write the result into
      another file, using a combination of redirections:
     </p><pre class="screen">sort  &lt; filelist.txt &gt; sorted_filelist.txt</pre></li><li><p>
      If a command generates a lengthy output, like <span class="command"><strong>ls
      <code class="option">-l</code></strong></span> may do, it may be useful to pipe the
      output to a viewer like <code class="literal">less</code> to be able to scroll
      through the pages. To do so, enter
     </p><pre class="screen">ls -l | less</pre><p>
      The list of contents of the current directory is shown in
      <code class="literal">less</code>.
     </p><p>
      The pipe is also often used in combination with the
      <span class="command"><strong>grep</strong></span> command in order to search for a certain
      string in the output of another command. For example, if you want to
      view a list of files in a directory which are owned by the user
      <code class="systemitem">tux</code>, enter
     </p><pre class="screen">ls -l | grep tux</pre></li></ol></div></div></div><div class="sect1" title="7.11. Starting Programs and Handling Processes"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.new.bash.jobs"></a>7.11. Starting Programs and Handling Processes<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.new.bash.jobs">¶</a></span></h2></div></div></div><a class="indexterm" name="id362876"></a><a class="indexterm" name="id362885"></a><a class="indexterm" name="id362894"></a><a class="indexterm" name="id362902"></a><a class="indexterm" name="id362911"></a><a class="indexterm" name="id362919"></a><p>
   As you have seen in <a class="xref" href="cha.new.bash.html#sec.new.bash.edit" title="7.7. Editing Texts">Section 7.7, &#8220;Editing Texts&#8221;</a>, programs can be
   started from the shell. Applications with a graphical user interface need
   the X Window System and can only be started from a terminal window within
   a graphical user interface. For example, if you want to open a file named
   <code class="filename">vacation.pdf</code> in your home directory from a terminal
   window in KDE or GNOME, simply run 
   <span class="command"><strong>okular ~/vacation.pdf</strong></span> (or 
   <span class="command"><strong>evince ~/vacation.pdf</strong></span>) to
   start a PDF viewer displaying your file.
  </p><p>
   When looking at the terminal window again you will realize that the
   command line is blocked as long as the PDF viewer is open, meaning that
   your prompt is not available. To change this, press <span class="keycap">Ctrl</span>+<span class="keycap">Z</span> to suspend
   the process and enter <a class="indexterm" name="id362968"></a> <span class="command"><strong>bg</strong></span> to send the process to the background.
   Now you can still have a look at <code class="filename">vacation.pdf</code> while
   your prompt is available for further commands. An easier way to achieve
   this is by sending a process to the background directly when starting it.
   To do so, add an ampersand at the end of the command:
  </p><pre class="screen">okular ~/vacation.pdf &amp;</pre><p>
   If you have started several background processes (also named jobs) from
   the same shell, the <span class="command"><strong>jobs</strong></span> <a class="indexterm" name="id363001"></a> command gives you an overview of the jobs. It also shows the
   job number in brackets and their status:
  </p><pre class="screen">tux@linux:~&gt; jobs
[1]   Running        okular book.opensuse.startup-xep.pdf &amp;
[2]-  Running        okular book.opensuse.reference-xep.pdf &amp;
[3]+  Stopped        man jobs</pre><p>
   To bring a job to the foreground again, enter <a class="indexterm" name="id363022"></a> <span class="command"><strong>fg <em class="replaceable"><code>job_number</code></em></strong></span>.
  </p><p>
   <a class="indexterm" name="id363043"></a> Whereas <span class="command"><strong>job</strong></span> only shows the background
   processes started from a specific shell, the <span class="command"><strong>ps</strong></span>
   command (run without options) shows a list of all your
   processes&#8212;those you started. Find an example output below:
  </p><pre class="screen">tux@linux:~&gt; ps
PID TTY          TIME CMD
15500 pts/1    00:00:00 bash
28214 pts/1    00:00:00 okular
30187 pts/1    00:00:00 kwrite
30280 pts/1    00:00:00 ps</pre><p>
   <a class="indexterm" name="id363072"></a> In case a program cannot be terminated in the normal way,
   use the <span class="command"><strong>kill</strong></span> command to stop the process (or
   processes) belonging to that program. To do so, specify the process ID
   (PID) shown by the output of <span class="command"><strong>ps</strong></span>. For example, to shut
   down the KWrite editor in the example above, enter
  </p><pre class="screen">kill 30187</pre><p>
   This sends a <span class="emphasis"><em>TERM</em></span> signal that instructs the program
   to shut itself down.
  </p><p>
   Alternatively, if the program or process you want to terminate is a
   background job and is shown by the <span class="command"><strong>jobs</strong></span> command, you
   can also use the <span class="command"><strong>kill</strong></span> command in combination with the
   job number to terminate this process. When identifying the job with the
   job number, you must prefix the number with a percent character
   (<code class="literal">%</code>):
  </p><pre class="screen">kill %<em class="replaceable"><code>job_number</code></em></pre><p>
   If <span class="command"><strong>kill</strong></span> does not help&#8212;as is sometimes the case
   for <span class="quote">&#8220;<span class="quote">runaway</span>&#8221;</span> programs&#8212;try
  </p><pre class="screen">kill -9 <em class="replaceable"><code>PID</code></em></pre><p>
   This sends a <span class="emphasis"><em>KILL</em></span> signal instead of a
   <span class="emphasis"><em>TERM</em></span> signal, bringing the specified process to an
   end in most cases.
  </p><p>
   This section is intended to introduce the most basic set of commands for
   handling jobs and processes. Find an overview for system administrators
   in Section &#8220;Processes&#8221; (Chapter 13, <i>System Monitoring Utilities</i>, &#8593;Reference).
  </p></div><div class="sect1" title="7.12. Important Linux Commands"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.shell.commands"></a>7.12. Important Linux Commands<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.shell.commands">¶</a></span></h2></div></div></div><a class="indexterm" name="idx.Shell_Befehle"></a><a class="indexterm" name="idx.Befehle"></a><p>
  This section gives insight into the most important commands. There are
  many more commands than listed in this chapter. Along with the individual
  commands, parameters are listed and, where appropriate, a typical sample
  application is introduced. To learn more about the various commands, use
  the manual pages, accessed with <span class="command"><strong>man</strong></span> followed by the
  name of the command, for example, <span class="command"><strong>man ls</strong></span>. <a class="indexterm" name="id363225"></a> <a class="indexterm" name="id363236"></a> <a class="indexterm" name="id363248"></a>
 </p><p>
  Man pages are displayed directly in the shell. To navigate them, move up
  and down with <span class="keycap">Page &#8593;</span> and
  <span class="keycap">Page &#8595;</span>. Move between the beginning and the end of a
  document with <span class="keycap">Home</span> and <span class="keycap">End</span>. End
  this viewing mode by pressing <span class="keycap">Q</span>. Learn more about the
  <span class="command"><strong>man</strong></span> command itself with <span class="command"><strong>man man</strong></span>.
 </p><p>
  In the following overview, the individual command elements are written in
  different typefaces. The actual command and its mandatory options are
  always printed as <span class="command"><strong>command option</strong></span>. Specifications or
  parameters that are not required are placed in <code class="option">[square
  brackets]</code>.
 </p><p>
  Adjust the settings to your needs. It makes no sense to write <span class="command"><strong>ls
  file</strong></span> if no file named <code class="filename">file</code> actually exists.
  You can usually combine several parameters, for example, by writing
  <span class="command"><strong>ls -la</strong></span> instead of <span class="command"><strong>ls -l -a</strong></span>.
 </p><div class="sect2" title="7.12.1. File Commands"><div class="titlepage"><div><div><h3 class="title"><a name="sec.commands.file"></a>7.12.1. File Commands<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.file">¶</a></span></h3></div></div></div><p>
   The following section lists the most important commands for file
   management. It covers everything from general file administration to the
   manipulation of file system ACLs.
  </p><div class="sect3" title="7.12.1.1. File Administration"><div class="titlepage"><div><div><h4 class="title"><a name="sec.shell.fileadmin"></a>7.12.1.1. File Administration<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.shell.fileadmin">¶</a></span></h4></div></div></div><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>ls</strong></span> <code class="option">[options]</code> <code class="option">[files]</code>
     <a class="indexterm" name="id363365"></a><a class="indexterm" name="id363373"></a></span></dt><dd><p>
       If you run <span class="command"><strong>ls</strong></span> without any additional parameters,
       the program lists the contents of the current directory in short
       form.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-l</code>
        </span></dt><dd><p>
          Detailed list
         </p></dd><dt><span class="term"><code class="option">-a</code>
        </span></dt><dd><p>
          Displays hidden files
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>cp</strong></span> <code class="option">[options]</code> <code class="option">source target</code>
     <a class="indexterm" name="id363446"></a><a class="indexterm" name="id363455"></a><a class="indexterm" name="id363460"></a></span></dt><dd><p>
       Copies <code class="filename">source</code> to <code class="filename">target</code>.
      </p><div class="variablelist"><dl><dt><span class="term">-i</span></dt><dd><p>
          Waits for confirmation, if necessary, before an existing
          <code class="literal">target</code> is overwritten
         </p></dd><dt><span class="term">-r</span></dt><dd><p>
          Copies recursively (includes subdirectories)
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>mv</strong></span> <code class="option">[options]</code> <code class="option">source target</code>
     <a class="indexterm" name="id363539"></a><a class="indexterm" name="id363547"></a><a class="indexterm" name="id363552"></a></span></dt><dd><p>
       Copies <code class="filename">source</code> to <code class="filename">target</code>
       then deletes the original <code class="filename">source</code>.
      </p><div class="variablelist"><dl><dt><span class="term">-b</span></dt><dd><p>
          Creates a backup copy of the <code class="filename">source</code> before
          moving
         </p></dd><dt><span class="term">-i</span></dt><dd><p>
          Waits for confirmation, if necessary, before an existing
          <code class="filename">targetfile</code> is overwritten
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>rm</strong></span> <code class="option">[options]</code> <code class="option">files</code>
     <a class="indexterm" name="id363639"></a><a class="indexterm" name="id363648"></a><a class="indexterm" name="id363652"></a></span></dt><dd><p>
       Removes the specified files from the file system. Directories are not
       removed by <span class="command"><strong>rm</strong></span> unless the option
       <code class="option">-r</code> is used.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-r</code>
        </span></dt><dd><p>
          Deletes any existing subdirectories
         </p></dd><dt><span class="term"><code class="option">-i</code>
        </span></dt><dd><p>
          Waits for confirmation before deleting each file
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>ln</strong></span> <code class="option">[options]</code> <code class="option">source</code> <code class="option">target</code>
     <a class="indexterm" name="id363737"></a><a class="indexterm" name="id363745"></a></span></dt><dd><p>
       Creates an internal link from <code class="option">source</code> to
       <code class="option">target</code>. Normally, such a link points directly to
       <code class="option">source</code> on the same file system. However, if
       <span class="command"><strong>ln</strong></span> is executed with the <code class="option">-s</code>
       option, it creates a symbolic link that only points to the directory
       in which <code class="filename">source</code> is located, enabling linking
       across file systems.
      </p><div class="variablelist"><dl><dt><span class="term">-s</span></dt><dd><p>
          Creates a symbolic link
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>cd</strong></span> <code class="option">[options]</code> <code class="filename">[directory]</code>
     <a class="indexterm" name="id363818"></a><a class="indexterm" name="id363827"></a><a class="indexterm" name="id363831"></a></span></dt><dd><p>
       Changes the current directory. <span class="command"><strong>cd</strong></span> without any
       parameters changes to the user's home directory.
      </p></dd><dt><span class="term"><span class="command"><strong>mkdir</strong></span> <code class="option">[options]</code> <code class="option">directory</code>
     <a class="indexterm" name="id363869"></a><a class="indexterm" name="id363878"></a><a class="indexterm" name="id363882"></a></span></dt><dd><p>
       Creates a new directory.
      </p></dd><dt><span class="term"><span class="command"><strong>rmdir</strong></span> <code class="option">[options]</code> <code class="option">directory</code>
     <a class="indexterm" name="id363916"></a><a class="indexterm" name="id363924"></a><a class="indexterm" name="id363929"></a></span></dt><dd><p>
       Deletes the specified directory if it is already empty.
      </p></dd><dt><span class="term"><span class="command"><strong>chown</strong></span> <code class="option">[options] username[:[group]]</code> <code class="filename">files</code>
     <a class="indexterm" name="id363963"></a><a class="indexterm" name="id363972"></a></span></dt><dd><p>
       Transfers ownership of a file to the user with the specified
       username.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-R</code>
        </span></dt><dd><p>
          Changes files and directories in all subdirectories
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>chgrp</strong></span> <code class="option">[options]</code> <code class="option">groupname</code> <code class="filename">files</code>
     <a class="indexterm" name="id364027"></a><a class="indexterm" name="id364036"></a></span></dt><dd><p>
       Transfers the group ownership of a given <code class="filename">file</code> to
       the group with the specified group name. The file owner can change
       group ownership only if a member of both the current and the new
       group.
      </p></dd><dt><span class="term"><span class="command"><strong>chmod</strong></span> <code class="option">[options]</code> <code class="option">mode</code> <code class="option">files</code>
     <a class="indexterm" name="id364074"></a><a class="indexterm" name="id364083"></a><a class="indexterm" name="id364088"></a></span></dt><dd><p>
       Changes the access permissions.
      </p><p>
       The <code class="literal">mode</code> parameter has three parts:
       <code class="literal">group</code>, <code class="literal">access</code>, and
       <code class="literal">access type</code>. <code class="literal">group</code> accepts the
       following characters:
      </p><div class="variablelist"><dl><dt><span class="term">u</span></dt><dd><p>
          User
         </p></dd><dt><span class="term">g</span></dt><dd><p>
          Group
         </p></dd><dt><span class="term">o</span></dt><dd><p>
          Others
         </p></dd></dl></div><p>
       For <code class="literal">access</code>, grant access with <code class="literal">+</code>
       and deny it with <code class="literal">-</code>.
      </p><p>
       The <code class="literal">access type</code> is controlled by the following
       options:
      </p><div class="variablelist"><dl><dt><span class="term">r</span></dt><dd><p>
          Read
         </p></dd><dt><span class="term">w</span></dt><dd><p>
          Write
         </p></dd><dt><span class="term">x</span></dt><dd><p>
          Execute&#8212;executing files or changing to the directory
         </p></dd><dt><span class="term">s</span></dt><dd><p>
          Setuid bit&#8212;the application or program is started as if it
          were started by the owner of the file
         </p></dd></dl></div><p>
       As an alternative, a numeric code can be used. The four digits of
       this code are composed of the sum of the values 4, 2, and 1&#8212;the
       decimal result of a binary mask. The first digit sets the set user ID
       (SUID) (4), the set group ID (2), and the sticky (1) bits. The second
       digit defines the permissions of the owner of the file. The third
       digit defines the permissions of the group members and the last digit
       sets the permissions for all other users. The read permission is set
       with 4, the write permission with 2, and the permission for executing
       a file is set with 1. The owner of a file would usually receive a 6
       or a 7 for executable files.
      </p></dd><dt><span class="term"><span class="command"><strong>gzip</strong></span> <code class="option">[parameters]</code> <code class="filename">files</code>
     <a class="indexterm" name="id364291"></a><a class="indexterm" name="id364299"></a><a class="indexterm" name="id364304"></a></span></dt><dd><p>
       This program compresses the contents of files using complex
       mathematical algorithms. Files compressed in this way are given the
       extension <code class="filename">.gz</code> and need to be uncompressed before
       they can be used. To compress several files or even entire
       directories, use the <span class="command"><strong>tar</strong></span> command.
      </p><div class="variablelist"><dl><dt><span class="term">-d</span></dt><dd><p>
          Decompresses the packed gzip files so they return to their
          original size and can be processed normally (like the command
          <span class="command"><strong>gunzip</strong></span>)
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>tar</strong></span> <code class="option">options</code> <code class="option">archive</code> <code class="option">files</code>
     <a class="indexterm" name="id364374"></a><a class="indexterm" name="id364383"></a><a class="indexterm" name="id364388"></a></span></dt><dd><p>
       <span class="command"><strong>tar</strong></span> puts one or more files into an archive.
       Compression is optional. <span class="command"><strong>tar</strong></span> is a quite complex
       command with a number of options available. The most frequently used
       options are:
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-f</code>
        </span></dt><dd><p>
          Writes the output to a file and not to the screen as is usually
          the case
         </p></dd><dt><span class="term"><code class="option">-c</code>
        </span></dt><dd><p>
          Creates a new tar archive
         </p></dd><dt><span class="term"><code class="option">-r</code>
        </span></dt><dd><p>
          Adds files to an existing archive
         </p></dd><dt><span class="term"><code class="option">-t</code>
        </span></dt><dd><p>
          Outputs the contents of an archive
         </p></dd><dt><span class="term"><code class="option">-u</code>
        </span></dt><dd><p>
          Adds files, but only if they are newer than the files already
          contained in the archive
         </p></dd><dt><span class="term"><code class="option">-x</code>
        </span></dt><dd><p>
          Unpacks files from an archive (<span class="emphasis"><em>extraction</em></span>)
         </p></dd><dt><span class="term"><code class="option">-z</code>
        </span></dt><dd><p>
          Packs the resulting archive with <span class="command"><strong>gzip</strong></span>
         </p></dd><dt><span class="term"><code class="option">-j</code>
        </span></dt><dd><p>
          Compresses the resulting archive with <span class="command"><strong>bzip2</strong></span>
         </p></dd><dt><span class="term"><code class="option">-v</code>
        </span></dt><dd><p>
          Lists files processed
         </p></dd></dl></div><p>
       The archive files created by <span class="command"><strong>tar</strong></span> end with
       <code class="filename">.tar</code>. If the tar archive was also compressed
       using <span class="command"><strong>gzip</strong></span>, the ending is
       <code class="filename">.tgz</code> or <code class="filename">.tar.gz</code>. If it was
       compressed using <span class="command"><strong>bzip2</strong></span>, the ending is
       <code class="filename">.tar.bz2</code>.
       

      </p></dd><dt><span class="term"><span class="command"><strong>locate</strong></span> <code class="option">patterns</code>
     <a class="indexterm" name="id364631"></a><a class="indexterm" name="id364639"></a><a class="indexterm" name="id364644"></a></span></dt><dd><p>
       This command is only available if you have installed the
       <code class="systemitem">findutils-locate</code> package.
       The <span class="command"><strong>locate</strong></span> command can find in which directory a
       specified file is located. If desired, use wild cards <a class="indexterm" name="id364670"></a> to specify filenames. The program is very fast, because
       it uses a database specifically created for the purpose (rather than
       searching through the entire file system). This very fact, however,
       also results in a major drawback: locate is unable to find any files
       created after the latest update of its database. The database can be
       generated by <code class="systemitem">root</code> with
       <span class="command"><strong>updatedb</strong></span>.
      </p></dd><dt><span class="term"><span class="command"><strong>updatedb</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id364705"></a><a class="indexterm" name="id364714"></a></span></dt><dd><p>
       This command performs an update of the database used by
       <span class="command"><strong>locate</strong></span>. To include files in all existing
       directories, run the program as
       <code class="systemitem">root</code>. It also makes sense
       to place it in the background by appending an ampersand
       (<code class="systemitem">&amp;</code>), so you can immediately continue
       working on the same command line (<span class="command"><strong>updatedb &amp;</strong></span>).
       This command usually runs as a daily cron job (see
       <code class="filename">cron.daily</code>).
      </p></dd><dt><span class="term"><span class="command"><strong>find</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id364763"></a><a class="indexterm" name="id364771"></a><a class="indexterm" name="id364776"></a></span></dt><dd><p>
       With <span class="command"><strong>find</strong></span>, search for a file in a given directory.
       The first argument specifies the directory in which to start the
       search. The option <span class="command"><strong>-name</strong></span> must be followed by a
       search string, which may also include wild cards. Unlike
       <span class="command"><strong>locate</strong></span>, which uses a database,
       <span class="command"><strong>find</strong></span> scans the actual directory.
      </p></dd></dl></div></div><div class="sect3" title="7.12.1.2. Commands to Access File Contents"><div class="titlepage"><div><div><h4 class="title"><a name="sec.commands.filecontents"></a>7.12.1.2. Commands to Access File Contents<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.filecontents">¶</a></span></h4></div></div></div><a class="indexterm" name="id364823"></a><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>file</strong></span> <code class="option">[options]</code> <code class="option">[files]</code>
     <a class="indexterm" name="id364850"></a><a class="indexterm" name="id364859"></a></span></dt><dd><p>
       With <span class="command"><strong>file</strong></span>, detect the contents of the specified
       files.
      </p><div class="variablelist"><dl><dt><span class="term">-z</span></dt><dd><p>
          Tries to look inside compressed files
         </p></dd></dl></div></dd></dl></div><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>cat</strong></span> <code class="option">[options]</code> <code class="filename">files</code>
     <a class="indexterm" name="id364915"></a><a class="indexterm" name="id364924"></a></span></dt><dd><p>
       The <span class="command"><strong>cat</strong></span> command displays the contents of a file,
       printing the entire contents to the screen without interruption.
      </p><div class="variablelist"><dl><dt><span class="term">-n</span></dt><dd><p>
          Numbers the output on the left margin
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>less</strong></span> <code class="option">[options]</code> <code class="filename">files</code>
     <a class="indexterm" name="id364977"></a><a class="indexterm" name="id364986"></a></span></dt><dd><p>
       This command can be used to browse the contents of the specified
       file. Scroll half a screen page up or down with <span class="keycap">PgUp</span>
       and <span class="keycap">PgDn</span> or a full screen page down with
       <span class="keycap">Space</span>. Jump to the beginning or end of a file using
       <span class="keycap">Home</span> and <span class="keycap">End</span>. Press
       <span class="keycap">Q</span> to exit the program.
      </p></dd><dt><span class="term"><span class="command"><strong>grep</strong></span> <code class="option">[options]</code> <code class="option">searchstring</code> <code class="filename">files</code>
     <a class="indexterm" name="id365043"></a><a class="indexterm" name="id365052"></a><a class="indexterm" name="id365056"></a></span></dt><dd><p>
       The grep command finds a specific search string in the specified
       files. If the search string is found, the command displays the line
       in which <code class="literal">searchstring</code> was found along with the
       filename.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-i</code>
        </span></dt><dd><p>
          Ignores case
         </p></dd><dt><span class="term"><code class="option">-H</code>
        </span></dt><dd><p>
          Only displays the names of the relevant files, but not the text
          lines
         </p></dd><dt><span class="term"><code class="option">-n</code>
        </span></dt><dd><p>
          Additionally displays the numbers of the lines in which it found a
          hit
         </p></dd><dt><span class="term"><code class="option">-l</code>
        </span></dt><dd><p>
          Only lists the files in which <code class="literal">searchstring</code> does
          not occur
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>diff</strong></span> <code class="option">[options]</code> <code class="filename">file1</code> <code class="filename">file2</code>
     <a class="indexterm" name="id365177"></a><a class="indexterm" name="id365186"></a><a class="indexterm" name="id365191"></a></span></dt><dd><p>
       The <span class="command"><strong>diff</strong></span> command compares the contents of any two
       files. The output produced by the program lists all lines that do not
       match. This is frequently used by programmers who need only to send
       their program alterations and not the entire source code.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-q</code>
        </span></dt><dd><p>
          Only reports whether the two files differ
         </p></dd><dt><span class="term"><code class="option">-u</code>
        </span></dt><dd><p>
          Produces a <span class="quote">&#8220;<span class="quote">unified</span>&#8221;</span> diff, which makes the output
          more readable
         </p></dd></dl></div></dd></dl></div></div><div class="sect3" title="7.12.1.3. File Systems"><div class="titlepage"><div><div><h4 class="title"><a name="sec.commands.filesystems"></a>7.12.1.3. File Systems<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.filesystems">¶</a></span></h4></div></div></div><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>mount</strong></span> <code class="option">[options]</code> <code class="option">[device]</code> <code class="filename">mountpoint</code>
     <a class="indexterm" name="id365292"></a><a class="indexterm" name="id365300"></a><a class="indexterm" name="id365305"></a><a class="indexterm" name="id365314"></a></span></dt><dd><p>
       This command can be used to mount any data media, such as hard disks,
       CD-ROM drives, and other drives, to a directory of the Linux file
       system.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-r</code>
        </span></dt><dd><p>
          Mount read-only
         </p></dd><dt><span class="term"><code class="option">-t filesystem</code>
        </span></dt><dd><p>
          Specify the file system, commonly <code class="literal">ext2</code> for
          Linux hard disks, <code class="literal">msdos</code> for MS-DOS media,
          <code class="literal">vfat</code> for the Windows file system, and
          <code class="literal">iso9660</code> for CDs
         </p></dd></dl></div><p>
       For hard disks not defined in the file
       <code class="filename">/etc/fstab</code>, the device type must also be
       specified. In this case, only
       <code class="systemitem">root</code> can mount it. If the
       file system needs to also be mounted by other users, enter the option
       <code class="literal">user</code> in the appropriate line in the
       <code class="filename">/etc/fstab</code> file (separated by commas) and save
       this change. Further information is available in the
       <code class="systemitem">mount(1)</code> man page.
      </p></dd><dt><span class="term"><span class="command"><strong>umount</strong></span> <code class="option">[options]</code> <code class="filename">mountpoint</code>
     <a class="indexterm" name="id365430"></a><a class="indexterm" name="id365438"></a><a class="indexterm" name="id365443"></a></span></dt><dd><p>
       This command unmounts a mounted drive from the file system. To
       prevent data loss, run this command before taking a removable data
       medium from its drive. Normally, only
       <code class="systemitem">root</code> is allowed to run the
       commands <span class="command"><strong>mount</strong></span> and <span class="command"><strong>umount</strong></span>. To
       enable other users to run these commands, edit the
       <code class="filename">/etc/fstab</code> file to specify the option
       <code class="literal">user</code> for the relevant drive.
      </p></dd></dl></div></div></div><div class="sect2" title="7.12.2. System Commands"><div class="titlepage"><div><div><h3 class="title"><a name="sec.commands.system"></a>7.12.2. System Commands<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.system">¶</a></span></h3></div></div></div><p>
   The following section lists a few of the most important commands needed
   for retrieving system information and controlling processes and the
   network.
  </p><div class="sect3" title="7.12.2.1. System Information"><div class="titlepage"><div><div><h4 class="title"><a name="sec.commands.systeminfo"></a>7.12.2.1. System Information<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.systeminfo">¶</a></span></h4></div></div></div><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>df</strong></span> <code class="option">[options]</code> <code class="filename">[directory]</code>
     <a class="indexterm" name="id365530"></a><a class="indexterm" name="id365539"></a></span></dt><dd><p>
       The <span class="command"><strong>df</strong></span> (disk free) command, when used without any
       options, displays information about the total disk space, the disk
       space currently in use, and the free space on all the mounted drives.
       If a directory is specified, the information is limited to the drive
       on which that directory is located.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-h</code>
        </span></dt><dd><p>
          Shows the number of occupied blocks in gigabytes, megabytes, or
          kilobytes&#8212;in human-readable format
         </p></dd><dt><span class="term"><code class="option">-T</code>
        </span></dt><dd><p>
          Type of file system (ext2, nfs, etc.)
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>du</strong></span> <code class="option">[options]</code> <code class="filename">[path]</code>
     <a class="indexterm" name="id365614"></a><a class="indexterm" name="id365623"></a></span></dt><dd><p>
       This command, when executed without any parameters, shows the total
       disk space occupied by files and subdirectories in the current
       directory.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-a</code>
        </span></dt><dd><p>
          Displays the size of each individual file
         </p></dd><dt><span class="term"><code class="option">-h</code>
        </span></dt><dd><p>
          Output in human-readable form
         </p></dd><dt><span class="term"><code class="option">-s</code>
        </span></dt><dd><p>
          Displays only the calculated total size
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>free</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id365707"></a><a class="indexterm" name="id365715"></a></span></dt><dd><p>
       The command <span class="command"><strong>free</strong></span> displays information about RAM
       and swap space usage, showing the total and the used amount in both
       categories. See Section &#8220;The free Command&#8221; (Chapter 18, <i>Special System Features</i>, &#8593;Reference) for more information.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-b</code>
        </span></dt><dd><p>
          Output in bytes
         </p></dd><dt><span class="term"><code class="option">-k</code>
        </span></dt><dd><p>
          Output in kilobytes
         </p></dd><dt><span class="term"><code class="option">-m</code>
        </span></dt><dd><p>
          Output in megabytes
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>date</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id365807"></a><a class="indexterm" name="id365816"></a></span></dt><dd><p>
       This simple program displays the current system time. If run as
       <code class="systemitem">root</code>, it can also be used
       to change the system time. Details about the program are available in
       the date(1) man page.
      </p></dd></dl></div></div><div class="sect3" title="7.12.2.2. Processes"><div class="titlepage"><div><div><h4 class="title"><a name="sec.commands.processes"></a>7.12.2.2. Processes<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.processes">¶</a></span></h4></div></div></div><a class="indexterm" name="id365849"></a><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>top</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id365868"></a><a class="indexterm" name="id365877"></a></span></dt><dd><p>
       <span class="command"><strong>top</strong></span> provides a quick overview of the currently
       running processes. Press <span class="keycap">H</span> to access a page that
       briefly explains the main options for customizing the program.
      </p></dd><dt><span class="term"><span class="command"><strong>ps</strong></span> <code class="option">[options]</code> <code class="option">[process_ID]</code>
     <a class="indexterm" name="id365915"></a><a class="indexterm" name="id365923"></a><a class="indexterm" name="id365928"></a></span></dt><dd><p>
       If run without any options, this command displays a table of all your
       own programs or processes&#8212;those you started. The options for
       this command are not preceded by hyphen.
      </p><div class="variablelist"><dl><dt><span class="term">aux</span></dt><dd><p>
          Displays a detailed list of all processes, independent of the
          owner
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>kill</strong></span> <code class="option">[options]</code> <code class="option">process_ID</code>
     <a class="indexterm" name="id365982"></a><a class="indexterm" name="id365991"></a><a class="indexterm" name="id365996"></a></span></dt><dd><p>
       Unfortunately, sometimes a program cannot be terminated in the normal
       way. In most cases, you should still be able to stop such a runaway
       program by executing the <span class="command"><strong>kill</strong></span> command, specifying
       the respective process ID (see <span class="command"><strong>top</strong></span> and
       <span class="command"><strong>ps</strong></span>). <span class="command"><strong>kill</strong></span> sends a
       <span class="emphasis"><em>TERM</em></span> signal that instructs the program to shut
       itself down. If this does not help, the following parameter can be
       used:
      </p><div class="variablelist"><dl><dt><span class="term">-9</span></dt><dd><p>
          Sends a <span class="emphasis"><em>KILL</em></span> signal instead of a
          <span class="emphasis"><em>TERM</em></span> signal, bringing the specified process
          to an end in almost all cases
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>killall</strong></span> <code class="option">[options]</code> <code class="option">processname</code>
     <a class="indexterm" name="id366078"></a><a class="indexterm" name="id366086"></a></span></dt><dd><p>
       This command is similar to <span class="command"><strong>kill</strong></span>, but uses the
       process name (instead of the process ID) as an argument, killing all
       processes with that name.
      </p></dd></dl></div></div><div class="sect3" title="7.12.2.3. Network"><div class="titlepage"><div><div><h4 class="title"><a name="sec.commands.network"></a>7.12.2.3. Network<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.network">¶</a></span></h4></div></div></div><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>ping</strong></span> <code class="option">[options]</code> <code class="option">hostname_or_IP address</code>
     <a class="indexterm" name="id366135"></a><a class="indexterm" name="id366144"></a></span></dt><dd><p>
       The <span class="command"><strong>ping</strong></span> command is the standard tool for testing
       the basic functionality of TCP/IP networks. It sends a small data
       packet to the destination host, requesting an immediate reply. If
       this works, <span class="command"><strong>ping</strong></span> displays a message to that
       effect, which indicates that the network link is basically
       functioning.
      </p><div class="variablelist"><dl><dt><span class="term"><code class="option">-c</code><em class="replaceable"><code>number</code></em>
        </span></dt><dd><p>
          Determines the total number of packages to send and ends after
          they have been dispatched (by default, there is no limitation set)
         </p></dd><dt><span class="term"><code class="option">-f</code>
        </span></dt><dd><p>
          <span class="emphasis"><em>flood ping</em></span>: sends as many data packages as
          possible; a popular means, reserved for
          <code class="systemitem">root</code>, to test networks
         </p></dd><dt><span class="term"><code class="option">-i</code><em class="replaceable"><code>value</code></em>
        </span></dt><dd><p>
          Specifies the interval between two data packages in seconds
          (default: one second)
         </p></dd></dl></div></dd><dt><span class="term"><span class="command"><strong>host</strong></span> <code class="option">[options]</code> <code class="option">hostname</code> <code class="option">[server]</code>
     <a class="indexterm" name="id366260"></a><a class="indexterm" name="id366269"></a></span></dt><dd><p>
       The domain name system resolves domain names to IP addresses. With
       this tool, send queries to name servers (DNS servers).
      </p></dd><dt><span class="term"><span class="command"><strong>ssh</strong></span> <code class="option">[options]</code> <code class="option">[user@]hostname</code> <code class="option">[command]</code>
     <a class="indexterm" name="id366303"></a><a class="indexterm" name="id366312"></a></span></dt><dd><p>
       SSH is actually an Internet protocol that enables you to work on
       remote hosts across a network. SSH is also the name of a Linux
       program that uses this protocol to enable operations on remote
       computers.
      </p></dd></dl></div></div><div class="sect3" title="7.12.2.4. Miscellaneous"><div class="titlepage"><div><div><h4 class="title"><a name="sec.commands.misc"></a>7.12.2.4. Miscellaneous<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.commands.misc">¶</a></span></h4></div></div></div><div class="variablelist"><dl><dt><span class="term"><span class="command"><strong>passwd</strong></span> <code class="option">[options]</code> <code class="option">[username]</code>
     <a class="indexterm" name="id366358"></a><a class="indexterm" name="id366367"></a><a class="indexterm" name="id366371"></a></span></dt><dd><p>
       Users may change their own passwords at any time using this command.
       The administrator <code class="systemitem">root</code> can
       use the command to change the password of any user on the system.
      </p></dd><dt><span class="term"><span class="command"><strong>su</strong></span> <code class="option">[options]</code> <code class="option">[username]</code>
     <a class="indexterm" name="id366412"></a><a class="indexterm" name="id366420"></a></span></dt><dd><p>
       The <span class="command"><strong>su</strong></span> command makes it possible to log in under a
       different username from a running session. Specify a username and the
       corresponding password. The password is not required from
       <code class="systemitem">root</code>, because
       <code class="systemitem">root</code> is authorized to
       assume the identity of any user. When using the command without
       specifying a username, you are prompted for the
       <code class="systemitem">root</code> password and change to
       the superuser (<code class="systemitem">root</code>). Use
       <span class="command"><strong>su -</strong></span> to start a login shell for a different user.
      </p></dd><dt><span class="term"><span class="command"><strong>halt</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id366481"></a><a class="indexterm" name="id366489"></a><a class="indexterm" name="id366494"></a></span></dt><dd><p>
       To avoid loss of data, you should always use this program to shut
       down your system.
      </p></dd><dt><span class="term"><span class="command"><strong>reboot</strong></span> <code class="option">[options]</code>
     <a class="indexterm" name="id366525"></a><a class="indexterm" name="id366533"></a><a class="indexterm" name="id366538"></a></span></dt><dd><p>
       Does the same as <span class="command"><strong>halt</strong></span> except the system performs
       an immediate reboot.
      </p></dd><dt><span class="term"><span class="command"><strong>clear</strong></span>
     <a class="indexterm" name="id366568"></a><a class="indexterm" name="id366577"></a></span></dt><dd><p>
       This command cleans up the visible area of the console. It has no
       options.
      </p></dd></dl></div><a class="indexterm" name="id366592"></a><a class="indexterm" name="id366598"></a></div></div><div class="sect2" title="7.12.3. For More Information"><div class="titlepage"><div><div><h3 class="title"><a name="sec.shell.commands.info"></a>7.12.3. For More Information<span class="permalink"><a alt="Permalink" title="Copy Permalink" href="#sec.shell.commands.info">¶</a></span></h3></div></div></div><p>
   There are many more commands than listed in this chapter. For information
   about other commands or more detailed information, the O'Reilly
   publication <span class="emphasis"><em>Linux in a Nutshell</em></span> is recommended.
  </p></div></div></div><div class="navfooter"><table width="100%" summary="Navigation footer" border="0" class="bctable"><tr><td width="80%"><div class="breadcrumbs"><p><a href="index.html"> Documentation</a><span class="breadcrumbs-sep"> &gt; </span><a href="book.opensuse.startup.html">Start-Up</a><span class="breadcrumbs-sep"> &gt; </span><a href="part.basics.html">Basics</a><span class="breadcrumbs-sep"> &gt; </span><strong><a accesskey="p" title="Chapter 6. Basic Concepts" href="cha.new.html"><span>&#9664;</span></a> </strong></p></div></td></tr></table></div></body></html>

ACC SHELL 2018