The Unix File System
The Unix File System
By contrast, a file system consists of files, relationships to other files, as well as the
attributes of each file. File attributes are information relating to the file, but do not
include the data contained within a file. File attributes for a generic operating system
might include (but are not limited to):
Additionally, file systems provide tools which allow the manipulation of files, provide a
logical organization as well as provide services which map the logical organization of
files to physical devices.
From the beginners perspective, the Unix file system is essentially composed of files
and directories. Directories are special files that may contain other files.
The Unix file system has a hierarchical (or tree-like) structure with its highest level
directory called root (denoted by /, pronounced slash). Immediately below the root level
directory are several subdirectories, most of which contain system files. Below this can
exist system files, application files, and/or user data files. Similar to the concept of the
process parent-child relationship, all files on a Unix system are related to one another.
That is, files also have a parent-child existence. Thus, all files (except one) share a
common parental link, the top-most file (i.e. /) being the exception.
Below is a diagram (slice) of a "typical" Unix file system. As you can see, the top-most
directory is / (slash), with the directories directly beneath being system directories. Note
that as Unix implementaions and vendors vary, so will this file system hierarchy.
However, the organization of most file systems is similar.
While this diagram is not all inclusive, the following system files (i.e. directories) are
present in most Unix filesystems:
/bin - short for binaries, this is the directory where many commonly used
executable commands reside
/dev - contains device specific files
/etc - contains system configuration files
/home - contains user directories and files
/lib - contains all library files
/mnt - contains device files related to mounted devices
/proc - contains files related to system processes
/root - the root users' home directory (note this is different than /)
/sbin - system binary files reside here. If there is no sbin directory on your
system, these files most likely reside in etc
/tmp - storage for temporary files which are periodically removed from the
filesystem
/usr - also contains executable commands
/usr/bin : This directory stores all binary programs distributed with the operating
system not residing in /bin, /sbin or (rarely) /etc.
/usr/include : Stores the development headers used throughout the system.
Header files are mostly used by the #include directive in C/C++ programming
language.
/usr/lib : Stores the required libraries and data files for programs stored within /usr
or elsewhere.
/var : A short for “variable.” A place for files that may change often – especially in
size, for example e-mail sent to users on the system, or process-ID lock files.
/var/log : Contains system log files.
/var/mail : The place where all the incoming mails are stored. Users (other than
root) can access their own mail only. Often, this directory is a symbolic link to
/var/spool/mail.
/var/spool : Spool directory. Contains print jobs, mail spools and other queued
tasks.
/var/tmp : A place for temporary files which should be preserved between system
reboots.
File Types
From a user perspective in a Unix system, everything is treated as a file. Even such
devices such as printers and disk drives.
How can this be, you ask? Since all data is essentially a stream of bytes, each device
can be viewed logically as a file.
All files in the Unix file system can be loosely categorized into 3 types, specifically:
1. ordinary files
2. directory files
3. device files 1
While the latter two may not intuitively seem like files, they are considered "special"
files.
The first type of file listed above is an ordinary file, that is, a file with no "special-ness".
Ordinary files are comprised of streams of data (bytes) stored on some physical device.
Examples of ordinary files include simple text files, application data files, files containing
high-level source code, executable text files, and binary image files. Note that unlike
some other OS implementations, files do not have to be binary Images to be executable
(more on this to come).
The second type of file listed above is a special file called a directory (please don't call it
a folder?). Directory files act as a container for other files, of any category. Thus we can
have a directory file contained within a directory file (this is commonly referred to as a
subdirectory). Directory files don't contain data in the user sense of data, they merely
contain references to the files contained within them.
It is perhaps noteworthy at this point to mention that any "file" that has files directly
below (contained within) it in the hierarchy must be a directory, and any "file" that does
not have files below it in the hierarchy can be an ordinary file, or a directory, albeit
empty.
The third category of file mentioned above is a device file. This is another special file
that is used to describe a physical device, such as a printer or a portable drive. This file
contains no data whatsoever, it merely maps any data coming its way to the physical
device it describes.
1
Device file types typically include: character device files, block device files, Unix
domain sockets, named pipes and symbolic links. However, not all of these file types
may be present across various Unix implementations.
1. Hierarchical organization: The hierarchical structure of the Unix file system makes it
easy to organize and navigate files and directories.
2. Robustness: The Unix file system is known for its stability and reliability. It can handle
large amounts of data without becoming unstable or crashing.
3. Security: The Unix file system uses a set of permissions that allows administrators to
control who has access to files and directories.
4. Compatibility: The Unix file system is widely used and supported, which means that
files can be easily transferred between different Unix-based systems.