The Unix file system is a hierarchical structure that allows users to store information by name. At the top of the hierarchy is the root directory, which always has the name /. A typical Unix file system might look like:

A  UNIX directory  tree

The location of a file in the file system is called its path. Since the root directory is at the top of the hierarchy, all paths start from /. Using the sample file system illustrated above, let us determine the path for quiz1.txt:

Unix assigns a special "shorthand" notation for specifying commonly used paths. These special paths and their shorthand names are listed below:

Now that we know how Unix organizes files, let us attempt to define what we mean by the term file.

Files and Directories

There are 3 kinds of files: ordinary files (files), directory files (directories), and special files.

Every file has an associated data structure that contains important information about that file. This data structure is known as an i-node. An i-node has information about the length of the file, the time the file was most recently modified or accessed, the time the i-node itself was most recently modified, the owner of the file, the group identifications and access permissions, the number of links to the file (we will discuss these shortly), and pointers to the location on the disk where the data contained in the file is stored. A filename is used to refer to an i-node. A directory is a file that contains a list of names, and for each name there is a pointer to the i-node for the file or directory. The following picture offers a graphical interpretation of files, their i-nodes, and the blocks that they occupy on disk:

Directory structure with i-nodes

Filenames The name given to a file or directory can contain almost any character that can be typed on the keyboard and be of almost any length. It is common to use only letters and digits for the first character of a filename, and use only letters, digits, periods [.], hyphens [-] and underscores [_] for the remainder of the filename. However, the following characters should never be used in filenames:

These characters all have special meaning to Unix. Also, Unix is case sensitive. For example, the files hello.cpp, Hello.cpp and HELLO.cpp are three different filenames representing three different files in Unix.

In the Macintosh and Windows operating systems, an extension is automatically assigned to each file when it is created (an extension is a special string that is added at the end of a filename to indicate its type, and is separated from the rest of the file name by a period, such as .doc or .xls). By default, Unix filenames do not have any extension. Therefore, Unix users often add this extension themselves to indicate the type of data a file contains. Some examples are .cpp for C++ program files (e.g., hello.cpp), .txt for text files (e.g., document.txt), and .ps for PostScript documents (e.g., outline.ps).