\chapter{Overview}
\label{cha:lin-win-overview}
\parskip = 12pt 
{\mns


\subsection{Objectives}
\label{sec:overview-objects}

Having completed this module, you will have an overview of a Linux
system, including its:

\begin{itemize}
\item Underlying philosophy
\item System layering --- kernel vs. applications
\item Core services
\item Multiuser and timesharing facilities
\item File System
\item Network Services
\item Desktop and X windowing system
\end{itemize}




\section{Generic Features of Unix}
\label{sec:overview-features-of-linux}

\begin{itemize}
\item Component-based systems
\item Very popular with technically skilled
\item Not `solution' oriented
\item Building blocks not the building
\item Highly network-aware
\item Robust, powerful, reliable
\end{itemize}



\section{Linux --- The Kernel of a System}
\label{sec:overview-components-of-gnulinux}




  \begin{figure}[htbp]
    \begin{center}
\input{../images/kernel-layering.tex}        
      \caption{kernel-layering}
      \label{fig:Kernel layering}
    \end{center}
  \end{figure}



\begin{itemize}
\item What is {\em called} Linux is actually a collection of
  components from many sources
  \begin{itemize}
  \item freely copiable, under `open source' licences
  \end{itemize}
\item Linux is, strictly, just the {\kwd kernel} which provides:
  \begin{itemize}
  \item A common interface between {\kwd user process} and hardware
  \item Minimal functions to user applications, i.e. system calls
  \item Scheduling


%\includegraphics[width=280pt]{../images/overview2}

  \end{itemize}
\end{itemize}




\section{Fundamental Characteristics of Linux}
\label{sec:overview-characteristics-of-linux}

\begin{itemize}
\item Multi-tasking
\item Multi-user access
\item Multi-processor
\item Architecture independence 
\item POSIX 1003.1 plus basic System V and BSD
\item Protected memory mode
\item Multiple filesystem types
\item Comprehensive networking (TCP/IP and others)
\item Multiple executable formats (MS-DOS, iBCS UNIX, SCO, etc)
\end{itemize}






\section{Multiuser Multitasking and Time-sharing}
\label{sec:overview-multiuser}

\begin{itemize}
\item Designed as a multi-user system
  \begin{itemize}
  \item Each user's shells, apps and commands are separate processes
  \item Number of simultaneous users limited only by:
  \begin{itemize}
  \item CPU speed and available memory
  \item Min. response times required by users/apps
  \end{itemize}
  \end{itemize}
\item Multi-tasking:
  \begin{itemize}
  \item Many jobs can be under way at the same time
  \item Jobs truly {\em simultaneous} on multi-cpu
  \end{itemize}
\item Time-sharing:
  
  A single cpu is shared by all processes
  \begin{itemize}
  \item Processes exec briefly, passing cpu to others
  \item {\kwd Process switches} occur in miliseconds or less
  \item Kernel gives process a sense of total control
  \end{itemize}
\end{itemize}



\section{Protected memory mode}
\label{sec:overview-protected-mem-mode}

\begin{itemize}
\item Uses the processor's protection mechanisms
\item Prevent access to memory already allocated to kernel or other processes
\item Bad programs can't crash the system
\begin{itemize}
  \item Theoretically
\end{itemize}
\end{itemize}


\section{Multiple Filesystem Types}
\label{sec:overview-fs-types}

\begin{itemize}
\item Native FS is ext3 (Third Extended File System)
  \begin{itemize}
  \item File names up to 255 chars
  \item More secure than conventional UNIX
  \end{itemize}
\item Others include:
  \begin{itemize}
  \item MS-DOS (FAT16), VFAT, FAT32
  \item ISO9660 (CD-ROM)
  \item HPFS (OS/2)
  \item NTFS (Windows NT)
  \item reiserfs, XFS, other journalling file systems for Linux,
  \item UPS, SysV and other proprietory UNIX
  \item NFS (Unix network file system)
  \item SMB / CIFS (MS Windows file sharing)
  \end{itemize}
\end{itemize}







\section{The Many Faces of a GNU/Linux System}
\label{sec:overview-faces-of-gnulinux-system}

\begin{itemize}
\item The user may see up to five aspects of Linux:
  \begin{itemize}
  \item the {\kwd filesystem}
  \item {\kwd processes}
  \item the {\kwd shell}
  \item the X {\kwd windowing system}
  \item {\kwd Inter-Process Communication} (IPC)
  \end{itemize}
\item The system is very highly configurable
\item Different users may experience totally different views of the
  same system
\item Multiple simultaneous users are normal
  \begin{itemize}
\item Linux is designed from the ground up as a {\kwd multi-user
    system}, NOT a `personal' system
  \end{itemize}
\end{itemize}






\section{The Filesystem}
\label{sec:overview-filesystem}

\begin{itemize}
\item The filesystem contains all data in the system
\item A name in the filesystem can refer to:
  \begin{itemize}
  \item a {\kwd data file}, which can be:
    \begin{itemize}
    \item a {\kwd plain file}
    \item a {\kwd directory}
    \end{itemize}
  \item a {\kwd device} (disk, tape etc.)
  \item internal memory
  \item OS information (the {\kwd proc} system)
  \end{itemize}
\item Directories are groups of files
\begin{itemize}
  \item Grouped in hierarchical {\kwd trees} 
\end{itemize}
\item Files are fully specified with their {\kwd pathname}
\item An original Unix structure; copied by most OSs
\end{itemize}




\section{Filenames}
\label{sec:overview-filenames}


\begin{itemize}
\item Maximum length depends on filesystem type
  \begin{itemize}
  \item Most allow up to 255 characters
  \end{itemize}
\item Can use almost any character in a filename, but avoid ambiguity by sticking to:
  \begin{itemize}
  \item (\texttt{A}-\texttt{Z}) Uppercase letters
  \item (\texttt{a}-\texttt{z}) Lowercase letters
  \item (\texttt{0}-\texttt{9}) Numbers
  \item (\texttt{.})   Full-stop
  \item (\texttt{,})   Comma
  \item (\texttt{\_})  Underscore
  \item (\texttt{-})  Hyphen
  \end{itemize}
\item Should convey meaningful info about contents
\item Type longer filenames using completion for:
  \begin{itemize}
  \item Filenames
  \item Pathnames
  \item Commands
  \end{itemize}
\end{itemize}





\section{Filename Extensions and File Types}
\label{sec:overview-filename-extensions-and-file-types}

\begin{itemize}
\item Filenames {\em don't} determine other attributes of file, 
  \begin{quote}
    i.e. do not, {\em automatically}, cause command interpreters to
    treat them in a particular way
  \end{quote}
\item However:
  \begin{itemize}
  \item Extensions can enable meaningful naming and automatic file
    manipulation
  \item C compilers and some other programs {\em do} depend on specific file
    extensions to carry out particular tasks  
  \end{itemize}
\item Common conventions for extensions: \\[16pt]
  \begin{table}[htbp]
    \begin{center}
{\myss
      \begin{tabular}{|l|l|}  \hline
Filename      &   Meaning of Extension   \\ \hline \hline
program.c     &   C programming source file   \\ \hline  
program.o     &   Object code   \\ \hline 
program.sh    &   Shell executable   \\ \hline 
letter.txt    &   Text file of a letter   \\ \hline 
letter.ps     &   Postscript version of same letter file   \\ \hline 
letter.ps.gz  &   {\pgn gzip} compressed version of same   \\ \hline 
letter.tar.bz2 &   {\pgn tar} archive of same compressed by {\pgn bzip2}   \\ \hline 
letter.tgz    &   {\pgn tar} archive of same compressed by {\pgn gzip}   \\ \hline 
letter.tar.gz &   Another, more common, way of naming {\fn *.tgz}   \\ \hline 
letter.Z      &   Same file compressed with outdated {\pgn compress} utility   \\ \hline 

      \end{tabular}
}
      \caption{Common conventions for filename extensions}
      \label{tab:common-conventions-for-filename-extensions}
    \end{center}
  \end{table}
\end{itemize}


\section{Hidden Filenames}
\label{sec:overview-hidden-filenames}

\begin{itemize}
\item Filenames beginning with a full-stop are {\em hidden}
\item Typically used:
  \begin{itemize}
  \item To hide personal configuration files
  \item To avoid cluttering dirs with rarely used files
  \end{itemize}
\item Every dir contains 2 special hidden files:

  \begin{tabular}{ll}
       &                             \\
  .    &  The current directory file \\ 
  ..   &  The parent directory file  \\
  \end{tabular}
\end{itemize}





\section{The Shell ({\pgn bash})}
\label{sec:overview-the-shell}

\begin{itemize}
\item A {\kwd shell} is a program that you interact with
\vspace{10pt}

% \input{overview3.tex}
%\includegraphics[viewport= 14 14 602 582,width=200pt]{../images/overview3}
\includegraphics{../images/overview3-shell}
\item Can be any program, but is normally a {\kwd command interpreter}
\item A command interpreter is usually started when you log in (but
  this is just one way)
\item The `standard' Linux command interpreter is a {\kwd {\pgn Bourne}
    shell} look-alike called {\pgn bash}~\footnote{{\pgn Bash} has
    more functions than true {\pgn Bourne} shells; incorporating most of the
    innovations added by the {\pgn C} and {\pgn Korn} shells.  {\pgn
      Bash} functions and flags differ between implementations of UNIX
    and Linux.  The version of {\pgn bash} in current Linux releases
    tends to be the most fully functional {\pgn Bourne} shell around.}
\item The command line syntax provided by {\pgn bash} enables
  manipulation of files \& processes
\item The command-line frightens beginners but is the preferred home
  of the skilled
\end{itemize}



\section{Key Features of the Bash Shell}
\label{sec:overview-bash-key-features}

\begin{itemize}
\item Command history
\item Command aliasing
\item Shell scripting
\item Filename completion
\item Command completion
\item Command line editing ({\pgn emacs} and {\pgn vi} styles)
\item Job control
\item Key Bindings
\item Directory stacking
\item Tilde directory notation 
\item Help function, e.g. {\myts \begin{verbatim}
$ help history
history: history [n] [ [-awrn] [filename]]
    Display the history list with line numbers.  Lines listed with
    with a `*' have been modified.  Argument of N says to list only
    the last N lines.  Argument `-w' means to write out the current
    history file;
\end{verbatim}%
}%$


\end{itemize}




\section{Interacting with a Linux `Terminal'}
\label{sec:overview-interact-with-terminal}

\begin{itemize}
\item Linux can support any number of `terminal' types
  \begin{itemize}
  \item nowadays, monitor/keyboard combinations
  \item previously, dumb terminals
  \item occasionally, printers (debugging servers) 
  \end{itemize}
\item Most will use the {\kwd console} or a windowed terminal, but if
  not:
  \begin{itemize}
  \item Linux usually keeps a database of terminal capabilities in
    {\fn /etc/termcap}~\footnote{AT\&T flavours of UNIX use {\fn
        /usr/lib/terminfo} to store the same information and Linux
      can, if necessary.}
  \item If your terminal type is not recorded in {\fn /etc/termcap},
    you'll have problems running certain programs e.g.
    
    \begin{itemize}
    \item cursor driven apps ({\pgn top}, {\pgn linuxconf}, {\pgn vi} etc)
    \end{itemize}
  \item The {\kwd environmental variable} {\var TERM} tells programs
    what terminal type you are using
\end{itemize}
\end{itemize}





\section{Software Tools: The UNIX Philosophy}
\label{sec:overview-linux-philosophy}


\begin{itemize}
\item True UNIX-like systems treat programs as {\em tools}
\begin{itemize}
\item Each tool should:
  \begin{itemize}
  \item Do just one thing well
  \item Be generic (untied to specific applications)
  \end{itemize}
\item For new jobs, build new tools
\item (Re-)combine, don't complicate old tools
\end{itemize}
\item Linux can do this because it has:
\begin{itemize}
\item two simple {\em objects}:
  \begin{itemize}
  \item the file
  \item the process
  \end{itemize}
\item simple methods of {\em connecting}:
  \begin{itemize}
  \item processes to files
  \item processes to processes \\[12pt]
\includegraphics{../images/linux_overview_unix_philosophy}
  \end{itemize}
\end{itemize}
\end{itemize}




\section{Tasks/Processes}
\label{sec:overview-processes}

\begin{itemize}
\item A {\kwd program} is an execut{\em able} object, stored in a file
\item A {\kwd process} is an execut{\em ing} object, i.e.~\footnote{Processes are often called {\em tasks}, as in `multi-tasking'}
  \begin{itemize}
  \item an {\em instance} of a program currently being run 
  \end{itemize}
\item Existing processes can `{\kwd fork}' to create other processes
  \begin{itemize}
  \item the only way to make new processes
  \end{itemize}
\item A user may run multiple copies of same program
\item Multiple users may run single/multiple copies
\item System tracks {\kwd ownership} and {\kwd permission}
\end{itemize}



\section{Process Communication}
\label{sec:overview-process-communication}

\begin{itemize}
\item Processes may need to co-operate by
  \begin{itemize}
  \item sharing files
  \item signalling events
  \item direct transfer of data
  \item pipelines (data streams)
  \item synchronising with each other
  \end{itemize}
\item Linux provides facilities for:
  \begin{itemize}
  \item signals
  \item shared memory
  \item pipes, both named and unnamed
  \item semaphores
  \item and others
  \end{itemize}
\item Processes may use network connections for communication,
  permitting {\kwd client-server} model
  \begin{itemize}
  \item Common for shared services like printing
  \end{itemize}
\end{itemize}



\section{Re-directing I/O to and from Files}
\label{sec:overview-pipes-anon-io}

\begin{itemize}
  \item Most processes will take input from the keyboard and output to the
        screen
  \item Both input and output streams can be {\kwd re-directed} to/from files
  \item Output to a file (creating or overwriting):\\
  {\sco \$ ls > my-system.txt}
  \item Appending output to a file:
  {\sco \$ who >{}> my-system.txt}
\end{itemize}
{\center
\includegraphics{../images/linux_overview_redirect_IO_1}}



\section{Re-directing I/O to and from Files (continued)}
\label{sec:overview-pipes-anon-io-continued}
\begin{itemize}
  \item Take input from one file, output to another:
  \mbox{\sco \$ sort  < /etc/passwd > pwd.sorted}\\[46pt]
\begin{center}
  %\includegraphics[width=220pt]{../images/linux_overview_redirect_IO_2}
  \includegraphics{../images/linux_overview_redirect_IO_2}
\end{center}
\end{itemize}




\section{Pipes \& Tools}
\label{sec:overview-pipes-and-tools}

\begin{itemize}
\item Linux tools act as filters:
  \begin{itemize}
  \item taking data from input streams, modifying it, sending it elsewhere
  \item expecting data to come from other tools
  \item producing output which {\em any} other tool can process, e.g. ASCII text
  \end{itemize}
\item One tool's output is connected to another's input:
  \begin{itemize}
  \item {\em Indirectly}, via a file created by the first tool
  \item {\em Directly}, via a {\kwd pipe} or {\kwd pipeline}
  \end{itemize}
  
\item For example, to page through a reverse-sorted version of your
  password file on screen:

{\sco \$ sort -r < /etc/passwd | less}\\[48pt]
{\center
\includegraphics{../images/linux_overview_pipes_and_tools}}
\end{itemize}


\section{Linux as a Programming Environment}
\label{sec:overview-programming-env}

\begin{itemize}
\item {\em Hierarchical Filestore}
\item Extensive set of {\em powerful tools}
  \begin{itemize}
  \item for software production, admin and support
  \end{itemize}
\item A {\em common system interface}
  \begin{itemize}
  \item only one set of procedures to learn
  \end{itemize}
\item Processes interface with {\em anonymous files}
  \begin{itemize}
  \item programs output to files or devices identically
  \end{itemize}
\item {\em Modular architecture} provides for a completely customised
  OS, e.g.
  \begin{itemize}
  \item An OS dedicated solely to graphics rendering
  \item A general-purpose system on one floppy
  \end{itemize}
\item {\em Flexible user interface} allows for uniquely customised
    programming environments
\end{itemize}

















\section{Networking} 
\label{sec:overview-networking}

\begin{itemize}
\item Linux is a network operating system. 
\item The Internet network protocols (TCP/IP) are implemented in the kernel
\item Although other media are supported (e.g. radio, infra-red),
  links are usually across:
  \begin{itemize}
  \item Ethernet
  \item Serial Line (Point-to-point)
  \end{itemize}
\item Proprietory file/print serving protocols supported:
  \begin{itemize}
  \item Appletalk
  \item DECNET
  \item IPX / Novell Netware
  \item SMB / CIFS (MS Windows/NT)
  \end{itemize}
\end{itemize}




\section{TCP/IP}
\label{sec:overview-tcpip}

\begin{itemize}
\item A suite of Internet-standard protocols and apps for managing
  data transfers
\item Depicted as a `stack'
  \begin{itemize}
  \item hardware and transport control protocols at the bottom
  \item user applications (e.g. browsers) at the top 
  \end{itemize}
\item Client-server apps provide facilities for:
\begin{itemize}
\item Remote login
\item File transfer
\item Resource sharing (e.g. expensive peripherals)
\item Remote command execution
\item Email (internet/intranet/extranet) 
\item Web browsing
\end{itemize}
\end{itemize}








\section{Documentation}
\label{sec:overview-documentation}

\begin{itemize}
\item Copious, but fragmented and/or duplicated
\vspace{10pt}
  \begin{table}[htbp]
    \begin{center}
  \begin{tabular}[t]{|>{\PBS\rr}p{120pt}|>{\PBS\rr}p{243pt}|} \hline 
{\kwd Programmer's Manual} {\fn /usr/man} & The classic `{\kwd man pages}', first stop for skilled users, worth learning \\ \hline 
{\pgn info} pages &  hypertext browsable texts, often identical or updated versions of man pages \\ \hline 
{\fn /usr/share/doc/{\usb program-name}} &  ascii/html docs installed with the named program \\ \hline 
{\kwd Howtos} &  Tutorials on Linux-related topics, available on-line if installed (usually in {\fn /usr/share/doc}) \\ \hline 
www & Recently-released programs are usually documented on authorised web sites, many (including older tools) are documented by third-party sites  \\ \hline
  \end{tabular}
      \caption{Sources of Linux Documentation}
      \label{tab:sources-of-linux-docs}
    \end{center}
  \end{table}



\item Linux man pages divided into sections: 
\vspace{10pt}
{\myfs
  \begin{enumerate}
  \item User Commands
  \item {\kwd System calls}
  \item Subroutines (inc library routines)
  \item Devices (inc network interfaces)
  \item File Formats
  \item Games
  \item Miscellaneous
  \item System Administration
  \end{enumerate}
}

\vspace{10pt}
\item The {\pgn apropos} command word searches the description line in man pages.  Thus:

{\myss
\begin{alltt}
$ \textbf{apropos printer}
\end{alltt}
}
will find man pages relating to printers, e.g.

{\myss
\begin{verbatim}
lp (4)   - line printer devices
lpd (8)  - line printer spooler daemon
lprm (1) - remove jobs from the line printer spooling queue
\end{verbatim}
}



\end{itemize}



\section{Using the {\kwd man pages} (On-Line Manual)}
\label{sec:overview-on-line-manual}

\begin{itemize}
  
\item Use {\pgn man} to see man pages on a named command, e.g
\begin{verbatim}
$ man date
\end{verbatim}%$
\item The result should be something like:
  
  {\myss
\begin{verbatim}
DATE(1)                        FSF                        DATE(1)

NAME
       date - print or set the system date and time

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
\end{verbatim}
    }
\item {\sco DATE(1)} Shows page is in manual section 1
\item To view a page from a certain section use:
  
  {\cmdn \$ man -S {\usb section-number} {\usb command-name}}
\item Square brackets surround optional arguments
\begin{verbatim}
ls  [-abcdfgiklmnpqrstuxABCFGLNQRSUX1]
\end{verbatim}

\end{itemize}





\section{Overview Exercises}
\label{sec:overview-exs}


{\normalsize

\subsection{What should I focus on?}

At the end of this practical session, as a minimum, you should be able
to:
\begin{itemize}
\item within a {\pgn man} page, be able to:
  \begin{itemize}
  \item go to the beginning of the {\pgn man} page with one keystroke
  \item similarly, go to the end of the {\pgn man} page
  \item search for a word within the {\pgn man} page
  \item search again for the same word using one keystroke.
  \end{itemize}

\item Find the {\pgn man} page that you need:
  \begin{itemize}
  \item quickly find a man page with a description that matches a
    keyword
  \item exhaustively search all man pages to find all that contain a keyword.
  \end{itemize}

\item You should know how to use the {\pgn df} command to tell how
  much space is left in your root (\texttt{/}) partition
\item Have a basic understanding of what a pipe (\verb!|!) is
  useful for.
\item You should know how to use the {\pgn wc} command, and clearly
  understand that it has nothing much to do with the wash room.
\end{itemize}

\subsection{The exercises}

\begin{enumerate}
%% \item {\em Logging in}


%% \begin{enumerate}
  
%% \item Practice logging in by typing your username and password in
%%   response to the {\sco Login:} and {\sco Password:} prompts, e.g.~\footnote{\small A {\kbk
%%       <RETURN>} is required after each input, to tell the shell that
%%     you have finished typing and it should start processing your
%%     request.  Note that the password is not displayed on the screen;
%%     to keep it secret}

%%     {\sco Login: mikeb\\
%%       Password:\\
%%       \$}
  
%%     Once you have logged in, the {\pgn bash} prompt ({\sco \$}) is
%%     printed; indicating the shell is ready to take commands.

%%   \item Log out, by typing {\uin exit} at the {\sco \$} prompt.  You should
%%     get a new {\sco Login:} prompt, at which you can login
%%     again.
%% \end{enumerate}


\item {\em Changing password}




\begin{enumerate}
\item Set yourself a new password using the {\pgn passwd} command. Run
  the command by typing {\uin passwd}, followed by a {\kbk
    <RETURN>}~.
\end{enumerate}



\item {\em Navigating Man Pages}
  \begin{enumerate}
  \item Type {\uin man man} to open the man page which details how to
    use the {\pgn man} command
  \item Press the {\kbk h} (help) key, which opens a ``Summary of Less
    Commands'', including all the keystrokes you need to navigate a
    man page
  \item Make sure you can quit this page (by typing {\kbk q}) and quit
    the man page (by typing {\kbk q} again).  When you get back to the
    shell prompt, repeat the first 2 steps to open the ``Summary of
    Less Commands'' from the {\pgn man} man page.
  \item Use the ``Summary of Less Commands'' to make sure you know how
    to do the following bits of navigation inside a man page:
    \begin{enumerate}
    \item Move to the top and bottom of the man page
    \item Move up and down one screen of text
    \item Move up and down one line of text
    \item Search forward for a {\usb pattern} (e.g. a word)
    \item Search backwards for a {\usb pattern}
    \item Repeat a forward {\usb pattern} search using one key
    \item Repeat a backward {\usb pattern} search using one key
    \item Move to a specific line number.  For this, read the text at
      the top of ``Summary of Less
      Commands'', particularly:
      \begin{quote}
        Commands marked with \texttt{*} may be preceded by a number,
        $N$\@.  Notes in parentheses indicate the behavior if $N$ is
        given.
      \end{quote}
      The phrase \emph{preceded by a number $N$} means that the number
      $N$ may come first, before the command.

      Next, have a look at what is under the heading ``Jumping''.
      Note that you can check where you are by pressing
      ``\texttt{=}'', which shows the line numbers at the first and
      last lines in the terminal window.

      Try this on the \texttt{man} page for ethereal, which has more
      than 40,000 lines.  See if you can go to line 10,000.
    \end{enumerate}
  \item With a partner, test each other on how well you can navigate
    the {\pgn man} man page, e.g. set each other target locations or
    words to go to.
  \end{enumerate}


  
\item {\em Invoking the Right Man Pages}
  
  Note that some time after you start your lab session, a program
  automatically builds a file \texttt{/var/cache/man/whatis} which
  contains the one summary line from each of the thousands of
  \texttt{man} pages on your computer.  There are two programs,
  \texttt{apropos}, mentioned in
  section~\vref{sec:overview-documentation}.  There is another
  program, \texttt{whatis}, that matches a program name in the same
  ``whatis'' database.  The \texttt{man} command has options that call
  these programs.  Each has their own \texttt{man} page.
  \begin{enumerate}
  \item Using the {\pgn man} man page, find the command string you
    need to use to get the following:
    \begin{enumerate}
    \item A list of man pages whose description lines contain
      details about the `whatis' database
    \item A list of man pages containing the string
      `cdrom'~\footnote{\small Actually running this sort of search can take
        a long time, given that many systems contain over 10,000 man
        pages, some of which are very long.}
    \item A list of man pages from a specific section (e.g. 1) of the
      manual, whose description lines contain `print'
    \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 bitmap formats like jpg, gif, xpm, bmp
    \item communications concepts like modem, serial, telnet, pcmcia, ppp
    \item filesystems like NFS, ext3, ext2, FAT, vfat, msdos, samba
    \end{enumerate}
  \end{enumerate}



\item {\em Finding Out About Your System and Users}
  \begin{enumerate}
  \item Type the following commands. Identify what each of them tells
    you about your system.
    \begin{enumerate}
    \item {\cmdn \$ \textbf{whoami}}
    \item {\cmdn \$ \textbf{who am i}}
    \item {\cmdn \$ \textbf{users}}
    \item {\cmdn \$ \textbf{who}}
    \item {\cmdn \$ \textbf{w}}
    \item {\cmdn \$ \textbf{date}}
    \item {\cmdn \$ \textbf{cal 10 2003}}
    \item {\cmdn \$ \textbf{cal 9 1752}}\ ~\footnote{\small You should notice something
        very strange about the output from this string.  The {\pgn
          cal} utility is perfectly functional, so what's wrong?}
    \item {\cmdn \$ \textbf{df}}
    \item {\cmdn \$ \textbf{which man}}
    \item {\cmdn \$ \textbf{type man}}
    \item {\cmdn \$ \textbf{whereis less}}
    \item {\cmdn \$ \textbf{help cd}}
    \item {\cmdn \$ \textbf{time sleep 2}}
    \end{enumerate}
  \item  Use the appropriate man page, to check that you have
    interpreted the screen output correctly

\end{enumerate}

\item {\em Creating New Files}
  \begin{enumerate}
  \item Try creating a new {\em empty} file in your home directory using the
    {\pgn touch} command, e.g.

{\cmdn \$ \textbf{touch {\usb filename}}}
\item Get the file details on {\usb filename} using this command:

{\cmdn \$ \textbf{ls -l {\usb filename}}}
\item Wait 1 minute, then repeat the previous two steps, i.e.

{\cmdn \$ \textbf{touch {\usb filename}}}

{\cmdn \$ \textbf{ls -l {\usb filename}}}
\begin{enumerate}
\item Which of the file details have changed?
\item What does this tell you about the purpose of {\pgn touch}?
  Check the man page if you are unsure.
\end{enumerate} 

\item Creating new files using re-direction
  \begin{enumerate}
  \item Create a new file containing the output from the {\pgn df}
  command, using re-direction, e.g.

{\cmdn \$ \textbf{df > diskspace.txt}}

\item Ask a partner to create new files, with appropriate filenames,
  containing output from the commands used in the questions on
  ``Finding Out About Your System and Users''.
  \end{enumerate}
\end{enumerate}

\item {\em Appending information to files}
  \begin{enumerate}
  \item With a partner, choose several of the system information
    commands whose outputs may have changed since you completed the
    previous question.  Practice appending the updated information to
    the file which contains the earlier output.
  \item Create a file containing output from {\pgn w}, then append the
    output from {\pgn date} to it, i.e. time-stamp the output data.
  \end{enumerate}

\item {\em Using Simple Pipes}
  \begin{enumerate}
  \item Pipe the output from {\pgn who} through the {\pgn sort} command to reverse its order.
  \item \label{que:sort-passwd}Sort your {\fn /etc/passwd} file
    alphabetically and send the output to a new file ({\fn
      passwd.sorted}).
  \item Find out what {\pgn wc} does from its man page, then use it at
    the end of a pipe to analyse the output from other utlities.
  \item Repeat the last step, limiting {\pgn wc} to counting words only
  \end{enumerate}
\end{enumerate}

\section{Overview Solutions}

\includeversion{Solutions}%
\excludeversion{noSolutions}%

\begin{Solutions}
\begin{enumerate}
% \stepcounter{enumi}
%% \item At the graphical login screen, you can enter your LDAP user name
%%   and password.  Your LDAP username is your student number.  You
%%   received your password by email to your Institute account.

%%   You can switch to a text console by holding down the Control-Alt-F$n$
%%   key combination, where $1 \le n \le 6$.  You can switch back to a
%%   graphical screen by the key combination Control-Alt-F7\@.

\item {\em Changing password}

\begin{enumerate}
\item The system will tell you it is changing your LDAP password.  It
  also tests the quality of your password using a library called
  \texttt{cracklib}, which rejects passwords that are too short or are
  dictionary words, or that are too closely related to your user name.
\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 \$ \textbf{man -k  whatis}}

      or, slightly differently: 

      {\sco \$ man -f whatis}
      
    \item {\sco \$ man -K cdrom} will print each man page name and ask
      you if you want to view the page or quit: \texttt{[ynq]}\@.  If
      you just want the list of man pages and not view the man pages,
      you could answer ``\texttt{n}'' to each question using the
      \texttt{yes n} command, which just prints ``\texttt{n}'' to each
      prompt.  You could do it like this:
\begin{alltt}
$ \textbf{yes n | man -K cdrom}
\end{alltt}%$
\ldots and if you wanted the names each on a line, with no prompt,
then you could filter the output still further with the stream editor
\texttt{sed}:
\begin{alltt}
$ \textbf{yes n | man -K cdrom | sed 's/\bs? \bs[ynq\bs] /\bs{}n/g'}
\end{alltt}%$
but you would need to wait a while for the output.

Suppose you wanted the output with just the name of the command
without the directory name or the ``\texttt{.gz}'' at the end?  Well,
you could do this:
\begin{alltt}
$ \textbf{yes n | man -K cdrom | sed 's/\bs? \bs[ynq\bs] /\bs{}n/g' | xargs --replace basename \{\} .gz}
\end{alltt}%$
And suppose\ldots{}  Oh well, never mind.  Nick really gets carried
away sometimes.
    \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.
      You could do it like this:
\begin{alltt}
$ \textbf{man -k print | fgrep '(1)'}
\end{alltt}%$
    \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 \$ \textbf{man -K jpg}}
    \item e.g. {\sco \$ \textbf{man -K modem}}
    \item  e.g. {\sco \$ \textbf{man -K NFS}}
    \end{enumerate}
  \end{enumerate}

\item {\em Finding Out About Your System and Users}
  \begin{enumerate}
    \stepcounter{enumii}

  \item See Table~\vref{tab:output-from-basic-system-info-commands}.

% |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 10 2003}      &   Calendar for October 2003 \\   
{\cmdn \$ cal 9 1752}      &   Calendar for September 1752.  Strange
because 12 days were `lost' in the transition from Gregorian to Julian
calendars.  Simply search for ``September 1752'' in Google \\
{\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}
\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{alltt}
$ \textbf{touch filename.txt}
$ \textbf{ls -l filename.txt}
-rw-rw-r--   1 davef  davef  0 Jul 21 17:59 filename.txt
$ \textbf{touch filename.txt}
$ \textbf{ls -l filename.txt}
-rw-rw-r--   1 davef  davef  0 Jul 21 18:01 filename.txt
\end{alltt}
    \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 diskspace.txt} should produce something like this:
{\small
\begin{alltt}
$ \textbf{cat diskpace.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{alltt}
}
%$
    \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{alltt}
$ \textbf{w > test.txt}
$ \textbf{date >> test.txt}
$ \textbf{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{alltt}
}
%$
  \end{enumerate}
\item {\em Using Simple Pipes}
  \begin{enumerate}
  \item {\cmdn \$ \textbf{who | sort -r}}
  \item {\cmdn \$ \textbf{sort /etc/passwd > passwd}}\\
    or\\
    {\cmdn \$ \textbf{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{alltt}
$ \textbf{cat /etc/mime.types | wc}
    480     726   12682
\end{alltt}
%$

i.e. 480 lines, 726 words, and 12682 bytes~\footnote{\small N.B. {\pgn
    wc} only counts whitespace-separated words}

Another way of doing the same thing without a pipe is
\begin{alltt}
$ \textbf{wc /etc/mime.types}
    480     726   12682 /etc/mime.types
\end{alltt}%$

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

  We can get a similar result by typing:\\
  {\cmdn \$ \textbf{wc -w /etc/mime.types}}
\end{enumerate}
\end{enumerate}
\end{Solutions}
\begin{noSolutions}
  We will provide solutions soon.
\end{noSolutions}
\label{endofchapter-linuxfundamentals}

} % end \normalsize from overview exercises
} % end {\mns from chapter start

\excludeversion{Solutions}%
\includeversion{noSolutions}%

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "planet_basic_course_masterfile"
%%% End: 
