\documentclass[a4paper,12pt]{article}

\usepackage{fancyhdr}
\usepackage{array}
\usepackage{graphicx}
% \usepackage{eepic}
%\usepackage{pictex}
\usepackage{latexsym}
\usepackage{alltt}
\usepackage{geometry}
\usepackage{array}
\usepackage{tabularx}
\usepackage{booktabs}
%\usepackage{layout}
%\usepackage{key} % for showing keys.
\usepackage{varioref}
\usepackage{hyperref} % for pdflatex, more useful output.
\pagestyle{fancy}

\makeatother
\newcommand{\PBS}[1]{\let\temp=\\#1\let\\=\temp}
\newcommand{\kbk}{\tt}
\newcommand{\kwd}{\em}
%\newcommand{\url}{\tt}
\newcommand{\usb}{\em}
\newcommand{\sco}{\tt}
\newcommand{\uin}{\tt}
\newcommand{\pgn}{\normalfont\tt}
\newcommand{\var}{\tt}
\newcommand{\sig}{\tt}
\newcommand{\fn}{\pgn}
\newcommand{\str}{\pgn}
\newcommand{\cmdn}{\tt}
\newcommand{\rr}{\raggedright}
\newcommand{\myss}{\Large}
\newcommand{\myfs}{\large}
\newcommand{\myts}{\normalsize}
\newcommand{\mns}{\LARGE}
\newcommand{\ns}{\normalsize}
\renewcommand{\footnotesize}{\myfs}

\begin{document}
\section{Overview Solutions}

\begin{enumerate}
\stepcounter{enumi}

\item {\em Changing password}

\begin{enumerate}
\item Responses will vary from system to system, depending on whether
  or not good password practice is enforced.
\end{enumerate}

\item {\em Navigating Man Pages}
  \begin{enumerate}

    \stepcounter{enumii}

  \item It is possible that some Linux distributions won't use {\pgn
      less} to display man pages.  If that is the case, try to find out
    how you navigate under that setup and answer the same questions
    about it.

    \stepcounter{enumii}

  \item Keystrokes for basic man page navigation:
    \begin{table}[htbp]
      \begin{center}
    \begin{tabular}[t]{|l|l|} \hline
Instruction                             & Keystroke(s) \\ \hline \hline
Top of man page                         & {\kbk g  <  ESC-<}            \\
Bottom of man page                      & {\kbk G  >  ESC->}            \\
Forward one screen                      & {\kbk f  \^{}F  \^{}V  SPACE}     \\
Backward one screen                     & {\kbk b  \^{}B  ESC-v}          \\
Up one line                             & {\kbk y  \^{}Y  k  \^{}K  \^{}P}    \\
Down one line                           & {\kbk e  \^{}E  j  \^{}N  RETURN}     \\
{\usb pattern} Search forward           & {\kbk /{\usb pattern}}        \\
{\usb pattern} Search backward          & {\kbk ?{\usb pattern}}        \\
Repeat {\usb pattern} Search forward    & {\kbk n}                      \\
Repeat {\usb pattern} Search backward   & {\kbk N}                      \\
Move to {\usb n}th line                 & {\kbk {\usb n}g}       \\  \hline
    \end{tabular}
        \caption{Keystrokes for basic man page navigation}
        \label{tab:keystrokes-for-basic-man-page-navigation}
      \end{center}
    \end{table}
  \end{enumerate}

\vspace{-14pt}

N.B. Several different keystrokes can be used for the same
movement.  This is common in UNIX tools designed to operate from
any keyboard.  {\pgn less} always has a single key method.
Multi-key  methods are shown without spaces between them.

\item {\em Invoking the Right Man Pages}
  \begin{enumerate}
  \item 
    \begin{enumerate}
    \item {\sco \$ man -k  whatis}

      or, slightly differently: 

      {\sco \$ man -f whatis}

    \item {\sco \$ man -K cdrom}
    \item There is no easy way to do this yet. Later on you will learn
      about {\cmdn grep} which will allow you to filter the output of
      {\cmdn man -k print} to see only the information you require.
    \end{enumerate}
  \item Practice using these flags to find and view man pages which
    deal with computer keywords your partner sets for you (and vice
    versa), e.g.
    \begin{enumerate}
    \item e.g. {\sco \$ man -K jpg}
    \item e.g. {\sco \$ man -K modem}
    \item  e.g. {\sco \$ man -K NFS}
    \end{enumerate}
  \end{enumerate}

\item {\em Finding Out About Your System and Users}
  \begin{enumerate}
  \item The listed command strings tell you about:

% |p{100pt}|>{\PBS\rr}p{233pt}|
  
  \begin{table}[htbp]
\begin{center}
    \begin{tabular}[t]{|p{100pt}|>{\PBS\rr}p{233pt}|} \hline
Command string            &   Output  \\ \hline \hline
{\cmdn \$ whoami}          &   Your username \\   
{\cmdn \$ who am i}        &   Your username plus machine(s) and terminal you are on\\   
{\cmdn \$ users}           &   Usernames of currently logged on users\\   
{\cmdn \$ who}             &   Who is logged on, when and where\\   
{\cmdn \$ w}               &   Who's logged on, when, where, what process and what system resources they are using\\   
{\cmdn \$ date}            &   Current date and time, can set date/time\\   
{\cmdn \$ cal 8 1999}      &   Calendar for August 1999 \\   
{\cmdn \$ cal 9 1752}      &   Calendar for September 1752.  Strange because 12 days were `lost' in the transition from Gregorian to Julian calendars \\
{\cmdn \$ df}              &   Disk free, i.e. summarises disk usage \\   
{\cmdn \$ which man}       &   Full file and path name for the {\pgn man} executable file  \\   
{\cmdn \$ type man}        &   Much the same as {\cmdn which man}\\   
{\cmdn \$ whereis less}    &   Locates the {\pgn less} executable and its man page\\   
{\cmdn \$ help cd}         &   Very brief help notes on the {\cmdn cd} command.  N.B. help only works on very few built-in commands\\ 
{\cmdn \$ time sleep 2}    &   The {\cmdn sleep} command puts itself to sleep for 2 seconds.  The {\cmdn time} command then times the whole process and provides other data on the operation of the {\cmdn sleep} command \\   \hline
    \end{tabular}
      \caption{Output from basic system information commands}
      \label{tab:output-from-basic-system-info-commands}
\end{center}
    \end{table}

  \item See Table~\ref{tab:output-from-basic-system-info-commands}
\end{enumerate}
\item {\em Creating new files}
  \begin{enumerate}
  \item Your output should be something like:
\begin{verbatim}
$ touch filename.txt
\end{verbatim}
  \item Your output should be something like:
\begin{verbatim}
$ ls -l filename.txt
-rw-rw-r--   1 davef  davef  0 Jul 21 17:59 filename.txt
\end{verbatim}
  \item  Your output should now be something like:
\begin{verbatim}
$ touch filename.txt
$ ls -l filename.txt
-rw-rw-r--   1 davef  davef  0 Jul 21 17:59 filename.txt
$ touch filename.txt
$ ls -l filename.txt
-rw-rw-r--   1 davef  davef  0 Jul 21 18:01 filename.txt
\end{verbatim}
    \begin{enumerate}
    \item The time stamp has changed
    \item The real purpose of touch is to change time stamps, but it
      is handy for creating new empty files
    \end{enumerate}
  \item 
    \begin{enumerate}
    \item Reading {\fn {\usb diskspace}.txt} should produce something like this:
{\small
\begin{verbatim}
$ cat test.txt
Filesystem     Used Available Capacity Mounted on
/dev/hda1     65571   406394     14%   /
/dev/hdc1   5030416   650563     89%   /backup
/dev/hda5   2000097   857401     70%   /home
/dev/hda7     14289   457676      3%   /tmp
/dev/hda6   1136861   741727     61%   /usr
/dev/hdb     653004        0    100%   /mnt/cdrom
\end{verbatim}
}
%$
    \stepcounter{enumii}

    \end{enumerate}
  \end{enumerate}
\item {\em Appending information to files}
  \begin{enumerate}
    \stepcounter{enumii}

  \item Your screen should look something like this:
{\small
\begin{verbatim}
$ w > test.txt
$ date >> test.txt
$ cat test.txt
  6:36pm  up 16 days, 23:07,  4 users,  load average: 1.03, 1.08, 1.02
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU  WHAT
davef    ttyp7    oakleigh:0.0      9:39am  0.00s  2.58s  0.02s  w 
mikeb    ttyp4    kebab            Tue 3pm 23:07   0.20s  0.13s  -bash 
davef    ttyp2    oakleigh          9:04am 15:34   7:24   0.07s  -bash 
davef    ttypb    oakleigh          3:02pm  3:15m  3:00m  0.08s  -bash 
Wed Jul 21 18:36:39 BST 1999
\end{verbatim}
}
%$
  \end{enumerate}
\item {\em Using Simple Pipes}
  \begin{enumerate}
  \item {\cmdn \$ who | sort -r}
  \item  {\cmdn sort /etc/passwd > passwd}\\
    or\\
    {\cmdn \$ cat {\fn /etc/passwd} |  sort > {\fn passwd.sorted}}
  \item {\pgn wc} prints the number of lines, words, and bytes in files.  To get these details for your {\fn /etc/mime.types} file, you could do the following:
\begin{verbatim}
$ cat /etc/mime.types | wc
    291     524    7751
\end{verbatim}
%$

i.e. 275 lines, 488 words, and 7373 bytes~\footnote{\small N.B. {\pgn
    wc} only counts whitespace-separated words}

Another way of doing the same thing without a pipe is
\begin{verbatim}
$ wc /etc/mime.types
    291     524    7751 /etc/mime.types
\end{verbatim}

\item E.g. 
\begin{verbatim}
$ cat /etc/mime.types | wc -w
    524
\end{verbatim}
%$

  We can get a similar result by typing:\\
  {\cmdn \$ wc -w /etc/mime.types}
\end{enumerate}
\end{enumerate}

\label{endofchapter-linuxfundamentals}

\end{document}
