The Unix file system



Last revision August 3, 2004

Table of Contents:
  1. The Unix file system
  2. The directory tree
  3. File ownership and permissions
  4. Files as units
  5. Examining file contents
  6. Other commands
  7. Standard Files and Data Pipes

A file is simply a data stream - one byte after another with no inherent internal structure imposed by Unix. Programs interpret how to divide this stream into lines or records or fields.

By convention, Unix programs that deal with text generally break up the stream of bytes into lines wherever a new line control character is found (octal code 012). This is only a convention. It is not imposed by the operating system and different programs could use different ways to indicate the end of a line.

This is significantly different from most other server operating systems. In those systems, the operating system, not the program, structures the file into records, or lines, or indexed fields. Usually, many different types of files are provided, each of which must be used differently within a program.

DOS/Windows and Macintosh programs also use some kind of control character to indicate end-of-line. These differences in line terminator conventions can cause problems when transferring files between Unix and DOS/Windows or Macintosh. You can use the Unix tr utility to convert between these line terminator conventions.

  • For DOS/Windows, the two characters new line (octal 012) and carriage return (octal 15) are used together at the end of each line.
  • For Macintosh, the carriage return (octal 15) usually indicates end of paragraph - there is no consistent end of line character. Most Macintosh programs automatically break the lines according to the width of the window or page.

Unix file names can be arbitrary. Any character (except the slash /) can be used as part of a filename. Up to 256 total characters are allowed in a filename in modern Unix systems. WARNING: When naming files, only use the normal alphabet, numerals, dot (period), hyphen (dash) and underscore characters to avoid problems with special character interpretation by the shell.

Files are hierarchically organized in a system of directories and sub-directories which gives a tree structure to the system. Use to organize or isolate files into groups. No matter how many physical disks or other storage devices there are, the file system is a single unified directory tree. You do not need to know which physical device has the file.

Each file and directory has an owner account and a set of access permissions associated with it.

A consequence of simple data stream organization is that all input/output devices (terminals, tape drives, etc.) are accessed through the file system as device files - programs open them, write to or read from them, and close them as if they were files on disk.

    First Section -->

Comments or Questions?