-->
Previous | Table of Contents | Next |
Linux, as well as most modern versions of UNIX, has another kind of link called a symbolic link. For such a link, the directory entry contains the inode of a file that is itself a reference to another file somewhere else in the logical Linux file system. A symbolic link can point to another file or directory on the same disk, another disk, or to a file or directory on another computer.
One major difference between an ordinary link and a symbolic link is that with ordinary links, every link has equal standing (that is, the system treats every link as though it were the original file), and the actual data isnt deleted until the last link to that file is deleted. With symbolic links, when the original file is deleted, all symbolic links to that file are also deleted. Symbolically linked files dont have the same standing as the original file.
To create a symbolic link you use the -s option to the ln command. For example, to create a symbolic link from a file called named in the /etc/rc.d/initd directory to the file S55named, you would use the following command:
ln -s /etc/rc.d/initd/named /etc/rc.d/rc3.d/S55named
Other than these subtle differences between links and files, links are treated and accessed exactly as files are.
You can tell a file is a link by using the ls -l command. If it is a link, the response shows the local filename and then an indication of the linked file like this:
lrwxrwxrwx 1 root root 4 Oct 17 15:27 Info -> info/
The file permission flags begin with l to indicate that the file is a linked file.
Every physical device associated with a Linux system, including disks, terminals, and printers, are represented in the file system. Most, if not all, devices are located in the /dev directory. For example, if youre working on the system console, your associated device is named /dev/console. If youre working on a standard terminal, your device name might be /dev/tty01. Terminals, or serial lines, are called tty devices (which stands for teletype, the original UNIX terminal). To determine what the name of your tty device is, type the command tty. The system responds with the name of the device to which youre connected.
Printers and terminals are called character-special devices. They can accept and produce a stream of characters. Disks, on the other hand, store data in blocks addressed by cylinder and sector. You cant access just one character on a disk; you must read and write entire blocks. The same is usually true of magnetic tapes. This kind of device is called a block-special device. To make life even more complex, disks and other block-special devices must be able to act like character-oriented devices, so every block-special device has a matching character-special device. Linux makes the translation by reading data being sent to a character device and translating it for the block device. This happens without you doing anything.
You might run into at least one other type of special device: a FIFO (first-in-first-out buffer), also known as a named pipe. FIFOs look like ordinary files: If you write to them, they grow. But if you read a FIFO, it shrinks in size. FIFOs are used mainly in system processes to allow many programs to send information to a single controlling process. For example, when you print a file with the lp command, lp sets up the printing process and signals the lpsched daemon by sending a message to a FIFO. A daemon, sometimes called a demon, is a system process that acts without a user requesting an action.
One device-special filethe bit bucket, or /dev/nullis very useful. Anything you send to /dev/null is ignored, which is useful when you dont want to see the output of a command. For example, if you dont want any diagnostic reports printed on the standard error device, you can pour them into the bit bucket with the following command:
ls -la> /dev/null
File permissions mean more in Linux than just what permissions you have on a file or directory. Although permissions determine who can read, write, or execute a file, they also determine the file type and how the file is executed.
You can display the permissions of a file with the long form of the listing command, ls -l. The -l flag tells the ls command to use the long listing. If you type ls -l, you might see a directory listing that looks like this:
Drwx------ 2 sglines doc 512 Jan 1 13:44 Mail Drwx------ 5 sglines doc 1024 Jan 17 08:22 News -rw------- 1 sglines doc 1268 Dec 7 15:01 biblio drwx------ 2 sglines doc 512 Dec 15 21:28 bin -rw------- 1 sglines doc 44787 Oct 20 06:59 books -rw------ 1 sglines doc 23801 Dec 14 22:50 bots.msg -rw-r---- 1 sglines doc 105990 Dec 27 21:24 duckie.gif
This listing shows virtually everything that can be known about a file from the directory entry and the inode of the file. The first column shows the file permissions, the second column shows the number of links to a file (or extra blocks in a directory), and the third column shows who owns the file. (In Linux, ownership has three possibilities: the owner, the owners group, and everyone else. Ownership is detailed later in this chapter.) The fourth column shows the group to which the file belongs. The fifth column shows the number of bytes in the file, the sixth column shows the date and time of creation, and the seventh column shows the name of the file itself.
The permissions field (the first column) can be broken into four distinct subfields:
- rwx rwx rwx
The first subfield defines the file type. A normal file has a hyphen (-) as a placeholder; directories are marked with a d. Table 16.2 shows the permissible values for the file-type subfield.
Character | Meaning |
---|---|
- | Ordinary file |
b | Block-special file |
c | Character-special file |
d | Directory |
l | Symbolic link |
The next three subfields show the read, write, and execute permissions of the file. For example, an rwx in the first of these subfields means that the file has read, write, and execute permission for the owner. The next three characters show the same information for the group ownership of the file. Finally, the third set of characters shows the permissions allowed for everyone else.
Previous | Table of Contents | Next |