Like VMS, Unix uses a tree-structured directory made up of a root directory and a hierarchy of subdirectories.
The root of the directory hierarchy is called the root directory, and is designated by / . So, for example, the command:
ls /
would list the contents of this directory.
Any point in the directory hierarchy may be specified by giving a complete path from the root to the point in question. Such a path will begin with a /, indicating that it starts at the root, and will contain all the directories lying on the path, separated by slashes.
For example, home directories for users are typically put in the directory
users
, which is a subdirectory of usr
, which is a
subdirectory of the root. Suppose a user named foo has created a file named
bar. Then a complete path specification for this file would be:
/usr/users/foo/bar
Like VMS, Unix has the notion of a current default directory for a process.
For example, when you log in, your default directory is set to a home
directory created for you by the system manager at the time your account was
created. You may change your default directory at any time by using the
cd
(change directory) command; and you may show your current
default directory at any time by using the pwd
(print working
directory command). The operation of these commands is analogous to the VMS
SET DEFAULT and SHOW DEFAULT commands.
You can change back to your previous default directory with the command
cd -
When specifying a file outside your current default directory, you may
either specify an absolute path to the file from the root of the file system
(/
), or you may specify a relative path, beginning at your current
working directory. The distinction is made as follows: absolute paths
always begin with /
, and relative paths never do. Instead, they
begin with the name of a subdirectory of your current working directory.
For example, suppose a user foo has a home directory /usr/users/foo
.
In his home directory, he has created a subdirectory bar, which contains a
file baz
. If his home directory is his current directory, then he
may reference this file by either one of the following paths:
/usr/users/foo/bar/baz
or
bar/baz
(Note that the former specification will always work correctly regardless of
his current directory, while the latter relies on the fact that
/usr/users/foo
is his current directory.)
In addition to beginning with /
or a directory name, a path
specification may also begin with "." or "..". A single dot (.) refers to
the current directory, and two dots (..) refers to the parent of the current
directory (analogous to [-] on VMS). For example, consider the following
partial directory hierarchy:
/
|
-------------------------------------------------
| | | |
bin dev etc usr
|
-------------------------------------------------
| | | |
bin lib ucb users
|
--------------------------------------
| | |
aardvark foo zebra
| |
xxx -----------------
| |
bar bin
| |
----------------- ---------------
| | | |
baz frobbish ...
Now, suppose that your current working directory is
/usr/users/foo/bar
.
baz
./baz
../bar/baz
/usr/users/foo/bar/baz
../bin
/usr/users/foo/bin
../../aardvark/xxx
/usr/users/aardvark/xxx
../../../bin
/usr/bin
../../../../bin
/bin
(Clearly, in this case, the absolute pathname seems preferable!)
Under VMS, the full name of a file consists of a directory specification followed by a file name, file type, and version number. We have seen that Unix likewise includes a directory specification as the first part of a full file name. However, unlike VMS, Unix has no concept of file type and version - only of a file name. A filename, then, simply consists of a string of some number of characters, normally drawn from the sets of lower-case alphabetic characters and decimal digits. However, uppercase letters may be used to call special attention to a file, and certain other characters (such as '_' and '.') may also appear.
As was noted above, the character '.' may appear in a filename, and is
regarded by Unix as any other character. It is not used, as in VMS, to
divide the filename into distinct name and type fields. In fact, under Unix
a dot may actually appear more than once in a filename - for example, a
filename like ch.1.3.4
is perfectly legal. The dot does, however,
have two special uses.
Because Unix treats the dot as just another character in a filename, you can use it anywhere in a name. However, if you create a file whose name begins with a ., the ls command will not ordinarily list it for you when you do a directory (though there is a command option that will cause it to do so.) This feature creates files that are in some sense hidden from every day viewing, though they can be accessed by name like any other files.
It is a Unix convention to use filenames beginning with dot for various
initialization tasks when a new session or program is started. The following
are some important files used by bash
(the Bourne-Again Shell),
which you may want to create/edit for your own purposes. (Some of these
files may be automatically placed in your home directory when your account
is created.)
.bash_profile
contains commands that are executed by bash
when you first
log in (like LOGIN.COM
on VMS)
.bashrc
contains commands that are executed by bash
when you create
a new shell process in the middle of a session. (It is conventional
to have .bash_profile
explicitly invoke this file so that
it is also executed by your login process.)
.bash_history
used by bash
to keep track of commands you have entered
during the current session, to enable command-line recall.
(Note: other shells have similar files, but with different names.)
The language compilers on Unix make use of a dot in filenames in much the same way that VMS uses the dot to separate a file's name from it's type. For example:
All three compilers produce assembly-language translations of the higher-level-language source with names ending in .s and from these produce object files with names ending .o, but these files are normally deleted for you automatically as part of the linking process, so you will seldom see them.
Finally, the heading files used by the C-preprocessor have names ending in .h.
Remember, though, that .c, .cc, .p etc. are not file types in the VMS sense, but simply the last two or three characters in the filename!
As was noted above, a dot can be used at the beginning of a path name to stand for the current directory, and ".." to stand for the parent of the current directory. Both of these actually exist as entries in every directory - i.e. when created, a directory contains an entry named "." that points to itself, and one named .. that points to its parent. These entries will show up if you use an ls option that shows other filenames beginning with ".".