The File System

As with Windows, the Unix file system is arranged as a hierarchy of files and directories. Unix uses a forward slash (/) character instead of Windows's back slash (\) character as a delimiter between the components of a path. Compare

Windows: \SUBDIR\SUBDIR\FILE.TXT
Unix   : /subdir/subdir/file.txt

Unix has no drive specifiers (no A:, C:, F:, etc). Instead all files on all disks appear to be under one directory tree. For example, files under the /floppy directory might actually be on the floppy disk. Thus instead of using A:... to refer to a file on the floppy disk, you use /floppy/... In other words, all files appear to be in the same file system. As another example, manual files on a CD ROM might appear under a directory such as /archives/lib/manuals.

This is usually much easier for users to understand. Instead of having to remember both in which directory and on which disk a file is located, the user must just remember the directory name. Also, as the system grows, files can be moved to new disks without changing the logical arrangement of the files. In fact, the entire file system can be arranged on the disks differently without the users even knowing what has happened.

Unix file names are case sensitive. That is, the names xyz, XYZ, and Xyz all refer to different files. By tradition, most file names are in lower case. The maximum number of characters allowed in a file name varies from system to system. However it is typically 252 or more. Technically, all characters are legal in a file name except for the slash character and the null character. A file could be named \<*>!. File names can even contain spaces and control characters. In practice, dealing with unusual file names is a hassle; you should avoid it.

Unix does not assign any special significance to file extensions. In contrast, Windows requires, for example, that all executable files have a .exe or a .com extension (this isn't entirely true for modern Windows systems). Unix has no similar requirement; most executable files have no extension. Note that some programs require certain extensions in the names of their data files.

If a file name starts with a '.' character, the Unix file listing program, ls, will not display it unless explicitly directed to do so. Such files are said to be "hidden" files. They are not really hidden. You can manipulate them exactly like other files. However to see them in a directory listing, you must invoke ls with the -a option. Also most programs that scan over directories skip the "dot files" unless told otherwise. Hidden dot files are useful for configuration files and other files that have to be around, but that you don't want cluttering up your directory listing.

In general, file names are specified by giving a path from the root directory to the file itself. For example

/                         The root directory itself
/subdir                   A subdirectory under /
/subdir/subdir            A subdirectory under /subdir
/subdir/subdir/file.txt   A file located in /subdir/subdir

These fully elaborated names (that contain all the directories, etc) are called "absolute pathnames".

At any give moment, a program has a working or default directory. You can specify files more easily by using relative pathnames that start at the working directory. Relative pathnames never start with a slash; absolute pathnames always do. For example

afile.txt                In the working directory.
subdir/afile.txt         In a dir below the working dir.

When you use relative pathnames, you can use the special name .. to refer to the directory immediately above the working directory. For example

../afile.txt             In the parent directory.
../subdir/afile.txt      In a sibling directory.
../../afile.txt          In a grandparent directory.

You can also use the special name . to refer to the working directory. This is useful when a command requires a directory name and you want to use the working directory, but don't want to bother typing its absolute pathname. For example

$ cp ../*.txt .

copies all files matching *.txt from the parent directory to the working directory.

In general, you use an absolute pathname whenever you aren't sure what the working directory is. For example, absolute pathnames are common in shell scripts since the author of the script can never be sure from which directory the script will be launched. You use relative pathnames more often interactively since they are usually less typing.

As with Windows, there is no obvious way to determine if a name is a name of a subdirectory or the name of a file. For example, faced with a name such as /abc/def/ghi you can't tell by looking at it if ghi is a file or a directory. Some commands operate differently depending on whether or not they've been given the name of a file or of a directory. These commands must refer to the disk to determine this information. They cannot tell by looking at the name itself.