📄 308-310.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Understanding the File and Directory System</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=16//-->
<!--PAGES=308-310//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="306-308.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="311-314.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>Linux, as well as most modern versions of UNIX, has another kind of link called a <I>symbolic link</I>. 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.</P>
<P>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 isn’t 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 don’t have the same standing as the original file.</P>
<P>To create a symbolic link you use the <TT>-s</TT> option to the <TT>ln</TT> 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:</P>
<!-- CODE SNIP //-->
<PRE>
ln -s /etc/rc.d/initd/named /etc/rc.d/rc3.d/S55named
</PRE>
<!-- END CODE SNIP //-->
<P>Other than these subtle differences between links and files, links are treated and accessed exactly as files are.
</P>
<P>You can tell a file is a link by using the <TT>ls -l</TT> command. If it is a link, the response shows the local filename and then an indication of the linked file like this:</P>
<!-- CODE SNIP //-->
<PRE>
lrwxrwxrwx 1 root root 4 Oct 17 15:27 Info -> info/
</PRE>
<!-- END CODE SNIP //-->
<P>The file permission flags begin with <TT>l</TT> to indicate that the file is a linked file.</P>
<H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">Special Files</FONT></H4>
<P>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 you’re working on the system console, your associated device is named /dev/console. If you’re working on a standard terminal, your device name might be /dev/tty01. Terminals, or serial lines, are called <I>tty devices</I> (which stands for <I>teletype</I>, the original UNIX terminal). To determine what the name of your tty device is, type the command <B><TT>tty</TT></B>. The system responds with the name of the device to which you’re connected.</P>
<P>Printers and terminals are called <I>character-special devices.</I> They can accept and produce a stream of characters. Disks, on the other hand, store data in blocks addressed by cylinder and sector. You can’t 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 <I>block-special device.</I> 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.</P>
<P>You might run into at least one other type of special device: a FIFO (first-in-first-out buffer), also known as a <I>named pipe.</I> 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 <TT>lp</TT> command, <TT>lp</TT> sets up the printing process and signals the <TT>lpsched</TT> daemon by sending a message to a FIFO. A <I>daemon</I>, sometimes called a <I>demon</I>, is a system process that acts without a user requesting an action.</P>
<P>One device-special file—the bit bucket, or /dev/null—is very useful. Anything you send to <TT>/dev/null</TT> is ignored, which is useful when you don’t want to see the output of a command. For example, if you don’t want any diagnostic reports printed on the standard error device, you can pour them into the bit bucket with the following command:</P>
<!-- CODE SNIP //-->
<PRE>
ls -la> /dev/null
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">File Permissions</FONT></H4>
<P>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.
</P>
<P>You can display the permissions of a file with the long form of the listing command, <TT>ls -l.</TT> The <TT>-l</TT> flag tells the <TT>ls</TT> command to use the long listing. If you type <B><TT>ls -l</TT></B>, you might see a directory listing that looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
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
</PRE>
<!-- END CODE SNIP //-->
<P>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 owner’s 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.
</P>
<P>The permissions field (the first column) can be broken into four distinct subfields:</P>
<!-- CODE SNIP //-->
<PRE>
- rwx rwx rwx
</PRE>
<!-- END CODE SNIP //-->
<P>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.
</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 16.2</B> Valid Entries for the File-Type Subfield
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="25%" ALIGN="LEFT">Character
<TH WIDTH="75%" ALIGN="LEFT">Meaning
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TD>-
<TD>Ordinary file
<TR>
<TD>b
<TD>Block-special file
<TR>
<TD>c
<TD>Character-special file
<TR>
<TD>d
<TD>Directory
<TR>
<TD>l
<TD>Symbolic link
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P>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.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="306-308.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="311-314.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -