% Linux Installation and Getting Started    -*- TeX -*-
% concepts.tex
% Copyright (c) 1992, 1993 by Matt Welsh, Larry Greenfield and Karl Fogel
%
% This file is freely redistributable, but you must preserve this copyright 
% notice on all copies, and it must be distributed only as part of "Linux 
% Installation and Getting Started". This file's use is covered by
% the copyright for the entire document, in the file "copyright.tex".

\section{Basic UNIX Concepts}

\index{UNIX!basic concepts|(}
\index{UNIX!multitasking!defined}
\index{multitasking!defined}
\index{multiuser!defined}
\index{login name!defined}
\index{password!defined}
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 MS-DOS, where only one
person can use the system at any one time.) Under UNIX, for users to
identify themselves to the system, they must {\bf log in}, which 
entails two steps: Entering your {\bf login name} (the name which the
system identifies you as), and entering your {\bf password}, which 
is your personal secret key to logging into your account. Because only
you know your password, no one else can login to the system under your
username.

On traditional UNIX systems, the system administrator will assign you
a username and an initial password when you are given an account on the
system. However, because you are the system administrator, you must 
set up your own account before you can login---see 
Section~\ref{sec-create-account}, below. For the following discussions, 
we'll use the imaginary username ``{\tt larry}''.

\index{hostname!defined}
In addition, each UNIX system has a {\bf hostname} assigned to it.
It is this hostname that gives your machine a name, gives it character
and charm. The hostname is used to identify individual machines on 
a network, but even if your machine isn't networked, it should have a
hostname. In Section~\ref{sec-set-hostname} we'll cover setting your
system's hostname. For our examples, below, the system's hostname is
``{\tt mousehouse}''.

\subsection{Creating an account}\label{sec-create-account}
\index{user account!creating}
\index{account!creating}
Before you can use the system, you must set up a user account 
for yourself. This is because it's usually not a good idea to use the
{\tt root} account for normal use. The {\tt root} account should
be reserved for running privileged commands and for maintaining the
system, as discussed in Section~\ref{sec-hats}.

In order to create an account for yourself, you need to login as
{\tt root} and use the {\tt useradd} or {\tt adduser} command. See
Section~\ref{sec-add-user} for information on this procedure.

\subsection{Logging in}
\index{logging in}
\index{login} At login time, you'll see a prompt resembling
the following on your screen:

\begin{tscreen}
mousehouse login:
\end{tscreen}

Here, enter your username, and press the \key{Return} key. Our
hero, {\tt larry}, would type the following:

\begin{tscreen}
mousehouse login: {\em larry} \\
Password: 
\end{tscreen}

Now, enter your password. It won't be echoed to the screen when you
login, so type carefully. If you mistype your password, you'll see
the message
\begin{tscreen}
Login incorrect
\end{tscreen}
and you'll have to try again.

Once you have correctly entered the username and password, you are
officially logged into the system, and are free to roam.

\subsection{Virtual consoles}
\index{console!virtual}
\index{console!defined}
The system's {\bf console} is the monitor and keyboard connected directly
to the system. (Because UNIX is a multiuser operating system, you may
have other terminals connected to serial ports on your system, but these
would not be the console.) Linux, like some other versions of UNIX, provides
access to {\bf virtual consoles} (or VC's), which allow you to have more than 
one login session from your console at a time.

To demonstrate this, login to your system (as demonstrated above). Now,
press \key{alt-F2}. You should see the {\tt login:} prompt again. You're
looking at the second virtual console---you logged into the first. To
switch back to the first VC, press \key{alt-F1}. {\em Voila!\/} You're
back to your first login session.

A newly-installed Linux system probably allows you to access the first
four VC's, using \key{alt-F1} through \key{alt-F4}. However, it is
possible to enable up to 12 VC's---one for each function key on your 
keyboard. As you can see, use of VC's can be very powerful---you can
be working on several different VC's at once. 

While the use of VC's is somewhat limiting (after all, you can only
be looking at one VC at a time), it should give you a feel for UNIX's
multiuser capabilities. While you're working on VC \#1, you
can switch over to VC \#2 and start working on something else. 


\subsection{Shells and commands}\label{sec-shells-cmds}

\index{shells!defined}
For most of your explorations in the world of UNIX, you'll be
talking to the system through the use of a {\bf shell}.
A shell is just a program which takes user input (e.g., commands which
you type) and translates them into instructions. This can be compared
to the {\tt COMMAND.COM} program under MS-DOS, which does essentially
the same thing. The shell is just one interface to UNIX. There are 
many possible interfaces---such as the X~Window System, which lets you 
run commands by using the mouse and keyboard in conjunction. 

As soon as you login, the system starts the shell, and you can type
commands to it. Here's a quick example. Here, Larry logs in, and is
left sitting at the shell {\bf prompt}.
\begin{tscreen}
mousehouse login: {\em larry} \\
Password: {\em larry's password} \\
Welcome to Mousehouse! \\
\\
/home/larry\# 
\end{tscreen}
\index{shells!prompt}
``{\tt /home/larry\#}'' is the shell's prompt, indicating that it's
ready to take commands. (More on what the prompt itself means later.) 
Let's try telling the system to do something interesting:

\begin{tscreen}
/home/larry\# {\em make love} \\
make: *** No way to make target `love'. Stop. \\
/home/larry\#
\end{tscreen}

Well, as it turns out {\tt make} was the name of an actual program
on the system, and the shell executed this program when given the command. 
(Unfortunately, the system was being unfriendly.) 

\index{command!defined}
\index{command!argument!defined}
\index{argument!command!defined}
This brings us to one burning question: What are commands? What 
happens when you type ``{\tt make love}''? The first word on the command 
line, ``{\tt make}'', is the name of the command to be executed. Everything
else on the command line is taken as arguments to this command. Examples:
\begin{tscreen}
/home/larry\# {\em cp foo bar} 
\end{tscreen}
Here, the name of the command is ``{\tt cp}'', and the arguments are
``{\tt foo}'' and ``{\tt bar}''. 

When you type a command, the shell does several things. First of all, it
looks at the command name, and checks to see if it is a command which
is internal to the shell. (That is, a command which the shell knows how
to execute itself. There are a number of these commands, and we'll go
into them later.) The shell also checks to see if the command is an 
alias, or substitute name, for another command. If neither of these conditions
apply, the shell looks for a program, on the disk, with the command's name.
If it finds such a program, the shell runs it, giving the program the
arguments specified on the command line. 

In our example, the shell looks for the program called {\tt make}, and 
runs it with the argument {\tt love}. {\tt Make} is a program often used 
to compile large programs, and it takes as arguments the name of a 
``target'' to compile. In the case of ``{\tt make love}'', we instructed
{\tt make} to compile the target {\tt love}. Because {\tt make} can't
find a target by this name, it fails with a humorous error message, and
we are returned to the shell prompt.

\index{command not found error message@{\tt command not found} error message}
\index{error messages!command not found@error messages!{\tt command not found}}
What happens if we type a command to a shell, and the shell can't
find a program with the command name to run? Well, we can try it:
\begin{tscreen}
/home/larry\# {\em eat dirt} \\
eat: command not found \\
/home/larry\#
\end{tscreen}
Quite simply, if the shell can't find a program with the name given
on the command line (here, ``{\tt eat}''), it prints an error message
which should be self-explanatory. You'll often see this error message
if you mistype a command (for example, if you had typed ``{\tt mkae love}''
instead of ``{\tt make love}''). 

\subsection{Logging out}
\index{logging out!with exit command@with {\tt exit} command}
\index{exit@{\tt exit}}
Before we delve much further, we should tell you how to log out of the
system. At the shell prompt, use the command
\begin{tscreen}
/home/larry\# {\em exit}
\end{tscreen}
to logout. There are other ways of logging out as well, but this
is the most foolproof one.

\subsection{Changing your password}
\index{password!changing with passwd@changing with {\tt passwd}}
\index{passwd@{\tt passwd}}
You should also be aware of how to change your password. The command
{\tt passwd} will prompt you for your old password, and your new password.
It will ask you to reenter the new password for validation. Be careful
not to forget your password---if you do, you will have to ask the
system administrator to reset it for you. (If you're the system 
administrator, see Section~\ref{sec-manage-users}.)


\subsection{Files and directories}
\index{files!defined}
Under most operating systems (UNIX included), there is the concept of a 
{\bf file}, which is just a bundle of information which is given a 
name (called a {\bf filename}). Examples of files would be your
history term paper, an e-mail message, or an actual program which can be
executed. Essentially, anything which is saved on disk is saved in 
an individual file. 

\index{filename!defined}
Files are identified by their filenames. For example, the file containing 
your history paper might be saved with the filename {\tt history-paper}. 
These names usually identify the file and its contents in some form
which is meaningful to you. There is no standard format for filenames
as there is under MS-DOS and other operating systems; in general, filenames
may contain any character (except {\tt /}---see the discussion of
pathnames, below), and are limited to 256 characters in length.

\index{directory!defined}
With the concept of files comes the concept of directories. A
{\bf directory} is just a collection of files. It can be thought of
as a ``folder'' which contains many different files. Directories
themselves are given names, with which you can identify them. 
Furthermore, directories are maintained in a tree-like structure;
that is, directories may contain other directories. 

\index{pathname!defined}
A file may be referred to by its {\bf pathname}, which is made up of
the filename, preceded by the name of the directory which contains the file.
For example, let's say that Larry has a directory called {\tt papers},
which contains three files: {\tt history-final}, {\tt english-lit},
and {\tt masters-thesis}. (Each of these three files contains information
for three of Larry's ongoing projects.) To refer to the file
{\tt english-lit}, Larry can specify the file's pathname: 
\begin{tscreen}
papers/english-lit
\end{tscreen}

\index{/@{\tt /}!in pathnames}
As you can see, the directory and file names are separated by a single
slash ({\tt /}). For this reason, filenames themselves cannot contain the
{\tt /} character.  MS-DOS users will find this convention familiar, 
although in the MS-DOS world, the backslash (\verb+\+) is used instead.

\index{directory!nesting}
As mentioned, directories can be nested within each other as well. For
example, let's say that Larry has another directory, within {\tt papers}, 
called {\tt notes}. This directory contains the files {\tt math-notes}
and {\tt cheat-sheet}. The pathname of the file {\tt cheat-sheet} would be
\begin{tscreen}
papers/notes/cheat-sheet
\end{tscreen}

\index{directory!parent}
\index{parent directory}
Therefore, the pathname really is a ``path'' which you take to
locate a certain file. The directory above a given subdirectory is
known as the {\bf parent directory}. Here, the directory {\tt papers}
is the parent of the {\tt notes} directory.

\subsection{The directory tree}
\index{directory!tree}
\index{directory!structure}
\index{directory!root!defined}
\index{root directory!defined}
\index{/@{\tt /}!root directory name}
\index{UNIX!directory structure}
Most UNIX systems have a standard layout for files, so that system
resources and programs can be easily located. This layout forms a 
directory tree, which starts at the ``{\tt /}'' directory, also known
as ``the root directory''. Directly underneath {\tt /} are some important
subdirectories: {\tt /bin}, {\tt /etc}, {\tt /dev}, and {\tt /usr},
among others. These directories in turn contain other directories which
contain system configuration files, programs, and so on.

\index{directory!home!defined}
\index{home directory!defined}
In particular, each user has a {\bf home directory}, which is the
directory set aside for that user to store his or her files. In the
examples above, all of Larry's files (such as {\tt cheat-sheet} and
{\tt history-final}) were contained in Larry's home directory. Usually,
user home directories are contained under {\tt /home}, and are named
for the user who owns that directory. Therefore, Larry's home directory
is {\tt /home/larry}.

\iflotex  % No dirtree if ASCII.
\else {
In Figure~\ref{dirtree} a sample directory tree is represented. It 
should give you some idea of how the directory tree on your system
is organized. 

\unitlength=1.0pt
\begin{figure}[tb]
\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}}    % I am, I am, don't worry! :-)
\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}}      % Come on, all of it!
\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}
\label{dirtree}
\caption{A typical (abridged) Unix directory tree.}
\end{figure} } \fi % Kill dirtree if ASCII.

\subsection{The current working directory}
\index{directory!current working!defined}
\index{directory!working!defined}
\index{current working directory!defined}
\index{working directory!defined}
At any given time, commands that you type to the shell are given in
terms of your {\bf current working directory}. You can think of your
working directory as the directory in which you are currently ``located''.
When you first login, your working directory is set to your home 
directory---{\tt /home/larry} in our case. Whenever you reference a file,
you may refer to it in relationship to your current working directory,
instead of specifying the full pathname of the file.

Here's an example. Larry has the directory {\tt papers}, and
{\tt papers} contains the file 
{\tt history-final}. If Larry wants to look at this file, he can use
the command
\begin{tscreen}
/home/larry\# {\em more /home/larry/papers/history-final}
\end{tscreen}
The {\tt more} command simply displays a file, one screen at a time.
However, because Larry's current working directory is {\tt /home/larry},
he can instead refer to the file {\em relative\/} to his current
location. The command would be
\begin{tscreen}
/home/larry\# {\em more papers/history-final}
\end{tscreen}
\index{pathname!relative}
Therefore, if you begin a filename (such as {\tt papers/final}) with a
character other than ``{\tt /}'', the system assumes that you're
referring to the file in terms relative to your current working directory.
This is known as a {\bf relative pathname}. 

\index{pathname!full}
\index{pathname!absolute}
On the other hand, if you begin a filename with a ``{\tt /}'', the system 
interprets this as a full pathname---that is, a pathname including 
the entire path to the file, starting from the root directory, {\tt /}. 
This is known as an {\bf absolute pathname}.

\subsection{Referring to home directories}
\index{directory!home!\~ to refer to@{\tt \~{}} to refer to}
\index{home directory!\~ to refer to@{\tt \~{}} to refer to}
\index{\~@{\tt \~{}}!to refer to home directory}
Under both {\tt tcsh} and {\tt bash},\footnote{{\tt tcsh} and {\tt bash}
are two {\em shells} running under Linux. The shell is the program
which reads user commands and executes them; most Linux systems enable
either {\tt tcsh} or {\tt bash} for new user accounts.}
your home directory can be referred
to using the tilde character (``{\tt \~{}}''). For example, the command
\begin{tscreen}
/home/larry\# {\em more \~{}/papers/history-final}
\end{tscreen}
is equivalent to
\begin{tscreen}
/home/larry\# {\em more /home/larry/papers/history-final}
\end{tscreen}
The ``{\tt \~{}}'' character is simply replaced with the name of your 
home directory by the shell.

In addition, you can specify other user's home directories with the
tilde as well. The pathname ``{\tt \~{}karl/letters}'' translates to
``{\tt /home/karl/letters}'' by the shell (if {\tt /home/karl} is
karl's home directory). The use of the tilde is simply a shortcut;
there is no directory named ``{\tt \~{}}''---it's just syntactic sugar
provided by the shell.

\index{UNIX!basic concepts|)}
