WSU logo


College of Engineering & CS
Wright State University
Dayton, Ohio 45435-0001

CEG 333: Introduction to Unix

Prabhaker Mateti

The UNIX File System


In Unix, all directories are subdirectories of the / directory, which is called the "root", or base of the file system. A directory is also a file. To disambiguate, we refer to a file that is not a directory an ordinary file. A directory can contain an unlimited number of ordinary files and subdirectories. Unix file names can be long, the exact max length depends on the underlying file system design, and unimportant in this course. Unix file names typically contain letters (a-z, A-Z), digits (0-9), and the dot ('.'). They can also contain spaces, tabs, and punctuation characters such as comma, etc. but these can be troublesome, so we will avoid them.

Note: The shell has a featured called tab completion which makes typing long pathnames less painful. Experiment with typing a partial filename and pressing tab.

Unix internally identifies a file with a number called the i-number. Two different files will have different i-numbers. An i-number is an index into an array called the i-node array. A directory should be thought of as a table of two columns: first column lists the name of the file, the second lists its i-number. The internal order of the rows of this table is unimportant.

Unix files of any system form a hierarchical tree — all internal nodes are directories, all ordinary files are leaves, and some leaf nodes are empty directories. Every file is reachable by walking a path starting from the root, to the parent directory of the file, and finally to the file. This is known as the absolute path name. An example absolute path name is /d1/d2/d3/myFile.txt. Unix path names use the forward slash ('/') to separate the directory names. The back slash ('\') has a special meaning to be discussed much later.

Unix files are typically organized as follows:

Directory Contains
/bin Executable files (programs)
/etc et cetera; Configuration files
/lib Library files (executable code shared by multiple programs)
/mnt Subdirectories expected to be used as mount points
/sbin Executable programs used for system maintenance
/tmp Any user can create temporary files here. File permissions do apply.
/usr Programs for day to day use of the system (such as Emacs and web browsers), as distributed by the OS vendor
/dev Special files for accessing peripherals (such as hard drives or joysticks)
proc Information about currently running processes
/var Files of variable size, such as logs or queues for printer or mail servers

The bin, sbin subdirectory name often reoccur. E.g., a Unix system may have /bin, /usr/bin, /usr/local/bin, /sbin, /usr/sbin, /usr/local/sbin, /opt/kde/bin, and /common/bin. See man hier for more information.

A system that has multiple local disks mounts the partitions on the subdirectories of /mnt so that the end result is again a single hierarchical tree. It is also possible to have one physical disk partition shared by multiple systems via a LAN.

Every directory contains two special entries: (i) the dot refers to itself, a self-loop; and (ii) the dot-dot refers to the parent directory.

When referring to the Unix file system as a tree, we are excluding these two from every directory. Another exception occurs via what are known as links—hard, or soft. These are discussed later.

File extensions have no special meaning in Unix. They are a convention to make things easier for human users, and as such have no special meaning to the operating system. However, it is always best to follow these conventions to prevent later confusion.

Other Unix filename conventions include those for backup (created by an editor after saving a file) and auto-save files (copies of unsaved changes made by editors at regular intervals). Backup filenames are made by appending a tilde (~) to the original filename. Auto-save filenames are the original filename with a pound signs (#) before and after it.