\documentstyle[11pt]{article}
\nofiles
\input{use-full-page}

\begin{document}
\noindent
CS/CE 218 --- Unix and C Programming
\hfill \today \\

\begin{center}
{\huge Essential Unix}
\end{center}

\section{On-line Manual Pages}

To find out about a command type \verb|man| followed by the command name.
For example to find out about the emacs editor, type \verb|man emacs|.
To find out about the command interpreter, type {\tt man csh}.

Suppose you want to find how to run C programs.
You type \verb|man C| and the system responds
``No manual entry for C.''
To find the names of commands related to C type
\verb|man -k C|
and you will see a list of manual entries and short descriptions,
all of which contain  the string ``C''---too many in fact.
To get a shorter list try \verb*|man -k " C "|, where \verb*| | is a space.
Among these is {\tt cc(1)}, which claims to be the C compiler.
You then type {\tt man cc} to see the manual page.

Type {\tt man man} for more details about the {\tt man} command.

Basic manual pages to read are {\tt sh} (the shell), {\tt pg} (paging),
{\tt ls} (listing directory and file info), and {\tt mv}, {\tt cp}, {\tt rm},
and {\tt mkdir}.

\section{Editing}

To use emacs, type {\tt emacs}, and then read what it says on the screen
about the on-line tutorial.  Do it and learn as you go.
Be sure to learn how to use the on-line help facility!

If you're already used to {\tt vi} (ugh!), learn how to use the emacs
info facility (type {\tt C-h i}, where {\tt C-h} is control-H),
read the info entry about ``info'', and then about ``vip'', which
is a {\tt vi} emulator.

\section{Printing}

To see a copy of a file {\tt myprog.c} on the screen,
type {\tt pg myprog.c}.

To print out {\tt myprog.c} on the line printer,
type {\tt lpr myprog.c}.
This will print on line printer number 1,
to print on the other printers use {\tt lpr -2 myprog.c}
or {\tt lpr -3 myprog.c}

To print out a manual page pipe the output of {\tt man}
to {\tt lpr -n}, but you probably shouldn't do this for anything very long.
For example, to print out the manual page for {\tt cc}
on printer 2,
execute \verb!man cc |col -b | lpr -n2!.

\section{Mail}

The basic mail program is called {\tt mail}.
But a better way to read and send mail is to use emacs.
In emacs type {\tt M-x rmail} to read mail.  Use {\tt C-x m} to send mail.
When sending mail, fill in the blanks, then type {\tt C-c C-c}.

\section{Version Control}

The Unix file system does not provide automatic recording of each changed
version of a file.
However, when you are developing a program,
it is often useful to track the program's changes so that you can boldly
make changes and, if necessary, undo them.
The revision control system (RCS) provides the this facility.
Look at the manual page named {\tt rcsintro} for more information.

\section{C programming}

The C compiler is called {\tt gcc} (the GNU C Compiler);
this is an ANSI C compiler.
Besides the manual page, more information by consulting the info database
through emacs; to do this, run emacs, enter info (type {\tt M-x info}
or {\tt C-h i}), then select gcc from the menu ({\tt m} and then {\tt gcc}),
and then browse.
(The standard {\tt cc} is not an ANSI compiler, but used with the {\tt -Ac}
option it approximates one.)

Supposing that your program is in a file {\tt main.c}, you can compile it
by executing
\verb|cc main.c|.
This will produce a file called {\tt a.out}, if you then execute {\tt a.out}
it will run your program.
There must be one function called ``main''.
You can also compile directly from emacs; this has several advantages for
beginners, since the list of errors is automatically put in another buffer.

Debugging C programs can be done by inserting print statements.
There is a debugger called {\tt gdb} which unfortunately doesn't have
a manual page.  However, information about it is kept in the info database,
just select the topic {\tt gdb}.
See also the debuggers {\tt cdb} and {\tt xdb}
(which may only work with {\tt cc} output).

For separate compilation, the command {\tt cc -c file.c} produces an object
file {\tt file.o}, which can then be linked together with other objects
by a command such as \verb|cc f1.o f2.o main.o|.
Read the manual page for {\tt make}.

\end{document}

\section{Timing Commands}

Several of the programming assignments will ask you to time the execution
of a program.  This is done using the csh (built-in) command {\tt time}.
For example, to time the execution of the command \verb|a.out<foo|,
one executes:
\begin{verbatim}
time a.out <foo
\end{verbatim}

The information printed (after your program's output) looks like the following:
\begin{verbatim}
2.0u 0.6s 0:26 10%
\end{verbatim}
This says that your command took 2.0 seconds of ``user time'',
0.6 seconds of ``system time'', 26 seconds of real time,
and had a utilization percentage of 10 percent.
The ``user time'' is time spent in your program itself,
while ``system time'' is mainly due to input/output activity
(it counts time spent in the operating system's kernel on behalf of your
program).
The real time is the same as you would measure using a stopwatch.
The utilization percentage is the ratio of user plus system time to real time.

The size of a program can be determined using the {\tt size} command.









