File system

The file system organizes the files on a storage medium (usually a magnetic disk.) Here we discuss how files are named, next, how they are organized, and, finally, how you refer to them on a command line.

File names and wild cards

File names can be constructed from nearly any characters, but to avoid confusion it is best to limit use to only letters (Unix is case sensitive, so upper and lower case are different), numbers, and a few special characters, such as underscore _, dash -, and period . (dot). Do not use spaces in file names, as is common in Windows.

Files with names beginning with dot . are treated as ``hidden'' and are usually ignored unless you take special steps to include them. For example, the command ls does not list hidden files, but the command ls -a does.

Unix can operate on several files of the same name through the use of ``wild card'' characters. The wild card * stands for any or no characters. Thus the command ls s* lists all files with names beginning with the letter s. The wild card ? stands for exactly one character. It can be repeated. Thus the command ls s?? lists all files with three-character names beginning with s.

File system organization

Since practically everything you do with a computer involves working with a file, it is important to understand how the file system is organized. It is arranged in a hierarchical fashion like the branches on an inverted tree. These branches are called directories (known as folders in the Macintosh and Windows operating systems). Any directory can contain files as well as subdirectories. (It is the same in Windows: any folder can contain files as well as folders.) Each user has a personal home directory. By default when you log on you are ``connected'' to your home directory. After logging on, if you type the Unix command pwd, you will see a complete specification of your current working directory. Try it! For example you might see

   % pwd
   /u/course/u0123456
A slash / separates the names of the directories. They are listed in order with top level directory first and lower level directories next. In this case the user's name is u0123456 and this user has a home directory with the same name. This directory is a subdirectory under the directory class (which happens to contain the home directories for all students in physics classes). The class directory is in turn a subdirectory under the u directory, that contains all departmental user accounts for research and education among other directories. Finally the u directory is under the very top of the inverted tree, sometimes referred to as just /, and sometimes called the ``root'' directory, which ``contains'' the entire file tree for your machine, including all system files, applications files, and user accounts.

Relative and Absolute Paths

A path to a file or directory is a sequence of directories that take you to the file. Sometimes the term ``path'' also includes the name of the file itself.

The characters /u/course/u0123456/ specify the path to all the files and subdirectories in your home directory. It is called an ``absolute'' path, because it starts from a fixed location, namely the root directory, so it means the same thing regardless of what the current working directory may be. All paths that start from the root (top level) directory / are called ``absolute''. (Please note that ~ or ~u0123456 are convenient abbreviations for your home directory, so any path starting with ~ is also absolute.)

Unix keeps track of your current working directory. The ``relative'' path specifies a location relative to the current working directory. Its meaning depends on where you are in the file system, i.e. what the current working directory may be. Extending the above example, suppose you (u0123456) had subdirectories asst01 and asst02 in your home directory and your home directory is your current working directory. Then the shorthand asst01 specifies the relative path to all the files in your asst01 subdirectory and asst02 specifies the relative path to all the files in the asst02 subdirectory.

The special directory .. means ``the parent of the current directory''. It is used in relative paths to go back up in the tree. Continuing with the above example, suppose that /u/class/u0123456/asst01 is the current working directory. Then ../asst02 is the relative path to all the files in the sister asst02 subdirectory.

For completeness, we note that the special directory . means ``the current directory''.