Special File Types   «Prev  Next»
Lesson 2 Regular files and directories
Objective Describe how UNIX treats Regular Files and Directories differently than other Operating Systems.

Describe how UNIX treats Regular Files and Directories differently than other Operating Systems

Regular Files

A regular file is anything that is not one of the special file types we will look at below. In UNIX, all regular files are stored as sequences of bytes. Unlike some operating systems, UNIX makes no distinctions between binary files and text files. In addition, file "extensions" have no significance in UNIX. All filename extensions are managed by convention. For example, most C compilers expect C source code programs to be named file.c, but the operating system does not treat .c files in any special way. Files may have multiple extensions, such as file.tar.gz (a commonly used naming convention for archive files created with the tar program and compressed with the gzip program).


A directory file contains a list of the files in the directory. As we have seen, directory files are marked in ls -l listings by a d in the initial position of the permission string (for example, drwxr-xr-x).
So far in this course, we have concentrated on regular files and directories, which are the two files you will deal with most often. However, thanks to the UNIX "everything is a file" philosophy, you will find a number of other things that look like files, but have some special properties.

Home and Working Directories

When a user logs in, the UNIX system puts the user in the home directory. The directory in which the user is working is called the working directory (also known as the current directory).
For the C and Korn shells, the tilde (~) character can be used as the shell metacharacter for the home directory. The working directory can be substituted with . (dot). The parent of the working directory is substituted with .. (double dots).

Unix Tree

File-Based Concepts

To gain a full picture of the internal operation of filesystems, it is necessary to understand what the user sees, why things are presented they way they are, and what the main concepts are. Users experienced in UNIX may wish to skip this module. On the other hand, users new to UNIX and those starting to program in the UNIX environment will find these concepts useful. A basic implementation of the ls program helps to reinforce the material presented and provides an introduction to file-related libraries and system calls, a topic that will be expanded upon in the next module. One peculiarity that UNIX introduced was the notion that everything in the UNIX namespace (file tree) is visible as a file and that the same operations can be applied to all file types. Thus one can open and read a directory in the same way in which a file can be opened and read. Of course, this does not always have the desired effect. For example, running the UNIX command cat on a directory will likely produce a screen full of unreadable characters. However, these and other simple concepts are one of the great strengths of UNIX. The following sections provide introductory material which describe file-based concepts and start to paint a picture of how these components fit together.