\documentstyle[linuxdoc]{book}

% some general concerns:
% is \ldots sufficent to note that there is a lot of output in here,
% and I don't want to list it all?

\begin{document}

\chapter{Doing Something}

{\bf Before reading this chapter, you should have installed \linux\ and
created an account for yourself. If you haven't done so, go back and
do so now.}

\section{Introduction}

This is an introduction to Unix for people who have just installed the
SLS release of \linux.  It assumes that you know what a computer is,
and aren't scared of them, and that you have access to the SLS system
in question.

This guide is especially molded for DOS users, but people who have
used other operating systems should be able to catch on.  However, you
should remember that Unix is a very complex operating system, and
can't be learned in a day.  The effort that you put into learning Unix
will be repayed, but it might take a while to see the results.  So
hang on --- you'll understand soon enough.

Remember, the easiest way of learning something is to do.  You can't
learn to swim without getting wet.  Try out the examples in this
chapter.  Play around.  Try do some really stupid things.  In general,
you can't hurt the system.  There are a few commands you should be
careful of, and there will be warnings whenever I introduce one.

This chapter won't tell you everything about Unix --- hopefully, there
will be a more complete user's manual to do that.  In here, you will
learn enough to do some productive work, to explore the system, and to
have fun.  I'm presenting the material like a tutorial, walking you
through the steps.  At the end of each section, I hope to step back
and explain the big picture.

\section{Logging In}

Unix is a multitasking, multiuser operating system.  This means that
there can be many people using one computer at the same time, running
many different applications.  This differs from DOS, where only one
user can use only one application without special software.  Since
more than one user can be logged on at a time, the system supplies
mechanisms for telling the users apart.  To start using the system you
must identify yourself by {\bf logging in}.

The first thing we must do to start using a \linux\ system is called
logging in.  \index{login} You'll see the a prompt resembling
the following on your screen:

\begin{screen}\begin{verbatim}
INSERT SLS BANNER HERE
mousehouse login:
\end{verbatim}\end{screen}

The above banner means that the system, named {\tt mousehouse}, is
waiting for you to do is enter a {\bf username}. \index{username} For
the purpose of this guide, I'll use the username {\tt larry}. You'll
have to type whatever username you added in the installation steps. If
I want to login, I type:

\begin{screen}\begin{verbatim}
INSERT SLS BANNER HERE
mousehouse login: larry
Password: 
\end{verbatim}\end{screen}

As the prompt implies, you now have to enter a {\bf password}.
\index{password} If you gave your account a password, type it now.  If
you choose not to give your account a password, you won't be prompted
for one, and will be logged right in.

Notice when you type your password, it won't be echoed (printed back)
onto the screen.  This is for security purposes.  It also increases
the chance of making a typing mistake, but don't worry about this.  If
you do make a mistake, you just have to type your username again.  (No
police officers are automatically summoned, as this is a feature only
on high end versions of Unix.)

What happens immediately after you login is the system starts up what
is called a {\bf shell}\index{shell} for you.  A shell is where you
issue commands for the system to execute.  Most of the problems people
experience while trying to learn Unix is how to get the shell to
properly understand what you are trying to tell it to do.

\section{Basic Unixisms}

\subsection{What's a shell?}

There are many different shells\index{shell}, or command interpretors.
There are only two major ``flavors'' though, the bourne shells and C
shells.  The shell you are using is called {\tt bash}\index{bash},
which stands for the ``bourne again shell''. (You'll notice that many
commands in Unix stem from puns of some type.  Many of the puns aren't
too good, and some involve prior knowledge to understand them.)

Bourne shells are more standard, although traditionally less easy to
use for interactive work.  Luckily, the standard \linux\ shell is a more
advanced bourne shell put out by the FSF\index{free software
foundation}.  This shell allows interactive editing, useful if you
mistype something, and command history, so you can see what you've
done in that past.

Using the shell is actually fairly easy, although a bit cryptic at
times.  When you first login, you'll notice a screen like this:

\begin{screen}\begin{verbatim}
mousehouse login: larry
Password:

Welcome to SLS version 0.96. (CORRECT THE MOTD!)

/home/larry#
\end{verbatim}\end{screen}

The welcome message is from a file (set up by the adminstrator) called
{\tt motd}, standing for ``message of the day''.  The part you should
be interested in right now is {\tt /home/larry\#}.  That is the {\bf
prompt}.  You should be reasonable careful with your typing here,
since one feature of Unix is the lack of ``Are you sure?''
confirmation messages.  For instance ({\bf do not type this}), {\tt rm
-r *} would wipe out all your files without remorse.

\subsection{Directories}

First let me explain the parts of the prompt to you. The {\tt \#} means
nothing, just the end of a prompt. (Easy enough.) The {\tt
/home/larry} is your current working {\bf directory}\index{directory}.
A directory is like (to borrow an anology from the macintosh) a
folder, containing different files.  I won't go into this in too much
detail, as many people have experience with directories before.  Let
me just say that directories are like a tree structure---you start
with the ``root'' directory, named {\tt /} which contains files and
other directories, one of which is named ``home''. The home directory
is named {\tt /home}, and contains user directories, or workspace
reserved for the individual users.  Thus, {\tt /home/larry} is a
directory inside a directory, home, inside another directory, called
``root''.

The root directory is never referenced as {\tt /root}, but just by a
single slash.

% here would be a good place to put in a diagram about the overall
% system structure
% like so:

\unitlength=1.0pt
\begin{figure}[tb]
\caption{A typical (abridged) Unix directory tree.}
\label{dirtree}
\begin{picture}(148.00,365.00)(0.00,450.00)
\put(9.00,805.00){\line(1,0){29.00}} % / -> bin
\put(26.00,805.00){\line(0,-1){112.00}} % /'s children
\put(26.00,791.00){\line(1,0){12.00}} % dev
\put(26.00,777.00){\line(1,0){12.00}} % etc
\put(26.00,763.00){\line(1,0){12.00}} % home
\put(64.50,763.00){\line(1,0){29.00}} % home -> larry
\put(81.50,763.00){\line(0,-1){14.00}} % home's children
\put(81.50,749.00){\line(1,0){12.00}} % sam
\put(26.00,735.00){\line(1,0){12.00}} % lib
\put(26.00,721.00){\line(1,0){12.00}} % proc
\put(26.00,707.00){\line(1,0){12.00}} % tmp
\put(26.00,693.00){\line(1,0){12.00}} % usr
\put(55.50,693.00){\line(1,0){29.00}} % usr -> X386
\put(72.50,693.00){\line(0,-1){238.00}} % usr's children
\put(72.50,676.00){\line(1,0){12.00}} % bin
\put(72.50,659.00){\line(1,0){12.00}} % emacs
\put(72.50,642.00){\line(1,0){12.00}} % etc
\put(72.50,625.00){\line(1,0){12.00}} % g++-include
\put(72.50,608.00){\line(1,0){12.00}} % include
\put(72.50,591.00){\line(1,0){12.00}} % lib
\put(72.50,574.00){\line(1,0){12.00}} % local
\put(107.00,574.00){\line(1,0){29.00}} % local -> bin
\put(124.00,574.00){\line(0,-1){51.00}} % local's children
\put(124.00,557.00){\line(1,0){12.00}} % emacs
\put(124.00,540.00){\line(1,0){12.00}} % etc
\put(124.00,523.00){\line(1,0){12.00}} % lib
\put(72.50,506.00){\line(1,0){12.00}} % man
\put(72.50,489.00){\line(1,0){12.00}} % spool
\put(72.50,472.00){\line(1,0){12.00}} % src
\put(100.50,472.00){\line(1,0){29.00}} % src -> linux
\put(72.50,455.00){\line(1,0){12.00}} % tmp
\put(8.50,805.00){\makebox(0,0)[rc]{/}}
\put(39.50,805.00){\makebox(0,0)[lc]{bin}}
\put(39.50,791.00){\makebox(0,0)[lc]{dev}}
\put(39.50,777.00){\makebox(0,0)[lc]{etc}}
\put(39.50,763.00){\makebox(0,0)[lc]{home}}
\put(95.00,763.00){\makebox(0,0)[lc]{larry}}
\put(95.00,749.00){\makebox(0,0)[lc]{sam}}
\put(39.50,735.00){\makebox(0,0)[lc]{lib}}
\put(39.50,721.00){\makebox(0,0)[lc]{proc}}
\put(39.50,707.00){\makebox(0,0)[lc]{tmp}}
\put(39.50,693.00){\makebox(0,0)[lc]{usr}}      % I'm expecting you to
\put(86.00,693.00){\makebox(0,0)[lc]{X386}}	% proof-read this!
\put(86.00,676.00){\makebox(0,0)[lc]{bin}}
\put(86.00,659.00){\makebox(0,0)[lc]{emacs}}
\put(86.00,642.00){\makebox(0,0)[lc]{etc}}
\put(86.00,625.00){\makebox(0,0)[lc]{g++-include}}
\put(86.00,608.00){\makebox(0,0)[lc]{include}}
\put(86.00,591.00){\makebox(0,0)[lc]{lib}}
\put(86.00,574.00){\makebox(0,0)[lc]{local}}
\put(137.50,574.00){\makebox(0,0)[lc]{bin}}
\put(137.50,557.00){\makebox(0,0)[lc]{emacs}}
\put(137.50,540.00){\makebox(0,0)[lc]{etc}}
\put(137.50,523.00){\makebox(0,0)[lc]{lib}}
\put(86.00,506.00){\makebox(0,0)[lc]{man}}
\put(86.00,489.00){\makebox(0,0)[lc]{spool}}
\put(86.00,472.00){\makebox(0,0)[lc]{src}}
\put(130.50,472.00){\makebox(0,0)[lc]{linux}}
\put(86.00,455.00){\makebox(0,0)[lc]{tmp}}
\end{picture}
\end{figure}

Each Unix system has a directory structure.  Usually, the directories
directly below the root directory are {\tt bin}, {\tt etc}, {\tt mnt},
{\tt tmp}, {\tt usr}, {\tt dev}, {\tt home}, and {\tt lib}.  Please
take a look at figure \ref{dirtree}.  Notice that {\tt mnt} isn't
there---I'd like you to get used to the fact that there will be
differences between this manual and your actually
system.\footnote{Besides the fact I'm too lazy to redo my diagram.}
There will be other directories there too, but I'm only going to
discuss these.
 
Before I explain the function of each of these directories, I'd like
you to learn how to ``move'' around the {\bf file system}\index{file
system}.  The file system refers to the collection of directories and
data files that makes up the system.

\subsection{Moving Around}

The main command for moving around in the directory structure is
called {\tt cd}\index{cd}, short for change directory.  You'll notice
that many often used Unix commands are two or three letters.  The cd
command is used like this:

\begin{screen}\begin{verbatim}
mousehouse login: larry
Password:

Welcome to SLS version 0.96. (CORRECT THE BANNER!)

/home/larry# cd /home
/home# 
\end{verbatim}\end{screen}

That is, you type {\tt cd}, and then the directory you want to change
to, and then a \ret.  To simplify the explaining of new commands,
you'll see them introduced like this:

\begin{screen}
cd {\sl /usr/bin}
\end{screen}

That means the command is {\tt cd}, and needs one {\bf parameter},
{\sl /usr/bin}.  Parameters are simply the characters that come after
the command.  (The command is usually the first word on the line, and
consists of only one word without any spaces in it.)

Whenever you see something slanted it means that this just represents
one possible parameter, but there can be others.

Try to use the {\tt cd} command to change to the {\tt /home}
directory, the root directory, and the {\tt /usr} directory.  Now,
change back to your home directory, {\tt /home/{\sl username}}).
Hopefully, nothing terrible has happened, and you saw something like:

\begin{screen}\begin{verbatim}
/home/larry# cd /home
/home# cd /
/# cd /usr
/usr# cd /home/larry
/home/larry#
\end{verbatim}\end{screen}

Now that you know how to move around directories you probably think,
``So what?''  The basic skill of moving around directories is fairly
useless, so let's introduce a new command, called {\tt ls}.  Try it
out:

\begin{screen}\begin{verbatim}
/home/larry# ls
/home/larry#
\end{verbatim}\end{screen}

Great!  You've just run a command that's done absolutely nothing!
Actually, it did do quite a bit.  It searched your present directory
for files, and printed them out.  It turns out you didn't have any
files, so it didn't print anything out.  Notice how this differs from
DOS, which would say {\em something\/} even if you didn't have any
files in your directory.  To see the {\tt ls} command do something,
change to another directory, say {\tt /etc}.

\begin{screen}\begin{verbatim}
/home/larry# cd /etc
/etc# ls
Images          ftpusers        lpc             rc.new          shells
adm             getty           magic           rc0.d           startcons
bcheckrc        gettydefs       motd            rc1.d           swapoff
brc             group           mount           rc2.d           swapon
brc~            inet            mtab            rc3.d           syslog.conf
csh.cshrc       init            mtools          rc4.d           syslog.pid
csh.login       init.d          pac             rc5.d           syslogd.reload
default         initrunlvl      passwd          rmt             termcap
disktab         inittab         printcap        rpc             umount
fdprm           inittab.old     profile         rpcinfo         update
fstab           issue           psdatabase      securetty       utmp
ftpaccess       lilo            rc              services        wtmp
<IT WOULD BE BEST TO REPLACE THIS BY A VIRGIN SLS SETUP!!!>
/etc#
\end{verbatim}\end{screen}

The exact directory listing you see may be slightly different from the
above, but the general idea is the same.  (For those old DOS users out
there, notice how the files can be longer than 8 characters, and can
have periods in any position.  It is even possible to have more than one
period.) The above files happen to be system files, so you should
avoid playing with them.  (In your account, you shouldn't be able to
cause any damage, but better safe than sorry.)

Let's move to a directory that's safer to play with, say, {\tt
/usr/bin}. While you can get there quickly by methods you already
know, there's another way I'd like to teach you.  In Unix, like in
DOS, it's possible to move up one directory on the tree by typing {\tt
cd ..}.  Try that command now.

Now that you're in the root directory, you want to move down the tree,
but this time into the {\tt usr} branch.  That's easy to do: {\tt cd
usr}. After that, you want to move to {\tt bin}, so {\tt cd bin}.
What should have happened on your screen is:

\begin{screen}\begin{verbatim}
/etc# cd ..
/# cd usr
/usr# cd bin
/usr/bin#
\end{verbatim}\end{screen}

Try moving around various directory with {\tt ls} and {\tt cd} now.
If you want to find out which of the entries in a {\tt ls} listing is
a directory, invoke {\tt ls} by typing {\tt ls -F}.  Any entry that
ends in a slash is a directory, and you can {\tt cd} to it.  Well,
that is if you, as a user, are allowed into that directory.  There may
be some closed off to you.

You should be aware that you can move down directories in multiply
steps, like {\tt cd usr/bin}, and that a single period refers to the
current directory. (Try {\tt cd .}.) Another useful fact is that {\tt
~/} refers to your home directory.  Try typing {\tt cd ~/}. (Actually,
just typing {\tt cd} without any parameters will move you to your home
directory just fine.)

\subsection{Your own directories}

Change to your home directory by any of the methods listed above, and
do a {\tt ls}.  There probably isn't anything there, but if there is,
ignore it.

It's time to learn how to create directories.  Try the following:

\begin{screen}\begin{verbatim}
/home/larry# mkdir gs1
/home/larry# ls -F
gs1/
/home/larry# cd gs1
/home/larry/gs1# ls
/home/larry/gs1#
\end{verbatim}\end{screen}

Congrats!  You've just made a new directory and changed to it.  Since
there aren't any files (see the {\tt ls} up there), let's {\bf copy}
some files in.  Copying files is done with the command {\tt cp}:

\begin{screen}
\begin{verbatim}
/home/larry/gs1# cp /etc/termcap .
/home/larry/gs1# cp /etc/magic .
/home/larry/gs1# cp /etc/shells .
\end{verbatim}
\end{screen}

Now list the files in the directory.  You should see:

\begin{screen}
\begin{verbatim}
/home/larry/gs1# ls -F
magic    shells   termcap
/home/larry/gs1#
\end{verbatim}
\end{screen}

The {\tt cp} command takes two parameters: the file to copy, and where
to copy it to.  ({\tt cp} {\sl file destination}) Remember a single
period refers to the current directory.  Notice how we can supply the
{\bf path} to the files, or the sequence of directories needed to find
the file, instead of manually changing to that directory.

Make another directory {\em inside} the {\tt gs1} directory, called
{\tt the\_place}.  (Notice that there is no eight character limit,
although some versions of \linux\ have a fourteen character limit.)
Copy the file named {\tt termcap} into it.

A new command named {\tt mv} moves files, instead of copying them.
Move the file named {\tt magic} to {\tt the\_place}.  The {\tt mv}
command is used just like the {\tt cp} command, so the syntax is, {\tt
mv} {\sl filename destination}.

\begin{screen}\begin{verbatim}
/home/larry/gs1# mv magic the_place
/home/larry/gs1# ls -F
shells     termcap     the_place/
/home/larry/gs1# 
\end{verbatim}\end{screen}

Now do an {\tt ls}, and then try {\tt ls the\_place}, which lists the
files in the directory {\tt the\_place}. The {\tt mv} command will
also rename files.  For example, try {\tt mv rc frog}.  (Remember to
move it back, since we'll go on assuming you have a file named {\tt
rc}.) You'll have to keep in mind that if the second argument to {\tt
mv} is a directory, the file gets moved there. Otherwise, the file
will be renamed.  However, if you {\tt mv rc the\_place/frog}, you
move and rename {\tt rc} at the same time.

\blackdiamond {\tt mv} will always overwrite a file without asking
you.  So, be careful when you move a file into another directory:
there can already be a file with the same name in that directory!

Try to restore the files so that the files {\tt shells} and {\tt
termcap} are in {\tt gs1} and {\tt magic} and {\tt termcap} (another
copy) are in {\tt the\_place}.  (If you overwrote one of the files,
you can always copy it from {\tt /etc} again.)

You now have two copies of the {\tt termcap} file lying around.  Let's
get rid of one.  In DOS, this would be handled by the {\tt del}
command.  The Unix equivalent is called {\tt rm} (for remove).  {\tt
rm}'s syntax is: {\tt rm} {\sl file1 file2 \ldots} (it can take quite
a few files as parameters to delete).  Let's get rid of {\tt shells}
and the copy of {\tt termcap} in {\tt gs1} ({\em not\/} in {\tt
the\_place}!) now.

\begin{screen}\begin{verbatim}
/home/larry/gs1# rm termcap inittab
/home/larry/gs1# ls -F
the_place/
/home/larry/gs1#
\end{verbatim}\end{screen}

Gone!

A related command to {\tt rm} is {\tt rmdir}. Create a new directory
called ``forever''. Do a {\tt ls} to make sure everything is okay. Now
try {\tt rmdir forever}. Following standard Unix procedure, the
command did nothing. But if you do another {\tt ls}, you'll find the
directory is gone.

Now try deleting {\tt the\_place}. You'll find that you can't --- {\tt
rmdir} tells you, ``rmdir: the\_place: Directory not empty''. This
merely shows that directories must be empty before they're deleted.

We've done real great so far: we've copied files, moved files, deleted
files, and found the name of files, and we {\em still\/} don't know
what's in them!

\subsection{Looking at files}

The commands {\tt more} and {\tt cat} are used for listing files.
Change to {\tt the\_place} and type:

\begin{screen}\begin{verbatim}
/home/larry/gs1# more termcap
\end{verbatim}\end{screen}

What is printed out is the first screenful of the {\tt termcap} file.
For your information, the {\tt termcap} file is a guide to tell the
computer about the different types of terminals that are hooked up to
your machine.  (For \linux, most likely there aren't any terminals,
but it's always possible. Remember, Unix is a multiuser operating
system.)

At the bottom of the screen, many things can be displayed, depending
on your exact version of {\tt more}.  To really confuse you, I'll tell
you that you're version of {\tt more} might actually be a program
called {\tt less}. (You'll notice that Unix programmer's {\em love\/}
puns.) That isn't very important.

The basic commands for {\tt more} (or {\tt less}) are:

\begin{dispitems}
\item [\key{Space}] Move to the next page of text.

\item [{\tt b}] Move to the previous page of text.

\item [{\tt /}] After entering this command, enter a {\bf string}, or
some text to search for. Then press \ret. If the string is in the file
after the place you are looking at, {\tt more} will jump there. (This
is important: if you're half way down the file, and search for
something near the beginning, {\tt more} won't find it.)

\item [{\tt q}] This will quit the program.

\item [{\tt ?}] This {\em should\/} get you help, although {\tt more}
and {\tt less} are always bad about doing this correctly.
\end{dispitems}

Quit {\tt more} and try {\tt cat termcap}. The text will probably fly
by much too quickly for you to read it.  {\tt cat} isn't very useful
for reading files, although it does do other things which are quite
helpful. In general, if you, a human, want to read a file, use {\tt
more}.

\subsection{Summary of Basic Commands}

This subsection lists the commands gone over in this section. To help
recovering DOS users, it also lists DOS equivalents. The options are
the ones proceeded by dashes on the command line, while the parameters
are files or directories to act on.

Please note that I will lie where applicable: this is a simple
listing, and should not be taken seriously.

\begin{dispitems}

% this could be nicer formatted
\item [cd] DOS equiv.: cd\\
           This command let's you change your current directory.  This
is equivalent to changing your vantage point. Most commands are
relative to your current directory.\\
Options: none\\
Parameters: Directory to change to. (``.'' references the current
directory, ``..'' the parent directory.)\\
Sample: {\tt cd ../gs1}

\item [ls] DOS equiv.: dir\\
	   This command lists the files in the current directory. (It
also lists the subdirectories, or the directories in the current
directory.) It is one of the most often used Unix commands.\\
Options: ``F'' postfixes directories and executables with special
characters to distinguish them from ordinary data-files. ``l'' will
list additional information about files.\\
Parameters: Directories/files to list.\\
Sample: {\tt ls -F ..}

\item [cp] DOS equiv.: copy\\
	   This command will copy one file to another. It will copy
the file to other directories, change it's name, and overwrite other
files with the new copy.\\
Options: none\\
Parameters: The first parameter is what file to copy, the second is
where/what to copy it to.\\
Sample: {\tt cp ../frog joe}

\item [mv] DOS equiv.: none\\
	   This command does the equivalent of a copy followed by a
deletion of the original. It will move the file to other directories,
change it's name, and overwrite other files with the new copy.\\
Options: none\\
Parameters: The first parameter is what to move, the second is where
to move it.\\
Sample: {\tt mv ../frog joe}

\item [rm] DOS equiv.: del\\
	   This command deletes the files listed without remorse.
These files are unrecoverable under most situations. (A future version
of \linux\ {\em might\/} support undeletion, but you probably don't
have it and shouldn't count on it.)\\ 
Options: ``i'' will ask for confirmation. A dangerous way of removing
directories is with the ``r'' option. It removes the directory and
everything below it without asking permission. Be {\em very\/} careful
with this. (That is, {\tt rm} can remove directories if given the
``r'' option.)\\
Parameters: The parameters are all files to delete.\\
Sample: {\tt rm /home/larry/joe}

\item [mkdir] DOS equiv.: mkdir\\
	      This command creates a new directory.\\
Options: none\\
Parameters: The only parameter is the directory to create.\\
Sample: {\tt mkdir /home/larry/test}

\item [rmdir] DOS equiv.: rmdir\\
	      This command removes empty directories. Note that you
can't be in a directory when you remove it: {\tt rmdir .} won't
work.\\
Options: none\\
Parameters: The directories to remove.\\
Sample: {\tt rmdir the\_place}

\item [more] DOS equiv.: none\\
	     This command displays the contents of a text file,
pausing after each screenful of output.\\
Options: none\\
Parameters: Files to list.\\
Sample: {\tt more frog}

\item [cat] DOS equiv.: type\\
	    This command displays the contents of any file (it doesn't
check to see if it's text) without pausing. Sometimes, this behavoir
can even mess up your screen.\\
Options: none\\
Parameters: Files to list.\\
Sample: {\tt cat dog}
\end{dispitems}

\section{Exploring the File System}

I promised before to escort you around the filesystem. The time has
come.  You have the skills and the knowledge to make sense out of what
I'm saying, and you have a roadmap. (Remember figure \ref{dirtree}?
Please refer back to that every so often.)

% incomplete

\section{The Power of Unix}

As I have mentioned too many times before, Unix is a multitasking,
multiuser operating system.  Since \linux\ runs on a PC, most likely
you won't care about the multiuser part.\footnote{In a couple of
months you might: there are many possibilities, like hooking up a '286
to your machine.}

Multitasking is {\em very\/} useful, and once you get used to it,
you'll want it all the time. Also, the shell\index{shell} offers more
advanced ways of communicating with the user than DOS. Some basic
features of the shell are mentioned in this section.\index{bash}

\subsection{Wildcards}

A key feature of most Unix shells is the ability to reference most
than one file with special characters. The first such character is
``{\tt *}''.

A {\tt *} is substituted by the shell for all the files. DOS users are
probably familar with ``{\tt *.*}'' This concept can be hard to grasp,
but once you understand, you'll love it. The easist way to explore
this is using a command called {\tt echo}. All echo does is repeat
it's commands back to you.

Try {\tt echo joe}, and {\tt echo frog}. {\tt echo} is a simple
command, and you should pick it up quickly.

Let's try some examples. Make sure you're in {\tt gs1/the\_place}. Try
the following commands:

\begin{screen}\begin{verbatim}
/home/larry/gs1/the_place# ls
magic    termcap
/home/larry/gs1/the_place# echo *
magic termcap
/home/larry/gs1/the_place# echo m*
magic
/home/larry/gs1/the_place# echo *c*
magic termcap
/home/larry/gs1/the_place# echo t*p
termcap
/home/larry/gs1/the_place#
\end{verbatim}\end{screen}

Now, some people may have already figured out the meaning of ``{\tt *}''
from those examples. If you didn't, don't dispair. What the ``{\tt
*}'' is doing is simply replacing itself with filenames that would fit
in there. The command {\tt echo t*p} searched for all files beginning
with ``t'', and ending with ``p'' in the current directory. {\tt
termcap} was the only file matching those criteria. So, the {\tt t*p}
was replaced by {\tt termcap}, and then the command {\tt echo termcap}
was executed.

Hopefully the above made things slightly clearer for you. If it
didn't, don't worry. Let's try an application of this command:

\begin{screen}\begin{verbatim}
1 /home/larry/gs1/the_place# cp /etc/* .
2 /home/larry/gs1/the_place# ls
  ...
3 /home/larry/gs1/the_place# rm t*
  /home/larry/gs1/the_place# ls
  ...
  /home/larry/gs1/the_place#
\end{verbatim}\end{screen}

By the steps, what the above did was:
\begin{enumerate}
\item Copied all the files in the directory {\tt /etc} into the
current directory, {\tt /home/larry/gs1/the\_place}. This actually got
expanded to:
\begin{quote}
{\tt cp /etc/bcheckrc /etc/brc /etc/crond.pid \ldots\ /etc/wtmp .}
\end{quote}
\item This listed the files, and got a long list, equivalent to the 
directory is {\tt /etc}. However, you might note that subdirectories
of {\tt /etc} were {\em not\/} copied.
\item Removed all the files beginning with t.
\end{enumerate}

By the way, the process of changing a ``{\tt *}'' into filenames is
called {\bf wildcard expansion} and is done by the shell. (This is
important: the individual commands {\em never\/} see a ``{\tt *}''.)

Another special character is ``{\tt ?}''.  ``{\tt ?}'' will only
expand to one character. Thus, {\tt rm ?} will remove all one
character filenames, and {\tt rm termca?} would remove {\tt termcap}
but {\em not\/} {\tt termcap.backup}.

I'd like to mention two more things about wildcard expansion and how
it relates to commands. First of all, we should update our {\tt mv}
and {\tt cp} commands to:

\begin{quote}
{\tt cp} {\sl file1 file2 file3 \ldots fileN destination}\\
{\tt mv} {\sl file1 file2 file3 \ldots fileN destination}
\end{quote}

When you {\tt cp} or {\tt mv} more than one file at the time, they
can't be renamed. The last parameter is a multi-file {\tt cp}/{\tt mv}
must be a directory. However, Unix assumes you know what you're doing,
and may not give error messages in some cases.

Secondly, files that start with a single period are treated
differently. Classically, any files that start with a period are
configuration files and are not shown by {\tt ls} and not touched by
{\tt cp}, {\tt mv}, or {\tt rm}. For example, try {\tt mv termcap
.frog}, and then do an {\tt ls}.

You won't see a {\tt .frog} in the file list. But it will show up if
you try {\tt ls -a}. {\tt ls -a} will also show the two ``dummy
directories'', {\tt .} and {\tt ..}.

This is important to remember because, for instance, {\tt mv * ..}
will {\em not\/} move files that start with a single period. To move
those files, type {\tt mv .* ..}, which will work. However, that
command won't move all the other files.

Some important configuration files are stored in your home starting
with a period, although you probably don't have many, if any, since
your account is so new.

\subsection{Being a Plumber}

Many Unix commands accept input until they receive what is called an
EOF character, or end-of-file character. That merely marks, as it
sounds like, the end of a file. (Now, wasn't that easy?)

For example, let's take a small look at the {\tt sort} program. As the
name suggests, the {\tt sort} program sorts things. It sorts by lines,
but rather than explain it, let's run it. Type in {\tt sort} now, and
hit \ret.

Type in some random text over several lines. (Remember to hit return:
don't let the text just wrap around.) Now, type the EOF character,
ctrl-D. (That means, hold down the key marked ``Ctrl'' and press
``d''.)

The text you inputted should be repeated back to you, now in sorted
form. Simple. {\tt sort} will also take a parameter, a file, to sort.
It won't actually modify the file, just output the sorted file. 

However, what I'm trying to illustrate is that {\tt sort} is what we
call a {\bf filter}: it accepts text from {\bf standard input} and
prints it to {\bf standard output}.

If you're like most humans, you don't know what I just said. Never
fear. Standard input (abbreviated as stdin) is simple what you type
in. Standard output (stdout) is most of what a program outputs.
However, Unix also provides standard error (stderr), which is also a
form of output. {\bf Standard error} usually goes directly to the
terminal (and therefore the user), while standard output is frequently
{\bf redirected}.

So a filter reads in information, does something to the information,
and prints it out. It usually will print any errors out, but to
stderr. The key to this is three symbols used in {\bf redirection}:
{\tt <}, {\tt >}, and {\tt |}. The first symbol redirects the standard
input from a file, instead of from a terminal:

\begin{screen}\begin{verbatim}
/home/larry/cprogs# ls -F
Makefile    bigints.c   forest.o    hmm         testdata1   
backups/    forest.c    generate.c  outdata1    
/home/larry/cprogs# cat testdata1
the toad
jumps over
the frog
/home/larry/cprogs# sort < testdata1
jumps over
the frog
the toad
/home/larry/cprogs# sort testdata1
jumps over
the frog
the toad
/home/larry/cprogs#
\end{verbatim}\end{screen}

The difference between {\tt sort < testdata1} and {\tt sort testdata1}
is that {\tt sort < testdata1} acted like you typed in {\tt
testdata1}, instead of {\tt sort} reading the file. Some commands
don't accept parameters like {\tt sort}, so this can come in handy.

The second symbol, {\tt >}, redirects output to a file:

\begin{screen}\begin{verbatim}
/home/larry/cprogs# sort < testdata1 > testdata1.sorted
/home/larry/cprogs# ls
Makefile          forest.c          hmm               testdata1.sorted 
backups/          forest.o          outdata1          
bigints.c         generate.c        testdata1         
/home/larry/cprogs# cat testdata1.sorted
jumps over
the frog
the toad
/home/larry/cprogs#
\end{verbatim}\end{screen}

{\tt cat} is also multi-purposed. If you type {\tt cat} on a line by
itself, it will let you enter characters and echo them back to you.
Enter EOF to quit it. Knowing this property, can you tell what {\tt
cat > today} does?

Try it, enter some stuff, and hit EOF. Now do a {\tt ls}, and {\tt cat
today}. You've made a mini text editor! {\tt cat} turns out to be
amazingly useful. If you wanted to con{\em cat\/}enate some files, you
can just {\tt cat file1 file2 file3 > newfile}.

{\tt >} destroys whatever file it is ``aimed'' at. However, there is
also a tool to append to a file: {\tt >>} will merely add to a file,
and not overwrite it. (If the file doesn't exist, {\tt >>} acts just
like {\tt >}.)

The last symbol, {\tt |}, called a {\bf pipe}, redirects stdout to
{\em another program}. Now, this doesn't sound like a big deal, but in
fact is very powerful. For example, {\tt cd /usr/bin}. List the files.
Whoa! A little too many there, right?

Why not pipe the output of {\tt ls} to {\tt more}, which pauses after
a screen? Try {\tt ls | more}. Now, isn't that better? Of course, you
don't have to stop there. {\tt ls} usually sorts things, but if it
didn't, it would be perfectly legal (and helpful) to {\tt ls | sort |
more}.

Sometimes, you might want to redirect stderr (although not usually).
To do this, you merely {\tt cat frog >\& joe}. This redirects both
stdout and stderr to the file {\tt joe}.

Now, that stuff may seem a little confusing, but use it. It is {\em
very\/} useful, and the more you use it, the more useful it becomes.

\subsection{File Permissions}

Since Unix is a multiuser operating system\footnote{I'll stop saying
that as soon as you remember.} there are mechanisms to prevent users
from reading, writing, and modifying other users files. Each file also
has an owner and a group.

Permissions fall into three main divisons: read, write, and execute.
(All will be explained.) Under each of these divisons, permissions may
be granted for the owner, for his group, and for everybody outside of
his group. Let's take an example. Change to your {\tt gs1} directory,
and copy a random file in from {\tt /etc}:

\begin{screen}\begin{verbatim}
/home/larry/gs1/the_place# cd ..
/home/larry/gs1# cp /etc/passwd .
/home/larry/gs1# ls -l passwd
-rw-r--r--   1 larry    users         505 Mar 13 19:05 passwd
/home/larry/gs1#
\end{verbatim}\end{screen}

The opening {\tt -rw-r--r--} are the permissions. (Your permissions
may not be exactly the same as those permissions.) The ``1'' is how
many links there are to this file. (Please forget this. I'd rather not
explain it right now.) The next word is the user who owns this file:
{\tt larry}, and then his group, {\tt users}. The 505 is the size, in
bytes, of the file, and then the date the file was last modified.
Finally, we come to the name of the file.

The first dash means that this isn't a device file\index{device}, or a file
that represents a device. (Remember, in the {\tt /dev} directory there
are many different files, each of which represent a different hardware
device on the computer.)

Now, the next three characters in the permissions, {\tt -rw}, are the
permissions for the owner. The dash means I don't have rights to
execute this file, which is completely normal. The {\tt passwd} file
isn't a program, it's data. If I {\em could\/} execute it, I'd have a
``x'' there: {\tt -rwxr--r--} or {\tt -rwxr-xr-x}.

The ``r'' refers to the fact that I can read my own file. I can
perform operations like {\tt cat}, {\tt more}, and {\tt sort} on it.
(Remember that {\tt sort} doesn't write to the disk unless I redirect
the output.) The ``w'' refers to the fact that I can change this file.
Basically, with this right you can do everything {\em but\/} delete
this file.

The next group of three characters, {\tt r--}, are the permissions for
the group. The group in this case is {\tt users}. This means any other
user in the group called {\tt users} can read this file. Then the last
three characters are for people not in the group, and follow along
just like the proceeding two examples.

There are permissions in directories, too. The execute permission says
that the user/group/other can {\tt cd} to that directory; the read
permission says that the user can {\tt ls} that directory; the write
permission says that a user can modify that directory: create and
delete files.

Those are the basic permissions: there are more, but I'll leave them
to a more in-depth text to cover. Needless to say, {\em many\/}
problems are caused by incorrect permissions, so I'll get you slightly
familar with them. The three primary programs used to manipulate
permissions have great names: {\tt chown}, {\tt chgrp}, and {\tt
chmod}.

Since you have to be root to use {\tt chown} and {\tt chgrp}, I'll
skip over them. (They just change the owner and group of the file,
respectively.) The {\tt chmod} (for change mode) manipulates the
permissions.

It takes the form of:
\begin{quote}
{\tt chmod} \{a,u,g,o\}\{+,-\}\{r,w,x\} {\sl filenames}
\end{quote}

Hmm\ldots That didn't really help. Briefly, you supply one or more of
{\bf a}ll, {\bf u}ser, {\bf g}roup, {\bf o}ther. Then you say whether
you are added rights, or taking them away, and then one or more of
{\bf r}ead, {\bf w}rite, e{\bf x}ecute. So some examples of legal
commands are (note that these don't make sense):

\begin{screen}\begin{verbatim}
1 /home/larry/gs1# chmod a+r passwd
2 /home/larry/gs1# chmod og-x passwd
3 /home/larry/gs1# chmod u+wrx passwd
4 /home/larry/gs1# chmod og-rwx passwd
5 /home/larry/gs1# chmod +r passwd
6 /home/larry/gs1#
\end{verbatim}\end{screen}

By the numbers:
\begin{enumerate}
\item Let all users read the file {\tt passwd}.
\item Don't let users other than the owner of the file execute {\tt
passwd}.
\item Let the owner of the file do whatever he wants to it! (Execute
it, read it, and change it.)
\item Don't let anyone but the owner of the file read, write, or
execute it.
\item This is equivalent to 1: let all users read {\tt passwd}.
\end{enumerate}

Hopefully, in the system manager's section, there will be some common
problems and solutions with permissions.

% will there be?

\subsection{Multitasking}

I've been babbling about how \linux\ is a multitasking operating
system. Now is the time for you to learn how to use it.

\chapter{To Do\ldots}

tour of the filesystem,
job control,
man,
misc. commands,
new commands \& how not to mess up,

\end{document}

