UNIX / Linux Tutorial

1.6  Exploring The File System  |  1.7 Types Of Shells
 
1.6  Exploring The File System

A  file system is the collection of files and the hierarchy of directories on a system. The
time has now come to escort you around the file system.

You now have the skills and the knowledge to understand the Linux file system, and
you have a roadmap.

First, change to the root directory (cd /), and then enter ls -F to display a listing
of its contents. You'll probably see the following directories:

 bin, dev, etc, home, install, lib, mnt, proc, root, tmp, user, usr,and var.

Note:
 You may see others, and you might not see all of them. Every release of Linux 
differs in some respects.

Now, let's take a look at each of these directories.

/bin   
/bin is short for "binaries", or executables, where many essential system
programs reside. Use 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 cp, ls and mv. These are the actual programs for these commands.
When you use the cp command, for example, you're running the
program /bin/cp.

Using ls -F, you'll see that most (if not all) of the files in /bin have
an asterisk ("*") appended to their filenames. This indicates that the files
are executables.

/dev    
The "files"  in/dev are device files—they access system devices and
resources like disk drives, modems, and memory. Just as your system can
read data from a file, it can also read input from the mouse by accessing
/dev/mouse.

Filenames that begin with fd are floppy disk devices. fd0 is the first
floppy disk drive, and fd1 is the second. You may have noticed that there
are more floppy disk devices than the two listed above: these represent
specific types of floppy disks. For example, fd1H1440 accesses high-density,
3.5" diskettes in drive 1.

The following is a list of some of the most commonly used device files.
Even though you may not have some of the physical devices listed below,
chances are that you'll have drivers in /dev for them anyway.

	 /dev/console refers to the system's console—that is, the monitor
connected directly to your system.

	 The various /dev/ttyS and /dev/cua devices are used for accessing
serial ports. /dev/ttyS0 refers to "COM1" under MS-DOS.
The /dev/cua devices are "callout" devices, and used with
a modem.

	 Device names beginning with hd access hard drives. /dev/hda
refers to the whole first hard disk, while /dev/hda1 refers to the
first partition on /dev/hda.

	 Device names that begin with sd are SCSI drives. If you have a
SCSI hard drive, instead of accessing it through /dev/hda, you
would access /dev/sda. SCSI tapes are accessed via st devices,
and SCSI CD-ROM via sr devices.

	 Device names that begin with lp access parallel ports. /dev/lp0
is the same as "LPT1" in the MS-DOS world.
	
 /dev/null is used as a "black hole"—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 /dev/null. We'll talk more about this later.

	 Devices whose names are /dev/tty followed by a number refer
to the "virtual consoles" on your system (accessed by pressing
Alt-F1 , Alt-F2 , and so on). /dev/tty1 refers to the first
VC, /dev/tty2 refers to the second, and so on.

	 Device names beginning with /dev/pty are pseudo-terminals,
which are used to provide a "terminal" to remote login sessions.
For example, if your machine is on a network, incoming telnet
logins would use one of the /dev/pty devices.

/etc    
/etc contains a number of miscellaneous system configuration files.
These include /etc/passwd (the user database), /etc/rc (the system
initialization script), and so on.

/sbin    
/sbin contains essential system binaries that are used for system administration.

/home     
/home contains user's home directories. For example, /home/patrick
is the home directory for the user "patrick". On a newly installed system,
there may not be any users in this directory.

/lib      
/lib contains shared library images, which are files that contain code
which many programs share in common. Rather than each program using
its own copy of these shared routines, they are all stored in one common
place, in /lib. This makes executable files smaller, and saves space on
your system.

/proc     
/proc supports a "virtual file system", where the files are stored in
memory, not on disk. These "files" refer to the various processes running
on the system, and let you get information about the programs and
processes that are running at any given time.

/tmp    
Many programs store temporary information and in a file that is deleted
when the program has finished executing. The standard location for these
files is in /tmp.

/usr    
/usr is a very important directory which contains subdirectories that
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 items found in /usr are optional. However, it is
these optional items that make the system useful and interesting. Without
/usr, you'd have a boring system that supports only programs like cp
and ls. /usr contains most of the larger software packages and the
configuration files that accompany them.

/usr/X11R6 
/usr/X11R6 contains The X Window System, if you installed it. The
X Window System is a large, powerful graphical environment that 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 familiar.
The /usr/X11R6 directory contains all of the X Windows executables,
configuration files, and support files. This is covered in more detail
in Chapter ??.

/usr/bin        
/usr/bin is the real warehouse for software on any Linux system, 
containing most of the executables for programs not found in other places,
like /bin.

/usr/etc     
Just as /etc contains essential miscellaneous system programs and 
configuration files, /usr/etc contains miscellaneous utilities and files,
that in general, are not essential to the system.

/usr/include
/usr/include contains include files for the C compiler. These files
(most of which end in .h, for "header") declare data structure names,
subroutines, and constants used when writing programs in C. Files in.
/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 like stdio.h, which declare functions
like printf().

/usr/g++-include
/usr/g++-include contains include files for the C++ compiler
(much like /usr/include).

/usr/lib     
/usr/lib contains the "stub" and "static" library equivalents for the
files found in /lib. When compiling a program, the program is "linked"
with the libraries found in /usr/lib, which then directs the program
to look in /lib when it needs the actual code in the library. In addition,
various other programs store configuration files in /usr/lib.

/usr/local     
/usr/local is much like /usr—it contains various programs and
files not essential to the system, but which make the system fun and exciting.
In general, programs in /usr/local are specialized for your
system—consequently, /usr/local differs greatly between Linux
systems.

/usr/man     
This directory contains manual pages. There are two subdirectories
in it for every manual page "section" (use the command man 
for details). For example, /usr/man/man1 contains the source
(that is, the unformatted original) for manual pages in section 1, and
/usr/man/cat1 contains the formatted manual pages for section 1.

/usr/src     
/usr/src contains the source code (the uncompiled instructions) for
various programs on your system. The most important directory here
is /usr/src/linux, which contains the source code for the Linux
kernel.


/var      
/var holds directories that often change in size or tend to grow. Many
of those directories used to reside in /usr, but since those who support
Linux are trying to keep it relatively unchangeable, the directories
that change often have been moved to /var. Some Linux distributions
maintain their software package databases in directories under /var.

/var/log       
/var/log contains various files of interest to the system administra-
tor, specifically system logs, which record 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 4.

/var/spool        
/var/spool contains files which are "spooled" to another program.
For example, if your machine is connected to a network, incoming mail
is stored in /var/spool/mail until you read or delete it. Outgoing
or incoming news articles are in /var/spool/news, and so on.

1.7 Types Of Shells

As mentioned before, Linux is a multitasking, multi-user operating system. Multitasking
is very useful, and once you understand it, you'll use it all of the time. Before long, you'll
run programs in the background, switch between tasks, and pipeline programs together to
achieve complicated results with a single command.

Many of the features we'll cover in this section are features provided by the shell itself.
Be careful not to confuse Linux (the actual operating system) with a shell—a shell is just
an interface to the underlying system. The shell provides functionality in addition to Linux
itself.

A shell is not only an interpreter for the interactive commands you type at the prompt,
but also a powerful programming language. It lets you to write shell scripts, to "batch"
several shell commands together in a file. If you know MS-DOS you'll recognize the
similarity to "batch files". Shell scripts are a very powerful tool, that will let you automate
and expand your use of Linux.

There are several types of shells in the Linux world. The two major types are the
"Bourne shell" and the "C shell". The Bourne shell uses a command syntax like the original
shell on early UNIX systems, like System III. The name of the Bourne shell on most Linux
systems is /bin/sh (where sh stands for "shell"). The C shell (not to be confused with
sea shell) uses a different syntax, somewhat like the programming language C, and on most
Linux systems is named /bin/csh.

Under Linux, several variations of these shells are available. The two most commonly
used are the Bourne Again Shell, or "Bash" (/bin/bash), and "Tcsh" (/bin/tcsh).
bash is a form of the Bourne shell that includes many of the advanced features found in
the C shell. Because bash supports a superset of the Bourne shell syntax, shell scripts
written in the standard Bourne shell should work with bash. If you prefer to use the C
shell syntax, Linux supports tcsh, which is an expanded version of the original C shell.

The type of shell you decide to use is mostly a religious issue. Some people prefer
the Bourne shell syntax with the advanced features of bash, and some prefer the more
structured C shell syntax. As far as normal commands such as cp and ls are concerned,
the shell you use doesn't matter—the syntax is the same. Only when you start to write shell
scripts or use advanced features of a shell do the differences between shell types begin to
matter.

As we discuss the features of the various shells, we'll note differences between Bourne
and C shells. However, for the purposes of this manual most of those differences are
minimal. (If you're really curious at this point, read the man pages for bash and tcsh).

HOME

1.1 Introduction   1.2.10 Referring To Home Directories   1.3.4  Copying Files

1.6 Exploring The File System   1.8   Wildcards   1.9.3 Pipes   1.10.3 Permissions Dependencies

1.12.4  Stopping And Restarting Jobs   1.13.3 Inserting Text   1.13.9 Including Other Files

1.14.3 Shell Initialization Scripts   System Administration   2.3.1 The /etc/imitate file

2.4 Managing File Systems   2.6 Managing Users  2.6.5 Groups   2.7.2 gzip and compress

2.8.3 Making Backups To Tape Devices   2.9.1 Upgrading The Kernel   

2.9.3 Installing A Device Driver Module

BOOK: LINUX QUICK COMMAND REFERENCE

http://personal.atl.bellsouth.net/~psadler

© copyright KnowledgeWorks, Inc. (2001)