UNIX System File Types


The file is the basic unit of the UNIX System. Within UNIX, there are four different types of files: ordinary files, directories, symbolic links, and special files.

Ordinary Files

As a user, most of the information that you work with will be stored as an ordinary file. An ordinary file can contain data, such as text for documents or programs. Image files and binary executables are also examples of ordinary files.

Links

Sometimes it is useful to have a file that is accessible from several directories, without making separate copies of the file. For example, suppose you are working with someone else, and you need to share information contained in a single data file that each of you can update. It would be convenient for each of you to have a copy in your home directory However, you do not want to make separate copies of the file, because it will be hard to keep them in sync.

A link is not a kind of file but instead is a second name for a file. With a link, only one file exists on the disk, but it may appear in two places in the directory structure. This can allow two users to share the same file. Any changes that are made to the file will be seen by both users. This type of link is sometimes called a hard link, to distinguish it from a symbolic link.

Symbolic Links

Hard links can be used to assign more than one name to a file, but they have some important limitations. They cannot be used to give a directory more than one name, and they cannot be used to link files on different computers.

These limitations can be eliminated by using symbolic links (sometimes called symlinks). A symbolic link is a file that only contains the name (including the full pathname) of another file. When the operating system operates on a symbolic link, it is directed to the file that the symbolic link points to. Essentially, the symbolic link is a pointer to the other file. If you are familiar with the Windows operating system, you may be reminded of shortcuts, which are very similar to symbolic links.

Symbolic links can be used to assign more than one name to a file or directory, or to make it possible to access a file from several locations. (For example, you could use a symbolic link to give a short name, like ff, to a file with a long pathname, like /usr/bin/firefox/firefox.) Symbolic links can also be used for files or directories that reside on a different physical file system, such as files on different computers that are connected by a network. (File systems are discussed in detail in Chapter 14.)

Using Links: An Example

Suppose that Rebecca and Nathan are working on a project together, and they need to share the file project.index, which is in Nathan’s home directory Rebecca could make a copy of the file for herself, but then if she makes any changes to the file, Nathan won’t see them in his copy So instead, Rebecca makes a link (a hard link) to that file. Now she has a file called project.index in her home directory, too, even though there is only one copy of the information in that file saved on the disk. This means that if Rebecca makes any changes in the file, Nathan will see those changes, too. However, the file can be found in two different places in the file system-in Nathan’s home directory, and in Rebecca’s. If Nathan deletes the file from his home directory, Rebecca will still have the file in her directory If she deletes her file, too, then it will really be gone.

Now, suppose there is another file in Nathan’s directory they need to share, called project.data. This time, Rebecca makes a symbolic link to the file, and calls it project.data.symlink. Rebecca can still make changes to the file, and Nathan will be able to see them. However, if Nathan deletes the project.data, Rebecca won’t have the file anymore, either. If she tries to use project.data.symlink after the original file is deleted, she will get an error message.

Directories

A directory is actually a type of file too, a file that holds other files. For each directory, the UNIX file system stores a list of all the files and subdirectories that it contains, as well as their file types (whether they are ordinary files, symbolic links, directories, or special files) and other attributes.

Special Files

Special files are an unusual feature of the UNIX file system. A special file represents a physical device, such as a printer or a CD-ROM drive. From the user’s perspective, the file system treats special files just as it does ordinary files. This means that the commands that work on ordinary files also work on special files, so you can read or write to devices exactly the way you read and write to ordinary files. For example, you can use a command to take the characters typed at your keyboard and write them to a text file, or you could use the same command to send them to a printer. The UNIX System causes these read and write commands to activate the hardware connected to the device.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net