old-www/LDP/www.debian.org/doc/manuals/debian-reference/ch01.en.html

4319 lines
216 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 1. GNU/Linux tutorials</title>
<link rel="stylesheet" href="debian-reference.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.en.html" title="Debian Reference">
<link rel="up" href="index.en.html" title="Debian Reference">
<link rel="prev" href="pr01.en.html" title="Preface">
<link rel="next" href="ch02.en.html" title="Chapter 2. Debian package management">
<link rel="preface" href="pr01.en.html" title="Preface">
<link rel="chapter" href="ch01.en.html" title="Chapter 1. GNU/Linux tutorials">
<link rel="chapter" href="ch02.en.html" title="Chapter 2. Debian package management">
<link rel="chapter" href="ch03.en.html" title="Chapter 3. The system initialization">
<link rel="chapter" href="ch04.en.html" title="Chapter 4. Authentication">
<link rel="chapter" href="ch05.en.html" title="Chapter 5. Network setup">
<link rel="chapter" href="ch06.en.html" title="Chapter 6. Network applications">
<link rel="chapter" href="ch07.en.html" title="Chapter 7. The X Window System">
<link rel="chapter" href="ch08.en.html" title="Chapter 8. I18N and L10N">
<link rel="chapter" href="ch09.en.html" title="Chapter 9. System tips">
<link rel="chapter" href="ch10.en.html" title="Chapter 10. Data management">
<link rel="chapter" href="ch11.en.html" title="Chapter 11. Data conversion">
<link rel="chapter" href="ch12.en.html" title="Chapter 12. Programming">
<link rel="appendix" href="apa.en.html" title="Appendix A. Appendix">
<link rel="section" href="ch01.en.html#_console_basics" title="1.1. Console basics">
<link rel="section" href="ch01.en.html#_unix_like_filesystem" title="1.2. Unix-like filesystem">
<link rel="section" href="ch01.en.html#_midnight_commander_mc" title="1.3. Midnight Commander (MC)">
<link rel="section" href="ch01.en.html#_the_basic_unix_like_work_environment" title="1.4. The basic Unix-like work environment">
<link rel="section" href="ch01.en.html#_the_simple_shell_command" title="1.5. The simple shell command">
<link rel="section" href="ch01.en.html#_unix_like_text_processing" title="1.6. Unix-like text processing">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 1. GNU/Linux tutorials</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="pr01.en.html"><img src="images/prev.gif" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="ch02.en.html"><img src="images/next.gif" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="_gnu_linux_tutorials"></a>Chapter 1. GNU/Linux tutorials</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"><a href="ch01.en.html#_console_basics">1.1. Console basics</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="ch01.en.html#_the_shell_prompt">1.1.1. The shell prompt</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_shell_prompt_under_x">1.1.2. The shell prompt under X</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_root_account">1.1.3. The root account</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_root_shell_prompt">1.1.4. The root shell prompt</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_gui_system_administration_tools">1.1.5. GUI system administration tools</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_virtual_consoles">1.1.6. Virtual consoles</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_how_to_leave_the_command_prompt">1.1.7. How to leave the command prompt</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_how_to_shutdown_the_system">1.1.8. How to shutdown the system</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_recovering_a_sane_console">1.1.9. Recovering a sane console</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_additional_package_suggestions_for_the_newbie">1.1.10. Additional package suggestions for the newbie</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_an_extra_user_account">1.1.11. An extra user account</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_sudo_configuration">1.1.12. sudo configuration</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_play_time">1.1.13. Play time</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="ch01.en.html#_unix_like_filesystem">1.2. Unix-like filesystem</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="ch01.en.html#_unix_file_basics">1.2.1. Unix file basics</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_filesystem_internals">1.2.2. Filesystem internals</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_filesystem_permissions">1.2.3. Filesystem permissions</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_control_of_permissions_for_newly_created_files_umask">1.2.4. Control of permissions for newly created files: umask</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_permissions_for_groups_of_users_group">1.2.5. Permissions for groups of users (group)</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_timestamps">1.2.6. Timestamps</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_links">1.2.7. Links</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_named_pipes_fifos">1.2.8. Named pipes (FIFOs)</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_sockets">1.2.9. Sockets</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_device_files">1.2.10. Device files</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_special_device_files">1.2.11. Special device files</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_procfs_and_sysfs">1.2.12. procfs and sysfs</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_tmpfs">1.2.13. tmpfs</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="ch01.en.html#_midnight_commander_mc">1.3. Midnight Commander (MC)</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="ch01.en.html#_customization_of_mc">1.3.1. Customization of MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_starting_mc">1.3.2. Starting MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_file_manager_in_mc">1.3.3. File manager in MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_command_line_tricks_in_mc">1.3.4. Command-line tricks in MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_internal_editor_in_mc">1.3.5. The internal editor in MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_internal_viewer_in_mc">1.3.6. The internal viewer in MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_auto_start_features_of_mc">1.3.7. Auto-start features of MC</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_ftp_virtual_filesystem_of_mc">1.3.8. FTP virtual filesystem of MC</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="ch01.en.html#_the_basic_unix_like_work_environment">1.4. The basic Unix-like work environment</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="ch01.en.html#_the_login_shell">1.4.1. The login shell</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_customizing_bash">1.4.2. Customizing bash</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_special_key_strokes">1.4.3. Special key strokes</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_unix_style_mouse_operations">1.4.4. Unix style mouse operations</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_pager">1.4.5. The pager</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_the_text_editor">1.4.6. The text editor</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_setting_a_default_text_editor">1.4.7. Setting a default text editor</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_customizing_vim">1.4.8. Customizing vim</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_recording_the_shell_activities">1.4.9. Recording the shell activities</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_basic_unix_commands">1.4.10. Basic Unix commands</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="ch01.en.html#_the_simple_shell_command">1.5. The simple shell command</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="ch01.en.html#_command_execution_and_environment_variable">1.5.1. Command execution and environment variable</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_literal_lang_literal_variable">1.5.2. "<code class="literal">$LANG</code>" variable</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_literal_path_literal_variable">1.5.3. "<code class="literal">$PATH</code>" variable</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_literal_home_literal_variable">1.5.4. "<code class="literal">$HOME</code>" variable</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_command_line_options">1.5.5. Command line options</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_shell_glob">1.5.6. Shell glob</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_return_value_of_the_command">1.5.7. Return value of the command</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_typical_command_sequences_and_shell_redirection">1.5.8. Typical command sequences and shell redirection</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_command_alias">1.5.9. Command alias</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="ch01.en.html#_unix_like_text_processing">1.6. Unix-like text processing</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="ch01.en.html#_unix_text_tools">1.6.1. Unix text tools</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_regular_expressions">1.6.2. Regular expressions</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_replacement_expressions">1.6.3. Replacement expressions</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_global_substitution_with_regular_expressions">1.6.4. Global substitution with regular expressions</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_extracting_data_from_text_file_table">1.6.5. Extracting data from text file table</a></span></dt>
<dt><span class="section"><a href="ch01.en.html#_script_snippets_for_piping_commands">1.6.6. Script snippets for piping commands</a></span></dt>
</dl></dd>
</dl>
</div>
<p>I think learning a computer system is like learning a new foreign language. Although tutorial books and documentation are helpful, you have to practice it yourself. In order to help you get started smoothly, I elaborate a few basic points.</p>
<p>The powerful design of <a class="ulink" href="http://www.debian.org" target="_top">Debian</a> <a class="ulink" href="http://en.wikipedia.org/wiki/GNU" target="_top">GNU</a>/<a class="ulink" href="http://en.wikipedia.org/wiki/Linux" target="_top">Linux</a> comes from the <a class="ulink" href="http://en.wikipedia.org/wiki/Unix" target="_top">Unix</a> operating system, i.e., a <a class="ulink" href="http://en.wikipedia.org/wiki/Multi-user" target="_top">multiuser</a>, <a class="ulink" href="http://en.wikipedia.org/wiki/Computer_multitasking" target="_top">multitasking</a> operating system. You must learn to take advantage of the power of these features and similarities between Unix and GNU/Linux.</p>
<p>Don't shy away from Unix oriented texts and don't rely solely on GNU/Linux texts, as this robs you of much useful information.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>If you have been using any <a class="ulink" href="http://en.wikipedia.org/wiki/Unix-like" target="_top">Unix-like</a> system for a while with command line tools, you probably know everything I explain here. Please use this as a reality check and refresher.</p></td></tr>
</table></div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="_console_basics"></a>1.1. Console basics</h2></div></div></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_shell_prompt"></a>1.1.1. The shell prompt</h3></div></div></div>
<p>Upon starting the system, you are presented with the character based login screen if you did not install <a class="ulink" href="http://en.wikipedia.org/wiki/X_Window_System" target="_top">X Window System</a> with the display manager such as <code class="literal">gdm3</code>. Suppose your hostname is <code class="literal">foo</code>, the login prompt looks as follows.</p>
<pre class="screen">foo login:</pre>
<p>If you did install a <a class="ulink" href="http://en.wikipedia.org/wiki/Graphical_user_interface" target="_top">GUI</a> environment such as <a class="ulink" href="http://en.wikipedia.org/wiki/GNOME" target="_top">GNOME</a> or <a class="ulink" href="http://en.wikipedia.org/wiki/KDE" target="_top">KDE</a>, then you can get to a login prompt by Ctrl-Alt-F1, and you can return to the GUI environment via Alt-F7 (see <a class="xref" href="ch01.en.html#_virtual_consoles" title="1.1.6. Virtual consoles">Section 1.1.6, “Virtual consoles”</a> below for more).</p>
<p>At the login prompt, you type your username, e.g. <code class="literal">penguin</code>, and press the Enter-key, then type your password and press the Enter-key again.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Following the Unix tradition, the username and password of the Debian system are case sensitive. The username is usually chosen only from the lowercase. The first user account is usually created during the installation. Additional user accounts can be created with <span class="citerefentry"><span class="refentrytitle">adduser</span>(8)</span> by root.</p></td></tr>
</table></div>
<p>The system starts with the greeting message stored in "<code class="literal">/etc/motd</code>" (Message Of The Day) and presents a command prompt.</p>
<pre class="screen">Debian GNU/Linux lenny/sid foo tty1
foo login: penguin
Password:
Last login: Sun Apr 22 09:29:34 2007 on tty1
Linux snoopy 2.6.20-1-amd64 #1 SMP Sun Apr 15 20:25:49 UTC 2007 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
foo:~$</pre>
<p>Here, the main part of the greeting message can be customized by editing the "<code class="literal">/etc/motd.tail</code>" file. The first line is generated from the system information using "<code class="literal">uname -snrvm</code>".</p>
<p>Now you are in the <a class="ulink" href="http://en.wikipedia.org/wiki/Shell_(computing)" target="_top">shell</a>. The shell interprets your commands.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_shell_prompt_under_x"></a>1.1.2. The shell prompt under X</h3></div></div></div>
<p>If you installed <a class="ulink" href="http://en.wikipedia.org/wiki/X_Window_System" target="_top">X Window System</a> with a display manager such as <a class="ulink" href="http://en.wikipedia.org/wiki/GNOME" target="_top">GNOME</a>'s <code class="literal">gdm3</code> by selecting "Desktop environment" task during the installation, you are presented with the graphical login screen upon starting your system. You type your username and your password to login to the non-privileged user account. Use tab to navigate between username and password, or use the mouse and primary click.</p>
<p>You can gain the shell prompt under X by starting a <code class="literal">x-terminal-emulator</code> program such as <span class="citerefentry"><span class="refentrytitle">gnome-terminal</span>(1)</span>, <span class="citerefentry"><span class="refentrytitle">rxvt</span>(1)</span> or <span class="citerefentry"><span class="refentrytitle">xterm</span>(1)</span>. Under the GNOME Desktop environment, clicking "Applications" → "Accessories" → "Terminal" does the trick.</p>
<p>You can also see the section below <a class="xref" href="ch01.en.html#_virtual_consoles" title="1.1.6. Virtual consoles">Section 1.1.6, “Virtual consoles”</a>.</p>
<p>Under some other Desktop systems (like <code class="literal">fluxbox</code>), there may be no obvious starting point for the menu. If this happens, just try (right) clicking the center of the screen and hope for a menu to pop-up.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_root_account"></a>1.1.3. The root account</h3></div></div></div>
<p>The root account is also called <a class="ulink" href="http://en.wikipedia.org/wiki/Superuser" target="_top">superuser</a> or privileged user. From this account, you can perform the following system administration tasks.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
Read, write, and remove any files on the system irrespective of their file permissions
</p></li>
<li class="listitem"><p>
Set file ownership and permissions of any files on the system
</p></li>
<li class="listitem"><p>
Set the password of any non-privileged users on the system
</p></li>
<li class="listitem"><p>
Login to any accounts without their passwords
</p></li>
</ul></div>
<p>This unlimited power of root account requires you to be considerate and responsible when using it.</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Never share the root password with others.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>File permissions of a file (including hardware devices such as CD-ROM etc. which are just another file for the Debian system) may render it unusable or inaccessible by non-root users. Although the use of root account is a quick way to test this kind of situation, its resolution should be done through proper setting of file permissions and user's group membership (see <a class="xref" href="ch01.en.html#_filesystem_permissions" title="1.2.3. Filesystem permissions">Section 1.2.3, “Filesystem permissions”</a>).</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_root_shell_prompt"></a>1.1.4. The root shell prompt</h3></div></div></div>
<p>Here are a few basic methods to gain the root shell prompt by using the root password.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
Type <code class="literal">root</code> at the character based login prompt.
</p></li>
<li class="listitem"><p>
Click "Applications" → "Accessories" → "Root Terminal", under the GNOME Desktop environment.
</p></li>
<li class="listitem">
<p>
Type "<code class="literal">su -l</code>" from any user shell prompt.
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle"><li class="listitem"><p>
This does not preserve the environment of the current user.
</p></li></ul></div>
</li>
<li class="listitem">
<p>
Type "<code class="literal">su</code>" from any user shell prompt.
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle"><li class="listitem"><p>
This preserves some of the environment of the current user.
</p></li></ul></div>
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_gui_system_administration_tools"></a>1.1.5. GUI system administration tools</h3></div></div></div>
<p>When your desktop menu does not start GUI system administration tools automatically with the appropriate privilege, you can start them from the root shell prompt of the X terminal emulator, such as <span class="citerefentry"><span class="refentrytitle">gnome-terminal</span>(1)</span>, <span class="citerefentry"><span class="refentrytitle">rxvt</span>(1)</span>, or <span class="citerefentry"><span class="refentrytitle">xterm</span>(1)</span>. See <a class="xref" href="ch01.en.html#_the_root_shell_prompt" title="1.1.4. The root shell prompt">Section 1.1.4, “The root shell prompt”</a> and <a class="xref" href="ch07.en.html#_running_x_clients_as_root" title="7.8.4. Running X clients as root">Section 7.8.4, “Running X clients as root”</a>.</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Never start the X display/session manager under the root account by typing in <code class="literal">root</code> to the prompt of the display manager such as <span class="citerefentry"><span class="refentrytitle">gdm3</span>(1)</span>.</p></td></tr>
</table></div>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Never run untrusted remote GUI program under X Window when critical information is displayed since it may eavesdrop your X screen.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_virtual_consoles"></a>1.1.6. Virtual consoles</h3></div></div></div>
<p>In the default Debian system, there are six switchable <a class="ulink" href="http://en.wikipedia.org/wiki/VT100" target="_top">VT100-like</a> character consoles available to start the command shell directly on the Linux host. Unless you are in a GUI environment, you can switch between the virtual consoles by pressing the <code class="literal">Left-Alt-key</code> and one of the <code class="literal">F1</code><code class="literal">F6</code> keys simultaneously. Each character console allows independent login to the account and offers the multiuser environment. This multiuser environment is a great Unix feature, and very addictive.</p>
<p>If you are under the X Window System, you gain access to the character console 1 by pressing <code class="literal">Ctrl-Alt-F1</code> key, i.e., the <code class="literal">left-Ctrl-key</code>, the <code class="literal">left-Alt-key</code>, and the <code class="literal">F1-key</code> are pressed together. You can get back to the X Window System, normally running on the virtual console 7, by pressing <code class="literal">Alt-F7</code>.</p>
<p>You can alternatively change to another virtual console, e.g. to the console 1, from the commandline.</p>
<pre class="screen"># chvt 1</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_how_to_leave_the_command_prompt"></a>1.1.7. How to leave the command prompt</h3></div></div></div>
<p>You type <code class="literal">Ctrl-D</code>, i.e., the <code class="literal">left-Ctrl-key</code> and the <code class="literal">d-key</code> pressed together, at the command prompt to close the shell activity. If you are at the character console, you return to the login prompt with this. Even though these control characters are referred as "control D" with the upper case, you do not need to press the Shift-key. The short hand expression, <code class="literal">^D</code>, is also used for <code class="literal">Ctrl-D</code>. Alternately, you can type "exit".</p>
<p>If you are at <span class="citerefentry"><span class="refentrytitle">x-terminal-emulator</span>(1)</span>, you can close <code class="literal">x-terminal-emulator</code> window with this.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_how_to_shutdown_the_system"></a>1.1.8. How to shutdown the system</h3></div></div></div>
<p>Just like any other modern OS where the file operation involves <a class="ulink" href="http://en.wikipedia.org/wiki/Cache" target="_top">caching data</a> in memory for improved performance, the Debian system needs the proper shutdown procedure before power can safely be turned off. This is to maintain the integrity of files, by forcing all changes in memory to be written to disk. If the software power control is available, the shutdown procedure automatically turns off power of the system. (Otherwise, you may have to press power button for few seconds after the shutdown procedure.)</p>
<p>You can shutdown the system under the normal multiuser mode from the commandline.</p>
<pre class="screen"># shutdown -h now</pre>
<p>You can shutdown the system under the single-user mode from the commandline.</p>
<pre class="screen"># poweroff -i -f</pre>
<p>Alternatively, you may type <code class="literal">Ctrl-Alt-Delete</code> (The <code class="literal">left-Ctrl-key</code>, the <code class="literal">left-Alt-Key</code>, and the <code class="literal">Delete</code> are pressed together) to shutdown if "<code class="literal">/etc/inittab</code>" contains "<code class="literal">ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -h now</code>" in it. See <span class="citerefentry"><span class="refentrytitle">inittab</span>(5)</span> for details.</p>
<p>See <a class="xref" href="ch06.en.html#_how_to_shutdown_the_remote_system_on_ssh" title="6.9.6. How to shutdown the remote system on SSH">Section 6.9.6, “How to shutdown the remote system on SSH”</a>.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_recovering_a_sane_console"></a>1.1.9. Recovering a sane console</h3></div></div></div>
<p>When the screen goes berserk after doing some funny things such as "<code class="literal">cat &lt;some-binary-file&gt;</code>", type "<code class="literal">reset</code>" at the command prompt. You may not be able to see the command echoed as you type. You may also issue "<code class="literal">clear</code>" to clean up the screen.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_additional_package_suggestions_for_the_newbie"></a>1.1.10. Additional package suggestions for the newbie</h3></div></div></div>
<p>Although even the minimal installation of the Debian system without any desktop environment tasks provides the basic Unix functionality, it is a good idea to install few additional commandline and curses based character terminal packages such as <code class="literal">mc</code> and <code class="literal">vim</code> with <span class="citerefentry"><span class="refentrytitle">apt-get</span>(8)</span> for beginners to get started by the following.</p>
<pre class="screen"># apt-get update
...
# apt-get install mc vim sudo
...</pre>
<p>If you already had these packages installed, no new packages are installed.</p>
<div class="table">
<a name="listofinterestineprogrampackages"></a><p class="title"><b>Table 1.1. List of interesting text-mode program packages</b></p>
<div class="table-contents"><table summary="List of interesting text-mode program packages" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
package
</th>
<th align="left">
popcon
</th>
<th align="left">
size
</th>
<th align="left">
description
</th>
</tr></thead>
<tbody>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/mc" target="_top">
<code class="literal">mc</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=mc" target="_top">http://qa.debian.org/popcon.php?package=mc</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/m/mc.html" target="_top">1303</a></td>
<td align="left">
A text-mode full-screen file manager
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/sudo" target="_top">
<code class="literal">sudo</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=sudo" target="_top">http://qa.debian.org/popcon.php?package=sudo</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/s/sudo.html" target="_top">1397</a></td>
<td align="left">
A program to allow limited root privileges to users
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/vim" target="_top">
<code class="literal">vim</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=vim" target="_top">http://qa.debian.org/popcon.php?package=vim</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/v/vim.html" target="_top">1873</a></td>
<td align="left">
Unix text editor Vi IMproved, a programmers text editor (standard version)
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/vim-tiny" target="_top">
<code class="literal">vim-tiny</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=vim-tiny" target="_top">http://qa.debian.org/popcon.php?package=vim-tiny</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/v/vim-tiny.html" target="_top">830</a></td>
<td align="left">
Unix text editor Vi IMproved, a programmers text editor (compact version)
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/emacs23" target="_top">
<code class="literal">emacs23</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=emacs23" target="_top">http://qa.debian.org/popcon.php?package=emacs23</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/e/emacs23.html" target="_top">13038</a></td>
<td align="left">
GNU project Emacs, the Lisp based extensible text editor (version 23)
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/w3m" target="_top">
<code class="literal">w3m</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=w3m" target="_top">http://qa.debian.org/popcon.php?package=w3m</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/w/w3m.html" target="_top">1825</a></td>
<td align="left">
Text-mode WWW browsers
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/gpm" target="_top">
<code class="literal">gpm</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=gpm" target="_top">http://qa.debian.org/popcon.php?package=gpm</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/g/gpm.html" target="_top">584</a></td>
<td align="left">
The Unix style cut-and-paste on the text console (daemon)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>It may be a good idea to read some informative documentations.</p>
<div class="table">
<a name="listofinformativentationpackages"></a><p class="title"><b>Table 1.2. List of informative documentation packages</b></p>
<div class="table-contents"><table summary="List of informative documentation packages" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
package
</th>
<th align="left">
popcon
</th>
<th align="left">
size
</th>
<th align="left">
description
</th>
</tr></thead>
<tbody>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/doc-debian" target="_top">
<code class="literal">doc-debian</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=doc-debian" target="_top">http://qa.debian.org/popcon.php?package=doc-debian</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/doc-debian.html" target="_top">408</a></td>
<td align="left">
Debian Project documentation, (Debian FAQ) and other documents
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/debian-policy" target="_top">
<code class="literal">debian-policy</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=debian-policy" target="_top">http://qa.debian.org/popcon.php?package=debian-policy</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/debian-policy.html" target="_top">3381</a></td>
<td align="left">
Debian Policy Manual and related documents
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/developers-reference" target="_top">
<code class="literal">developers-reference</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=developers-reference" target="_top">http://qa.debian.org/popcon.php?package=developers-reference</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/developers-reference.html" target="_top">1299</a></td>
<td align="left">
Guidelines and information for Debian developers
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/maint-guide" target="_top">
<code class="literal">maint-guide</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=maint-guide" target="_top">http://qa.debian.org/popcon.php?package=maint-guide</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/m/maint-guide.html" target="_top">693</a></td>
<td align="left">
Debian New Maintainers' Guide
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/debian-history" target="_top">
<code class="literal">debian-history</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=debian-history" target="_top">http://qa.debian.org/popcon.php?package=debian-history</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/debian-history.html" target="_top">3571</a></td>
<td align="left">
History of the Debian Project
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/debian-faq" target="_top">
<code class="literal">debian-faq</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=debian-faq" target="_top">http://qa.debian.org/popcon.php?package=debian-faq</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/debian-faq.html" target="_top">1212</a></td>
<td align="left">
Debian FAQ
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/doc-linux-text" target="_top">
<code class="literal">doc-linux-text</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=doc-linux-text" target="_top">http://qa.debian.org/popcon.php?package=doc-linux-text</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/doc-linux-text.html" target="_top">NOT_FOUND</a></td>
<td align="left">
Linux HOWTOs and FAQ (text)
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/doc-linux-html" target="_top">
<code class="literal">doc-linux-html</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=doc-linux-html" target="_top">http://qa.debian.org/popcon.php?package=doc-linux-html</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/doc-linux-html.html" target="_top">NOT_FOUND</a></td>
<td align="left">
Linux HOWTOs and FAQ (html)
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/sysadmin-guide" target="_top">
<code class="literal">sysadmin-guide</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=sysadmin-guide" target="_top">http://qa.debian.org/popcon.php?package=sysadmin-guide</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/s/sysadmin-guide.html" target="_top">964</a></td>
<td align="left">
The Linux System Administrators' Guide
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>You can install some of these packages by the following.</p>
<pre class="screen"># apt-get install package_name</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_an_extra_user_account"></a>1.1.11. An extra user account</h3></div></div></div>
<p>If you do not want to use your main user account for the following training activities, you can create a training user account, e.g. <code class="literal">fish</code> by the following.</p>
<pre class="screen"># adduser fish</pre>
<p>Answer all questions.</p>
<p>This creates a new account named as <code class="literal">fish</code>. After your practice, you can remove this user account and its home directory by the following.</p>
<pre class="screen"># deluser --remove-home fish</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_sudo_configuration"></a>1.1.12. sudo configuration</h3></div></div></div>
<p>For the typical single user workstation such as the desktop Debian system on the laptop PC, it is common to deploy simple configuration of <span class="citerefentry"><span class="refentrytitle">sudo</span>(8)</span> as follows to let the non-privileged user, e.g. <code class="literal">penguin</code>, to gain administrative privilege just with his user password but without the root password.</p>
<pre class="screen"># echo "penguin ALL=(ALL) ALL" &gt;&gt; /etc/sudoers</pre>
<p>Alternatively, it is also common to do as follows to let the non-privileged user, e.g. <code class="literal">penguin</code>, to gain administrative privilege without any password.</p>
<pre class="screen"># echo "penguin ALL=(ALL) NOPASSWD:ALL" &gt;&gt; /etc/sudoers</pre>
<p>This trick should only be used for the single user workstation which you administer and where you are the only user.</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Do not set up accounts of regular users on multiuser workstation like this because it would be very bad for system security.</p></td></tr>
</table></div>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>The password and the account of the <code class="literal">penguin</code> in the above example requires as much protection as the root password and the root account.</p></td></tr>
</table></div>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>Administrative privilege in this context belongs to someone authorized to perform the system administration task on the workstation. Never give some manager in the Admin department of your company or your boss such privilege unless they are authorized and capable.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>For providing access privilege to limited devices and limited files, you should consider to use <span class="strong"><strong>group</strong></span> to provide limited access instead of using the <code class="literal">root</code> privilege via <span class="citerefentry"><span class="refentrytitle">sudo</span>(8)</span>.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>With more thoughtful and careful configuration, <span class="citerefentry"><span class="refentrytitle">sudo</span>(8)</span> can grant limited administrative privileges to other users on a shared system without sharing the root password. This can help with accountability with hosts with multiple administrators so you can tell who did what. On the other hand, you might not want anyone else to have such privileges.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_play_time"></a>1.1.13. Play time</h3></div></div></div>
<p>Now you are ready to play with the Debian system without risks as long as you use the non-privileged user account.</p>
<p>This is because the Debian system is, even after the default installation, configured with proper file permissions which prevent non-privileged users from damaging the system. Of course, there may still be some holes which can be exploited but those who worry about these issues should not be reading this section but should be reading <a class="ulink" href="http://www.debian.org/doc/manuals/securing-debian-howto/" target="_top">Securing Debian Manual</a>.</p>
<p>We learn the Debian system as a <a class="ulink" href="http://en.wikipedia.org/wiki/Unix-like" target="_top">Unix-like</a> system with the following.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p><a class="xref" href="ch01.en.html#_unix_like_filesystem" title="1.2. Unix-like filesystem">Section 1.2, “Unix-like filesystem”</a> (basic concept)
</p></li>
<li class="listitem"><p><a class="xref" href="ch01.en.html#_midnight_commander_mc" title="1.3. Midnight Commander (MC)">Section 1.3, “Midnight Commander (MC)”</a> (survival method)
</p></li>
<li class="listitem"><p><a class="xref" href="ch01.en.html#_the_basic_unix_like_work_environment" title="1.4. The basic Unix-like work environment">Section 1.4, “The basic Unix-like work environment”</a> (basic method)
</p></li>
<li class="listitem"><p><a class="xref" href="ch01.en.html#_the_simple_shell_command" title="1.5. The simple shell command">Section 1.5, “The simple shell command”</a> (shell mechanism)
</p></li>
<li class="listitem"><p><a class="xref" href="ch01.en.html#_unix_like_text_processing" title="1.6. Unix-like text processing">Section 1.6, “Unix-like text processing”</a> (text processing method)
</p></li>
</ul></div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="_unix_like_filesystem"></a>1.2. Unix-like filesystem</h2></div></div></div>
<p>In GNU/Linux and other <a class="ulink" href="http://en.wikipedia.org/wiki/Unix-like" target="_top">Unix-like</a> operating systems, <a class="ulink" href="http://en.wikipedia.org/wiki/Computer_file" target="_top">files</a> are organized into <a class="ulink" href="http://en.wikipedia.org/wiki/Directory_(file_systems)" target="_top">directories</a>. All files and directories are arranged in one big tree rooted at "<code class="literal">/</code>". It's called a tree because if you draw the filesystem, it looks like a tree but it is upside down.</p>
<p>These files and directories can be spread out over several devices. <span class="citerefentry"><span class="refentrytitle">mount</span>(8)</span> serves to attach the filesystem found on some device to the big file tree. Conversely, <span class="citerefentry"><span class="refentrytitle">umount</span>(8)</span> detaches it again. On recent Linux kernels, <span class="citerefentry"><span class="refentrytitle">mount</span>(8)</span> with some options can bind part of a file tree somewhere else or can mount filesystem as shared, private, slave, or unbindable. Supported mount options for each filesystem are available in "<code class="literal">/share/doc/linux-doc-2.6.*/Documentation/filesystems/</code>".</p>
<p><span class="strong"><strong>Directories</strong></span> on Unix systems are called <span class="strong"><strong>folders</strong></span> on some other systems. Please also note that there is no concept for <span class="strong"><strong>drive</strong></span> such as "<code class="literal">A:</code>" on any Unix system. There is one filesystem, and everything is included. This is a huge advantage compared to Windows.</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_unix_file_basics"></a>1.2.1. Unix file basics</h3></div></div></div>
<p>Here are some Unix file basics.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
Filenames are <span class="strong"><strong>case sensitive</strong></span>. That is, "<code class="literal">MYFILE</code>" and "<code class="literal">MyFile</code>" are different files.
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>root directory</strong></span> means root of the filesystem referred as simply "<code class="literal">/</code>". Don't confuse this with the home directory for the root user: "<code class="literal">/root</code>".
</p></li>
<li class="listitem"><p>
Every directory has a name which can contain any letters or symbols <span class="strong"><strong>except "<code class="literal">/</code>"</strong></span>. The root directory is an exception; its name is "<code class="literal">/</code>" (pronounced "slash" or "the root directory") and it cannot be renamed.
</p></li>
<li class="listitem"><p>
Each file or directory is designated by a <span class="strong"><strong>fully-qualified filename</strong></span>, <span class="strong"><strong>absolute filename</strong></span>, or <span class="strong"><strong>path</strong></span>, giving the sequence of directories which must be passed through to reach it. The three terms are synonymous.
</p></li>
<li class="listitem"><p>
All <span class="strong"><strong>fully-qualified filenames</strong></span> begin with the "<code class="literal">/</code>" directory, and there's a "<code class="literal">/</code>" between each directory or file in the filename. The first "<code class="literal">/</code>" is the top level directory, and the other "<code class="literal">/</code>"'s separate successive subdirectories, until we reach the last entry which is the name of the actual file. The words used here can be confusing. Take the following <span class="strong"><strong>fully-qualified filename</strong></span> as an example: "<code class="literal">/usr/share/keytables/us.map.gz</code>". However, people also refers to its basename "<code class="literal">us.map.gz</code>" alone as a filename.
</p></li>
<li class="listitem"><p>
The root directory has a number of branches, such as "<code class="literal">/etc/</code>" and "<code class="literal">/usr/</code>". These subdirectories in turn branch into still more subdirectories, such as "<code class="literal">/etc/init.d/</code>" and "<code class="literal">/usr/local/</code>". The whole thing viewed collectively is called the <span class="strong"><strong>directory tree</strong></span>. You can think of an absolute filename as a route from the base of the tree ("<code class="literal">/</code>") to the end of some branch (a file). You also hear people talk about the directory tree as if it were a <span class="strong"><strong>family</strong></span> tree encompassing all direct descendants of a single figure called the root directory ("<code class="literal">/</code>"): thus subdirectories have <span class="strong"><strong>parents</strong></span>, and a path shows the complete ancestry of a file. There are also relative paths that begin somewhere other than the root directory. You should remember that the directory "<code class="literal">../</code>" refers to the parent directory. This terminology also applies to other directory like structures, such as hierarchical data structures.
</p></li>
<li class="listitem"><p>
There's no special directory path name component that corresponds to a physical device, such as your hard disk. This differs from <a class="ulink" href="http://en.wikipedia.org/wiki/RT-11" target="_top">RT-11</a>, <a class="ulink" href="http://en.wikipedia.org/wiki/CP/M" target="_top">CP/M</a>, <a class="ulink" href="http://en.wikipedia.org/wiki/OpenVMS" target="_top">OpenVMS</a>, <a class="ulink" href="http://en.wikipedia.org/wiki/MS-DOS" target="_top">MS-DOS</a>, <a class="ulink" href="http://en.wikipedia.org/wiki/AmigaOS" target="_top">AmigaOS</a>, and <a class="ulink" href="http://en.wikipedia.org/wiki/Microsoft_Windows" target="_top">Microsoft Windows</a>, where the path contains a device name such as "<code class="literal">C:\</code>". (However, directory entries do exist that refer to physical devices as a part of the normal filesystem. See <a class="xref" href="ch01.en.html#_filesystem_internals" title="1.2.2. Filesystem internals">Section 1.2.2, “Filesystem internals”</a>.)
</p></li>
</ul></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>While you <span class="strong"><strong>can</strong></span> use almost any letters or symbols in a file name, in practice it is a bad idea to do so. It is better to avoid any characters that often have special meanings on the command line, including spaces, tabs, newlines, and other special characters: <code class="literal">{ } ( ) [ ] ' ` " \ / &gt; &lt; | ; ! # &amp; ^ * % @ $</code> . If you want to separate words in a name, good choices are the period, hyphen, and underscore. You could also capitalize each word, "<code class="literal">LikeThis</code>". Experienced Linux users tend to avoid spaces in filenames.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The word "root" can mean either "root user" or "root directory". The context of their usage should make it clear.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The word <span class="strong"><strong>path</strong></span> is used not only for <span class="strong"><strong>fully-qualified filename</strong></span> as above but also for the <span class="strong"><strong>command search path</strong></span>. The intended meaning is usually clear from the context.</p></td></tr>
</table></div>
<p>The detailed best practices for the file hierarchy are described in the Filesystem Hierarchy Standard ("<code class="literal">/usr/share/doc/debian-policy/fhs/fhs-2.3.txt.gz</code>" and <span class="citerefentry"><span class="refentrytitle">hier</span>(7)</span>). You should remember the following facts as the starter.</p>
<div class="table">
<a name="listofusageofkeydirectories"></a><p class="title"><b>Table 1.3. List of usage of key directories</b></p>
<div class="table-contents"><table summary="List of usage of key directories" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
directory
</th>
<th align="left">
usage of the directory
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">/</code>
</td>
<td align="left">
the root directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/etc/</code>
</td>
<td align="left">
system wide configuration files
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/var/log/</code>
</td>
<td align="left">
system log files
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/home/</code>
</td>
<td align="left">
all the home directories for all non-privileged users
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_filesystem_internals"></a>1.2.2. Filesystem internals</h3></div></div></div>
<p>Following the <span class="strong"><strong>Unix tradition</strong></span>, the Debian GNU/Linux system provides the <a class="ulink" href="http://en.wikipedia.org/wiki/File_system" target="_top">filesystem</a> under which physical data on hard disks and other storage devices reside, and the interaction with the hardware devices such as console screens and remote serial consoles are represented in an unified manner under "<code class="literal">/dev/</code>".</p>
<p>Each file, directory, named pipe (a way two programs can share data), or physical device on a Debian GNU/Linux system has a data structure called an <a class="ulink" href="http://en.wikipedia.org/wiki/Inode" target="_top">inode</a> which describes its associated attributes such as the user who owns it (owner), the group that it belongs to, the time last accessed, etc. If you are really interested, see "<code class="literal">/usr/include/linux/fs.h</code>" for the exact definition of "<code class="literal">struct inode</code>" in the Debian GNU/Linux system. The idea of representing just about everything in the filesystem was a Unix innovation, and modern Linux kernels have developed this idea ever further. Now, even information about processes running in the computer can be found in the filesystem.</p>
<p>This abstract and unified representation of physical entities and internal processes is very powerful since this allows us to use the same command for the same kind of operation on many totally different devices. It is even possible to change the way the kernel works by writing data to special files that are linked to running processes.</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>If you need to identify the correspondence between the file tree and the physical entity, execute <span class="citerefentry"><span class="refentrytitle">mount</span>(8)</span> with no arguments.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_filesystem_permissions"></a>1.2.3. Filesystem permissions</h3></div></div></div>
<p><a class="ulink" href="http://en.wikipedia.org/wiki/File_system_permissions" target="_top">Filesystem permissions</a> of <a class="ulink" href="http://en.wikipedia.org/wiki/Unix-like" target="_top">Unix-like</a> system are defined for three categories of affected users.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
The <span class="strong"><strong>user</strong></span> who owns the file (<span class="strong"><strong>u</strong></span>)
</p></li>
<li class="listitem"><p>
Other users in the <span class="strong"><strong>group</strong></span> which the file belongs to (<span class="strong"><strong>g</strong></span>)
</p></li>
<li class="listitem"><p>
All <span class="strong"><strong>other</strong></span> users (<span class="strong"><strong>o</strong></span>) also referred to as "world" and "everyone"
</p></li>
</ul></div>
<p>For the file, each corresponding permission allows following actions.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
The <span class="strong"><strong>read</strong></span> (<span class="strong"><strong>r</strong></span>) permission allows owner to examine contents of the file.
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>write</strong></span> (<span class="strong"><strong>w</strong></span>) permission allows owner to modify the file.
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>execute</strong></span> (<span class="strong"><strong>x</strong></span>) permission allows owner to run the file as a command.
</p></li>
</ul></div>
<p>For the directory, each corresponding permission allows following actions.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
The <span class="strong"><strong>read</strong></span> (<span class="strong"><strong>r</strong></span>) permission allows owner to list contents of the directory.
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>write</strong></span> (<span class="strong"><strong>w</strong></span>) permission allows owner to add or remove files in the directory.
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>execute</strong></span> (<span class="strong"><strong>x</strong></span>) permission allows owner to access files in the directory.
</p></li>
</ul></div>
<p>Here, the <span class="strong"><strong>execute</strong></span> permission on a directory means not only to allow reading of files in that directory but also to allow viewing their attributes, such as the size and the modification time.</p>
<p><span class="citerefentry"><span class="refentrytitle">ls</span>(1)</span> is used to display permission information (and more) for files and directories. When it is invoked with the "<code class="literal">-l</code>" option, it displays the following information in the order given.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p><span class="strong"><strong>Type of file</strong></span> (first character)
</p></li>
<li class="listitem"><p>
Access <span class="strong"><strong>permission</strong></span> of the file (nine characters, consisting of three characters each for user, group, and other in this order)
</p></li>
<li class="listitem"><p><span class="strong"><strong>Number of hard links</strong></span> to the file
</p></li>
<li class="listitem"><p>
Name of the <span class="strong"><strong>user</strong></span> who owns the file
</p></li>
<li class="listitem"><p>
Name of the <span class="strong"><strong>group</strong></span> which the file belongs to
</p></li>
<li class="listitem"><p><span class="strong"><strong>Size</strong></span> of the file in characters (bytes)
</p></li>
<li class="listitem"><p><span class="strong"><strong>Date and time</strong></span> of the file (mtime)
</p></li>
<li class="listitem"><p><span class="strong"><strong>Name</strong></span> of the file
</p></li>
</ul></div>
<div class="table">
<a name="listofthefirstchacteroflsloutput"></a><p class="title"><b>Table 1.4. List of the first character of "<code class="literal">ls -l</code>" output</b></p>
<div class="table-contents"><table summary='List of the first character of "ls -l" output' border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
character
</th>
<th align="left">
meaning
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">-</code>
</td>
<td align="left">
normal file
</td>
</tr>
<tr>
<td align="left">
<code class="literal">d</code>
</td>
<td align="left">
directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">l</code>
</td>
<td align="left">
symlink
</td>
</tr>
<tr>
<td align="left">
<code class="literal">c</code>
</td>
<td align="left">
character device node
</td>
</tr>
<tr>
<td align="left">
<code class="literal">b</code>
</td>
<td align="left">
block device node
</td>
</tr>
<tr>
<td align="left">
<code class="literal">p</code>
</td>
<td align="left">
named pipe
</td>
</tr>
<tr>
<td align="left">
<code class="literal">s</code>
</td>
<td align="left">
socket
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p><span class="citerefentry"><span class="refentrytitle">chown</span>(1)</span> is used from the root account to change the owner of the file. <span class="citerefentry"><span class="refentrytitle">chgrp</span>(1)</span> is used from the file's owner or root account to change the group of the file. <span class="citerefentry"><span class="refentrytitle">chmod</span>(1)</span> is used from the file's owner or root account to change file and directory access permissions. Basic syntax to manipulate a <code class="literal">foo</code> file is the following.</p>
<pre class="screen"># chown &lt;newowner&gt; foo
# chgrp &lt;newgroup&gt; foo
# chmod [ugoa][+-=][rwxXst][,...] foo</pre>
<p>For example, you can make a directory tree to be owned by a user <code class="literal">foo</code> and shared by a group <code class="literal">bar</code> by the following.</p>
<pre class="screen"># cd /some/location/
# chown -R foo:bar .
# chmod -R ug+rwX,o=rX .</pre>
<p>There are three more special permission bits.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
The <span class="strong"><strong>set user ID</strong></span> bit (<span class="strong"><strong>s</strong></span> or <span class="strong"><strong>S</strong></span> instead of user's <span class="strong"><strong>x</strong></span>)
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>set group ID</strong></span> bit (<span class="strong"><strong>s</strong></span> or <span class="strong"><strong>S</strong></span> instead of group's <span class="strong"><strong>x</strong></span>)
</p></li>
<li class="listitem"><p>
The <span class="strong"><strong>sticky</strong></span> bit (<span class="strong"><strong>t</strong></span> or <span class="strong"><strong>T</strong></span> instead of other's <span class="strong"><strong>x</strong></span>)
</p></li>
</ul></div>
<p>Here the output of "<code class="literal">ls -l</code>" for these bits is <span class="strong"><strong>capitalized</strong></span> if execution bits hidden by these outputs are <span class="strong"><strong>unset</strong></span>.</p>
<p>Setting <span class="strong"><strong>set user ID</strong></span> on an executable file allows a user to execute the executable file with the owner ID of the file (for example <span class="strong"><strong>root</strong></span>). Similarly, setting <span class="strong"><strong>set group ID</strong></span> on an executable file allows a user to execute the executable file with the group ID of the file (for example <span class="strong"><strong>root</strong></span>). Because these settings can cause security risks, enabling them requires extra caution.</p>
<p>Setting <span class="strong"><strong>set group ID</strong></span> on a directory enables the <a class="ulink" href="http://en.wikipedia.org/wiki/Berkeley_Software_Distribution" target="_top">BSD-like</a> file creation scheme where all files created in the directory belong to the <span class="strong"><strong>group</strong></span> of the directory.</p>
<p>Setting the <span class="strong"><strong>sticky bit</strong></span> on a directory prevents a file in the directory from being removed by a user who is not the owner of the file. In order to secure contents of a file in world-writable directories such as "<code class="literal">/tmp</code>" or in group-writable directories, one must not only reset the <span class="strong"><strong>write</strong></span> permission for the file but also set the <span class="strong"><strong>sticky bit</strong></span> on the directory. Otherwise, the file can be removed and a new file can be created with the same name by any user who has write access to the directory.</p>
<p>Here are a few interesting examples of file permissions.</p>
<pre class="screen">$ ls -l /etc/passwd /etc/shadow /dev/ppp /usr/sbin/exim4
crw------- 1 root root 108, 0 2007-04-29 07:00 /dev/ppp
-rw-r--r-- 1 root root 1427 2007-04-16 00:19 /etc/passwd
-rw-r----- 1 root shadow 943 2007-04-16 00:19 /etc/shadow
-rwsr-xr-x 1 root root 700056 2007-04-22 05:29 /usr/sbin/exim4
$ ls -ld /tmp /var/tmp /usr/local /var/mail /usr/src
drwxrwxrwt 10 root root 4096 2007-04-29 07:59 /tmp
drwxrwsr-x 10 root staff 4096 2007-03-24 18:48 /usr/local
drwxrwsr-x 4 root src 4096 2007-04-27 00:31 /usr/src
drwxrwsr-x 2 root mail 4096 2007-03-28 23:33 /var/mail
drwxrwxrwt 2 root root 4096 2007-04-29 07:11 /var/tmp</pre>
<p>There is an alternative numeric mode to describe file permissions with <span class="citerefentry"><span class="refentrytitle">chmod</span>(1)</span>. This numeric mode uses 3 to 4 digit wide octal (radix=8) numbers.</p>
<div class="table">
<a name="thenumericmodefoinchmodbcommands"></a><p class="title"><b>Table 1.5. The numeric mode for file permissions in <span class="citerefentry"><span class="refentrytitle">chmod</span>(1)</span> commands</b></p>
<div class="table-contents"><table summary="The numeric mode for file permissions in chmod1 commands" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
digit
</th>
<th align="left">
meaning
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
1st optional digit
</td>
<td align="left">
sum of <span class="strong"><strong>set user ID</strong></span> (=4), <span class="strong"><strong>set group ID</strong></span> (=2), and <span class="strong"><strong>sticky bit</strong></span> (=1)
</td>
</tr>
<tr>
<td align="left">
2nd digit
</td>
<td align="left">
sum of <span class="strong"><strong>read</strong></span> (=4), <span class="strong"><strong>write</strong></span> (=2), and <span class="strong"><strong>execute</strong></span> (=1) permissions for <span class="strong"><strong>user</strong></span>
</td>
</tr>
<tr>
<td align="left">
3rd digit
</td>
<td align="left">
ditto for <span class="strong"><strong>group</strong></span>
</td>
</tr>
<tr>
<td align="left">
4th digit
</td>
<td align="left">
ditto for <span class="strong"><strong>other</strong></span>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>This sounds complicated but it is actually quite simple. If you look at the first few (2-10) columns from "<code class="literal">ls -l</code>" command output and read it as a binary (radix=2) representation of file permissions ("-" being "0" and "rwx" being "1"), the last 3 digit of the numeric mode value should make sense as an octal (radix=8) representation of file permissions to you.</p>
<p>For example, try the following</p>
<pre class="screen">$ touch foo bar
$ chmod u=rw,go=r foo
$ chmod 644 bar
$ ls -l foo bar
-rw-r--r-- 1 penguin penguin 17 2007-04-29 08:22 bar
-rw-r--r-- 1 penguin penguin 12 2007-04-29 08:22 foo</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>If you need to access information displayed by "<code class="literal">ls -l</code>" in shell script, you should use pertinent commands such as <span class="citerefentry"><span class="refentrytitle">test</span>(1)</span>, <span class="citerefentry"><span class="refentrytitle">stat</span>(1)</span> and <span class="citerefentry"><span class="refentrytitle">readlink</span>(1)</span>. The shell builtin such as "<code class="literal">[</code>" or "<code class="literal">test</code>" may be used too.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_control_of_permissions_for_newly_created_files_umask"></a>1.2.4. Control of permissions for newly created files: umask</h3></div></div></div>
<p>What permissions are applied to a newly created file or directory is restricted by the <code class="literal">umask</code> shell builtin command. See <span class="citerefentry"><span class="refentrytitle">dash</span>(1)</span>, <span class="citerefentry"><span class="refentrytitle">bash</span>(1)</span>, and <span class="citerefentry"><span class="refentrytitle">builtins</span>(7)</span>.</p>
<pre class="screen"> (file permissions) = (requested file permissions) &amp; ~(umask value)</pre>
<div class="table">
<a name="theumaskvalueexamples"></a><p class="title"><b>Table 1.6. The <span class="strong">umask</span> value examples</b></p>
<div class="table-contents"><table summary="The umask value examples" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
umask
</th>
<th align="left">
file permissions created
</th>
<th align="left">
directory permissions created
</th>
<th align="left">
usage
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">0022</code>
</td>
<td align="left">
<code class="literal">-rw-r--r--</code>
</td>
<td align="left">
<code class="literal">-rwxr-xr-x</code>
</td>
<td align="left">
writable only by the user
</td>
</tr>
<tr>
<td align="left">
<code class="literal">0002</code>
</td>
<td align="left">
<code class="literal">-rw-rw-r--</code>
</td>
<td align="left">
<code class="literal">-rwxrwxr-x</code>
</td>
<td align="left">
writable by the group
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>The Debian system uses a user private group (UPG) scheme as its default. A UPG is created whenever a new user is added to the system. A UPG has the same name as the user for which it was created and that user is the only member of the UPG. UPG scheme makes it is safe to set umask to <code class="literal">0002</code> since every user has their own private group. (In some Unix variants, it is quite common to setup all normal users belonging to a single <span class="strong"><strong><code class="literal">users</code></strong></span> group and is good idea to set umask to <code class="literal">0022</code> for security in such cases.)</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_permissions_for_groups_of_users_group"></a>1.2.5. Permissions for groups of users (group)</h3></div></div></div>
<p>In order to make group permissions to be applied to a particular user, that user needs to be made a member of the group using "<code class="literal">sudo vigr</code>".</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Alternatively, you may dynamically add users to groups during the authentication process by adding "<code class="literal">auth optional pam_group.so</code>" line to "<code class="literal">/etc/pam.d/common-auth</code>" and setting "<code class="literal">/etc/security/group.conf</code>". (See <a class="xref" href="ch04.en.html" title="Chapter 4. Authentication">Chapter 4, <i>Authentication</i></a>.)</p></td></tr>
</table></div>
<p>The hardware devices are just another kind of file on the Debian system. If you have problems accessing devices such as CD-ROM and USB memory stick from a user account, you should make that user a member of the relevant group.</p>
<p>Some notable system-provided groups allow their members to access particular files and devices without <code class="literal">root</code> privilege.</p>
<div class="table">
<a name="listofnotablesysupsforfileaccess"></a><p class="title"><b>Table 1.7. List of notable system-provided groups for file access</b></p>
<div class="table-contents"><table summary="List of notable system-provided groups for file access" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
group
</th>
<th align="left">
description for accessible files and devices
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">dialout</code>
</td>
<td align="left">
full and direct access to serial ports ("<code class="literal">/dev/ttyS[0-3]</code>")
</td>
</tr>
<tr>
<td align="left">
<code class="literal">dip</code>
</td>
<td align="left">
limited access to serial ports for <span class="strong"><strong>Dialup IP</strong></span> connection to trusted peers
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cdrom</code>
</td>
<td align="left">
CD-ROM, DVD+/-RW drives
</td>
</tr>
<tr>
<td align="left">
<code class="literal">audio</code>
</td>
<td align="left">
audio device
</td>
</tr>
<tr>
<td align="left">
<code class="literal">video</code>
</td>
<td align="left">
video device
</td>
</tr>
<tr>
<td align="left">
<code class="literal">scanner</code>
</td>
<td align="left">
scanner(s)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">adm</code>
</td>
<td align="left">
system monitoring logs
</td>
</tr>
<tr>
<td align="left">
<code class="literal">staff</code>
</td>
<td align="left">
some directories for junior administrative work: "<code class="literal">/usr/local</code>", "<code class="literal">/home</code>"
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>You need to belong to the <code class="literal">dialout</code> group to reconfigure modem, dial anywhere, etc. But if <code class="literal">root</code> creates pre-defined configuration files for trusted peers in "<code class="literal">/etc/ppp/peers/</code>", you only need to belong to the <code class="literal">dip</code> group to create <span class="strong"><strong>Dialup IP</strong></span> connection to those trusted peers using <span class="citerefentry"><span class="refentrytitle">pppd</span>(8)</span>, <span class="citerefentry"><span class="refentrytitle">pon</span>(1)</span>, and <span class="citerefentry"><span class="refentrytitle">poff</span>(1)</span> commands.</p></td></tr>
</table></div>
<p>Some notable system-provided groups allow their members to execute particular commands without <code class="literal">root</code> privilege.</p>
<div class="table">
<a name="listofnotablesysommandexecutions"></a><p class="title"><b>Table 1.8. List of notable system provided groups for particular command executions</b></p>
<div class="table-contents"><table summary="List of notable system provided groups for particular command executions" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
group
</th>
<th align="left">
accessible commands
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">sudo</code>
</td>
<td align="left">
execute <code class="literal">sudo</code> without their password
</td>
</tr>
<tr>
<td align="left">
<code class="literal">lpadmin</code>
</td>
<td align="left">
execute commands to add, modify, and remove printers from printer databases
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>For the full listing of the system provided users and groups, see the recent version of the "Users and Groups" document in "<code class="literal">/usr/share/doc/base-passwd/users-and-groups.html</code>" provided by the <code class="literal">base-passwd</code> package.</p>
<p>See <span class="citerefentry"><span class="refentrytitle">passwd</span>(5)</span>, <span class="citerefentry"><span class="refentrytitle">group</span>(5)</span>, <span class="citerefentry"><span class="refentrytitle">shadow</span>(5)</span>, <span class="citerefentry"><span class="refentrytitle">newgrp</span>(1)</span>, <span class="citerefentry"><span class="refentrytitle">vipw</span>(8)</span>, <span class="citerefentry"><span class="refentrytitle">vigr</span>(8)</span>, and <span class="citerefentry"><span class="refentrytitle">pam_group</span>(8)</span> for management commands of the user and group system.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_timestamps"></a>1.2.6. Timestamps</h3></div></div></div>
<p>There are three types of timestamps for a GNU/Linux file.</p>
<div class="table">
<a name="listoftypesoftimestamps"></a><p class="title"><b>Table 1.9. List of types of timestamps</b></p>
<div class="table-contents"><table summary="List of types of timestamps" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
type
</th>
<th align="left">
meaning
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<span class="strong"><strong>mtime</strong></span>
</td>
<td align="left">
the file modification time (<code class="literal">ls -l</code>)
</td>
</tr>
<tr>
<td align="left">
<span class="strong"><strong>ctime</strong></span>
</td>
<td align="left">
the file status change time (<code class="literal">ls -lc</code>)
</td>
</tr>
<tr>
<td align="left">
<span class="strong"><strong>atime</strong></span>
</td>
<td align="left">
the last file access time (<code class="literal">ls -lu</code>)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p><span class="strong"><strong>ctime</strong></span> is not file creation time.</p></td></tr>
</table></div>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
Overwriting a file changes all of the <span class="strong"><strong>mtime</strong></span>, <span class="strong"><strong>ctime</strong></span>, and <span class="strong"><strong>atime</strong></span> attributes of the file.
</p></li>
<li class="listitem"><p>
Changing ownership or permission of a file changes the <span class="strong"><strong>ctime</strong></span> and <span class="strong"><strong>atime</strong></span> attributes of the file.
</p></li>
<li class="listitem"><p>
Reading a file changes the <span class="strong"><strong>atime</strong></span> of the file.
</p></li>
</ul></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Even simply reading a file on the Debian system normally causes a file write operation to update <span class="strong"><strong>atime</strong></span> information in the <span class="strong"><strong>inode</strong></span>. Mounting a filesystem with "<code class="literal">noatime</code>" or "<code class="literal">relatime</code>" option makes the system skip this operation and results in faster file access for the read. This is often recommended for laptops, because it reduces hard drive activity and saves power. See <span class="citerefentry"><span class="refentrytitle">mount</span>(8)</span>.</p></td></tr>
</table></div>
<p>Use <span class="citerefentry"><span class="refentrytitle">touch</span>(1)</span> command to change timestamps of existing files.</p>
<p>For timestamps, the <code class="literal">ls</code> command outputs different strings under the modern English locale ("<code class="literal">en_US.UTF-8</code>") from under the old one ("<code class="literal">C</code>").</p>
<pre class="screen">$ LANG=en_US.UTF-8 ls -l foo
-rw-r--r-- 1 penguin penguin 3 2008-03-05 00:47 foo
$ LANG=C ls -l foo
-rw-r--r-- 1 penguin penguin 3 Mar 5 00:47 foo</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>See <a class="xref" href="ch09.en.html#_customized_display_of_time_and_date" title="9.2.5. Customized display of time and date">Section 9.2.5, “Customized display of time and date”</a> to customize "<code class="literal">ls -l</code>" output.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_links"></a>1.2.7. Links</h3></div></div></div>
<p>There are two methods of associating a file "<code class="literal">foo</code>" with a different filename "<code class="literal">bar</code>".</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<a class="ulink" href="http://en.wikipedia.org/wiki/Hard_link" target="_top">Hard link</a>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p>
Duplicate name for an existing file
</p></li>
<li class="listitem"><p>
"<code class="literal">ln foo bar</code>"
</p></li>
</ul></div>
</li>
<li class="listitem">
<p>
<a class="ulink" href="http://en.wikipedia.org/wiki/Symbolic_link" target="_top">Symbolic link or symlink</a>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p>
Special file that points to another file by name
</p></li>
<li class="listitem"><p>
"<code class="literal">ln -s foo bar</code>"
</p></li>
</ul></div>
</li>
</ul></div>
<p>See the following example for changes in link counts and the subtle differences in the result of the <code class="literal">rm</code> command.</p>
<pre class="screen">$ echo "Original Content" &gt; foo
$ ls -li foo
2398521 -rw-r--r-- 1 penguin penguin 17 2007-04-29 08:15 foo
$ ln foo bar # hard link
$ ln -s foo baz # symlink
$ ls -li foo bar baz
2398521 -rw-r--r-- 2 penguin penguin 17 2007-04-29 08:15 bar
2398538 lrwxrwxrwx 1 penguin penguin 3 2007-04-29 08:16 baz -&gt; foo
2398521 -rw-r--r-- 2 penguin penguin 17 2007-04-29 08:15 foo
$ rm foo
$ echo "New Content" &gt; foo
$ ls -li foo bar baz
2398521 -rw-r--r-- 1 penguin penguin 17 2007-04-29 08:15 bar
2398538 lrwxrwxrwx 1 penguin penguin 3 2007-04-29 08:16 baz -&gt; foo
2398540 -rw-r--r-- 1 penguin penguin 12 2007-04-29 08:17 foo
$ cat bar
Original Content
$ cat baz
New Content</pre>
<p>The hardlink can be made within the same filesystem and shares the same inode number which the "<code class="literal">-i</code>" option with <span class="citerefentry"><span class="refentrytitle">ls</span>(1)</span> reveals.</p>
<p>The symlink always has nominal file access permissions of "<code class="literal">rwxrwxrwx</code>", as shown in the above example, with the effective access permissions dictated by permissions of the file that it points to.</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>It is generally good idea not to create complicated symbolic links or hardlinks at all unless you have a very good reason. It may cause nightmares where the logical combination of the symbolic links results in loops in the filesystem.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>It is generally preferable to use symbolic links rather than hardlinks unless you have a good reason for using a hardlink.</p></td></tr>
</table></div>
<p>The "<code class="literal">.</code>" directory links to the directory that it appears in, thus the link count of any new directory starts at 2. The "<code class="literal">..</code>" directory links to the parent directory, thus the link count of the directory increases with the addition of new subdirectories.</p>
<p>If you are just moving to Linux from Windows, it soon becomes clear how well-designed the filename linking of Unix is, compared with the nearest Windows equivalent of "shortcuts". Because it is implemented in the filesystem, applications can't see any difference between a linked file and the original. In the case of hardlinks, there really is no difference.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_named_pipes_fifos"></a>1.2.8. Named pipes (FIFOs)</h3></div></div></div>
<p>A <a class="ulink" href="http://en.wikipedia.org/wiki/Named_pipe" target="_top">named pipe</a> is a file that acts like a pipe. You put something into the file, and it comes out the other end. Thus it's called a FIFO, or First-In-First-Out: the first thing you put in the pipe is the first thing to come out the other end.</p>
<p>If you write to a named pipe, the process which is writing to the pipe doesn't terminate until the information being written is read from the pipe. If you read from a named pipe, the reading process waits until there is nothing to read before terminating. The size of the pipe is always zero --- it does not store data, it just links two processes like the shell "<code class="literal">|</code>". However, since this pipe has a name, the two processes don't have to be on the same command line or even be run by the same user. Pipes were a very influential innovation of Unix.</p>
<p>For example, try the following</p>
<pre class="screen">$ cd; mkfifo mypipe
$ echo "hello" &gt;mypipe &amp; # put into background
[1] 8022
$ ls -l mypipe
prw-r--r-- 1 penguin penguin 0 2007-04-29 08:25 mypipe
$ cat mypipe
hello
[1]+ Done echo "hello" &gt;mypipe
$ ls mypipe
mypipe
$ rm mypipe</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_sockets"></a>1.2.9. Sockets</h3></div></div></div>
<p>Sockets are used extensively by all the Internet communication, databases, and the operating system itself. It is similar to the named pipe (FIFO) and allows processes to exchange information even between different computers. For the socket, those processes do not need to be running at the same time nor to be running as the children of the same ancestor process. This is the endpoint for <a class="ulink" href="http://en.wikipedia.org/wiki/Inter-process_communication" target="_top">the inter process communication (IPC)</a>. The exchange of information may occur over the network between different hosts. The two most common ones are <a class="ulink" href="http://en.wikipedia.org/wiki/Internet_socket" target="_top">the Internet socket</a> and <a class="ulink" href="http://en.wikipedia.org/wiki/Unix_domain_socket" target="_top">the Unix domain socket</a>.</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>"<code class="literal">netstat -an</code>" provides a very useful overview of sockets that are open on a given system.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_device_files"></a>1.2.10. Device files</h3></div></div></div>
<p><a class="ulink" href="http://en.wikipedia.org/wiki/Device_file" target="_top">Device files</a> refer to physical or virtual devices on your system, such as your hard disk, video card, screen, or keyboard. An example of a virtual device is the console, represented by "<code class="literal">/dev/console</code>".</p>
<p>There are 2 types of device files.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<span class="strong"><strong>Character device</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p>
Accessed one character at a time
</p></li>
<li class="listitem"><p>
1 character = 1 byte
</p></li>
<li class="listitem"><p>
E.g. keyboard device, serial port, …
</p></li>
</ul></div>
</li>
<li class="listitem">
<p>
<span class="strong"><strong>Block device</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p>
accessed in larger units called blocks
</p></li>
<li class="listitem"><p>
1 block &gt; 1 byte
</p></li>
<li class="listitem"><p>
E.g. hard disk, …
</p></li>
</ul></div>
</li>
</ul></div>
<p>You can read and write device files, though the file may well contain binary data which may be an incomprehensible-to-humans gibberish. Writing data directly to these files is sometimes useful for the troubleshooting of hardware connections. For example, you can dump a text file to the printer device "<code class="literal">/dev/lp0</code>" or send modem commands to the appropriate serial port "<code class="literal">/dev/ttyS0</code>". But, unless this is done carefully, it may cause a major disaster. So be cautious.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>For the normal access to a printer, use <span class="citerefentry"><span class="refentrytitle">lp</span>(1)</span>.</p></td></tr>
</table></div>
<p>The device node number are displayed by executing <span class="citerefentry"><span class="refentrytitle">ls</span>(1)</span> as the following.</p>
<pre class="screen">$ ls -l /dev/hda /dev/ttyS0 /dev/zero
brw-rw---- 1 root cdrom 3, 0 2007-04-29 07:00 /dev/hda
crw-rw---- 1 root dialout 4, 64 2007-04-29 07:00 /dev/ttyS0
crw-rw-rw- 1 root root 1, 5 2007-04-29 07:00 /dev/zero</pre>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
"<code class="literal">/dev/hda</code>" has the major device number 3 and the minor device number 0. This is read/write accessible by the user who belongs to <code class="literal">cdrom</code> group.
</p></li>
<li class="listitem"><p>
"<code class="literal">/dev/ttyS0</code>" has the major device number 4 and the minor device number 64. This is read/write accessible by the user who belongs to <code class="literal">dialout</code> group.
</p></li>
<li class="listitem"><p>
"<code class="literal">/dev/zero</code>" has the major device number 1 and the minor device number 5. This is read/write accessible by anyone.
</p></li>
</ul></div>
<p>In the Linux 2.6 system, the filesystem under "<code class="literal">/dev/</code>" is automatically populated by the <span class="citerefentry"><span class="refentrytitle">udev</span>(7)</span> mechanism.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_special_device_files"></a>1.2.11. Special device files</h3></div></div></div>
<p>There are some special device files.</p>
<div class="table">
<a name="listofspecialdevicefiles"></a><p class="title"><b>Table 1.10. List of special device files</b></p>
<div class="table-contents"><table summary="List of special device files" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
device file
</th>
<th align="left">
action
</th>
<th align="left">
description of response
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">/dev/null</code>
</td>
<td align="left">
read
</td>
<td align="left">
return "end-of-file (EOF) character"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/dev/null</code>
</td>
<td align="left">
write
</td>
<td align="left">
return nothing (a bottomless data dump pit)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/dev/zero</code>
</td>
<td align="left">
read
</td>
<td align="left">
return "the <code class="literal">\0</code> (NUL) character" (not the same as the number zero ASCII)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/dev/random</code>
</td>
<td align="left">
read
</td>
<td align="left">
return random characters from a true random number generator, delivering real entropy (slow)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/dev/urandom</code>
</td>
<td align="left">
read
</td>
<td align="left">
return random characters from a cryptographically secure pseudorandom number generator
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/dev/full</code>
</td>
<td align="left">
write
</td>
<td align="left">
return the disk-full (ENOSPC) error
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>These are frequently used in conjunction with the shell redirection (see <a class="xref" href="ch01.en.html#_typical_command_sequences_and_shell_redirection" title="1.5.8. Typical command sequences and shell redirection">Section 1.5.8, “Typical command sequences and shell redirection”</a>).</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_procfs_and_sysfs"></a>1.2.12. procfs and sysfs</h3></div></div></div>
<p>The <a class="ulink" href="http://en.wikipedia.org/wiki/Procfs" target="_top">procfs</a> and <a class="ulink" href="http://en.wikipedia.org/wiki/Sysfs" target="_top">sysfs</a> mounted on "<code class="literal">/proc</code>" and "<code class="literal">/sys</code>" are the pseudo-filesystem and expose internal data structures of the kernel to the userspace. In other word, these entries are virtual, meaning that they act as a convenient window into the operation of the operating system.</p>
<p>The directory "<code class="literal">/proc</code>" contains (among other things) one subdirectory for each process running on the system, which is named after the process ID (PID). System utilities that access process information, such as <span class="citerefentry"><span class="refentrytitle">ps</span>(1)</span>, get their information from this directory structure.</p>
<p>The directories under "<code class="literal">/proc/sys/</code>" contain interface to change certain kernel parameters at run time. (You may do the same through specialized <span class="citerefentry"><span class="refentrytitle">sysctl</span>(8)</span> command or its preload/configuration file "<code class="literal">/etc/sysctrl.conf</code>".)</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The Linux kernel may complain "Too many open files". You can fix this by increasing "<code class="literal">file-max</code>" value to a larger value from the root shell, e.g., "<code class="literal">echo "65536" &gt; /proc/sys/fs/file-max</code>" (This was needed on older kernels).</p></td></tr>
</table></div>
<p>People frequently panic when they notice one file in particular - "<code class="literal">/proc/kcore</code>" - which is generally huge. This is (more or less) a copy of the content of your computer's memory. It's used to debug the kernel. It is a virtual file that points to computer memory, so don't worry about its size.</p>
<p>The directory under "<code class="literal">/sys</code>" contains exported kernel data structures, their attributes, and their linkages between them. It also contains interface to change certain kernel parameters at run time.</p>
<p>See "<code class="literal">proc.txt(.gz)</code>", "<code class="literal">sysfs.txt(.gz)</code>" and other related documents in the Linux kernel documentation ("<code class="literal">/usr/share/doc/linux-doc-2.6.*/Documentation/filesystems/*</code>") provided by the <code class="literal">linux-doc-2.6.*</code> package.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_tmpfs"></a>1.2.13. tmpfs</h3></div></div></div>
<p>The <a class="ulink" href="http://en.wikipedia.org/wiki/Tmpfs#Linux" target="_top">tmpfs</a> is a temporary filesystem which keeps all files in the <a class="ulink" href="http://en.wikipedia.org/wiki/Virtual_memory" target="_top">virtual memory</a>. The data of the tmpfs in the <a class="ulink" href="http://en.wikipedia.org/wiki/Page_cache" target="_top">page cache</a> on memory may be swapped out to the <a class="ulink" href="http://en.wikipedia.org/wiki/Paging" target="_top">swap space</a> on disk as needed.</p>
<p>The directory "<code class="literal">/run</code>" is mounted as the tmpfs in the early boot process. This enables writing to it even when the directory "<code class="literal">/</code>" is mounted as read-only. This is the new location for the storage of transient state files and replaces several locations described in the <a class="ulink" href="http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard" target="_top">Filesystem Hierarchy Standard</a> version 2.3:</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
"<code class="literal">/var/run</code>" → "<code class="literal">/run</code>"
</p></li>
<li class="listitem"><p>
"<code class="literal">/var/lock</code>" → "<code class="literal">/run/lock</code>"
</p></li>
<li class="listitem"><p>
"<code class="literal">/dev/shm</code>" → "<code class="literal">/run/shm</code>"
</p></li>
</ul></div>
<p>See "<code class="literal">tmpfs.txt(.gz)</code>" in the Linux kernel documentation ("<code class="literal">/usr/share/doc/linux-doc-*/Documentation/filesystems/*</code>") provided by the <code class="literal">linux-doc-*</code> package.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="_midnight_commander_mc"></a>1.3. Midnight Commander (MC)</h2></div></div></div>
<p><a class="ulink" href="http://en.wikipedia.org/wiki/Midnight_Commander" target="_top">Midnight Commander (MC)</a> is a GNU "Swiss army knife" for the Linux console and other terminal environments. This gives newbie a menu driven console experience which is much easier to learn than standard Unix commands.</p>
<p>You may need to install the Midnight Commander package which is titled "<code class="literal">mc</code>" by the following.</p>
<pre class="screen">$ sudo apt-get install mc</pre>
<p>Use the <span class="citerefentry"><span class="refentrytitle">mc</span>(1)</span> command to explore the Debian system. This is the best way to learn. Please explore few interesting locations just using the cursor keys and Enter key.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
"<code class="literal">/etc</code>" and its subdirectories
</p></li>
<li class="listitem"><p>
"<code class="literal">/var/log</code>" and its subdirectories
</p></li>
<li class="listitem"><p>
"<code class="literal">/usr/share/doc</code>" and its subdirectories
</p></li>
<li class="listitem"><p>
"<code class="literal">/sbin</code>" and "<code class="literal">/bin</code>"
</p></li>
</ul></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_customization_of_mc"></a>1.3.1. Customization of MC</h3></div></div></div>
<p>In order to make MC to change working directory upon exit and <code class="literal">cd</code> to the directory, I suggest to modify "<code class="literal">~/.bashrc</code>" to include a script provided by the <code class="literal">mc</code> package.</p>
<pre class="screen">. /usr/lib/mc/mc.sh</pre>
<p>See <span class="citerefentry"><span class="refentrytitle">mc</span>(1)</span> (under the "<code class="literal">-P</code>" option) for the reason. (If you do not understand what exactly I am talking here, you can do this later.)</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_starting_mc"></a>1.3.2. Starting MC</h3></div></div></div>
<p>MC can be started by the following.</p>
<pre class="screen">$ mc</pre>
<p>MC takes care of all file operations through its menu, requiring minimal user effort. Just press F1 to get the help screen. You can play with MC just by pressing cursor-keys and function-keys.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>In some consoles such as <span class="citerefentry"><span class="refentrytitle">gnome-terminal</span>(1)</span>, key strokes of function-keys may be stolen by the console program. You can disable these features by "Edit" → "Keyboard Shortcuts" for <code class="literal">gnome-terminal</code>.</p></td></tr>
</table></div>
<p>If you encounter character encoding problem which displays garbage characters, adding "<code class="literal">-a</code>" to MC's command line may help prevent problems.</p>
<p>If this doesn't clear up your display problems with MC, see <a class="xref" href="ch09.en.html#_the_terminal_configuration" title="9.6.6. The terminal configuration">Section 9.6.6, “The terminal configuration”</a>.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_file_manager_in_mc"></a>1.3.3. File manager in MC</h3></div></div></div>
<p>The default is two directory panels containing file lists. Another useful mode is to set the right window to "information" to see file access privilege information, etc. Following are some essential keystrokes. With the <span class="citerefentry"><span class="refentrytitle">gpm</span>(8)</span> daemon running, one can use a mouse on Linux character consoles, too. (Make sure to press the shift-key to obtain the normal behavior of cut and paste in MC.)</p>
<div class="table">
<a name="thekeybindingsofmc"></a><p class="title"><b>Table 1.11. The key bindings of MC</b></p>
<div class="table-contents"><table summary="The key bindings of MC" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
key
</th>
<th align="left">
key binding
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">F1</code>
</td>
<td align="left">
help menu
</td>
</tr>
<tr>
<td align="left">
<code class="literal">F3</code>
</td>
<td align="left">
internal file viewer
</td>
</tr>
<tr>
<td align="left">
<code class="literal">F4</code>
</td>
<td align="left">
internal editor
</td>
</tr>
<tr>
<td align="left">
<code class="literal">F9</code>
</td>
<td align="left">
activate pull down menu
</td>
</tr>
<tr>
<td align="left">
<code class="literal">F10</code>
</td>
<td align="left">
exit Midnight Commander
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Tab</code>
</td>
<td align="left">
move between two windows
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Insert</code> or <code class="literal">Ctrl-T</code>
</td>
<td align="left">
mark file for a multiple-file operation such as copy
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Del</code>
</td>
<td align="left">
delete file (be careful---set MC to safe delete mode)
</td>
</tr>
<tr>
<td align="left">
Cursor keys
</td>
<td align="left">
self-explanatory
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_command_line_tricks_in_mc"></a>1.3.4. Command-line tricks in MC</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p><code class="literal">cd</code> command changes the directory shown on the selected screen.
</p></li>
<li class="listitem"><p><code class="literal">Ctrl-Enter</code> or <code class="literal">Alt-Enter</code> copies a filename to the command line. Use this with <span class="citerefentry"><span class="refentrytitle">cp</span>(1)</span> and <span class="citerefentry"><span class="refentrytitle">mv</span>(1)</span> commands together with command-line editing.
</p></li>
<li class="listitem"><p><code class="literal">Alt-Tab</code> shows shell filename expansion choices.
</p></li>
<li class="listitem"><p>
One can specify the starting directory for both windows as arguments to MC; for example, "<code class="literal">mc /etc /root</code>".
</p></li>
<li class="listitem"><p><code class="literal">Esc</code> + <code class="literal">n-key</code><code class="literal">Fn</code> (i.e., <code class="literal">Esc</code> + <code class="literal">1</code><code class="literal">F1</code>, etc.; <code class="literal">Esc</code> + <code class="literal">0</code><code class="literal">F10</code>)
</p></li>
<li class="listitem"><p>
Pressing <code class="literal">Esc</code> before the key has the same effect as pressing the <code class="literal">Alt</code> and the key together.; i.e., type <code class="literal">Esc</code> + <code class="literal">c</code> for <code class="literal">Alt-C</code>. <code class="literal">Esc</code> is called meta-key and sometimes noted as "<code class="literal">M-</code>".
</p></li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_internal_editor_in_mc"></a>1.3.5. The internal editor in MC</h3></div></div></div>
<p>The internal editor has an interesting cut-and-paste scheme. Pressing <code class="literal">F3</code> marks the start of a selection, a second <code class="literal">F3</code> marks the end of selection and highlights the selection. Then you can move your cursor. If you press F6, the selected area is moved to the cursor location. If you press F5, the selected area is copied and inserted at the cursor location. <code class="literal">F2</code> saves the file. <code class="literal">F10</code> gets you out. Most cursor keys work intuitively.</p>
<p>This editor can be directly started on a file using one of the following commands.</p>
<pre class="screen">$ mc -e filename_to_edit</pre>
<pre class="screen">$ mcedit filename_to_edit</pre>
<p>This is not a multi-window editor, but one can use multiple Linux consoles to achieve the same effect. To copy between windows, use Alt-F&lt;n&gt; keys to switch virtual consoles and use "File→Insert file" or "File→Copy to file" to move a portion of a file to another file.</p>
<p>This internal editor can be replaced with any external editor of choice.</p>
<p>Also, many programs use the environment variables "<code class="literal">$EDITOR</code>" or "<code class="literal">$VISUAL</code>" to decide which editor to use. If you are uncomfortable with <span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span> or <span class="citerefentry"><span class="refentrytitle">nano</span>(1)</span> initially, you may set these to "<code class="literal">mcedit</code>" by adding the following lines to "<code class="literal">~/.bashrc</code>".</p>
<pre class="screen">export EDITOR=mcedit
export VISUAL=mcedit</pre>
<p>I do recommend setting these to "<code class="literal">vim</code>" if possible.</p>
<p>If you are uncomfortable with <span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span>, you can keep using <span class="citerefentry"><span class="refentrytitle">mcedit</span>(1)</span> for most system maintenance tasks.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_internal_viewer_in_mc"></a>1.3.6. The internal viewer in MC</h3></div></div></div>
<p>MC is a very smart viewer. This is a great tool for searching words in documents. I always use this for files in the "<code class="literal">/usr/share/doc</code>" directory. This is the fastest way to browse through masses of Linux information. This viewer can be directly started using one of the following commands.</p>
<pre class="screen">$ mc -v path/to/filename_to_view</pre>
<pre class="screen">$ mcview path/to/filename_to_view</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_auto_start_features_of_mc"></a>1.3.7. Auto-start features of MC</h3></div></div></div>
<p>Press Enter on a file, and the appropriate program handles the content of the file (see <a class="xref" href="ch09.en.html#_customizing_program_to_be_started" title="9.5.11. Customizing program to be started">Section 9.5.11, “Customizing program to be started”</a>). This is a very convenient MC feature.</p>
<div class="table">
<a name="thereactiontotheenterkeyinmc"></a><p class="title"><b>Table 1.12. The reaction to the enter key in MC</b></p>
<div class="table-contents"><table summary="The reaction to the enter key in MC" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
file type
</th>
<th align="left">
reaction to enter key
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
executable file
</td>
<td align="left">
execute command
</td>
</tr>
<tr>
<td align="left">
man file
</td>
<td align="left">
pipe content to viewer software
</td>
</tr>
<tr>
<td align="left">
html file
</td>
<td align="left">
pipe content to web browser
</td>
</tr>
<tr>
<td align="left">
"<code class="literal">*.tar.gz</code>" and "<code class="literal">*.deb</code>" file
</td>
<td align="left">
browse its contents as if subdirectory
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>In order to allow these viewer and virtual file features to function, viewable files should not be set as executable. Change their status using <span class="citerefentry"><span class="refentrytitle">chmod</span>(1)</span> or via the MC file menu.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_ftp_virtual_filesystem_of_mc"></a>1.3.8. FTP virtual filesystem of MC</h3></div></div></div>
<p>MC can be used to access files over the Internet using FTP. Go to the menu by pressing <code class="literal">F9</code>, then type "<code class="literal">p</code>" to activate the FTP virtual filesystem. Enter a URL in the form "<code class="literal">username:passwd@hostname.domainname</code>", which retrieves a remote directory that appears like a local one.</p>
<p>Try "[http.us.debian.org/debian]" as the URL and browse the Debian archive.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="_the_basic_unix_like_work_environment"></a>1.4. The basic Unix-like work environment</h2></div></div></div>
<p>Although MC enables you to do almost everything, it is very important for you to learn how to use the command line tools invoked from the shell prompt and become familiar with the Unix-like work environment.</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_login_shell"></a>1.4.1. The login shell</h3></div></div></div>
<p>You can select your login shell with <span class="citerefentry"><span class="refentrytitle">chsh</span>(1)</span>.</p>
<div class="table">
<a name="list-of-shell-programs"></a><p class="title"><b>Table 1.13. List of shell programs</b></p>
<div class="table-contents"><table summary="List of shell programs" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
package
</th>
<th align="left">
popcon
</th>
<th align="left">
size
</th>
<th align="left">
POSIX shell
</th>
<th align="left">
description
</th>
</tr></thead>
<tbody>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/bash" target="_top">
<code class="literal">bash</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=bash" target="_top">http://qa.debian.org/popcon.php?package=bash</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/b/bash.html" target="_top">3935</a></td>
<td align="left">
Yes
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/Bash" target="_top">Bash</a>: the GNU Bourne Again SHell (de facto standard)
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/tcsh" target="_top">
<code class="literal">tcsh</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=tcsh" target="_top">http://qa.debian.org/popcon.php?package=tcsh</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/t/tcsh.html" target="_top">1213</a></td>
<td align="left">
No
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/Tcsh" target="_top">TENEX C Shell</a>: an enhanced version of <a class="ulink" href="http://en.wikipedia.org/wiki/C_shell" target="_top">Berkeley csh</a>
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/dash" target="_top">
<code class="literal">dash</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=dash" target="_top">http://qa.debian.org/popcon.php?package=dash</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/d/dash.html" target="_top">212</a></td>
<td align="left">
Yes
</td>
<td align="left">
Debian <a class="ulink" href="http://en.wikipedia.org/wiki/Almquist_shell" target="_top">Almquist Shell</a>, good for shell script
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/zsh" target="_top">
<code class="literal">zsh</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=zsh" target="_top">http://qa.debian.org/popcon.php?package=zsh</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/z/zsh.html" target="_top">11462</a></td>
<td align="left">
Yes
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/Z_shell" target="_top">Z shell</a>: the standard shell with many enhancements
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/pdksh" target="_top">
<code class="literal">pdksh</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=pdksh" target="_top">http://qa.debian.org/popcon.php?package=pdksh</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/p/pdksh.html" target="_top">388</a></td>
<td align="left">
Yes
</td>
<td align="left">
public domain version of the <a class="ulink" href="http://en.wikipedia.org/wiki/Korn_shell" target="_top">Korn shell</a>
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/csh" target="_top">
<code class="literal">csh</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=csh" target="_top">http://qa.debian.org/popcon.php?package=csh</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/c/csh.html" target="_top">340</a></td>
<td align="left">
No
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/OpenBSD" target="_top">OpenBSD</a> C Shell, a version of <a class="ulink" href="http://en.wikipedia.org/wiki/C_shell" target="_top">Berkeley csh</a>
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/sash" target="_top">
<code class="literal">sash</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=sash" target="_top">http://qa.debian.org/popcon.php?package=sash</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/s/sash.html" target="_top">946</a></td>
<td align="left">
Yes
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/Stand-alone_shell" target="_top">Stand-alone shell</a> with builtin commands (Not meant for standard "<code class="literal">/bin/sh</code>")
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/ksh" target="_top">
<code class="literal">ksh</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=ksh" target="_top">http://qa.debian.org/popcon.php?package=ksh</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/k/ksh.html" target="_top">3105</a></td>
<td align="left">
Yes
</td>
<td align="left">
the real, AT&amp;T version of the <a class="ulink" href="http://en.wikipedia.org/wiki/Korn_shell" target="_top">Korn shell</a>
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/rc" target="_top">
<code class="literal">rc</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=rc" target="_top">http://qa.debian.org/popcon.php?package=rc</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/r/rc.html" target="_top">169</a></td>
<td align="left">
No
</td>
<td align="left">
implementation of the <a class="ulink" href="http://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs" target="_top">AT&amp;T Plan 9</a> <a class="ulink" href="http://en.wikipedia.org/wiki/Rc" target="_top">rc shell</a>
</td>
</tr>
<tr>
<td align="left"><a class="ulink" href="http://packages.debian.org/sid/posh" target="_top">
<code class="literal">posh</code>
</a></td>
<td align="left"><a class="ulink" href="http://qa.debian.org/popcon.php?package=posh" target="_top">http://qa.debian.org/popcon.php?package=posh</a></td>
<td align="left"><a class="ulink" href="http://packages.qa.debian.org/p/posh.html" target="_top">201</a></td>
<td align="left">
Yes
</td>
<td align="left">
Policy-compliant Ordinary SHell (<code class="literal">pdksh</code> derivative)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>In this tutorial chapter, the interactive shell always means <code class="literal">bash</code>.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_customizing_bash"></a>1.4.2. Customizing bash</h3></div></div></div>
<p>You can customize <span class="citerefentry"><span class="refentrytitle">bash</span>(1)</span> behavior by "<code class="literal">~/.bashrc</code>".</p>
<p>For example, try the following.</p>
<pre class="screen"># CD upon exiting MC
. /usr/lib/mc/mc.sh
# set CDPATH to good one
CDPATH=.:/usr/share/doc:~:~/Desktop:~
export CDPATH
PATH="${PATH}":/usr/sbin:/sbin
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
export PATH
EDITOR=vim
export EDITOR</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>You can find more <code class="literal">bash</code> customization tips, such as <a class="xref" href="ch09.en.html#_colorized_commands" title="9.2.7. Colorized commands">Section 9.2.7, “Colorized commands”</a>, in <a class="xref" href="ch09.en.html" title="Chapter 9. System tips">Chapter 9, <i>System tips</i></a>.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_special_key_strokes"></a>1.4.3. Special key strokes</h3></div></div></div>
<p>In the <a class="ulink" href="http://en.wikipedia.org/wiki/Unix-like" target="_top">Unix-like</a> environment, there are few key strokes which have special meanings. Please note that on a normal Linux character console, only the left-hand <code class="literal">Ctrl</code> and <code class="literal">Alt</code> keys work as expected. Here are few notable key strokes to remember.</p>
<div class="table">
<a name="listofkeybindingsforbash"></a><p class="title"><b>Table 1.14. List of key bindings for bash</b></p>
<div class="table-contents"><table summary="List of key bindings for bash" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
key
</th>
<th align="left">
description of key binding
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">Ctrl-U</code>
</td>
<td align="left">
erase line before cursor
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-H</code>
</td>
<td align="left">
erase a character before cursor
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-D</code>
</td>
<td align="left">
terminate input (exit shell if you are using shell)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-C</code>
</td>
<td align="left">
terminate a running program
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-Z</code>
</td>
<td align="left">
temporarily stop program by moving it to the background job
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-S</code>
</td>
<td align="left">
halt output to screen
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-Q</code>
</td>
<td align="left">
reactivate output to screen
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-Alt-Del</code>
</td>
<td align="left">
reboot/halt the system, see <span class="citerefentry"><span class="refentrytitle">inittab</span>(5)</span>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Left-Alt-key</code> (optionally, <code class="literal">Windows-key</code>)
</td>
<td align="left">
meta-key for Emacs and the similar UI
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Up-arrow</code>
</td>
<td align="left">
start command history search under <code class="literal">bash</code>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-R</code>
</td>
<td align="left">
start incremental command history search under <code class="literal">bash</code>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Tab</code>
</td>
<td align="left">
complete input of the filename to the command line under <code class="literal">bash</code>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">Ctrl-V</code>
<code class="literal">Tab</code>
</td>
<td align="left">
input <code class="literal">Tab</code> without expansion to the command line under <code class="literal">bash</code>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>The terminal feature of <code class="literal">Ctrl-S</code> can be disabled using <span class="citerefentry"><span class="refentrytitle">stty</span>(1)</span>.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_unix_style_mouse_operations"></a>1.4.4. Unix style mouse operations</h3></div></div></div>
<p>Unix style mouse operations are based on the 3 button mouse system.</p>
<div class="table">
<a name="listofunixstylemouseoperations"></a><p class="title"><b>Table 1.15. List of Unix style mouse operations</b></p>
<div class="table-contents"><table summary="List of Unix style mouse operations" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
action
</th>
<th align="left">
response
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
Left-click-and-drag mouse
</td>
<td align="left">
select and copy to the clipboard
</td>
</tr>
<tr>
<td align="left">
Left-click
</td>
<td align="left">
select the start of selection
</td>
</tr>
<tr>
<td align="left">
Right-click
</td>
<td align="left">
select the end of selection and copy to the clipboard
</td>
</tr>
<tr>
<td align="left">
Middle-click
</td>
<td align="left">
paste clipboard at the cursor
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>The center wheel on the modern wheel mouse is considered middle mouse button and can be used for middle-click. Clicking left and right mouse buttons together serves as the middle-click under the 2 button mouse system situation. In order to use a mouse in Linux character consoles, you need to have <span class="citerefentry"><span class="refentrytitle">gpm</span>(8)</span> running as daemon.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_pager"></a>1.4.5. The pager</h3></div></div></div>
<p><span class="citerefentry"><span class="refentrytitle">less</span>(1)</span> is the enhanced pager (file content browser). Hit "<code class="literal">h</code>" for help. It can do much more than <span class="citerefentry"><span class="refentrytitle">more</span>(1)</span> and can be supercharged by executing "<code class="literal">eval $(lesspipe)</code>" or "<code class="literal">eval $(lessfile)</code>" in the shell startup script. See more in "<code class="literal">/usr/share/doc/lessf/LESSOPEN</code>". The "<code class="literal">-R</code>" option allows raw character output and enables ANSI color escape sequences. See <span class="citerefentry"><span class="refentrytitle">less</span>(1)</span>.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_the_text_editor"></a>1.4.6. The text editor</h3></div></div></div>
<p>You should become proficient in one of variants of <a class="ulink" href="http://en.wikipedia.org/wiki/Vim_(text_editor)" target="_top">Vim</a> or <a class="ulink" href="http://en.wikipedia.org/wiki/Emacs" target="_top">Emacs</a> programs which are popular in the Unix-like system.</p>
<p>I think getting used to Vim commands is the right thing to do, since Vi-editor is always there in the Linux/Unix world. (Actually, original <code class="literal">vi</code> or new <code class="literal">nvi</code> are programs you find everywhere. I chose Vim instead for newbie since it offers you help through <code class="literal">F1</code> key while it is similar enough and more powerful.)</p>
<p>If you chose either <a class="ulink" href="http://en.wikipedia.org/wiki/Emacs" target="_top">Emacs</a> or <a class="ulink" href="http://en.wikipedia.org/wiki/XEmacs" target="_top">XEmacs</a> instead as your choice of the editor, that is another good choice indeed, particularly for programming. Emacs has a plethora of other features as well, including functioning as a newsreader, directory editor, mail program, etc. When used for programming or editing shell scripts, it intelligently recognizes the format of what you are working on, and tries to provide assistance. Some people maintain that the only program they need on Linux is Emacs. Ten minutes learning Emacs now can save hours later. Having the GNU Emacs manual for reference when learning Emacs is highly recommended.</p>
<p>All these programs usually come with tutoring program for you to learn them by practice. Start Vim by typing "<code class="literal">vim</code>" and press F1-key. You should at least read the first 35 lines. Then do the online training course by moving cursor to "<code class="literal">|tutor|</code>" and pressing <code class="literal">Ctrl-]</code>.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Good editors, such as Vim and Emacs, can be used to handle UTF-8 and other exotic encoding texts correctly with proper option in the x-terminal-emulator on X under UTF-8 locale with proper font settings. Please refer to their documentation on multibyte text.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_setting_a_default_text_editor"></a>1.4.7. Setting a default text editor</h3></div></div></div>
<p>Debian comes with a number of different editors. We recommend to install the <code class="literal">vim</code> package, as mentioned above.</p>
<p>Debian provides unified access to the system default editor via command "<code class="literal">/usr/bin/editor</code>" so other programs (e.g., <span class="citerefentry"><span class="refentrytitle">reportbug</span>(1)</span>) can invoke it. You can change it by the following.</p>
<pre class="screen">$ sudo update-alternatives --config editor</pre>
<p>The choice "<code class="literal">/usr/bin/vim.basic</code>" over "<code class="literal">/usr/bin/vim.tiny</code>" is my recommendation for newbies since it supports syntax highlighting.</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>Many programs use the environment variables "<code class="literal">$EDITOR</code>" or "<code class="literal">$VISUAL</code>" to decide which editor to use (see <a class="xref" href="ch01.en.html#_the_internal_editor_in_mc" title="1.3.5. The internal editor in MC">Section 1.3.5, “The internal editor in MC”</a> and <a class="xref" href="ch09.en.html#_customizing_program_to_be_started" title="9.5.11. Customizing program to be started">Section 9.5.11, “Customizing program to be started”</a>). For the consistency on Debian system, set these to "<code class="literal">/usr/bin/editor</code>". (Historically, "<code class="literal">$EDITOR</code>" was "<code class="literal">ed</code>" and "<code class="literal">$VISUAL</code>" was "<code class="literal">vi</code>".)</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_customizing_vim"></a>1.4.8. Customizing vim</h3></div></div></div>
<p>You can customize <span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span> behavior by "<code class="literal">~/.vimrc</code>".</p>
<p>For example, try the following</p>
<pre class="screen">" -------------------------------
" Local configuration
"
set nocompatible
set nopaste
set pastetoggle=&lt;f2&gt;
syn on
if $USER == "root"
set nomodeline
set noswapfile
else
set modeline
set swapfile
endif
" filler to avoid the line above being recognized as a modeline
" filler
" filler</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_recording_the_shell_activities"></a>1.4.9. Recording the shell activities</h3></div></div></div>
<p>The output of the shell command may roll off your screen and may be lost forever. It is good practice to log shell activities into the file for you to review them later. This kind of record is essential when you perform any system administration tasks.</p>
<p>The basic method of recording the shell activity is to run it under <span class="citerefentry"><span class="refentrytitle">script</span>(1)</span>.</p>
<p>For example, try the following</p>
<pre class="screen">$ script
Script started, file is typescript</pre>
<p>Do whatever shell commands under <code class="literal">script</code>.</p>
<p>Press <code class="literal">Ctrl-D</code> to exit <code class="literal">script</code>.</p>
<pre class="screen">$ vim typescript</pre>
<p>See <a class="xref" href="ch09.en.html#_recording_the_shell_activities_cleanly" title="9.2.3. Recording the shell activities cleanly">Section 9.2.3, “Recording the shell activities cleanly”</a> .</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_basic_unix_commands"></a>1.4.10. Basic Unix commands</h3></div></div></div>
<p>Let's learn basic Unix commands. Here I use "Unix" in its generic sense. Any Unix clone OSs usually offer equivalent commands. The Debian system is no exception. Do not worry if some commands do not work as you wish now. If <code class="literal">alias</code> is used in the shell, its corresponding command outputs are different. These examples are not meant to be executed in this order.</p>
<p>Try all following commands from the non-privileged user account.</p>
<div class="table">
<a name="listofbasicunixcommands"></a><p class="title"><b>Table 1.16. List of basic Unix commands</b></p>
<div class="table-contents"><table summary="List of basic Unix commands" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
command
</th>
<th align="left">
description
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">pwd</code>
</td>
<td align="left">
display name of current/working directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">whoami</code>
</td>
<td align="left">
display current user name
</td>
</tr>
<tr>
<td align="left">
<code class="literal">id</code>
</td>
<td align="left">
display current user identity (name, uid, gid, and associated groups)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">file &lt;foo&gt;</code>
</td>
<td align="left">
display a type of file for the file "<code class="literal">&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">type -p &lt;commandname&gt;</code>
</td>
<td align="left">
display a file location of command "<code class="literal">&lt;commandname&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">which &lt;commandname&gt;</code>
</td>
<td align="left">
, ,
</td>
</tr>
<tr>
<td align="left">
<code class="literal">type &lt;commandname&gt;</code>
</td>
<td align="left">
display information on command "<code class="literal">&lt;commandname&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">apropos &lt;key-word&gt;</code>
</td>
<td align="left">
find commands related to "<code class="literal">&lt;key-word&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">man -k &lt;key-word&gt;</code>
</td>
<td align="left">
, ,
</td>
</tr>
<tr>
<td align="left">
<code class="literal">whatis &lt;commandname&gt;</code>
</td>
<td align="left">
display one line explanation on command "<code class="literal">&lt;commandname&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">man -a &lt;commandname&gt;</code>
</td>
<td align="left">
display explanation on command "<code class="literal">&lt;commandname&gt;</code>" (Unix style)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">info &lt;commandname&gt;</code>
</td>
<td align="left">
display rather long explanation on command "<code class="literal">&lt;commandname&gt;</code>" (GNU style)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ls</code>
</td>
<td align="left">
list contents of directory (non-dot files and directories)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ls -a</code>
</td>
<td align="left">
list contents of directory (all files and directories)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ls -A</code>
</td>
<td align="left">
list contents of directory (almost all files and directories, i.e., skip "<code class="literal">..</code>" and "<code class="literal">.</code>")
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ls -la</code>
</td>
<td align="left">
list all contents of directory with detail information
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ls -lai</code>
</td>
<td align="left">
list all contents of directory with inode number and detail information
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ls -d</code>
</td>
<td align="left">
list all directories under the current directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tree</code>
</td>
<td align="left">
display file tree contents
</td>
</tr>
<tr>
<td align="left">
<code class="literal">lsof &lt;foo&gt;</code>
</td>
<td align="left">
list open status of file "<code class="literal">&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">lsof -p &lt;pid&gt;</code>
</td>
<td align="left">
list files opened by the process ID: "<code class="literal">&lt;pid&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">mkdir &lt;foo&gt;</code>
</td>
<td align="left">
make a new directory "<code class="literal">&lt;foo&gt;</code>" in the current directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">rmdir &lt;foo&gt;</code>
</td>
<td align="left">
remove a directory "<code class="literal">&lt;foo&gt;</code>" in the current directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd &lt;foo&gt;</code>
</td>
<td align="left">
change directory to the directory "<code class="literal">&lt;foo&gt;</code>" in the current directory or in the directory listed in the variable "<code class="literal">$CDPATH</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd /</code>
</td>
<td align="left">
change directory to the root directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd</code>
</td>
<td align="left">
change directory to the current user's home directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd /&lt;foo&gt;</code>
</td>
<td align="left">
change directory to the absolute path directory "<code class="literal">/&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd ..</code>
</td>
<td align="left">
change directory to the parent directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd ~&lt;foo&gt;</code>
</td>
<td align="left">
change directory to the home directory of the user "<code class="literal">&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cd -</code>
</td>
<td align="left">
change directory to the previous directory
</td>
</tr>
<tr>
<td align="left">
<code class="literal">&lt;/etc/motd pager</code>
</td>
<td align="left">
display contents of "<code class="literal">/etc/motd</code>" using the default pager
</td>
</tr>
<tr>
<td align="left">
<code class="literal">touch &lt;junkfile&gt;</code>
</td>
<td align="left">
create a empty file "<code class="literal">&lt;junkfile&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">cp &lt;foo&gt; &lt;bar&gt;</code>
</td>
<td align="left">
copy a existing file "<code class="literal">&lt;foo&gt;</code>" to a new file "<code class="literal">&lt;bar&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">rm &lt;junkfile&gt;</code>
</td>
<td align="left">
remove a file "<code class="literal">&lt;junkfile&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">mv &lt;foo&gt; &lt;bar&gt;</code>
</td>
<td align="left">
rename an existing file "<code class="literal">&lt;foo&gt;</code>" to a new name "<code class="literal">&lt;bar&gt;</code>" ("<code class="literal">&lt;bar&gt;</code>" must not exist)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">mv &lt;foo&gt; &lt;bar&gt;</code>
</td>
<td align="left">
move an existing file "<code class="literal">&lt;foo&gt;</code>" to a new location "<code class="literal">&lt;bar&gt;/&lt;foo&gt;</code>" (the directory "<code class="literal">&lt;bar&gt;</code>" must exist)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">mv &lt;foo&gt; &lt;bar&gt;/&lt;baz&gt;</code>
</td>
<td align="left">
move an existing file "<code class="literal">&lt;foo&gt;</code>" to a new location with a new name "<code class="literal">&lt;bar&gt;/&lt;baz&gt;</code>" (the directory "<code class="literal">&lt;bar&gt;</code>" must exist but the directory "<code class="literal">&lt;bar&gt;/&lt;baz&gt;</code>" must not exist)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">chmod 600 &lt;foo&gt;</code>
</td>
<td align="left">
make an existing file "<code class="literal">&lt;foo&gt;</code>" to be non-readable and non-writable by the other people (non-executable for all)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">chmod 644 &lt;foo&gt;</code>
</td>
<td align="left">
make an existing file "<code class="literal">&lt;foo&gt;</code>" to be readable but non-writable by the other people (non-executable for all)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">chmod 755 &lt;foo&gt;</code>
</td>
<td align="left">
make an existing file "<code class="literal">&lt;foo&gt;</code>" to be readable but non-writable by the other people (executable for all)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">find . -name &lt;pattern&gt;</code>
</td>
<td align="left">
find matching filenames using shell "<code class="literal">&lt;pattern&gt;</code>" (slower)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">locate -d . &lt;pattern&gt;</code>
</td>
<td align="left">
find matching filenames using shell "<code class="literal">&lt;pattern&gt;</code>" (quicker using regularly generated database)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">grep -e "&lt;pattern&gt;" *.html</code>
</td>
<td align="left">
find a "&lt;pattern&gt;" in all files ending with "<code class="literal">.html</code>" in current directory and display them all
</td>
</tr>
<tr>
<td align="left">
<code class="literal">top</code>
</td>
<td align="left">
display process information using full screen, type "<code class="literal">q</code>" to quit
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ps aux | pager</code>
</td>
<td align="left">
display information on all the running processes using BSD style output
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ps -ef | pager</code>
</td>
<td align="left">
display information on all the running processes using Unix system-V style output
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ps aux | grep -e "[e]xim4*"</code>
</td>
<td align="left">
display all processes running "<code class="literal">exim</code>" and "<code class="literal">exim4</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ps axf | pager</code>
</td>
<td align="left">
display information on all the running processes with ASCII art output
</td>
</tr>
<tr>
<td align="left">
<code class="literal">kill &lt;1234&gt;</code>
</td>
<td align="left">
kill a process identified by the process ID: "&lt;1234&gt;"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">gzip &lt;foo&gt;</code>
</td>
<td align="left">
compress "<code class="literal">&lt;foo&gt;</code>" to create "<code class="literal">&lt;foo&gt;.gz</code>" using the Lempel-Ziv coding (LZ77)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">gunzip &lt;foo&gt;.gz</code>
</td>
<td align="left">
decompress "<code class="literal">&lt;foo&gt;.gz</code>" to create "<code class="literal">&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">bzip2 &lt;foo&gt;</code>
</td>
<td align="left">
compress "<code class="literal">&lt;foo&gt;</code>" to create "<code class="literal">&lt;foo&gt;.bz2</code>" using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding (better compression than <code class="literal">gzip</code>)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">bunzip2 &lt;foo&gt;.bz2</code>
</td>
<td align="left">
decompress "<code class="literal">&lt;foo&gt;.bz2</code>" to create "<code class="literal">&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">xz &lt;foo&gt;</code>
</td>
<td align="left">
compress "<code class="literal">&lt;foo&gt;</code>" to create "<code class="literal">&lt;foo&gt;.xz</code>" using the LempelZivMarkov chain algorithm (better compression than <code class="literal">bzip2</code>)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">unxz &lt;foo&gt;.xz</code>
</td>
<td align="left">
decompress "<code class="literal">&lt;foo&gt;.xz</code>" to create "<code class="literal">&lt;foo&gt;</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -xvf &lt;foo&gt;.tar</code>
</td>
<td align="left">
extract files from "<code class="literal">&lt;foo&gt;.tar</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -xvzf &lt;foo&gt;.tar.gz</code>
</td>
<td align="left">
extract files from gzipped "<code class="literal">&lt;foo&gt;.tar.gz</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -xvjf &lt;foo&gt;.tar.bz2</code>
</td>
<td align="left">
extract files from "<code class="literal">&lt;foo&gt;.tar.bz2</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -xvJf &lt;foo&gt;.tar.xz</code>
</td>
<td align="left">
extract files from "<code class="literal">&lt;foo&gt;.tar.xz</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -cvf &lt;foo&gt;.tar &lt;bar&gt;/</code>
</td>
<td align="left">
archive contents of folder "<code class="literal">&lt;bar&gt;/</code>" in "<code class="literal">&lt;foo&gt;.tar</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -cvzf &lt;foo&gt;.tar.gz &lt;bar&gt;/</code>
</td>
<td align="left">
archive contents of folder "<code class="literal">&lt;bar&gt;/</code>" in compressed "<code class="literal">&lt;foo&gt;.tar.gz</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -cvjf &lt;foo&gt;.tar.bz2 &lt;bar&gt;/</code>
</td>
<td align="left">
archive contents of folder "<code class="literal">&lt;bar&gt;/</code>" in "<code class="literal">&lt;foo&gt;.tar.bz2</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">tar -cvJf &lt;foo&gt;.tar.xz &lt;bar&gt;/</code>
</td>
<td align="left">
archive contents of folder "<code class="literal">&lt;bar&gt;/</code>" in "<code class="literal">&lt;foo&gt;.tar.xz</code>" archive
</td>
</tr>
<tr>
<td align="left">
<code class="literal">zcat README.gz | pager</code>
</td>
<td align="left">
display contents of compressed "<code class="literal">README.gz</code>" using the default pager
</td>
</tr>
<tr>
<td align="left">
<code class="literal">zcat README.gz &gt; foo</code>
</td>
<td align="left">
create a file "<code class="literal">foo</code>" with the decompressed content of "<code class="literal">README.gz</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">zcat README.gz &gt;&gt; foo</code>
</td>
<td align="left">
append the decompressed content of "<code class="literal">README.gz</code>" to the end of the file "<code class="literal">foo</code>" (if it does not exist, create it first)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Unix has a tradition to hide filenames which start with "<code class="literal">.</code>". They are traditionally files that contain configuration information and user preferences.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>For <code class="literal">cd</code> command, see <span class="citerefentry"><span class="refentrytitle">builtins</span>(7)</span>.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The default pager of the bare bone Debian system is <span class="citerefentry"><span class="refentrytitle">more</span>(1)</span> which cannot scroll back. By installing the <code class="literal">less</code> package using command line "<code class="literal">apt-get install less</code>", <span class="citerefentry"><span class="refentrytitle">less</span>(1)</span> becomes default pager and you can scroll back with cursor keys.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The "<code class="literal">[</code>" and "<code class="literal">]</code>" in the regular expression of the "<code class="literal">ps aux | grep -e "[e]xim4*"</code>" command above enable <code class="literal">grep</code> to avoid matching itself. The "<code class="literal">4*</code>" in the regular expression means 0 or more repeats of character "<code class="literal">4</code>" thus enables <code class="literal">grep</code> to match both "<code class="literal">exim</code>" and "<code class="literal">exim4</code>". Although "<code class="literal">*</code>" is used in the shell filename glob and the regular expression, their meanings are different. Learn the regular expression from <span class="citerefentry"><span class="refentrytitle">grep</span>(1)</span>.</p></td></tr>
</table></div>
<p>Please traverse directories and peek into the system using the above commands as training. If you have questions on any of console commands, please make sure to read the manual page.</p>
<p>For example, try the following</p>
<pre class="screen">$ man man
$ man bash
$ man builtins
$ man grep
$ man ls</pre>
<p>The style of man pages may be a little hard to get used to, because they are rather terse, particularly the older, very traditional ones. But once you get used to it, you come to appreciate their succinctness.</p>
<p>Please note that many Unix-like commands including ones from GNU and BSD display brief help information if you invoke them in one of the following ways (or without any arguments in some cases).</p>
<pre class="screen">$ &lt;commandname&gt; --help
$ &lt;commandname&gt; -h</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="_the_simple_shell_command"></a>1.5. The simple shell command</h2></div></div></div>
<p>Now you have some feel on how to use the Debian system. Let's look deep into the mechanism of the command execution in the Debian system. Here, I have simplified reality for the newbie. See <span class="citerefentry"><span class="refentrytitle">bash</span>(1)</span> for the exact explanation.</p>
<p>A simple command is a sequence of components.</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><p>
Variable assignments (optional)
</p></li>
<li class="listitem"><p>
Command name
</p></li>
<li class="listitem"><p>
Arguments (optional)
</p></li>
<li class="listitem"><p>
Redirections (optional: <code class="literal">&gt;</code> , <code class="literal">&gt;&gt;</code> , <code class="literal">&lt;</code> , <code class="literal">&lt;&lt;</code> , etc.)
</p></li>
<li class="listitem"><p>
Control operator (optional: <code class="literal">&amp;&amp;</code> , <code class="literal">||</code> , &lt;newline&gt; , <code class="literal">;</code> , <code class="literal">&amp;</code> , <code class="literal">(</code> , <code class="literal">)</code> )
</p></li>
</ol></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_command_execution_and_environment_variable"></a>1.5.1. Command execution and environment variable</h3></div></div></div>
<p>Values of some <a class="ulink" href="http://en.wikipedia.org/wiki/Environment_variable" target="_top">environment variables</a> change the behavior of some Unix commands.</p>
<p>Default values of environment variables are initially set by the PAM system and then some of them may be reset by some application programs.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
The display manager such as <code class="literal">gdm3</code> resets environment variables.
</p></li>
<li class="listitem"><p>
The shell in its start up codes resets environment variables in "<code class="literal">~/bash_profile</code>" and "<code class="literal">~/.bashrc</code>".
</p></li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_literal_lang_literal_variable"></a>1.5.2. "<code class="literal">$LANG</code>" variable</h3></div></div></div>
<p>The full locale value given to "<code class="literal">$LANG</code>" variable consists of 3 parts: "<code class="literal">xx_YY.ZZZZ</code>".</p>
<div class="table">
<a name="dpartsoflocalevalue"></a><p class="title"><b>Table 1.17. 3 parts of locale value</b></p>
<div class="table-contents"><table summary="3 parts of locale value" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
locale value
</th>
<th align="left">
meaning
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">xx</code>
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/ISO_639" target="_top">ISO 639 language codes (lower case) such as "en"</a>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">YY</code>
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/ISO_3166-3" target="_top">ISO 3166 country codes (upper case) such as "US"</a>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ZZZZ</code>
</td>
<td align="left">
<a class="ulink" href="http://en.wikipedia.org/wiki/Codeset" target="_top">codeset, always set to "UTF-8"</a>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>For language codes and country codes, see pertinent description in the "<code class="literal">info gettext</code>".</p>
<p>For the codeset on the modern Debian system, you should always set it to <span class="strong"><strong><code class="literal">UTF-8</code></strong></span> unless you specifically want to use the historic one with good reason and background knowledge.</p>
<p>For fine details of the locale configuration, see <a class="xref" href="ch08.en.html#_the_locale" title="8.3. The locale">Section 8.3, “The locale”</a>.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The "<code class="literal">LANG=en_US</code>" is not "<code class="literal">LANG=C</code>" nor "<code class="literal">LANG=en_US.UTF-8</code>". It is "<code class="literal">LANG=en_US.ISO-8859-1</code>" (see <a class="xref" href="ch08.en.html#_basics_of_encoding" title="8.3.1. Basics of encoding">Section 8.3.1, “Basics of encoding”</a>).</p></td></tr>
</table></div>
<div class="table">
<a name="listoflocalerecommendations"></a><p class="title"><b>Table 1.18. List of locale recommendations</b></p>
<div class="table-contents"><table summary="List of locale recommendations" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
locale recommendation
</th>
<th align="left">
Language (area)
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">en_US.UTF-8</code>
</td>
<td align="left">
English(USA)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">en_GB.UTF-8</code>
</td>
<td align="left">
English(Great_Britain)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">fr_FR.UTF-8</code>
</td>
<td align="left">
French(France)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">de_DE.UTF-8</code>
</td>
<td align="left">
German(Germany)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">it_IT.UTF-8</code>
</td>
<td align="left">
Italian(Italy)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">es_ES.UTF-8</code>
</td>
<td align="left">
Spanish(Spain)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ca_ES.UTF-8</code>
</td>
<td align="left">
Catalan(Spain)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">sv_SE.UTF-8</code>
</td>
<td align="left">
Swedish(Sweden)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">pt_BR.UTF-8</code>
</td>
<td align="left">
Portuguese(Brazil)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ru_RU.UTF-8</code>
</td>
<td align="left">
Russian(Russia)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">zh_CN.UTF-8</code>
</td>
<td align="left">
Chinese(P.R._of_China)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">zh_TW.UTF-8</code>
</td>
<td align="left">
Chinese(Taiwan_R.O.C.)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ja_JP.UTF-8</code>
</td>
<td align="left">
Japanese(Japan)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">ko_KR.UTF-8</code>
</td>
<td align="left">
Korean(Republic_of_Korea)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">vi_VN.UTF-8</code>
</td>
<td align="left">
Vietnamese(Vietnam)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>Typical command execution uses a shell line sequence as the following.</p>
<pre class="screen">$ date
Sun Jun 3 10:27:39 JST 2007
$ LANG=fr_FR.UTF-8 date
dimanche 3 juin 2007, 10:27:33 (UTC+0900)</pre>
<p>Here, the program <span class="citerefentry"><span class="refentrytitle">date</span>(1)</span> is executed with different values of the environment variable "<code class="literal">$LANG</code>".</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
For the first command, "<code class="literal">$LANG</code>" is set to the system default <a class="ulink" href="http://en.wikipedia.org/wiki/Locale" target="_top">locale</a> value "<code class="literal">en_US.UTF-8</code>".
</p></li>
<li class="listitem"><p>
For the second command, "<code class="literal">$LANG</code>" is set to the French UTF-8 <a class="ulink" href="http://en.wikipedia.org/wiki/Locale" target="_top">locale</a> value "<code class="literal">fr_FR.UTF-8</code>".
</p></li>
</ul></div>
<p>Most command executions usually do not have preceding environment variable definition. For the above example, you can alternatively execute as the following.</p>
<pre class="screen">$ LANG=fr_FR.UTF-8
$ date
dimanche 3 juin 2007, 10:27:33 (UTC+0900)</pre>
<p>As you can see here, the output of command is affected by the environment variable to produce French output. If you want the environment variable to be inherited to subprocesses (e.g., when calling shell script), you need to <span class="strong"><strong>export</strong></span> it instead by the following.</p>
<pre class="screen">$ export LANG</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>When filing a bug report, running and checking the command under "<code class="literal">LANG=en_US.UTF-8</code>" is good idea if you use non-English environment.</p></td></tr>
</table></div>
<p>See <span class="citerefentry"><span class="refentrytitle">locale</span>(5)</span> and <span class="citerefentry"><span class="refentrytitle">locale</span>(7)</span> for "<code class="literal">$LANG</code>" and related environment variables.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>I recommend you to configure the system environment just by the "<code class="literal">$LANG</code>" variable and to stay away from "<code class="literal">$LC_*</code>" variables unless it is absolutely needed.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_literal_path_literal_variable"></a>1.5.3. "<code class="literal">$PATH</code>" variable</h3></div></div></div>
<p>When you type a command into the shell, the shell searches the command in the list of directories contained in the "<code class="literal">$PATH</code>" environment variable. The value of the "<code class="literal">$PATH</code>" environment variable is also called the shell's search path.</p>
<p>In the default Debian installation, the "<code class="literal">$PATH</code>" environment variable of user accounts may not include "<code class="literal">/sbin</code>" and "<code class="literal">/usr/sbin</code>". For example, the <code class="literal">ifconfig</code> command needs to be issued with full path as "<code class="literal">/sbin/ifconfig</code>". (Similar <code class="literal">ip</code> command is located in "<code class="literal">/bin</code>".)</p>
<p>You can change the "<code class="literal">$PATH</code>" environment variable of Bash shell by "<code class="literal">~/.bash_profile</code>" or "<code class="literal">~/.bashrc</code>" files.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_literal_home_literal_variable"></a>1.5.4. "<code class="literal">$HOME</code>" variable</h3></div></div></div>
<p>Many commands stores user specific configuration in the home directory and changes their behavior by their contents. The home directory is identified by the environment variable "<code class="literal">$HOME</code>".</p>
<div class="table">
<a name="listofhomevalues"></a><p class="title"><b>Table 1.19. List of "<code class="literal">$HOME</code>" values</b></p>
<div class="table-contents"><table summary='List of "$HOME" values' border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
value of "<code class="literal">$HOME</code>"
</th>
<th align="left">
program execution situation
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">/</code>
</td>
<td align="left">
program run by the init process (daemon)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/root</code>
</td>
<td align="left">
program run from the normal root shell
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/home/&lt;normal_user&gt;</code>
</td>
<td align="left">
program run from the normal user shell
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/home/&lt;normal_user&gt;</code>
</td>
<td align="left">
program run from the normal user GUI desktop menu
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/home/&lt;normal_user&gt;</code>
</td>
<td align="left">
program run as root with "<code class="literal">sudo program</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">/root</code>
</td>
<td align="left">
program run as root with "<code class="literal">sudo -H program</code>"
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>Shell expands "<code class="literal">~/</code>" to current user's home directory, i.e., "<code class="literal">$HOME/</code>". Shell expands "<code class="literal">~foo/</code>" to <code class="literal">foo</code>'s home directory, i.e., "<code class="literal">/home/foo/</code>".</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_command_line_options"></a>1.5.5. Command line options</h3></div></div></div>
<p>Some commands take arguments. Arguments starting with "<code class="literal">-</code>" or "<code class="literal">--</code>" are called options and control the behavior of the command.</p>
<pre class="screen">$ date
Mon Oct 27 23:02:09 CET 2003
$ date -R
Mon, 27 Oct 2003 23:02:40 +0100</pre>
<p>Here the command-line argument "<code class="literal">-R</code>" changes <span class="citerefentry"><span class="refentrytitle">date</span>(1)</span> behavior to output <a class="ulink" href="http://tools.ietf.org/html/rfc2822" target="_top">RFC2822</a> compliant date string.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_shell_glob"></a>1.5.6. Shell glob</h3></div></div></div>
<p>Often you want a command to work with a group of files without typing all of them. The filename expansion pattern using the shell <span class="strong"><strong>glob</strong></span>, (sometimes referred as <span class="strong"><strong>wildcards</strong></span>), facilitate this need.</p>
<div class="table">
<a name="shellglobpatterns"></a><p class="title"><b>Table 1.20. Shell glob patterns</b></p>
<div class="table-contents"><table summary="Shell glob patterns" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
shell glob pattern
</th>
<th align="left">
description of match rule
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">*</code>
</td>
<td align="left">
filename (segment) not started with "<code class="literal">.</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">.*</code>
</td>
<td align="left">
filename (segment) started with "<code class="literal">.</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">?</code>
</td>
<td align="left">
exactly one character
</td>
</tr>
<tr>
<td align="left">
<code class="literal">[…]</code>
</td>
<td align="left">
exactly one character with any character enclosed in brackets
</td>
</tr>
<tr>
<td align="left">
<code class="literal">[a-z]</code>
</td>
<td align="left">
exactly one character with any character between "<code class="literal">a</code>" and "<code class="literal">z</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">[^…]</code>
</td>
<td align="left">
exactly one character other than any character enclosed in brackets (excluding "<code class="literal">^</code>")
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>For example, try the following</p>
<pre class="screen">$ mkdir junk; cd junk; touch 1.txt 2.txt 3.c 4.h .5.txt ..6.txt
$ echo *.txt
1.txt 2.txt
$ echo *
1.txt 2.txt 3.c 4.h
$ echo *.[hc]
3.c 4.h
$ echo .*
. .. .5.txt ..6.txt
$ echo .*[^.]*
.5.txt ..6.txt
$ echo [^1-3]*
4.h
$ cd ..; rm -rf junk</pre>
<p>See <span class="citerefentry"><span class="refentrytitle">glob</span>(7)</span>.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Unlike normal filename expansion by the shell, the shell pattern "<code class="literal">*</code>" tested in <span class="citerefentry"><span class="refentrytitle">find</span>(1)</span> with "<code class="literal">-name</code>" test etc., matches the initial "<code class="literal">.</code>" of the filename. (New <a class="ulink" href="http://en.wikipedia.org/wiki/POSIX" target="_top">POSIX</a> feature)</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>BASH can be tweaked to change its glob behavior with its shopt builtin options such as "<code class="literal">dotglob</code>", "<code class="literal">noglob</code>", "<code class="literal">nocaseglob</code>", "<code class="literal">nullglob</code>", "<code class="literal">nocaseglob</code>", "<code class="literal">extglob</code>", etc. See <span class="citerefentry"><span class="refentrytitle">bash</span>(1)</span>.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_return_value_of_the_command"></a>1.5.7. Return value of the command</h3></div></div></div>
<p>Each command returns its exit status (variable: "<code class="literal">$?</code>") as the return value.</p>
<div class="table">
<a name="commandexitcodes"></a><p class="title"><b>Table 1.21. Command exit codes</b></p>
<div class="table-contents"><table summary="Command exit codes" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
command exit status
</th>
<th align="left">
numeric return value
</th>
<th align="left">
logical return value
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
success
</td>
<td align="left">
zero, 0
</td>
<td align="left">
<span class="strong"><strong>TRUE</strong></span>
</td>
</tr>
<tr>
<td align="left">
error
</td>
<td align="left">
non-zero, -1
</td>
<td align="left">
<span class="strong"><strong>FALSE</strong></span>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>For example, try the following.</p>
<pre class="screen">$ [ 1 = 1 ] ; echo $?
0
$ [ 1 = 2 ] ; echo $?
1</pre>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Please note that, in the logical context for the shell, <span class="strong"><strong>success</strong></span> is treated as the logical <span class="strong"><strong>TRUE</strong></span> which has 0 (zero) as its value. This is somewhat non-intuitive and needs to be reminded here.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_typical_command_sequences_and_shell_redirection"></a>1.5.8. Typical command sequences and shell redirection</h3></div></div></div>
<p>Let's try to remember following shell command idioms typed in one line as a part of shell command.</p>
<div class="table">
<a name="shellcommandidioms"></a><p class="title"><b>Table 1.22. Shell command idioms</b></p>
<div class="table-contents"><table summary="Shell command idioms" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
command idiom
</th>
<th align="left">
description
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">command &amp;</code>
</td>
<td align="left">
<span class="strong"><strong>background</strong></span> execution of <code class="literal">command</code> in the subshell
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command1 | command2</code>
</td>
<td align="left">
<span class="strong"><strong>pipe</strong></span> the standard output of <code class="literal">command1</code> to the standard input of <code class="literal">command2</code> (<span class="strong"><strong>concurrent</strong></span> execution)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command1 2&gt;&amp;1 | command2</code>
</td>
<td align="left">
<span class="strong"><strong>pipe</strong></span> both standard output and standard error of <code class="literal">command1</code> to the standard input of <code class="literal">command2</code> (<span class="strong"><strong>concurrent</strong></span> execution)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command1 ; command2</code>
</td>
<td align="left">
execute <code class="literal">command1</code> and <code class="literal">command2</code> <span class="strong"><strong>sequentially</strong></span>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command1 &amp;&amp; command2</code>
</td>
<td align="left">
execute <code class="literal">command1</code>; if successful, execute <code class="literal">command2</code> <span class="strong"><strong>sequentially</strong></span> (return success if both <code class="literal">command1</code> <span class="strong"><strong>and</strong></span> <code class="literal">command2</code> are successful)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command1 || command2</code>
</td>
<td align="left">
execute <code class="literal">command1</code>; if not successful, execute <code class="literal">command2</code> <span class="strong"><strong>sequentially</strong></span> (return success if <code class="literal">command1</code> <span class="strong"><strong>or</strong></span> <code class="literal">command2</code> are successful)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command &gt; foo</code>
</td>
<td align="left">
redirect standard output of <code class="literal">command</code> to a file <code class="literal">foo</code> (overwrite)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command 2&gt; foo</code>
</td>
<td align="left">
redirect standard error of <code class="literal">command</code> to a file <code class="literal">foo</code> (overwrite)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command &gt;&gt; foo</code>
</td>
<td align="left">
redirect standard output of <code class="literal">command</code> to a file <code class="literal">foo</code> (append)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command 2&gt;&gt; foo</code>
</td>
<td align="left">
redirect standard error of <code class="literal">command</code> to a file <code class="literal">foo</code> (append)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command &gt; foo 2&gt;&amp;1</code>
</td>
<td align="left">
redirect both standard output and standard error of <code class="literal">command</code> to a file "<code class="literal">foo</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command &lt; foo</code>
</td>
<td align="left">
redirect standard input of <code class="literal">command</code> to a file <code class="literal">foo</code>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command &lt;&lt; delimiter</code>
</td>
<td align="left">
redirect standard input of <code class="literal">command</code> to the following lines until "<code class="literal">delimiter</code>" is met (here document)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">command &lt;&lt;- delimiter</code>
</td>
<td align="left">
redirect standard input of <code class="literal">command</code> to the following lines until "<code class="literal">delimiter</code>" is met (here document, the leading tab characters are stripped from input lines)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>The Debian system is a multi-tasking system. Background jobs allow users to run multiple programs in a single shell. The management of the background process involves the shell builtins: <code class="literal">jobs</code>, <code class="literal">fg</code>, <code class="literal">bg</code>, and <code class="literal">kill</code>. Please read sections of bash(1) under "SIGNALS", and "JOB CONTROL", and <span class="citerefentry"><span class="refentrytitle">builtins</span>(1)</span>.</p>
<p>For example, try the following</p>
<pre class="screen">$ &lt;/etc/motd pager</pre>
<pre class="screen">$ pager &lt;/etc/motd</pre>
<pre class="screen">$ pager /etc/motd</pre>
<pre class="screen">$ cat /etc/motd | pager</pre>
<p>Although all 4 examples of shell redirections display the same thing, the last example runs an extra <code class="literal">cat</code> command and wastes resources with no reason.</p>
<p>The shell allows you to open files using the <code class="literal">exec</code> builtin with an arbitrary file descriptor.</p>
<pre class="screen">$ echo Hello &gt;foo
$ exec 3&lt;foo 4&gt;bar # open files
$ cat &lt;&amp;3 &gt;&amp;4 # redirect stdin to 3, stdout to 4
$ exec 3&lt;&amp;- 4&gt;&amp;- # close files
$ cat bar
Hello</pre>
<p>Here, "<code class="literal"><span class="emphasis"><em>n</em></span>&lt;&amp;-</code>" and "<code class="literal"><span class="emphasis"><em>n</em></span>&gt;&amp;-</code>" mean to close the file descriptor "<code class="literal"><span class="emphasis"><em>n</em></span></code>".</p>
<p>The file descriptor 0-2 are predefined.</p>
<div class="table">
<a name="predefinedfiledescriptors"></a><p class="title"><b>Table 1.23. Predefined file descriptors</b></p>
<div class="table-contents"><table summary="Predefined file descriptors" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
device
</th>
<th align="left">
description
</th>
<th align="left">
file descriptor
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">stdin</code>
</td>
<td align="left">
standard input
</td>
<td align="left">
0
</td>
</tr>
<tr>
<td align="left">
<code class="literal">stdout</code>
</td>
<td align="left">
standard output
</td>
<td align="left">
1
</td>
</tr>
<tr>
<td align="left">
<code class="literal">stderr</code>
</td>
<td align="left">
standard error
</td>
<td align="left">
2
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_command_alias"></a>1.5.9. Command alias</h3></div></div></div>
<p>You can set an alias for the frequently used command.</p>
<p>For example, try the following</p>
<pre class="screen">$ alias la='ls -la'</pre>
<p>Now, "<code class="literal">la</code>" works as a short hand for "<code class="literal">ls -la</code>" which lists all files in the long listing format.</p>
<p>You can list any existing aliases by <code class="literal">alias</code> (see <span class="citerefentry"><span class="refentrytitle">bash</span>(1)</span> under "SHELL BUILTIN COMMANDS").</p>
<pre class="screen">$ alias
...
alias la='ls -la'</pre>
<p>You can identity exact path or identity of the command by <code class="literal">type</code> (see <span class="citerefentry"><span class="refentrytitle">bash</span>(1)</span> under "SHELL BUILTIN COMMANDS").</p>
<p>For example, try the following</p>
<pre class="screen">$ type ls
ls is hashed (/bin/ls)
$ type la
la is aliased to ls -la
$ type echo
echo is a shell builtin
$ type file
file is /usr/bin/file</pre>
<p>Here <code class="literal">ls</code> was recently searched while "<code class="literal">file</code>" was not, thus "<code class="literal">ls</code>" is "hashed", i.e., the shell has an internal record for the quick access to the location of the "<code class="literal">ls</code>" command.</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>See <a class="xref" href="ch09.en.html#_colorized_commands" title="9.2.7. Colorized commands">Section 9.2.7, “Colorized commands”</a>.</p></td></tr>
</table></div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="_unix_like_text_processing"></a>1.6. Unix-like text processing</h2></div></div></div>
<p>In Unix-like work environment, text processing is done by piping text through chains of standard text processing tools. This was another crucial Unix innovation.</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_unix_text_tools"></a>1.6.1. Unix text tools</h3></div></div></div>
<p>There are few standard text processing tools which are used very often on the Unix-like system.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
No regular expression is used:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">cat</span>(1)</span> concatenates files and outputs the whole content.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">tac</span>(1)</span> concatenates files and outputs in reverse.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">cut</span>(1)</span> selects parts of lines and outputs.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">head</span>(1)</span> outputs the first part of files.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">tail</span>(1)</span> outputs the last part of files.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">sort</span>(1)</span> sorts lines of text files.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">uniq</span>(1)</span> removes duplicate lines from a sorted file.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">tr</span>(1)</span> translates or deletes characters.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">diff</span>(1)</span> compares files line by line.
</p></li>
</ul></div>
</li>
<li class="listitem">
<p>
Basic regular expression (<span class="strong"><strong>BRE</strong></span>) is used:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">grep</span>(1)</span> matches text with patterns.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">ed</span>(1)</span> is a primitive line editor.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">sed</span>(1)</span> is a stream editor.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span> is a screen editor.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">emacs</span>(1)</span> is a screen editor. (somewhat extended <span class="strong"><strong>BRE</strong></span>)
</p></li>
</ul></div>
</li>
<li class="listitem">
<p>
Extended regular expression (<span class="strong"><strong>ERE</strong></span>) is used:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">egrep</span>(1)</span> matches text with patterns.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">awk</span>(1)</span> does simple text processing.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">tcl</span>(3tcl)</span> can do every conceivable text processing: <span class="citerefentry"><span class="refentrytitle">re_syntax</span>(3)</span>. Often used with <span class="citerefentry"><span class="refentrytitle">tk</span>(3tk)</span>.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">perl</span>(1)</span> can do every conceivable text processing. <span class="citerefentry"><span class="refentrytitle">perlre</span>(1)</span>.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">pcregrep</span>(1)</span> from the <code class="literal">pcregrep</code> package matches text with <a class="ulink" href="http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions" target="_top">Perl Compatible Regular Expressions (PCRE)</a> pattern.
</p></li>
<li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">python</span>(1)</span> with the <code class="literal">re</code> module can do every conceivable text processing. See "<code class="literal">/usr/share/doc/python/html/index.html</code>".
</p></li>
</ul></div>
</li>
</ul></div>
<p>If you are not sure what exactly these commands do, please use "<code class="literal">man command</code>" to figure it out by yourself.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Sort order and range expression are locale dependent. If you wish to obtain traditional behavior for a command, use <span class="strong"><strong>C</strong></span> locale instead of <span class="strong"><strong>UTF-8</strong></span> ones by prepnding command with "<code class="literal">LANG=C</code>" (see <a class="xref" href="ch01.en.html#_literal_lang_literal_variable" title='1.5.2. "$LANG" variable'>Section 1.5.2, “"<code class="literal">$LANG</code>" variable”</a> and <a class="xref" href="ch08.en.html#_the_locale" title="8.3. The locale">Section 8.3, “The locale”</a>).</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p><a class="ulink" href="http://en.wikipedia.org/wiki/Perl" target="_top">Perl</a> regular expressions (<span class="citerefentry"><span class="refentrytitle">perlre</span>(1)</span>), <a class="ulink" href="http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions" target="_top">Perl Compatible Regular Expressions (PCRE)</a>, and <a class="ulink" href="http://en.wikipedia.org/wiki/Python_(programming_language)" target="_top">Python</a> regular expressions offered by the <code class="literal">re</code> module have many common extensions to the normal <span class="strong"><strong>ERE</strong></span>.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_regular_expressions"></a>1.6.2. Regular expressions</h3></div></div></div>
<p><a class="ulink" href="http://en.wikipedia.org/wiki/Regular_expression" target="_top">Regular expressions</a> are used in many text processing tools. They are analogous to the shell globs, but they are more complicated and powerful.</p>
<p>The regular expression describes the matching pattern and is made up of text characters and <span class="strong"><strong>metacharacters</strong></span>.</p>
<p>The <span class="strong"><strong>metacharacter</strong></span> is just a character with a special meaning. There are 2 major styles, <span class="strong"><strong>BRE</strong></span> and <span class="strong"><strong>ERE</strong></span>, depending on the text tools as described above.</p>
<div class="table">
<a name="metacharactersforbreandere"></a><p class="title"><b>Table 1.24. Metacharacters for BRE and ERE</b></p>
<div class="table-contents"><table summary="Metacharacters for BRE and ERE" border="1">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
BRE
</th>
<th align="left">
ERE
</th>
<th align="left">
description of the regular expression
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal"> \ . [ ] ^ $ * </code>
</td>
<td align="left">
<code class="literal">\ . [ ] ^ $ *</code>
</td>
<td align="left">
common <span class="strong"><strong>metacharacters</strong></span>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\+ \? \( \) \{ \} \|</code>
</td>
<td align="left">
 
</td>
<td align="left">
BRE only "<code class="literal">\</code>" escaped <span class="strong"><strong>metacharacters</strong></span>
</td>
</tr>
<tr>
<td align="left">
 
</td>
<td align="left">
<code class="literal">+ ? ( ) { } |</code>
</td>
<td align="left">
ERE only non-"<code class="literal">\</code>" escaped <span class="strong"><strong>metacharacters</strong></span>
</td>
</tr>
<tr>
<td align="left">
<code class="literal">c</code>
</td>
<td align="left">
<code class="literal">c</code>
</td>
<td align="left">
match <span class="strong"><strong>non-metacharacter</strong></span> "<code class="literal">c</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\c</code>
</td>
<td align="left">
<code class="literal">\c</code>
</td>
<td align="left">
match a literal character "<code class="literal">c</code>" even if "<code class="literal">c</code>" is <span class="strong"><strong>metacharacter</strong></span> by itself
</td>
</tr>
<tr>
<td align="left">
<code class="literal">.</code>
</td>
<td align="left">
<code class="literal">.</code>
</td>
<td align="left">
match any character including newline
</td>
</tr>
<tr>
<td align="left">
<code class="literal">^</code>
</td>
<td align="left">
<code class="literal">^</code>
</td>
<td align="left">
position at the beginning of a string
</td>
</tr>
<tr>
<td align="left">
<code class="literal">$</code>
</td>
<td align="left">
<code class="literal">$</code>
</td>
<td align="left">
position at the end of a string
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\&lt;</code>
</td>
<td align="left">
<code class="literal">\&lt;</code>
</td>
<td align="left">
position at the beginning of a word
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\&gt;</code>
</td>
<td align="left">
<code class="literal">\&gt;</code>
</td>
<td align="left">
position at the end of a word
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\[abc…\]</code>
</td>
<td align="left">
<code class="literal">[abc…]</code>
</td>
<td align="left">
match any characters in "<code class="literal">abc…</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\[^abc…\]</code>
</td>
<td align="left">
<code class="literal">[^abc…]</code>
</td>
<td align="left">
match any characters except in "<code class="literal">abc…</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">r*</code>
</td>
<td align="left">
<code class="literal">r*</code>
</td>
<td align="left">
match zero or more regular expressions identified by "<code class="literal">r</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">r\+</code>
</td>
<td align="left">
<code class="literal">r+</code>
</td>
<td align="left">
match one or more regular expressions identified by "<code class="literal">r</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">r\?</code>
</td>
<td align="left">
<code class="literal">r?</code>
</td>
<td align="left">
match zero or one regular expressions identified by "<code class="literal">r</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">r1\|r2</code>
</td>
<td align="left">
<code class="literal">r1|r2</code>
</td>
<td align="left">
match one of the regular expressions identified by "<code class="literal">r1</code>" or "<code class="literal">r2</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\(r1\|r2\)</code>
</td>
<td align="left">
<code class="literal">(r1|r2)</code>
</td>
<td align="left">
match one of the regular expressions identified by "<code class="literal">r1</code>" or "<code class="literal">r2</code>" and treat it as a <span class="strong"><strong>bracketed</strong></span> regular expression
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>The regular expression of <span class="strong"><strong><code class="literal">emacs</code></strong></span> is basically <span class="strong"><strong>BRE</strong></span> but has been extended to treat "<code class="literal">+</code>"and "<code class="literal">?</code>" as the <span class="strong"><strong>metacharacters</strong></span> as in <span class="strong"><strong>ERE</strong></span>. Thus, there are no needs to escape them with "<code class="literal">\</code>" in the regular expression of <code class="literal">emacs</code>.</p>
<p><span class="citerefentry"><span class="refentrytitle">grep</span>(1)</span> can be used to perform the text search using the regular expression.</p>
<p>For example, try the following</p>
<pre class="screen">$ egrep 'GNU.*LICENSE|Yoyodyne' /usr/share/common-licenses/GPL
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
Yoyodyne, Inc., hereby disclaims all copyright interest in the program</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>See <a class="xref" href="ch09.en.html#_colorized_commands" title="9.2.7. Colorized commands">Section 9.2.7, “Colorized commands”</a>.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_replacement_expressions"></a>1.6.3. Replacement expressions</h3></div></div></div>
<p>For the replacement expression, some characters have special meanings.</p>
<div class="table">
<a name="thereplacementexpression"></a><p class="title"><b>Table 1.25. The replacement expression</b></p>
<div class="table-contents"><table summary="The replacement expression" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
replacement expression
</th>
<th align="left">
description of the text to replace the replacement expression
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">&amp;</code>
</td>
<td align="left">
what the regular expression matched (use <code class="literal">\&amp;</code> in <code class="literal">emacs</code>)
</td>
</tr>
<tr>
<td align="left">
<code class="literal">\n</code>
</td>
<td align="left">
what the n-th <span class="strong"><strong>bracketed</strong></span> regular expression matched ("n" being number)
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>For Perl replacement string, "<code class="literal">$n</code>" is used instead of "<code class="literal">\n</code>" and "<code class="literal">&amp;</code>" has no special meaning.</p>
<p>For example, try the following</p>
<pre class="screen">$ echo zzz1abc2efg3hij4 | \
sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/=&amp;=/'
zzz=1abc2efg3hij4=
$ echo zzz1abc2efg3hij4 | \
sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/\2===\1/'
zzzefg3hij4===1abc
$ echo zzz1abc2efg3hij4 | \
perl -pe 's/(1[a-z]*)[0-9]*(.*)$/$2===$1/'
zzzefg3hij4===1abc
$ echo zzz1abc2efg3hij4 | \
perl -pe 's/(1[a-z]*)[0-9]*(.*)$/=&amp;=/'
zzz=&amp;=</pre>
<p>Here please pay extra attention to the style of the <span class="strong"><strong>bracketed</strong></span> regular expression and how the matched strings are used in the text replacement process on different tools.</p>
<p>These regular expressions can be used for cursor movements and text replacement actions in some editors too.</p>
<p>The back slash "<code class="literal">\</code>" at the end of line in the shell commandline escapes newline as a white space character and continues shell command line input to the next line.</p>
<p>Please read all the related manual pages to learn these commands.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_global_substitution_with_regular_expressions"></a>1.6.4. Global substitution with regular expressions</h3></div></div></div>
<p>The <span class="citerefentry"><span class="refentrytitle">ed</span>(1)</span> command can replace all instances of "<code class="literal">FROM_REGEX</code>" with "<code class="literal">TO_TEXT</code>" in "<code class="literal">file</code>".</p>
<pre class="screen">$ ed file &lt;&lt;EOF
,s/FROM_REGEX/TO_TEXT/g
w
q
EOF</pre>
<p>The <span class="citerefentry"><span class="refentrytitle">sed</span>(1)</span> command can replace all instances of "<code class="literal">FROM_REGEX</code>" with "<code class="literal">TO_TEXT</code>" in "<code class="literal">file</code>".</p>
<pre class="screen">$ sed -ie 's/FROM_REGEX/TO_TEXT/g' file</pre>
<p>The <span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span> command can replace all instances of "<code class="literal">FROM_REGEX</code>" with "<code class="literal">TO_TEXT</code>" in "<code class="literal">file</code>" by using <span class="citerefentry"><span class="refentrytitle">ex</span>(1)</span> commands.</p>
<pre class="screen">$ vim '+%s/FROM_REGEX/TO_TEXT/gc' '+w' '+q' file</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>The "<code class="literal">c</code>" flag in the above ensures interactive confirmation for each substitution.</p></td></tr>
</table></div>
<p>Multiple files ("<code class="literal">file1</code>", "<code class="literal">file2</code>", and "<code class="literal">file3</code>") can be processed with regular expressions similarly with <span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span> or <span class="citerefentry"><span class="refentrytitle">perl</span>(1)</span>.</p>
<pre class="screen">$ vim '+argdo %s/FROM_REGEX/TO_TEXT/ge|update' '+q' file1 file2 file3</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>The "<code class="literal">e</code>" flag in the above prevents the "No match" error from breaking a mapping.</p></td></tr>
</table></div>
<pre class="screen">$ perl -i -p -e 's/FROM_REGEX/TO_TEXT/g;' file1 file2 file3</pre>
<p>In the perl(1) example, "<code class="literal">-i</code>" is for in-place editing, "<code class="literal">-p</code>" is for implicit loop over files.</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>Use of argument "<code class="literal">-i.bak</code>" instead of "<code class="literal">-i</code>" keeps each original file by adding "<code class="literal">.bak</code>" to its filename. This makes recovery from errors easier for complex substitutions.</p></td></tr>
</table></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p><span class="citerefentry"><span class="refentrytitle">ed</span>(1)</span> and <span class="citerefentry"><span class="refentrytitle">vim</span>(1)</span> are <span class="strong"><strong>BRE</strong></span>; <span class="citerefentry"><span class="refentrytitle">perl</span>(1)</span> is <span class="strong"><strong>ERE</strong></span>.</p></td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_extracting_data_from_text_file_table"></a>1.6.5. Extracting data from text file table</h3></div></div></div>
<p>Let's consider a text file called "<code class="literal">DPL</code>" in which some pre-2004 Debian project leader's names and their initiation days are listed in a
space-separated format.</p>
<pre class="screen">Ian Murdock August 1993
Bruce Perens April 1996
Ian Jackson January 1998
Wichert Akkerman January 1999
Ben Collins April 2001
Bdale Garbee April 2002
Martin Michlmayr March 2003</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>See <a class="ulink" href="http://www.debian.org/doc/manuals/project-history/" target="_top">"A Brief History of Debian"</a> for the latest <a class="ulink" href="http://www.debian.org/doc/manuals/project-history/ch-leaders" target="_top">Debian leadership history</a>.</p></td></tr>
</table></div>
<p>Awk is frequently used to extract data from these types of files.</p>
<p>For example, try the following</p>
<pre class="screen">$ awk '{ print $3 }' &lt;DPL # month started
August
April
January
January
April
April
March
$ awk '($1=="Ian") { print }' &lt;DPL # DPL called Ian
Ian Murdock August 1993
Ian Jackson January 1998
$ awk '($2=="Perens") { print $3,$4 }' &lt;DPL # When Perens started
April 1996</pre>
<p>Shells such as Bash can be also used to parse this kind of file.</p>
<p>For example, try the following</p>
<pre class="screen">$ while read first last month year; do
echo $month
done &lt;DPL
... same output as the first Awk example</pre>
<p>Here, the <code class="literal">read</code> builtin command uses characters in "<code class="literal">$IFS</code>" (internal field separators) to split lines into words.</p>
<p>If you change "<code class="literal">$IFS</code>" to "<code class="literal">:</code>", you can parse "<code class="literal">/etc/passwd</code>" with shell nicely.</p>
<pre class="screen">$ oldIFS="$IFS" # save old value
$ IFS=':'
$ while read user password uid gid rest_of_line; do
if [ "$user" = "bozo" ]; then
echo "$user's ID is $uid"
fi
done &lt; /etc/passwd
bozo's ID is 1000
$ IFS="$oldIFS" # restore old value</pre>
<p>(If Awk is used to do the equivalent, use "<code class="literal">FS=':'</code>" to set the field separator.)</p>
<p>IFS is also used by the shell to split results of parameter expansion, command substitution, and arithmetic expansion. These do not occur within double or single quoted words. The default value of IFS is &lt;space&gt;, &lt;tab&gt;, and &lt;newline&gt; combined.</p>
<p>Be careful about using this shell IFS tricks. Strange things may happen, when shell interprets some parts of the script as its <span class="strong"><strong>input</strong></span>.</p>
<pre class="screen">$ IFS=":," # use ":" and "," as IFS
$ echo IFS=$IFS, IFS="$IFS" # echo is a Bash builtin
IFS= , IFS=:,
$ date -R # just a command output
Sat, 23 Aug 2003 08:30:15 +0200
$ echo $(date -R) # sub shell --&gt; input to main shell
Sat 23 Aug 2003 08 30 36 +0200
$ unset IFS # reset IFS to the default
$ echo $(date -R)
Sat, 23 Aug 2003 08:30:50 +0200</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="_script_snippets_for_piping_commands"></a>1.6.6. Script snippets for piping commands</h3></div></div></div>
<p>The following scripts do nice things as a part of a pipe.</p>
<div class="table">
<a name="listofscriptsniporpipingcommands"></a><p class="title"><b>Table 1.26. List of script snippets for piping commands</b></p>
<div class="table-contents"><table summary="List of script snippets for piping commands" border="1">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">
script snippet (type in one line)
</th>
<th align="left">
effect of command
</th>
</tr></thead>
<tbody>
<tr>
<td align="left">
<code class="literal">find /usr -print</code>
</td>
<td align="left">
find all files under "<code class="literal">/usr</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal">seq 1 100</code>
</td>
<td align="left">
print 1 to 100
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | xargs -n 1 &lt;command&gt;</code>
</td>
<td align="left">
run command repeatedly with each item from pipe as its argument
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | xargs -n 1 echo</code>
</td>
<td align="left">
split white-space-separated items from pipe into lines
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | xargs echo</code>
</td>
<td align="left">
merge all lines from pipe into a line
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | grep -e &lt;regex_pattern&gt;</code>
</td>
<td align="left">
extract lines from pipe containing &lt;regex_pattern&gt;
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | grep -v -e &lt;regex_pattern&gt;</code>
</td>
<td align="left">
extract lines from pipe not containing &lt;regex_pattern&gt;
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | cut -d: -f3 -</code>
</td>
<td align="left">
extract third field from pipe separated by "<code class="literal">:</code>" (passwd file etc.)
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | awk '{ print $3 }'</code>
</td>
<td align="left">
extract third field from pipe separated by whitespaces
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | awk -F'\t' '{ print $3 }'</code>
</td>
<td align="left">
extract third field from pipe separated by tab
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | col -bx</code>
</td>
<td align="left">
remove backspace and expand tabs to spaces
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | expand -</code>
</td>
<td align="left">
expand tabs
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | sort| uniq</code>
</td>
<td align="left">
sort and remove duplicates
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | tr 'A-Z' 'a-z'</code>
</td>
<td align="left">
convert uppercase to lowercase
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | tr -d '\n'</code>
</td>
<td align="left">
concatenate lines into one line
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | tr -d '\r'</code>
</td>
<td align="left">
remove CR
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | sed 's/^/# /'</code>
</td>
<td align="left">
add "<code class="literal">#</code>" to the start of each line
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | sed 's/\.ext//g'</code>
</td>
<td align="left">
remove "<code class="literal">.ext</code>"
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | sed -n -e 2p</code>
</td>
<td align="left">
print the second line
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | head -n 2 -</code>
</td>
<td align="left">
print the first 2 lines
</td>
</tr>
<tr>
<td align="left">
<code class="literal"> | tail -n 2 -</code>
</td>
<td align="left">
print the last 2 lines
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>One-line shell script can loop over many files using <span class="citerefentry"><span class="refentrytitle">find</span>(1)</span> and <span class="citerefentry"><span class="refentrytitle">xargs</span>(1)</span> to perform quite complicated tasks. See <a class="xref" href="ch10.en.html#_idioms_for_the_selection_of_files" title="10.1.5. Idioms for the selection of files">Section 10.1.5, “Idioms for the selection of files”</a> and <a class="xref" href="ch09.en.html#_repeating_a_command_looping_over_files" title="9.5.9. Repeating a command looping over files">Section 9.5.9, “Repeating a command looping over files”</a>.</p>
<p>When using the shell interactive mode becomes too complicated, please consider to write a shell script (see <a class="xref" href="ch12.en.html#_the_shell_script" title="12.1. The shell script">Section 12.1, “The shell script”</a>).</p>
</div>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="pr01.en.html"><img src="images/prev.gif" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="ch02.en.html"><img src="images/next.gif" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Preface </td>
<td width="20%" align="center"><a accesskey="h" href="index.en.html"><img src="images/home.gif" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Chapter 2. Debian package management</td>
</tr>
</table>
</div>
</body>
</html>