What are files and directories in computer?

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:

  • The first field (file type) indicates the sort of file that is present in the listing. The following codes are some of those used (for a full list, see ls(1)):
    - ordinary file
    b block special file
    c character special file
    d directory
    l symbolic link
    p named pipe

  • The second field (permissions) shows who is permitted to read, write, or execute a file, or change to a directory. Users are split into the file's owner, people in the same work group as the owner, and other people. A separate set of permissions is maintained for each category. The notation used here is explained in detail in ``Access control for files and directories''.

  • The third field (links) shows the number of links that exist for the file (links are discussed in ``Creating links to files and directories'' ).

  • The fourth field (owner) shows the login name of the owner of the file.

  • The fifth field (group) shows the group to which the file belongs; that is, the group of users who have ``group'' access permission to the file. See ``Finding out your group'' for an explanation of groups.

  • The sixth field (size) shows the number of bytes in the file.

  • The seventh and eighth fields (date and time of last modification) show the date and time when the file was last modified.

  • The final field (filename) shows the name of the file. See ``Filenaming conventions'' for more on filenames.

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 . 255 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:

  • the uppercase letters (A-Z)

  • the lowercase letters (a-z)

  • the decimal digits (0-9)

  • the dot (.), the hyphen (-) and the underscore (_)

  • the slash (/): this is a special case which is discussed below
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