If you work with the Web long enough, chances are you’ll run into the need to communicate with a Unix machine. On Macs and PCs, most functions can be performed using tools with graphical interfaces; however, at times there is no substitute for a good old-fashioned telnet session. Besides, a little Unix never hurt anyone.
Telnet is a “terminal emulation” protocol that allows you to log in to other computer systems on a network (such as the Internet). It also refers to any application used for communicating with the telnet protocol. A telnet program will give you a character-based terminal window on another system from which you can enter simple command-line instructions. Figure 4.1 shows a typical telnet session.
This section provides a very brief introduction to basic terminology and commands that will enable you to manipulate files and directories on a Unix machine. If you are interested in learning more, read Learning the Unix Operating System and Unix in a Nutshell, both published by O’Reilly & Associates, Inc.
open a connection to a remote server with your telnet program, the
first thing you see is a prompt to log in to the system. Before you
can access the server, the system administrator has to set up a Unix
account for you. You will be given a name and password you can enter
password: prompts respectively.
When you log in successfully, you will get a Unix system prompt,
$ or a
sometimes #) depending on the flavor of Unix the server is running,
which tells you that the system is “ready.” At this
point, you are using a program called the
shell, which interprets the commands you type
and invokes the programs you ask for. You will automatically be
placed in your home directory.
To end the telnet session, simply type “logout” or “exit.”
Because the Web was spawned from the Unix environment, it follows many of the same conventions. For instance, writing correct URL pathnames in hyperlinks relies on an understanding of how directory structures work on the Unix platform.
Directories (“places” to store files) are organized into
a hierarchical structure that fans out like an upside-down tree. The
known as the root and is written as a forward
slash ( / ).
The root can contain several directories,
each of which can contain subdirectories; each of these can contain
more subdirectories, and so on. A subdirectory is said to be the
“child” of the directory that holds it (its
“parent”). Figure 4.2 shows a system
with five directories under the root. The directory
users has two subdirectories,
are two more subdirectories,
pers, and within
A pathname is the notation used to point to a particular file or directory; it tells you the path of directories you must travel to get to where you want to go. There are two types of pathnames: absolute and relative.
An absolute pathname
always starts from the root
directory, which is indicated by a slash ( / ). So, for example, the
/users/jen/pers, as shown in Figure 4.3
first slash indicates that we are starting at the root, and is
necessary for indicating that a pathname is absolute.
A relative pathname points to a file or directory relative to your current working directory. When building a web site on a single server, relative pathnames are commonly used within URLs to refer to files in other directories on the server.
Unless you specify an absolute name (starting with a slash) the shell assumes you are using a relative pathname. Starting in your current location (your working directory), you can trace your way up and down the directory hierarchy. This is best explained with an example.
If I am currently working in the directory
and I want to refer to the file
relative pathname would be
art.html is in the directory
pers, which is in the current directory,
jen. This is illustrated in Figure 4.4.
Going back up the hierarchy is a bit trickier. You go up a level by using the shorthand .. for the parent directory. Again, let’s use an example based on Figure 4.2.
If I am currently in the
jen directory, and I
want to refer to the directory
the pathname would be
.. /richard/work. The two
dots at the beginning of the path takes us back up one level to the
users directory, and from there we find
the directory called
richard and the
work, as shown in Figure 4.5.
If I am currently in my
pers directory and I
want to refer to Richard’s
I need to go up two levels, so the pathname would be
/richard/work, as shown in Figure 4.6.
Note that the absolute path
accomplishes the same thing. The decision whether to use an absolute
versus a relative pathname generally comes down to which is easiest
from where you
The command in bold must be typed in exactly as shown and the values in italics stand for variables that you supply. Some general guidelines for Unix syntax are:
Commands are entered in lowercase.
Options modify the
way in which a command works. They are often single letters prefixed
with a minus (-) sign and set off by any number of spaces or tabs.
The options listed in this chapter typically can be indicated in one
command line by setting them off individually or combining them after
a single minus sign. Note: This rule may vary depending on the type
of Unix system you are using. Ask your server administrator for help
if you run into problems.
filename is the name of a
file you want to manipulate in some way.
Spaces between commands, options, and filenames are important; e.g., “ls -al” works, “ls-al” doesn’t.
The asterisk symbol (
*) is a wildcard character
that can be used to substitute for any string of characters in a file
or directory name. For instance, a search for *.html will retrieve
all documents ending in .html.
The following is a brief list of Unix commands that are useful for navigating through directories and managing files.