% Linux Installation and Getting Started    -*- TeX -*-
% filesystem.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{Exploring the File System}\label{sec-filesystem-tour}

\index{filesystem!exploring|(}
The {\bf file system} is the collection of files and the hierarchy of
directories on your system. I promised before to escort you around the 
filesystem and the time has come.  

% No ref to dirtree if ASCII
\iftex {
You have the skills and the knowledge to make sense out of what
I'm saying, and you have a roadmap. (Refer to Figure~\ref{dirtree} on
page~\pageref{dirtree}).
} \fi

First, change to the root directory ({\tt cd /}), and do an {\tt ls -F}. 
You'll probably see these directories\footnote{You may see others, and
you might not see all of them. Don't worry. Every release of Linux
differs in some respects.}: {\tt bin}, {\tt
dev}, {\tt etc}, {\tt home}, {\tt install}, {\tt lib}, {\tt mnt}, {\tt
proc}, {\tt root}, {\tt tmp}, {\tt user}, {\tt usr}, and {\tt var}.

Let's take a look at each of these directories.

\begin{dispitems}
\index{directory!bin@{\tt /bin}}
\index{bin@{\tt /bin}}
\ditem{{\tt /bin}}
{\tt /bin} is short for ``binaries'',
or executables. This is where many essential system programs reside. 
Use the command ``{\tt ls -F /bin}'' to list the files here.
If you look down the list you may see a few commands
that you recognize, such as {\tt cp}, {\tt ls}, and {\tt mv}. These are
the actual programs for these commands. When you use the {\tt cp} command,
you're running the program {\tt /bin/cp}.

Using {\tt ls -F}, you'll see that most (if not all) of the files in
{\tt /bin} have an asterisk (``{\tt *}'') appended to their filenames.
This indicates that the files are executables, as described in 
Section~\ref{sec-ls}.

\index{directory!dev@{\tt /dev}}
\index{dev@{\tt /dev}}
\ditem{{\tt /dev}}
Next on our stop is {\tt /dev}. Take a look, again with 
{\tt ls -F}.

\index{device driver}
\index{files!device}
\index{devices!accessing}
The ``files'' in {\tt /dev} are known as {\bf device drivers}---they
are used to access system devices and resources, such as disk drives,
modems, memory, and so on. For example, just as you can read data from
a file, you can read input from the mouse by accessing {\tt /dev/mouse}.

\index{devices!fd@{\tt fd}}
\index{devices!floppy disk}
\index{floppy disk!device names for}
The filenames beginning with {\tt fd} are floppy disk devices. {\tt fd0} is 
the first floppy disk drive, {\tt fd1} the second. 
Now, the astute among you will notice that there are more floppy disk devices 
then just the two I've listed above: they represent specific types of floppy
disks. For example, {\tt fd1H1440} will access high-density, 3.5"
diskettes in drive 1.

Here is a list of some of the most commonly used device files. Note that
even though you may not have some of the devices listed below, the chances
are that you'll have entries in {\tt /dev} for them anyway.

\begin{itemize}
\index{devices!console}
\index{devices!/dev/console@{\tt /dev/console}}
\index{console!device name for}
\index{/dev/console@{\tt /dev/console}}
\item {\tt /dev/console} refers to the system's console---that is, the
monitor connected directly to your system.

\index{devices!serial ports}
\index{devices!/dev/ttyS@{\tt /dev/ttyS}}
\index{devices!/dev/cua@{\tt /dev/cua}}
\index{/dev/ttyS@{\tt /dev/ttyS}}
\index{/dev/cua@{\tt /dev/cua}}
\index{serial ports!device names for}
\item The various {\tt /dev/ttyS} and {\tt /dev/cua} devices are used
for accessing serial ports. For example, {\tt /dev/ttyS0} refers to
``{\tt COM1}'' under MS-DOS. The {\tt /dev/cua} devices are ``callout''
devices, which are used in conjunction with a modem.

\index{devices!hard drives}
\index{devices!/dev/hd@{\tt /dev/hd}}
\index{/dev/hd@{\tt /dev/hd}}
\index{hard drives!device names for}
\item The device names beginning with {\tt hd} access hard drives.
{\tt /dev/hda} refers to the {\em whole\/} first hard disk, while {\tt hda1} 
refers to the first {\em partition\/} on {\tt /dev/hda}.

\index{devices!SCSI}
\index{SCSI devices!names for}
\index{devices!/dev/sd@{\tt /dev/sd}}
\index{devices!/dev/st@{\tt /dev/st}}
\index{devices!/dev/sr@{\tt /dev/sr}}
\index{dev/sd@{\tt /dev/sd}}
\index{dev/st@{\tt /dev/st}}
\index{dev/sr@{\tt /dev/sr}}
\item The device names beginning with {\tt sd} are SCSI drives.
If you have a SCSI hard drive, instead of accessing it through 
{\tt /dev/hda}, you would access {\tt /dev/sda}. SCSI tapes are
accessed via {\tt st} devices, and SCSI CD-ROM via {\tt sr} devices.

\index{devices!parallel ports}
\index{devices!/dev/lp@{\tt /dev/lp}}
\index{/dev/lp@{\tt /dev/lp}}
\index{parallel port!device name for}
\item The device names beginning with {\tt lp} access parallel ports.
{\tt /dev/lp0} refers to ``{\tt LPT1}'' in the MS-DOS world.

\index{devices!null}
\index{devices!/dev/null@{\tt /dev/null}}
\index{/dev/null@{\tt /dev/null}}
\index{null file}
\item {\tt /dev/null} is used as a ``black hole''---any data sent to
this device is gone forever. Why is this useful? Well, if you wanted to
suppress the output of a command appearing on your screen, you could
send that output to {\tt /dev/null}. We'll talk more about this later.

\index{devices!virtual consoles}
\index{devices!/dev/tty@{\tt /dev/tty}}
\index{/dev/tty@{\tt /dev/tty}}
\index{virtual consoles}
\item The device names beginning with {\tt /dev/tty} refer to the
``virtual consoles'' on your system (accessed via by pressing 
\key{alt-F1}, \key{alt-F2}, and so on). {\tt /dev/tty1} refers to the
first VC, {\tt /dev/tty2} refers to the second, and so on.

\index{devices!pseudo-terminals}
\index{devices!/dev/pty@{\tt /dev/pty}}
\index{pseudo-terminals}
\index{/dev/pty@{\tt /dev/pty}}
\item The device names beginning with {\tt /dev/pty} are ``pseudo-terminals''.
They are used to provide a ``terminal'' to remote login sessions. For
example, if your machine is on a network, incoming {\tt telnet} logins would
use one of the {\tt /dev/pty} devices.
\end{itemize}

\index{directory!/etc@{\tt /etc}}
\index{/etc@{\tt /etc}}
\ditem{{\tt /etc}}
{\tt /etc} contains a number of miscellaneous system configuration files.
These include {\tt /etc/passwd} (the user database), {\tt /etc/rc} 
(the system initialization script), and so on. 

\index{directory!/sbin@{\tt /sbin}}
\index{/sbin@{\tt /sbin}}
\ditem{{\tt /sbin}}
{\tt sbin} is used for storing essential system binaries, to be used
by the system administrator. 

\index{directory!/home@{\tt /home}}
\index{/home@{\tt /home}}
\ditem{{\tt /home}}
{\tt /home} contains user's home directories. For example, {\tt /home/larry}
is the home directory for the user ``{\tt larry}''. On a newly-installed
system, there may not be any users in this directory.

\index{directory!/lib@{\tt /lib}}
\index{/lib@{\tt /lib}}
\ditem{{\tt /lib}}
{\tt /lib} contains {\bf shared library images}. These files contain
code which many programs share in common. Instead of each program 
containing its own copy of these shared routines, they are all stored
in one common place, in {\tt /lib}. This makes executable files smaller,
and saves space on your system.

\index{directory!/proc@{\tt /proc}}
\index{/proc@{\tt /proc}}
\ditem{{\tt /proc}}
{\tt /proc} is a ``virtual filesystem'', the files in which are stored
in memory, not on the drive. They refer to the various {\bf processes} running
on the system, and allow you to get information about what programs and
processes are running at any given time. We'll go into more detail in
Section~\ref{sec-process}.

\index{directory!/tmp@{\tt /tmp}}
\index{/tmp@{\tt /tmp}}
\ditem{{\tt /tmp}}
Many programs have a need to generate some information and store it in
a temporary file. The canonical location for these files is in {\tt /tmp}.

\index{directory!/usr@{\tt /usr}}
\index{/usr@{\tt /usr}}
\ditem{{\tt /usr}}
{\tt /usr} is a very important directory. It contains a number of
subdirectories which in turn contain some of the most important and
useful programs and configuration files used on the system.

The various directories described above are essential for the system
to operate, but most of the things found in {\tt /usr} are optional
for the system. However, it is those optional things which make the
system useful and interesting. Without {\tt /usr}, you'd more or less
have a boring system, only with programs like {\tt cp} and {\tt ls}.
{\tt /usr} contains most of the larger software packages and the
configuration files which accompany them.

\index{directory!/usr/X386@{\tt /usr/X386}}
\index{/usr/X386@{\tt /usr/X386}}
\ditem{{\tt /usr/X386}}
{\tt /usr/X386} contains The X Window System, if you installed it. 
The X Window System is a large, powerful graphical environment which
provides a large number of graphical utilities and programs, displayed
in ``windows'' on your screen. If you're at all familiar with the
Microsoft Windows or Macintosh environments, X~Windows will look very 
familiar. The {\tt /usr/X386} directory contains all of the X~Windows
executables, configuration files, and support files. This will be
covered in more detail in Section~\ref{sec-xwindows}.

\index{directory!/usr/bin@{\tt /usr/bin}}
\ditem{{\tt /usr/bin}}
{\tt /usr/bin} is the real warehouse for software on any UNIX system. 
It contains most of the executables for programs not found in other
places, such as {\tt /bin}. 

\index{directory!/usr/etc@{\tt /usr/etc}}
\index{/usr/etc@{\tt /usr/etc}}
\ditem{{\tt /usr/etc}}
Just as {\tt /etc} contained miscellaneous system programs and configuration
files, {\tt /usr/etc} contains even more of these utilities and files.
In general, the files found in {\tt /usr/etc} are not essential to the
system, unlike those found in {\tt /etc}, which are.

\index{directory!/usr/include@{\tt /usr/include}}
\index{/usr/include@{\tt /usr/include}}
\ditem{{\tt /usr/include}}
{\tt /usr/include} contains {\bf include files} for the C compiler.
These files (most of which end in {\tt .h}, for ``header'') declare
data structure names, subroutines, and constants used when writing programs
in C. Those files found in {\tt /usr/include/sys} are generally used
when programming on the UNIX system level. If you are familiar with
the C programming language, here you'll find header files such as 
{\tt stdio.h}, which declares functions such as {\tt printf()}. 

\index{directory!/usr/g++-include@{\tt /urs/g++-include}}
\index{/usr/g++-include@{\tt /urs/g++-include}}
\ditem{{\tt /usr/g++-include}}
{\tt /usr/g++-include} contains include files for the C++ compiler (much
like {\tt /usr/include}).

\index{directory!/usr/lib@{\tt /usr/lib}}
\index{/usr/lib@{\tt /usr/lib}}
\ditem{{\tt /usr/lib}}
{\tt /usr/lib} contains the ``stub'' and ``static'' library equivalents
to the files found in {\tt /lib}. When compiling a program, the program
is ``linked'' with the libraries found in {\tt /usr/lib}, which then directs
the program to look in {\tt /lib} when it needs the actual code in the
library. In addition, various other programs store configuration files in 
{\tt /usr/lib}.

\index{directory!/usr/local@{\tt /usr/local}}
\index{/usr/local@{\tt /usr/local}}
\ditem{{\tt /usr/local}}
{\tt /usr/local} is a lot like {\tt /usr}---it contains various programs
and files not essential to the system, but which make the system fun
and exciting. In general, those programs found in {\tt /usr/local} are
specialized for your system specifically---that is, {\tt /usr/local}
differs greatly between UNIX systems.

Here, you'll find large software packages such as \TeX\ (a document
formatting system) and Emacs (a large and powerful editor), if you
installed them.

\index{directory!/usr/man@{\tt /usr/man}}
\index{/usr/man@{\tt /usr/man}}
\ditem{{\tt /usr/man}}
This directory contains the actual man pages. There are two subdirectories
for every man page ``section'' (use the command {\tt man man} for details). 
For example, {\tt /usr/man/man1} contains the source (that is,
the unformatted original) for man pages in section 1, and {\tt /usr/man/cat1}
contains the formatted man pages for section 1. 

\index{directory!/usr/src@{\tt /usr/src}}
\index{/usr/src@{\tt /usr/src}}
\ditem{{\tt /usr/src}}
{\tt /usr/src} contains the source code (the uncompiled program) for various 
programs on your system. The most important thing here is {\tt /usr/src/linux},
which contains the source code for the Linux kernel. 

\index{directory!/var@{\tt /var}}
\index{/var@{\tt /var}}
\ditem{{\tt /var}}
{\tt /var} holds directories that often change in size or tend to grow.
Many of those directories used to reside in {\tt /usr}, but since we
are trying to keep it relatively unchangeable, the directories that
change often have been moved to {\tt /var}.  
Some of those directories are:

\index{directory!/var/adm@{\tt /var/adm}}
\index{/var/adm@{\tt /var/adm}}
\ditem{{\tt /var/adm}}
{\tt /var/adm} contains various files of interest to the system
administrator, specifically system logs, which record any errors or
problems with the system. Other files record logins to the system, as
well as failed login attempts. This will be covered in 
Chapter~\ref{chap-sysadm}.

\index{directory!/var/spool@{\tt /var spool}}
\index{/var/spool@{\tt /var spool}}
\ditem{{\tt /var/spool}}
{\tt /var/spool} contains files which are to be ``spooled'' to another
program. For example, if your machine is connected to a network, incoming
mail will be stored in {\tt /var/spool/mail}, until you read it or
delete it. Outgoing or incoming news articles may be found 
in {\tt /var/spool/news}, and so on.

\end{dispitems}
\index{filesystem!exploring|)}
