Unix has a hierarchical tree-like filestore. The filestore contains files and directories, as illustrated in the diagram below.
An illustration of a fragment of the Unix filestore hierarchy.
The top-level directory is known as the root. Beneath the root are several system directories. The root is designated by the / character.
The directories below the root are designated by the pathnames:
/bin /etc /usr
Confusingly, the / character is also used as a separator in pathnames. So, from the figure above, the directory lnp5jb can be referred to by the pathname /bin/home/sunserv1_b/lnp5jb. Historically, user directories were often kept in the directory /usr. However, it is often desirable to organise user directories in a different manner.
Users have their own directory in which they can create and delete files, and create their own sub-directories. For example:
belongs to someone whoe has the username eib035.
Some typical system directories below the root directory:
/bin contains many of the programs which will be executed
/etc files used by system administrators
/dev hardware peripheral devices
/lib system libraries
/usr normally contains applications software
/home home directories for different systems
This refers to your actual location in the filestore hierarchy. When you log in the current directory is set to the home directory. You can then change current directory, effectively moving around the filestore tree structure. The current directory is also called the "current working directory" and the "working directory". The current directory can be referred to in pathnames by the . character (a full stop).
The command cd is used to change your current directory. For example:
% cd bin
will move you from your current directory, down one "branch" to the directory bin, if such a directory exists. Typing cd with no arguments takes you to your home directory.
The command pwd is used to display your current directory. For example:
% pwd /home/sunserv1_b/lnp5jb/bin
Files and directories may be referred to by their absolute pathname. For example:
Files and directories may also be referred to by a relative pathname. For example, if your current directory is /home/sunserv1_b/lnp5jb, the above file can be referred to as:
Each user has a home directory. They will be attached to this directory when they log in. Jenny Brown's home directory is:
The symbol ~ can be used to refer to the home directory. If Jenny Brown wishes to refer to her file she can give:
rather than typing the long form:
The symbol ~ can also refer to other the home directory of other users. For example Jenny can refer to a file in John Smith's home directory using:
The parent directory is the directory above the current directory. The parent directory can be referred to by the .. characters (two full stops). For example to refer to the file test.dat in the parent directory:
The ln command can be used to link files and directories across the filestore system. The symbolic link function (ln -s) is the most useful. This enables a file or directory to appear to be in a particular directory when it is in fact stored somewhere else. This can save the user from having to type out long pathnames for frequently used files or directories. For example, if you want to use the files in /usr/games regularly, you can set up a symbolic link to this directory. If Jenny Brown is in her home directory and types:
% ln -s /usr/games fun
this will create what appears to be a new directory below her home directory, entitled fun. When she does cd fun she will move to /usr/games. If she now does pwd, the current directory will appear as /home/sunserv2_a/lnp5jb/fun. Some things may be a little surprising however: the parent directory, for example, will be that of the original file or directory.