About files and directories

Files and directories

The basic unit in which the UnixWare system stores information is the file. A file is a named collection of data that you can move around, copy, rename, or delete. Files are stored in a filesystem, a storage area on your computer's hard disk or disks. A filesystem is split into directories, which are smaller storage areas that make it easier to locate individual files.

Using files

The system is unconcerned with the structure of the information in a file; all it sees is a stream of characters. Individual programs may impose a structure on the file, and you may see references to records and fields within a file, but the file itself is the smallest piece of information that is stored under a name and recognized by the system.

Using directories

A typical system contains many files, perhaps tens of thousands. To keep track of them, they are divided into directories. A directory is an area of the filesystem that is assigned a name; it can contain files and, optionally, directories. By using the name of a directory instead of the name of a file as the parameter of a command, you can make the command operate on all the files stored in that directory simultaneously. The first, top level, directory on the system is called the root directory; all the other directories and files in the system trace their ancestry back to it.

Files belonging to a particular user are usually stored in that user's own directory; those associated with a single project or application are also often stored in a single directory. Users can also create directories within their home directory to store files relating to specific projects. The operating system looks after the organization of system files, but you are responsible for the organization of your own files.

File and directory attributes

The system handles files and directories in the same way; directories are just specialized files, containing other files and directories rather than program code or text. Files and directories both have a name, a path, and a set of attributes. Internally, the system keeps track of files and directories using inodes, or index nodes. See ``How the system manages files and directories''.

A simple way of checking some of the attributes of a file or directory is the long listing, obtained using the -l option to the ls(1) command:

How the system manages files and directories

Internally, the system keeps track of files and directories using inodes. An inode (or index node) is a representation of a file that stores all the data belonging to that file, such as owner, type, size, access permissions, access times and the file's layout on disk. Each inode has a unique number which is used by the system in file handling operations: the filename is simply a device to make the filesystem easier to use for humans. In fact, while a file may have only one inode number, it may have several filenames, these being links to the one inode. See ``Creating links to files and directories'' for more information on links to files and directories.

Filenaming conventions

The maximum permitted length of a file or directory name is 255 characters. In fact, this is controlled by the value of the {NAME_MAX} constant; to check the value of this, use the getconf(1) command, as follows:

   $ getconf NAME_MAX .
Pathnames, which are described in ``How directories are organized'', have a maximum permitted length of 1024 characters (as controlled by {PATH_MAX}, which is also controllable using getconf).

An important consideration, where Open Systems are an issue, is filename portability. Many of the international standards specify a character set that should be used for the construction of portable filenames. The IEEE POSIX standard, for example, specifies the following Portable Filename Character Set:

Portable filenames should not begin with a hyphen, although it may appear in any other position. Specifically, the following characters should not be used in file or directory names because they have a special meaning for the UNIX system:

! " ` ' ; / $ < > ( ) | { } [ ] ~

The slash character (/) signifies both the root directory and the pathname element separator, and is valid only in these contexts. See ``How directories are organized'' for more information on pathnames.

Filenames may begin with a dot (.), but this has the effect of excluding them from normal directory listings. See ``Listing the contents of a directory'' for details of how to list these ``hidden'' files.

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004