[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

User manual: basic commands chapter



Here is my first draft of the basic commands chapter, on which I
invite comments, on both form and content.

The debiandoc2text output is first and then the SGML source.


                      Debian GNU/Linux User's Manual
                      ------------------------------
             Ardo van Rangelrooij<ardo.van.rangelrooij@tip.nl>
                       version 0.1, 8 December 1997

0.1 Abstract
------------

     The Debian GNU/Linux User's Manual covers everything a user should
     know about a Debian GNU/Linux system from a user's view point. 

0.2 Contents
------------

...

     5.        Basic Commands and Tools
     5.1.      What this chapter covers
     5.2.      Running commands

...


-------------------------------------------------------------------------------


5. Basic Commands and Tools
---------------------------

     author = Oliver Elphick <Oliver.Elphick@lfix.co.uk> 

     topics = head, tail, grep, etc. 


5.1. What this chapter covers
-----------------------------

     This chapter tells you how to run the basic commands that you need in
     order to use Debian Linux.

     We assume that you have already logged in and are in a shell where you
     can enter commands. Refer back to <ref id="logging-in"> for
     instructions on how to log in. If you are not running X-Windows, you
     will normally be put in an interactive shell as soon as you log in. If
     you are running X-Windows, you should refer to <ref id="xterm"> for
     instructions on how to start up a window with a shell.

     The available shells are described in <ref id="shells">. All the
     examples given here assume that you are using the Bourne-Again Shell,
     /bin/bash, though in most cases there will be no difference between
     the command syntax for any shell. Bash is the default shell when
     Debian Linux is first installed.


5.2. Running commands
---------------------

5.2.1. How to enter commands
----------------------------

     To run a command, type the command at the prompt, followed by any
     necessary options, and then press the `Enter' key. The shell will
     interpret the command, first handling any special shell syntax, and
     will then start the command as a new process.

     Most commands operate silently unless they are specifically asked to
     say what they are doing. If there is no error message, the command
     should have worked.

5.2.2. How Linux finds commands
-------------------------------

     When you type in a command name, Linux has to find the file which
     contains the program you want to run. This is how it does it:

     The first word of what you type in is the command[1] itself. If this
     contains a slash character (`/') the whole command is taken to be a
     path, either absolute (if it starts with /) or relative to the current
     directory. The file indicated by that path is used, provided that it
     exists, that it is executable and (in the case of a script) that it is
     readable.

     [1]  There are exceptions: see the chapter on shells.

     If the command does not contain a slash, the shell searches for it in
     your current search path. This is a list of directories, separated one
     from another by colons. The command search path is held in the
     environment variable PATH: type `echo $PATH' to see what it is. 
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/bin/mh:/usr/local/pgsql/bin:/usr/uv/bin:/usr/games:/home/olly/bin:.
     Each directory is searched in turn, starting at the beginning of the
     list. If a match for the name is found, the shell also considers
     whether the file found is executable (and readable, if it is a
     script). As soon as such a match is found, the search stops[1].

     [1]  This is why system directories should be put first in the path;
          this ensures that the system commands will be run in preference
          to ones of the same name in user bin directories or in the
          current directory. If non-system programs are searched first,
          there is a security risk, because there may be non-standard
          programs with commonly-used names, and you cannot tell what they
          might do.

     If you need to change your path, you should add the new directories to
     the end of the list; the current directory (.) should go last of all.
     The command to use is `export PATH=$PATH:<new_directory>'[1] .

     [1]  The syntax given is for Bourne shell and its descendants. The
          syntax for C shell and its descendants is `setenv PATH
          $PATH:<new_directory>'

5.2.3. Command options
----------------------

     The operation of most commands can be changed by putting command
     options immediately after the command name. There are several styles
     of options used, and you have to check the documentation for each
     command to know what options it can take, and what they do.

     The most common form of option is a letter preceded by a hyphen, thus:
          ls -l
     With this option style, several single-character options can be
     combined into one, thus: 
          ls -ali
     which is equivalent to 
          ls -a -l -i

     Sometimes, single-letter options like this need an extra argument: 
          awk -F: -f /tmp/bar /tmp/foo
     Here `:' and `/tmp/bar' are arguments to the options `-F' and `-f'
     respectively.

     A few commands have options which need not be preceded by a hyphen.
     The one you are most likely to use is tar. 
          tar cvmf /dev/st0 /usr
     is the same as 
          tar -cvmf /dev/st0 /usr

     A third option style, commonly used by GNU programs, is whole words or
     phrases introduced by `--'. Many commands can use both the
     single-letter and whole-word options: 
          tar --create --verbose --modification-time --file /dev/st0 /usr

     Finally, commands may define completely different option patterns for
     themselves, such as options preceded by `+' as the opposite to `-'.

5.2.4. Essential commands
-------------------------

     These commands are the ones you really need to know to get anything
     done.

     We give only a brief description of the command, describing its basic
     use. For full details, you should always refer to the detailed
     documentation of the manual pages and the info files.

     In this chapter, things which are optional are shown <like this>.
     <Words looking like this> are to be replaced by whatever is
     appropriate to what you are trying to do.

5.2.4.1. Commands for reading documentation
-------------------------------------------

     To avoid annoying other users by questions on elementary matter, do,
     please, read the manuals!

     These are the commands to let you do that: 

     man [<section-number>] <subject>
          man shows the manual page on the command (use q or ctrl-C to get
          out of it if it doesn't terminate at the end of the text). More
          details are given in <ref id="manpages">.

          This command is crucial for helping you learn how to use it and
          other Linux commands.

     info [<subject>]
          A lot of Debian Linux documentation is provided in *info* format.
          This is similar to a hypertext format, in that you can jump to
          other sections of the documentation by following links embedded
          in the text.

          See <ref id="infopages"> for a full description of how to use
          info.

     help [<subject>]
          Use help for on-line help about bash's built-in commands.

          help by itself prints a list of subjects for which you can ask
          for help.


5.2.4.2. Commands for basic file-handling
-----------------------------------------

     A fuller description of file-systems and file-handling is given in
     <ref id="file-handling">.

     These are the commands that you really have to know:

     pwd
          Show the current directory.

     cd [<directory>]
          Change your current directory to the named <directory>. If you
          don't specify <directory>, you will be returned to your home
          directory.

     mv <source> <target>
          mv moves <source> file to <target> and deletes <source>; <source>
          can be a list of files, but in that case <target> must be a
          directory.

          This is also the way to rename a file or directory.

     cp <source> <target>
          cp copies <source> to <target>. Again, <target> can be a
          directory and <source> a list of files.

     ln <source> <target>
          ln links <source> to <target> with hard or symbolic links
          according to the options.

     rm <filelist>
          rm deletes files. With the -r option it can delete directories
          and their contents.

          Be very careful with rm; once a file is deleted, you cannot get
          it back. There is no undelete command.

     chmod <mode> <filelist>
          chmod changes the permissions of files and directories. The
          <mode> is either an octal number, such as `644', or a symbolic
          representation of it, such as `u=rw,go=r'.

     chown <owner>[.<group>] <filelist>
          chown changes the ownership of files. Use the `-R' option to do
          this for an entire directory tree.

          If .<group> is specified as well as <owner>, the group ownership
          of the files is changed as well.

     chgrp <group> <filelist>
          chgrp changes the group ownership of files. Use the `-R' option
          to do this for an entire directory tree.

     ls <directory>
          ls lists the contents of <directory>; by default, the output is
          sorted)

          There are more options to ls than to any other command. Those
          most commonly used are `-l', to show the file permissions and the
          latest change date and `-a', to show hidden dot-files.


5.2.4.3. These commands are used for managing file-systems
----------------------------------------------------------

     Files are organised into file-systems (see <ref id="file-systems">).

     Every Debian Linux system (and every Unix system) has a root
     file-system, called, simply, `/'. All files and devices in the system,
     and possibly files on other systems as well, are accessible under `/'.
     Files are placed under directories, which may themselves be placed in
     directories, and so on. Segments of this universal tree will be on
     different physical devices, or different sections (`partitions') of a
     single physical device. New file-systems, each with its own directory
     tree, may be grafted into the universal directory tree at arbitrary
     `mount-points'. (These are simply directories which are nominated to
     be the head of the new tree.)

     The process of grafting a segment into the main tree is called
     `mounting'; the filesystem is mounted on a mount-point, which is a
     directory.

     df
          df lists mounted partitions and shows the amount of space
          present, used and available. (The partitions will probably
          include /proc, which is a special `non-existent' partition, that
          contains information about the current state of the Linux
          kernel.)

     mount [<partition> <directory>]
          mount by itself lists mounted partitions.

          It is also the command to use to add a partition's file-system
          into the universal directory tree. For example: 
               mount /dev/hda2 /usr

          You have to be superuser (log in as `root' or run su) in order to
          mount or unmount file-systems.

     umount <directory>
          umount removes a partition's file-system from the universal
          directory tree. For example: 
               umount /usr

          You have to be superuser (log in as `root' or run su) in order to
          mount or unmount file-systems.


5.2.4.4. Looking at files
-------------------------

     Files include physical devices, executable programs and directories,
     as well as textfiles. It is as well not to look at compiled
     executables on the screen however. At best they will be garbage; at
     worst they will make everything on the screen unreadable (see <ref
     id="rmacs"> for a way to recover from this.)

     cat <textfile[s]>
          cat dumps <textfile[s]> to screen without paging (like DOS's
          type). If you name more than one file, each will be sent in
          order, with no break or heading.

     more <textfile[s]>
          more lists the <textfile[s]> to the screen in pages so that you
          can read it. Press `Spacebar' to move on one page, `Enter' to
          move on one line, and `b' to move back one page. Use `q' or
          `ctrl-c' to quit.

          more will quit automatically when it gets to the end of the last
          file.

     less <textfile[s]>
          less is like more but has more features and somewhat different
          behaviour. You have to type `Q' to terminate it.

     head <textfile[s]>
          head is used to see the first few lines of a file (by default, it
          shows 10 lines).

     tail <textfile[s]>
          tail is used to see the last few lines of a file (by default, it
          shows 10 lines).

     find <directory> -name <filename>
          find tells you where <filename> is in the tree starting at
          <directory>. This command has many other useful options.

     xargs <command>
          xargs is commonly used with find. It breaks long lists of files
          given to a command into chunks that are short enough for the
          shell to handle. In this way, you can run through the entire file
          system and execute some command on all the selected files: 
               find $HOME -mtime -2 | xargs chmod g+w

     grep <pattern> <filelist>
          grep scans each file in <filelist> for lines which match
          <pattern>.

     file <file>
          file reports what kind of thing <file> is.

     type <file>
          type says where to find <file> in your search path.

     whereis <file>
          whereis is like type, but gives more information.


5.2.4.5. Compressed files
-------------------------

     In order to save space on your disks, many files are compressed. They
     are scanned by a program such as gzip or compress and reduced in size,
     often to about one third of their original size.

     Compressed files cannot be read unless they are uncompressed again.

     gunzip <file.suffix>
          gunzip uncompresses <file.suffix> (where <suffix>is `.gz' or
          perhaps `.Z'), deletes it and writes an uncompressed file called
          <file>.

          In spite of its name, gunzip cannot handle zip format files
          created by PKZIP. There is a pkunzip program that can handle such
          files.

     zcat <compressed_file>
          zcat does the same job as cat, but uncompresses <compressed_file>
          first, without changing it on the disk.

     zmore <compressed_file>
          zmore does the same job as more, but uncompresses
          <compressed_file> first, without changing it on the disk.

     zless <compressed_file>
          zless does the same job as less, but uncompresses
          <compressed_file> first, without changing it on the disk.

     zgrep <compressed_file>
          zless does the same job as less, but uncompresses
          <compressed_file> first, without changing it on the disk.


5.2.4.6. Commands for backup
----------------------------

     You need to do regular backups, in order to be able to recover your
     system and data in case of disaster.

     These programs are used for backups of various kinds:

     tar
          tar is designed to archive directories with all their contents.
          It has many options, but here is a simple example of using it to
          create a backup of your home directory to a SCSI tape: 
               tar cvf /dev/st0 $HOME
          Here is how to read the contents of a tape that has been written
          with tar: 
               tar tf /dev/st0
          and here is how to restore a particular directory (with its
          contents) from such a tape backup: 
               tar xvf /dev/st0 $HOME/private/letters

          You can also restore a single file: 
               tar xvf /dev/st0 $HOME/private/letters/bank.21Aug

     cpio
          cpio is used to write individual files to a backup. A list of
          files is prepared in some way and then piped into the standard
          input of cpio. This is how to use it to archive your home
          directory to SCSI tape: 
               find $HOME -print | cpio -ovBH newc >/dev/st0
          Here is how to read the contents of a tape that has been written
          with cpio: 
               cpio -itBH newc </dev/st0
          and here is how to restore a set of files in one directory whose
          names all start with `bank' from such a tape backup: 
               cpio -itBH newc "$HOME/private/letters/bank*" </dev/st0

     afio
          afio is used like cpio to write individual files to a backup. It
          has the additional capability of compressing files before it
          writes them on the backup. This is useful if you have a lot of
          information to store on media of limited capacity. This is how to
          use it to archive your home directory to SCSI tape, using
          compression: 
               find $HOME -print | afio -ovZ >/dev/st0


5.2.4.7. Printing files
-----------------------

     There is one basic command for printing (though there are many for
     specialised uses):

     lpr <file>
          lpr prints <file> to the default printer. lpr is the user command
          for adding jobs to the spooler queue. The jobs will continue to
          print, even if you log out.

          If you have more than one printer, you can use the option
          -P<printer> to direct a job to one particular printer.

     lpq
          lpq shows the current list of jobs on the printer spool queue.

     lprm <jobId>
          lprm removes the job identified by <jobId> from the spooler
          queue. If a job is already printing, this may not stop it; the
          job may already be stored in the printer's memory


5.2.4.8. Changing files
-----------------------

     See <ref id="editors"> for information on editing files.

5.2.4.9. Session management
---------------------------

     A session is the series of events between logging in and logging out
     of the computer.

     When you first log in, you will see a prompt, whcih may contain your
     current machine's hostname, and perhaps the current directory. The
     prompt ends with a dollar sign: *$*, which indicates that you are an
     ordinary user. If you become superuser, the dollar sign should change
     to a hash (or sharp) sign: *#*. You need to know that you are
     superuser, because you can then do a great deal of damage to your
     system by mistyping ordinary commands.

     These commands relate to handling your session:

     exit or logout
          Use exit or logout to terminate your session and log out. All
          jobs you have started are terminated, unless they were started
          with nohup, and your screen should return you to the log-in
          prompt. You can often use Ctrl-D to do the same, but that
          capability can be disabled.

     su
          Use su to become superuser. You will be asked to enter a
          password; this is the password for the `root' login.

          Becoming superuser is almost the same as logging in as root. You
          get the same power to do damage. *Be very careful!*

          Use exit, logout or ctrl-D to stop being superuser.

     fg
          If you are running one job and want to run something else in the
          same screen without stopping the first job, you can put the first
          job in the background by typing Ctrl-Z. You can then run other
          commands. If the first job wants to send anything to the screen,
          it will stop and wait. You can bring it forward again and let it
          continue by using the command fg.

     script <file>
          Use script to record everything that appears on the screen (until
          the next exit) in <file>. This is useful if you need to record
          what's going on in order to include it in your message when you
          ask for help. Use exit, logout or ctrl-D to stop the recording
          session.

     ps
          Use ps to list your processes. 
               $ ps
                 PID  TT STAT   TIME COMMAND
                6122  p1 S      0:00 bash
                6123  p2 S      0:00 bash
                6408  p1 S      0:00 ftp
                6916  p4 R      0:00 ps
               13115  p7 SW     0:00 bash
               19102  p3 SW     0:00 bash
               19497  p4 S      0:00 -bash
               19554  p3 S     11:25 uvsh
               19623  p4 S      5:37 xemacs
               21272  p6 SW     0:00 bash

          You can also use ps to see all processes on the system: 
               $ ps -ax
                 PID  TT STAT   TIME COMMAND
                   1  ?  SW     0:18 init
                   2  ?  SW     0:04 kflushd
                   3  ?  SW<    0:00 kswapd
                  10  ?  S      0:18 update
                  31  ?  SW     0:00 nfsiod
                  32  ?  SW     0:00 nfsiod
                  33  ?  SW     0:00 nfsiod
                  34  ?  SW     0:00 nfsiod
                 143  ?  S      0:08 /sbin/syslogd
                 145  ?  S      0:00 klogd
                 154  ?  S      0:00 /sbin/kerneld
                 164  ?  S      0:00 inetd
                 167  ?  S      0:05 named
                 179  ?  SW     0:00 run_job
                 183  ?  SW     0:00 bootpd
                 205  ?  SW     0:00 gpm
                 209  ?  S      0:52 /usr/sbin/tcplogd
                 212  ?  SW     0:00 icmplogd
                 ... and so on ...

          The number in the column headed `PID' is the identifying number
          of the process. Under column `TT' is the tty (screen or window
          identifier) where it is running. A question mark here means that
          it is not attached to any screen or window, but is running in the
          background.

     tty
          tty shows you which terminal (screen or window) you are in. 
               $ tty
               /dev/ttyp4


5.2.4.10. Identity
------------------

     These commands relate to your identity as a user.

     passwd 
          Use passwd to change the password that you use when you log in.
          Follow the instructions on screen about what kind of password to
          choose. When you type the password in, it doesn't show on the
          screen, so you have to enter it twice, to ensure that you make no
          typing errors.

     id
          id tells you what user you are and what group you are in. 
$ id
uid=1000(olly) gid=1000(olly) groups=1000(olly),6(disk),20(dialout),25(floppy),26(tape),29(audio),34(backup),37(operator),101(priory)

          <uid> indicates your user number, <gid> your group number (which
          will be assigned to files that you create) and <groups> lists the
          other groups that you are a member of.

     who -u
          who -u reports everyone who is logged on


5.2.4.11. Turning off the computer
----------------------------------

     Turning the computer on and off is really a system administration
     subject, but I include it here because it is something that every user
     who is his own administrator needs to know. If someone else is
     responsible for administering the machine, you should neither need nor
     be able to shut it down.

     shutdown -t 0 -h now
          This command shuts the computer down safely. You can also use
          ctrl-alt-del if your system is set up for that. Never turn off a
          Unix machine without doing a safe shutdown: otherwise you will
          damage your filesystems.


5.2.5. Special characters in commands
-------------------------------------

     When you type a command, certain characters have a special meaning to
     the shell and are interpreted before the command starts to run. Full
     details are given in the chapter on shells, but you need to understand
     what is happening, or you will get results that you did not expect.

     Shell special characters are interpreted by the shell as soon as it is
     given the command. For example, if you type `ls *.bak', the shell
     translates `*.bak' to the list of all files in the current directory
     whose names end in `.bak'. *The ls command never sees the asterisk.*
     So if you want to search for files which actually have an asterisk in
     their names, you have to escape the asterisk to stop the shell from
     interpreting it.
          linda:/tmp/junk$ ls **
          fred     george*  joe      mary     peter*
          linda:/tmp/junk$ ls *\*
          george*  peter*
          linda:/tmp/junk$ 
     In the example, the first command matched all files; the second
     matched only those with a literal asterisk at the end of their names.

     The same goes for other special characters. here is the full list:

     \
          \ escapes itself and other specials

     []
          [] encloses patterns for matching a single character

     *
          * stands for anything (including nothing)

     ?
          ? stands for any single character

     ()
          () runs the contents of the parentheses in a subshell

     ;
          ; terminates a command pipeline - use it to separate commands on
          a single line

     &
          & runs the preceding pipeline in the background

     $word and ${word}
          $word and ${word} are interpreted as a shell variable (use
          ${word} if there is danger of ambiguity).

     ``
          `` The contents of the backquotes are run as a command and their
          output is used as part of this command

     ""
          The contents of the quotes are treated as one argument; any
          specials inside the quotes, except for $ and ``, are left
          uninterpreted.

     ''
          The contents of the single quotes are passed to the command
          without any interpretation.

     |
          The vertical bar sign is used to indicate a pipe. The command on
          the left-hand side of the pipe sends its output to the input of
          the command on the right side of the pipe.

     < and >
          These symbols are used for redirection; see below.

     &&
          The double ampersand is used between two commands (on the same
          line). It tells the shell to run the second command only if the
          first one was successful[1] .

          [1]  Successful means terminating with an exit status of 0.

     ||
          The double vertical bar is used between two commands (on the same
          line). It tells the shell to run the second command only if the
          first one was unsuccessful.

     For example, `ls -d /[uv]*' will list the names of all entries in the
     root directory that start with u or v. Unlike DOS, you can use
     patterns like `g*.gz' (with the wildcard bit in the middle).

5.2.6. Filters
--------------

     Many commands are filters, so you can pass the output of one command
     to the input of another: 
          awk -F: '{print $1 " " $6}' /etc/passwd | sort

     This is a fundamental concept of all Unix and Unix-like systems. Many
     commands are designed to be filters. They can therefore be used as
     building blocks to make more complex commands, in whatever way is
     needed at the time.

5.2.7. Standard input, standard output and standard error
---------------------------------------------------------

     When the shell starts a command for you, it opens files for standard
     input, standard output and standard error. By default, standard input
     is your keyboard, standard output is your screen, and standard error
     is also your screen.

     Although the defaults are keyboard and screen, this can easily be
     changed. In fact, the shell copies its own standard input, output and
     error when it starts a command, so the command inherits whatever the
     shell has. A command can change its own settings, by opening a
     different file, and you can tell the shell to use a file instead of
     the default of keyboard or screen.

     The file descriptor numbers for standard input, standard output and
     standard error are 0, 1 and 2 respectively.

5.2.8. Redirection
------------------

     You can redirect standard input, output and error by adding these
     sequences after a command:

     <
          < <file> means take input from <file>.

     >
          > <file> means send output to <file> (overwriting and destroying
          whatever is in the file already).

     >>
          >> <file> means append output to <file>.

     2>
          2> <file> means send error messages to <file> (overwriting).
          (This means that errors can be directed separately from normal
          output.) 

     There are more complex aspects to redirection, which may be studied in
     the shell manual pages. 

5.2.9. Shell programs
---------------------

     Redirection is a simple part of shell programming, for which see the
     manual pages of bash, zsh, tcsh, or whatever shell you have chosen. A
     shell program is a set of commands in a file or typed in. 
          for f in `grep -l widgets`
          	do
          		sed -e 's/widgets/gadgets/g' <$f ${f}gadget
          		echo $f
          	done
h

     Once you have stored a shell program in a program file, you have to
     make it executable by running chmod: 
                  chmod a+x <my_program_file>

5.2.10. Errors
--------------

     Unix commands normally execute silently unless asked to be verbose or
     unless there is an error. An error means something that does not make
     sense to Linux; it doesn't mean something you don't want to happen!

     For example, I once had a client who had some unwanted files in his
     root directory which were named &TEMP& and so on. As superuser in the
     root directory he typed `rm -rf /&*' when he should have typed `rm -rf
     \&*' What he actually asked for was to delete his entire file system,
     as a background job. It did too.


-------------------------------------------------------------------------------

...
<!-- <!doctype debiandoc system>
<debiandoc>
  <book>
    <titlepag>
      <title></title>
      <author>
	<name></name>
	<email></email>
      </author>
    </titlepag>
    <chapt>
      <heading>Basic commands and Tools</heading> -->
      <sect>
	<heading>What this chapter covers</heading>
      <p>
This chapter tells you how to run the basic commands that you need in
order to use Debian Linux.</p>
      <p>
We assume that you have already logged in and are in a shell where you
can enter commands.  Refer back to &lt;ref id="logging-in"&gt; for instructions
on how to log in.  If you are not running X-Windows, you will normally
be put in an interactive shell as soon as you log in.  If you are
running X-Windows, you should refer to &lt;ref id="xterm"&gt; for instructions
on how to start up a window with a shell.</p>
      <p>
The available shells are described in &lt;ref id="shells"&gt;.  All the examples
given here assume that you are using the Bourne-Again Shell, /bin/bash,
though in most cases there will be no difference between the command 
syntax for any shell.  Bash is the default shell when Debian Linux is
first installed.</p>
    
      </sect>
      <sect><heading>Running commands</heading>
	<sect1>
	  <heading>How to enter commands</heading>
      <p>To run a command, type the command at the prompt, followed by any
necessary options, and then press the <tt>Enter</tt> key. The shell will
interpret the command, first handling any special shell syntax, and will
then start the command as a new process.</p>
      <p>Most commands operate silently unless they are specifically
asked to say what they are doing.  If there is no error message, the
command should have worked.</p>
    </sect1>
	<sect1>
	  <heading>How Linux finds commands</heading>
	  <p>When you type in a command name, Linux has to find the file
which contains the program you want to run.  This is how it does it:</p>
	  <p>The first word of what you type in is the command<footnote>
	      <p>There are exceptions: see the chapter on shells.</p>
	    </footnote> itself.  If this contains a slash character (<tt>/</tt>)
the whole command is taken to be a path, either absolute (if it starts with /)
or relative to the current directory.  The file indicated by that path is used,
provided that it exists, that it is executable and (in the case of a script) that
it is readable.
</p>
	  <p>If the command does not contain a slash, the shell searches for it
in your current search path.  This is a list of directories, separated one from
another by colons.  The command search path is held in the environment variable
PATH: type <tt>echo $PATH</tt> to see what it is.
<example>

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/bin/mh:/usr/local/pgsql/bin:/usr/uv/bin:/usr/games:/home/olly/bin:.

</example>  Each directory is searched in turn, starting at the beginning
of the list.  If a match for the name is found, the shell also considers
whether the file found is executable (and readable, if it is a script).  As
soon as such a match is found, the search stops<footnote>
	      <p>This is why system directories should be put first in the
path; this ensures that the system commands will be run in preference to
ones of the same name in user bin directories or in the current directory. If 
non-system programs are searched first, there is a security risk, because 
there may be non-standard programs with commonly-used names, and you cannot tell
what they might do.</p>
	    </footnote>.</p>
	  <p>If you need to change your path, you should add the new directories
to the end of the list; the current directory (.) should go last of all.  The
command to use is <tt>export PATH=$PATH:<var>new_directory</var></tt><footnote>
	      <p>The syntax given is for Bourne shell and its descendants.  The
syntax for C shell and its descendants is <tt>setenv PATH $PATH:<var>new_directory</var></tt></p>
	    </footnote>
.</p>

	</sect1>
      <sect1><heading>Command options</heading>
      <p>The operation of most commands can be changed by putting command
options immediately after the command name.  There are several styles of
options used, and you have to check the documentation for each command to
know what options it can take, and what they do.</p>
      <p>The most common form of option is a letter preceded by a hyphen,
thus:
<example>ls -l</example>
With this option style, several single-character options can be combined
into one, thus:
<example>ls -ali</example>
which is equivalent to
<example>ls -a -l -i</example></p>
      <p>Sometimes, single-letter options like this need an extra argument:
<example>awk -F: -f /tmp/bar /tmp/foo</example>
Here <tt>:</tt> and <tt>/tmp/bar</tt> are arguments to the options <tt>-F</tt>
and <tt>-f</tt> respectively.</p>
      <p>A few commands have options which need not be preceded by a hyphen.
The one you are most likely to use is <prgn>tar</prgn>.
<example>tar cvmf /dev/st0 /usr</example>
is the same as
<example>tar -cvmf /dev/st0 /usr</example></p>
      <p>A third option style, commonly used by GNU programs, is whole
words or phrases introduced by <tt>--</tt>.  Many commands can use both
the single-letter and whole-word options:
<example>tar --create --verbose --modification-time --file /dev/st0 /usr</example></p>
      <p>Finally, commands may define completely different option patterns
for themselves, such as options preceded by <tt>+</tt> as the opposite to
<tt>-</tt>.</p>
	</sect1>

      <sect1><heading>Essential commands</heading>
      <p>These commands are the ones you really need to know to get anything
done.</p>
      <p>We give only a brief description of the command, describing its basic use.
For full details, you should always refer to the detailed documentation of
the manual pages and the info files.</p>	  	  
<p>In this chapter, things which are optional are shown <var>like this</var>. <var>Words looking like this</var> are to be replaced by
whatever is appropriate to what you are trying to do.</p>
    
      <sect2><heading>Commands for reading documentation</heading>
    <p>To avoid annoying other users by questions on elementary matter, do, please,
read the manuals!</p>
    <p>These are the commands to let you do that:

<taglist>
	<tag><prgn>man</prgn> [<var>section-number</var>] <var>subject</var></tag>
	<item><p><prgn>man</prgn> shows the manual page on the
command (use q or ctrl-C to get out of it if it doesn't terminate at the end
of the text). More details are given in &lt;ref id="manpages"&gt;.</p>
	  <p>This command is crucial for helping you learn how
to use it and other Linux commands.</p>
	</item>
	
	<tag><prgn>info</prgn> [<var>subject</var>]</tag>
	<item><p>A lot of Debian Linux documentation is provided
in <em>info</em> format.  This is similar to a
hypertext format, in that you can jump to other sections of the documentation
by following links embedded in the text.</p>
	  <p>See &lt;ref id="infopages"&gt; for a full description of
how to use <prgn>info</prgn>.</p>
	</item>
	
	<tag><prgn>help</prgn> [<var>subject</var>]</tag>
	<item><p>Use <prgn>help</prgn> for on-line help about bash's built-in
commands.</p>
	  <p><prgn>help</prgn> by itself prints a list of subjects for
which you can ask for help.</p>
	</item>
      </taglist></p>
</sect2>
    <sect2><heading>Commands for basic file-handling</heading>
    <p>A fuller description of file-systems and file-handling is given in
&lt;ref id="file-handling"&gt;.</p>
    <p>These are the commands that you really have to know:</p>
<p>
<taglist>
	<tag><prgn>pwd</prgn></tag>
	<item><p>Show the current directory.</p>
	</item>
	<tag><prgn>cd</prgn> [<var>directory</var>]</tag>
	<item><p>Change your current directory to the named
<var>directory</var>.  If you don't specify <var>directory</var>, you will be
returned to your home directory.</p>
	</item>
	
	<tag><prgn>mv</prgn> <var>source</var> <var>target</var></tag>
	<item><p><prgn>mv</prgn> moves <var>source</var> file to
<var>target</var> and deletes <var>source</var>; <var>source</var> can be a
list of files, but in that case <var>target</var> must be a directory.</p>
	  <p>This is also the way to rename a file or directory.</p>
	</item>

	<tag><prgn>cp</prgn> <var>source</var> <var>target</var></tag>
	<item><p><prgn>cp</prgn> copies <var>source</var> to <var>target</var>. Again, <var>target</var> can be a directory and  <var>source</var> a list of
files.
</p>
	</item>

	<tag><prgn>ln</prgn> <var>source</var> <var>target</var></tag>
	<item><p><prgn>ln</prgn> links <var>source</var> to <var>target</var>
with hard or symbolic links according to the options.</p>
	</item>

	<tag><prgn>rm</prgn> <var>filelist</var></tag>
	<item><p><prgn>rm</prgn> deletes files.  With the -r option it can
delete directories and their contents.</p>
	  <p>Be very careful with <prgn>rm</prgn>; once a file is deleted, you cannot get it back.  There is no <prgn>undelete</prgn> command.</p>
	</item>

	<tag><prgn>chmod</prgn> <var>mode</var> <var>filelist</var></tag>
	<item><p><prgn>chmod</prgn> changes the permissions of files and
directories.  The <var>mode</var> is either an octal number, such as
<tt>644</tt>, or a symbolic representation of it, such as
<tt>u=rw,go=r</tt>.</p>
	</item>

	<tag><prgn>chown</prgn> <var>owner</var>[.<var>group</var>] <var>filelist</var></tag>
	<item><p><prgn>chown</prgn> changes the ownership of files. Use the
<tt>-R</tt> option to do this for an entire directory tree.</p>
	  <p>If .<var>group</var> is specified as well as <var>owner</var>,
the group ownership of the files is changed as well.</p>
	</item>

	<tag><prgn>chgrp</prgn> <var>group</var> <var>filelist</var></tag>
	<item><p><prgn>chgrp</prgn> changes the group ownership of files. Use the
<tt>-R</tt> option to do this for an entire directory tree.</p>
	</item>

	<tag><prgn>ls</prgn> <var>directory</var></tag>
	<item><p><prgn>ls</prgn> lists the contents of <var>directory</var>;
by default, the output is sorted)</p>
	  <p>There are more options to <prgn>ls</prgn> than to any other
command. Those most commonly used are <tt>-l</tt>, to show the file
permissions and the latest change date and <tt>-a</tt>, to show hidden
dot-files.</p>
	</item>
</taglist></p>
</sect2>
      <sect2><heading>These commands are used for managing file-systems</heading>
      <p>Files are organised into file-systems (see &lt;ref id="file-systems"&gt;).</p>
      <p>Every Debian Linux system (and every Unix system) has a root
file-system, called, simply, <tt>/</tt>. All files and devices in the
system, and possibly files on other systems as well, are accessible under
<tt>/</tt>.  Files are placed under directories, which may themselves be
placed in directories, and so on.  Segments of this universal tree will be
on different physical devices, or different sections (`partitions') of a
single physical device. New file-systems, each with its own directory tree,
may be grafted into the universal directory tree at arbitrary `mount-points'.
(These are simply directories which are nominated to be the head of the new
tree.)</p>
      <p>The process of grafting a segment into the main tree is called
`mounting'; the filesystem is mounted on a mount-point, which is a
directory.</p><p>
<taglist>
	<tag><prgn>df</prgn></tag>
	<item><p><prgn>df</prgn> lists mounted partitions and shows the amount
of space present, used and available. (The partitions will probably include
/proc, which is a special `non-existent' partition, that contains information
about the current state of the Linux kernel.)</p>
	</item>

	<tag><prgn>mount</prgn> [<var>partition</var> <var>directory</var>]</tag>
	<item><p><prgn>mount</prgn> by itself lists mounted partitions.</p>
	  <p>It is also the command to use to add a partition's file-system
into the universal directory tree.  For example:
<example>mount /dev/hda2 /usr</example></p>
	  <p>You have to be superuser (log in as <tt>root</tt> or run
<prgn>su</prgn>) in order to mount or unmount file-systems.</p>
	</item>

	<tag><prgn>umount</prgn> <var>directory</var></tag>
	<item><p><prgn>umount</prgn> removes a partition's file-system
from the universal directory tree.  For example:
<example>umount /usr</example></p>
	  <p>You have to be superuser (log in as <tt>root</tt> or run
<prgn>su</prgn>) in order to mount or unmount file-systems.</p></item>
      </taglist></p>
</sect2>

      <sect2><heading>Looking at files</heading>
      <p>Files include physical devices, executable programs and directories,
as well as textfiles.  It is as well not to look at compiled executables
on the screen however.  At best they will be garbage; at worst they will
make everything on the screen unreadable (see &lt;ref id="rmacs"&gt; for a
way to recover from this.)</p>
<p>
<taglist>
	<tag><prgn>cat</prgn> <var>textfile[s]</var></tag>
	<item><p><prgn>cat</prgn> dumps <var>textfile[s]</var> to screen without
paging (like DOS's type).  If you name more than one file, each will be
sent in order, with no break or heading.</p>
	</item>

	<tag><prgn>more</prgn> <var>textfile[s]</var></tag>
	<item><p><prgn>more</prgn> lists the <var>textfile[s]</var> to the screen
in pages so that you can read it.  Press <tt>Spacebar</tt> to move on one page,
<tt>Enter</tt> to move on one line, and <tt>b</tt> to move back one page.  Use
<tt>q</tt> or <tt>ctrl-c</tt> to quit.</p>
	  <p><prgn>more</prgn> will quit automatically when it gets to the end
of the last file.</p>
	</item>

	<tag><prgn>less</prgn> <var>textfile[s]</var></tag>
	<item><p><prgn>less</prgn> is like <prgn>more</prgn> but has more
features and somewhat different behaviour.  You have to type <tt>Q</tt> to
terminate it.</p>
	</item>

	<tag><prgn>head</prgn> <var>textfile[s]</var></tag>
	<item><p><prgn>head</prgn> is used to see the first few lines of
a file (by default, it shows 10 lines).</p>
	</item>

	<tag><prgn>tail</prgn> <var>textfile[s]</var></tag>
	<item><p><prgn>tail</prgn> is used to see the last few lines of
a file (by default, it shows 10 lines).</p>
	</item>

	<tag><prgn>find</prgn> <var>directory</var> -name <var>filename</var></tag>
	<item><p><prgn>find</prgn> tells you where <var>filename</var> is in the
tree starting at <var>directory</var>.  This command has many other useful
options.</p>
</item>

	<tag><prgn>xargs</prgn> <var>command</var></tag>
	<item><p><prgn>xargs</prgn> is commonly used with <prgn>find</prgn>. It
breaks long lists of files given to a command into chunks that are short
enough for the shell to handle.  In this way, you can run through the
entire file system and execute some command on all the selected files:
<example>find $HOME -mtime -2 | xargs chmod g+w</example></p>
	</item>

	<tag><prgn>grep</prgn> <var>pattern</var> <var>filelist</var></tag>
	<item><p><prgn>grep</prgn> scans each file in <var>filelist</var> for
lines which match <var>pattern</var>.</p>
	</item>

	<tag><prgn>file</prgn> <var>file</var></tag>
	<item><p><prgn>file</prgn> reports what kind of thing <var>file</var> is.</p>
	</item>

	<tag><prgn>type</prgn> <var>file</var></tag>
	<item><p><prgn>type</prgn> says where to find <var>file</var> in your
search path.</p>
	</item>

	<tag><prgn>whereis</prgn> <var>file</var></tag>
	<item><p><prgn>whereis</prgn> is like <prgn>type</prgn>, but gives more
information.</p>
	</item>
      </taglist></p>
</sect2>
      <sect2><heading>Compressed files</heading>
      <p>In order to save space on your disks, many files are compressed.
They are scanned by a program such as <prgn>gzip</prgn> or <prgn>compress</prgn>
and reduced in size, often to about one third of their original size.</p>
      <p>Compressed files cannot be read unless they are uncompressed
again.</p>
<p>
<taglist>
	<tag><prgn>gunzip</prgn> <var>file.suffix</var></tag>
	<item><p><prgn>gunzip</prgn> uncompresses <var>file.suffix</var>
(where <var>suffix</var>is <tt>.gz</tt> or perhaps <tt>.Z</tt>), deletes it
and writes an uncompressed file called <var>file</var>.</p>
	  <p>In spite of its name, <prgn>gunzip</prgn> cannot handle zip
format files created by <prgn>PKZIP</prgn>.  There is a <prgn>pkunzip</prgn>
program that can handle such files.</p>
	</item>

	<tag><prgn>zcat</prgn> <var>compressed_file</var></tag>
	<item><p><prgn>zcat</prgn> does the same job as <prgn>cat</prgn>, but
uncompresses <var>compressed_file</var> first, without changing it on the
disk.</p>
	</item>

	<tag><prgn>zmore</prgn> <var>compressed_file</var></tag>
	<item><p><prgn>zmore</prgn> does the same job as <prgn>more</prgn>, but
uncompresses <var>compressed_file</var> first, without changing it on the
disk.</p>
	</item>

	<tag><prgn>zless</prgn> <var>compressed_file</var></tag>
	<item><p><prgn>zless</prgn> does the same job as <prgn>less</prgn>, but
uncompresses <var>compressed_file</var> first, without changing it on the
disk.</p>
	</item>

	<tag><prgn>zgrep</prgn> <var>compressed_file</var></tag>
	<item><p><prgn>zless</prgn> does the same job as <prgn>less</prgn>, but
uncompresses <var>compressed_file</var> first, without changing it on the
disk.</p>
	</item>
      </taglist></p>
</sect2>
      <sect2><heading>Commands for backup</heading>
      <p>You need to do regular backups, in order to be able to recover
your system and data in case of disaster.</p>
      <p>These programs are used for backups of various kinds:</p>
<p>
<taglist>
	<tag><prgn>tar</prgn></tag>
	<item><p><prgn>tar</prgn> is designed to archive directories with all
their contents.  It has many options, but here is a simple example of
using it to create a backup of your home directory to a SCSI tape:
<example>tar cvf /dev/st0 $HOME</example>
Here is how to read the contents of a tape that has been written with <prgn>tar</prgn>:
<example>tar tf /dev/st0</example>
and here is how to restore a particular directory (with its contents) from
such a tape backup:
<example>tar xvf /dev/st0 $HOME/private/letters</example></p><p>
You can also restore a single file:
<example>tar xvf /dev/st0 $HOME/private/letters/bank.21Aug</example></p>
</item>

	<tag><prgn>cpio</prgn></tag>
	<item>
<p><prgn>cpio</prgn> is used to write individual files to a backup.  A list of
files is prepared in some way and then piped into the standard input of
<prgn>cpio</prgn>. This is how to use it to archive your home directory
to SCSI tape:
<example>find $HOME -print | cpio -ovBH newc &gt;/dev/st0</example>
Here is how to read the contents of a tape that has been written with <prgn>cpio</prgn>:
<example>cpio -itBH newc &lt;/dev/st0</example>
and here is how to restore a set of files in one directory whose names all
start with `bank' from such a tape backup:
<example>cpio -itBH newc "$HOME/private/letters/bank*" &lt;/dev/st0</example></p>
	</item>
<tag><prgn>afio</prgn></tag>
	<item>
<p><prgn>afio</prgn> is used like cpio to write individual files to a backup.  It
has the additional capability of compressing files before it writes them
on the backup.  This is useful if you have a lot of information to store on
media of limited capacity. This is how to use it to archive your home directory
to SCSI tape, using compression:
<example>find $HOME -print | afio -ovZ &gt;/dev/st0</example></p>
	</item>
      </taglist></p>
</sect2>
      <sect2>
	<heading>Printing files</heading>
      <p>There is one basic command for printing (though there are many for
specialised uses):</p><p>
      <taglist>
	<tag><prgn>lpr</prgn> <var>file</var></tag>
	<item>
        <p><prgn>lpr</prgn> prints <var>file</var> to the default printer. 
<prgn>lpr</prgn> is the user command for adding jobs to the spooler queue.  The
jobs will continue to print, even if you log out.</p>
		  <p>If you have more than one printer, you can use the option
-P<var>printer</var> to direct a job to one particular printer.</p>
	</item>

	<tag><prgn>lpq</prgn></tag>
	<item>
        <p><prgn>lpq</prgn> shows the current list of jobs on the printer
spool queue.</p>
	</item>

	<tag><prgn>lprm</prgn> <var>jobId</var></tag>
	<item>
        <p><prgn>lprm</prgn> removes the job identified by <var>jobId</var> from the
spooler queue.  If a job is already printing, this may not stop it; the job
may already be stored in the printer's memory</p>
	</item>
      </taglist></p>
      </sect2>

      <sect2>
	<heading>Changing files</heading>
      <p>See &lt;ref id="editors"&gt; for information on editing files.</p>

      </sect2>
      <sect2>
	<heading>Session management</heading>
      <p>A session is the series of events between logging in and 
logging out of the computer.</p>
      <p>When you first log in, you will see a prompt, whcih may contain 
your current machine's hostname, and perhaps the current directory.  The
prompt ends with a dollar sign: <em>$</em>, which indicates that you are
an ordinary user.  If you become superuser, the dollar sign should change
to a hash (or sharp) sign: <em>#</em>.  You need to know that you are
superuser, because you can then do a great deal of damage to your system by
mistyping ordinary commands.</p>
      <p>These commands relate to handling your session:</p>
<p>
      <taglist>
	<tag><prgn>exit</prgn> or <prgn>logout</prgn></tag>
	<item>
	  <p>Use <prgn>exit</prgn> or <prgn>logout</prgn> to terminate your
session and log out.  All jobs you have started are terminated, unless they
were started with <prgn>nohup</prgn>, and your screen should return you
to the log-in prompt.  You can often use Ctrl-D to do the same, but that
capability can be disabled.</p>
	</item>

	<tag><prgn>su</prgn></tag>
	<item>
	  <p>Use <prgn>su</prgn> to become superuser.  You will be asked to enter a
password; this is the password for the <tt>root</tt> login.</p>
	  <p>Becoming superuser is almost the same as logging in as root.
You get the same power to do damage.  <em>Be very careful!</em></p>
	  <p>Use <prgn>exit</prgn>, <prgn>logout</prgn> or ctrl-D to stop
being superuser.</p>
	</item>

	<tag><prgn>fg</prgn></tag>
	<item>
	  <p>If you are running one job and want to run something else in
the same screen without stopping the first job, you can put the first job
in the background by typing Ctrl-Z.  You can then run other commands.  If
the first job wants to send anything to the screen, it will stop and
wait.  You can bring it forward again and let it continue by using the
command <prgn>fg</prgn>.</p>
	</item>
	<tag><prgn>script</prgn> <var>file</var></tag>
	<item>
	  <p>Use <prgn>script</prgn> to record everything that appears on the
screen (until the next exit) in <var>file</var>.  This is useful if you need
to record what's going on in order to include it in your message when you ask
for help.  Use exit, logout or ctrl-D to stop the recording session.</p>
	</item>
	<tag><prgn>ps</prgn></tag>
	<item>
	  <p>Use <prgn>ps</prgn> to list your processes. 
<example>
$ ps
  PID  TT STAT   TIME COMMAND
 6122  p1 S      0:00 bash 
 6123  p2 S      0:00 bash 
 6408  p1 S      0:00 ftp 
 6916  p4 R      0:00 ps 
13115  p7 SW     0:00 bash 
19102  p3 SW     0:00 bash 
19497  p4 S      0:00 -bash 
19554  p3 S     11:25 uvsh 
19623  p4 S      5:37 xemacs 
21272  p6 SW     0:00 bash
</example> </p>
	  <p>You can also use ps to see all processes on the system:
<example>
$ ps -ax
  PID  TT STAT   TIME COMMAND
    1  ?  SW     0:18 init 
    2  ?  SW     0:04 kflushd 
    3  ?  SW<    0:00 kswapd 
   10  ?  S      0:18 update 
   31  ?  SW     0:00 nfsiod 
   32  ?  SW     0:00 nfsiod 
   33  ?  SW     0:00 nfsiod 
   34  ?  SW     0:00 nfsiod 
  143  ?  S      0:08 /sbin/syslogd 
  145  ?  S      0:00 klogd 
  154  ?  S      0:00 /sbin/kerneld 
  164  ?  S      0:00 inetd 
  167  ?  S      0:05 named 
  179  ?  SW     0:00 run_job 
  183  ?  SW     0:00 bootpd 
  205  ?  SW     0:00 gpm 
  209  ?  S      0:52 /usr/sbin/tcplogd 
  212  ?  SW     0:00 icmplogd 
  ... and so on ...
</example></p>
	  <p>The number in the column headed <tt>PID</tt> is the identifying
number of the process.  Under column <tt>TT</tt> is the tty (screen or window
identifier) where it is running.  A question mark here means that it is
not attached to any screen or window, but is running in the background.</p>
	</item>
	<tag><prgn>tty</prgn></tag>
	<item>
	  <p><prgn>tty</prgn> shows you which terminal (screen or window)
you are in.
<example>
$ tty
/dev/ttyp4
</example></p>
	</item>
      </taglist></p>

      </sect2>
      <sect2>
	<heading>Identity</heading>
      <p>These commands relate to your identity as a user.</p><p>
      <taglist>
	<tag><prgn>passwd</prgn> </tag>
	<item>
	  <p>Use <prgn>passwd</prgn> to change the password that you
use when you log in.  Follow the instructions on screen about what kind
of password to choose.  When you type the password in, it doesn't show
on the screen, so you have to enter it twice, to ensure that you make
no typing errors.</p>
	</item>
	<tag><prgn>id</prgn></tag>
	<item>
	  <p><prgn>id</prgn> tells you what user you are and what group you
are in.
<example>$ id
uid=1000(olly) gid=1000(olly) groups=1000(olly),6(disk),20(dialout),25(floppy),26(tape),29(audio),34(backup),37(operator),101(priory)
</example></p>
	  <p><var>uid</var> indicates your user number, <var>gid</var> your
group number (which will be assigned to files that you create) and
<var>groups</var> lists the other groups that you are a member of.</p>
	</item>
		<tag><prgn>who -u</prgn></tag>
	<item>

<p><prgn>who -u</prgn> reports everyone who is logged on</p>
	</item>

      </taglist></p>
      </sect2>
	  <sect2>
	    <heading>Turning off the computer</heading>
	    <p>Turning the computer on and off is really a system administration
subject, but I include it here because it is something that every user who
is his own administrator needs to know.  If someone else is responsible
for administering the machine, you should neither need nor be able to shut
it down.</p>


	    <p>      <taglist>
	<tag><prgn>shutdown -t 0 -h now</prgn></tag>
	<item><p>This command shuts the computer down safely.  You can also
use ctrl-alt-del if your system is set up for that.  Never turn off a Unix
machine without doing a safe shutdown: otherwise you will damage your
filesystems.</p>
		</item></taglist></p>
	  </sect2>
	</sect1>

	<sect1>
	  <heading>Special characters in commands</heading>
	  <p>When you type a command, certain characters have a special
meaning to the shell and are interpreted before the command starts to
run.  Full details are given in the chapter on shells, but you need to
understand what is happening, or you will get results that you did not
expect.</p>
	  <p>Shell special characters are interpreted by the shell as soon
as it is given the command.  For example, if you type <tt>ls *.bak</tt>,
the shell translates <tt>*.bak</tt> to the list of all files in the current
directory whose names end in <tt>.bak</tt>.  <em>The <prgn>ls</prgn> command
never sees the asterisk.</em>  So if you want to search for files which
actually have an asterisk in their names, you have to escape the asterisk
to stop the shell from interpreting it.<example>
linda:/tmp/junk$ ls **
fred     george*  joe      mary     peter*
linda:/tmp/junk$ ls *\*
george*  peter*
linda:/tmp/junk$ 
</example>  In the example, the first command matched all files; the second
matched only those with a literal asterisk at the end of their names.</p>
	  <p>
 The same goes for other special characters.  here is the full list:</p>
	  <p><taglist>
	      <tag>\</tag>
	      <item>
		<p>\ escapes itself and other specials</p>
	      </item>
	      <tag>[]</tag>
	      <item>
		<p>[] encloses patterns for matching a single character</p>
	      </item>
	      <tag>*</tag>
	      <item>
		<p>* stands for anything (including nothing)</p>
	      </item>
	      <tag>?</tag>
	      <item>
		<p>? stands for any single character</p>
	      </item>
	      <tag>()</tag>
	      <item><p>() runs the contents of the parentheses in a subshell</p>
	      </item>
	      <tag>;</tag>
	      <item>
		<p>; terminates a command pipeline - use it to separate commands
     on a single line</p>
	      </item>
	      <tag>&</tag>
	      <item>
		<p>& runs the preceding pipeline in the background</p>
	      </item>
	      <tag>$word and ${word}</tag>
	      <item>
		<p>$word and 
${word} are interpreted as a shell variable (use ${word} if there
     is danger of ambiguity).</p>
	      </item>
	      <tag>``</tag>
	      <item>
		<p>The contents of the backquotes are run as a command and 
its output is used as part of this command</p>
	      </item>
	      <tag>""</tag>
	      <item>
		<p>The contents of the quotes are treated as one argument; any
specials inside the quotes, except for $ and ``, are left uninterpreted.</p>
	      </item>
	      <tag>''</tag>
	      <item>
		<p>The contents of the single quotes are passed to the
command without any interpretation.</p>
	      </item>
	      <tag>|</tag>
	      <item>
		<p>The vertical bar sign is used to indicate a pipe. The
command on the left-hand side of the pipe sends its output to the input of
the command on the right side of the pipe.</p>
	      </item>
	      <tag>&lt; and &gt;</tag>
	      <item>
		<p>These symbols are used for redirection; see below.</p>
	      </item>
	      <tag>&&</tag>
	      <item>
		<p>The double ampersand is used between two commands (on the
same line).  It tells the shell to run the second command only if the first
one was successful<footnote>
		    <p>Successful means terminating with an exit status of 0.</p>
		  </footnote>
.</p>
	      </item>
	      <tag>||</tag>
	      <item>
		<p>The double vertical bar is used between two commands (on the
same line).  It tells the shell to run the second command only if the first
one was unsuccessful.</p>
	      </item>
</taglist></p>
	  <p>
For example, <tt>ls -d /[uv]*</tt> will list  the names of all entries in
the root directory that start with u or v.  Unlike DOS, you can use
patterns like <tt>g*.gz</tt> (with the wildcard bit in the middle).
</p>
	</sect1>
	<sect1>
	  <heading>Filters</heading>
	  <p>
Many commands are filters, so you can pass the output of one command to
the input of another:

	<example>awk -F: '{print $1 " " $6}' /etc/passwd | sort</example> </p>

	  <p>This is a fundamental concept of all Unix and Unix-like systems.  
Many commands are designed to be filters.  They can therefore be used as
building blocks to make more complex commands, in whatever way is needed at
the time.</p>
	</sect1>
	<sect1>
	  <heading>Standard input, standard output and standard error</heading>
	  <p>When the shell starts a command for you, it opens files for standard
input, standard output and standard error.  By default, standard input is your
keyboard, standard output is your screen, and standard error is also your screen.
</p>
	  <p>Although the defaults are keyboard and screen, this can easily be
changed.  In fact, the shell copies its own standard input, output and error
when it starts a command, so the command inherits whatever the shell has.  A
command can change its own settings, by opening a different file, and you
can tell the shell to use a file instead of the default of keyboard or screen.</p>
	  <p>The file descriptor numbers for standard input, standard output and
standard error are 0, 1 and 2 respectively.</p>
	</sect1>
	<sect1>
	  <heading>Redirection</heading>
	  <p>
You can redirect standard input, output and error by adding
these sequences after a command:<taglist>
	      <tag>&lt;</tag>
	      <item>
		<p>&lt; <var>file</var> means take input from <var>file</var>.</p>
	      </item>
	      <tag>&gt;</tag>
	      <item>
		<p>&gt; <var>file</var> means send output to <var>file</var> (overwriting and destroying whatever is in the file already).</p>
	      </item>
	      <tag>&gt;&gt;</tag>
	      <item>
		<p>&gt;&gt; <var>file</var> means append output to <var>file</var>.</p>
	      </item>
	      <tag>2&gt;</tag>
	      <item>
		<p>2&gt; <var>file</var> means send error messages to <var>file</var> (overwriting).  (This means that errors can be directed separately from normal output.)
   </p>
	      </item></taglist></p>
	  <p>There are more complex aspects to redirection, which may be studied
in the shell manual pages.  </p>
</sect1>
	<sect1>
	  <heading>Shell programs</heading>
	  <p>
Redirection is a simple part of shell programming, for which see the
manual pages of bash, zsh, tcsh, or whatever shell you have chosen.
A shell program is a set of commands in a file or typed in.

	<example>for f in `grep -l widgets`
	do
		sed -e 's/widgets/gadgets/g' &lt;$f ${f}gadget
		echo $f
	done</example></p>

	  <p>Once you have stored a shell program in a program file, you have to make it
executable by running chmod:
<example>
        chmod a+x <var>my_program_file</var></example></p>
</sect1>
	<sect1>
	  <heading>Errors</heading>
	  <p>
Unix commands normally execute silently unless asked to be verbose
or unless there is an error. An error means something that does not
make sense to Linux; it doesn't mean something you don't want to
happen!</p>
	  <p>  For example, I once had a client who had some unwanted files
in his root directory which were named &amp;TEMP&amp; and so on.  As superuser
in the root directory he typed

	<tt>rm -rf /&amp;*</tt>

when he should have typed

	<tt>rm -rf \&amp;*</tt>

What he actually asked for was to delete his entire file system, as a
background job.  It did too.</p></sect1>
</sect>
<!-- </chapt></book></debiandoc> -->

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:2
sgml-indent-data:nil
sgml-doctype: (/usr/local/src/user_manual/user.sgml)
sgml-parent-document: (/usr/local/src/user_manual/user.sgml "debiandoc" "book" "chapt" )
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver

PGP key from public servers; key ID 32B8FAA1

Unsolicited email advertisements are not welcome; any person sending
such will be invoiced for telephone time used in downloading together
with a £25 administration charge.

Reply to: