📄 306-308.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=306-308//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="303-306.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="308-310.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>Table 16.1 explains the arguments for the <TT>file</TT> command.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 16.1</B> file Command Arguments
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="20%" ALIGN="LEFT">Argument
<TH WIDTH="80%" ALIGN="LEFT">Description
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TD VALIGN="TOP"><TT>-c</TT>
<TD>Prints out the parsed form of the <I>magic file</I> (/usr/lib/magic), which is a number in the first part of a binary file that identifies the file type. This is usually used with <TT>-m</TT> to debug a new magic file before installing it.
<TR>
<TD VALIGN="TOP"><TT>-z</TT>
<TD>Looks inside a compressed file and tries to figure out the file type.
<TR>
<TD><TT>-L</TT>
<TD>Causes symbolic links to be followed.
<TR>
<TD VALIGN="TOP"><TT>-f <I>namefile</I></TT>
<TD>Tells <TT>file</TT> that the list of files to identify is found in <I>namefile</I>, which is a text file. This is useful when many files must be identified.
<TR>
<TD VALIGN="TOP"><TT>-m <I>magicfile</I></TT>
<TD>Specifies an alternative file of magic numbers to use for determining file types. The default file is /usr/lib/magic.
<TR>
<TD><I><TT>filelist</TT></I>
<TD>Lists space-delimited files whose type you want to know.
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">Ordinary Files</FONT></H4>
<P><I>Ordinary files</I> are what you spend most of your time manipulating. Ordinary files can contain text, C language source code, shell scripts (programs interpreted by one of the Linux shells), binary executable programs, and data of various types. As far as Linux is concerned, a file is a file. The only difference that Linux knows is files marked as executable. Executable files can be executed directly—provided, of course, that the file contains something to execute and that it’s in your search path. Basically, the search path is a list of path names you’ve specified that Linux searches to find an executable file.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>• <B>See</B> “Understanding Shells,” <B>p. 339</B><HR></FONT>
</BLOCKQUOTE>
<P>Executable files are binary files—that is, files that execute machine code and shell scripts. The Linux <TT>file</TT> command discussed in the preceding section looks at the data in a file and makes a reasonable guess as to what’s inside. If you type <B><TT>file *</TT></B>, for example, you might see something similar to this:</P>
<!-- CODE //-->
<PRE>
INSTALL: symbolic link to /var/adm
ghostvw.txt: ascii text
linux: symbolic link to /usr/src/linux
mbox: mail text
mterm.txt: English text
seyon.txt: English text
xcalc.txt: English text
xclock.txt: English text
xeyes.txt: English text
xgrap.txt: English text
xlock.txt: English text
xspread.txt: English text
xtris.txt: empty
</PRE>
<!-- END CODE //-->
<P>All the files named in the first column are ordinary files that contain different kinds of data. All the files are located within the directory where the <TT>file</TT> command was executed.</P>
<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077">Directory Files</FONT></H4>
<P><I>Directories</I> are files that contain the names of files and subdirectories, as well as pointers to those files and subdirectories. Directory files are the only place that Linux stores names of files. When you list the contents of a directory with the <TT>ls</TT> command, all you’re doing is listing the contents of the directory file. You never touch the files themselves.</P>
<P>When you rename a file with the <TT>mv</TT> command and that file is in the current directory, all you’re doing is changing the entry in the directory file. If you move a file from one directory to another, all you’re doing is moving the description of the file from one directory file to another—provided, of course, that the new directory is on the same physical disk or partition. If not, Linux physically copies each byte of the program to the other disk.</P>
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Directories and Physical Disks</FONT></H4>
<P>Every file in a Linux system is assigned a unique number called an <I>inode</I>. The inode is stored in a table called the <I>inode table</I>, which is allocated when the disk is formatted. Every physical disk or partition has its own inode table. An inode contains all the information about a file, including the address of the data on the disk and the file type. File types include such things as ordinary files, directories, and special files.</P>
<P>The Linux file system assigns inode number 1 to the root directory. This gives Linux the address on disk of the root directory file. The root directory file contains a list of file and directory names and their respective inode numbers. Linux can find any file in the system by looking up a chain of directories, beginning with the root directory. The contents of the root directory file might look like this:</P>
<!-- CODE SNIP //-->
<PRE>
1 .
1 ..
45 etc
230 dev
420 home
123 .profile
</PRE>
<!-- END CODE SNIP //-->
<P>Notice that the files. (dot) and .. (double dot) are shown in the directory. Because this is the root directory,. and its parent directory, .., are identical. The contents of the /home directory file would be different and might look something like this:
</P>
<!-- CODE SNIP //-->
<PRE>
420 .
1 ..
643 fred
</PRE>
<!-- END CODE SNIP //-->
<P>Notice that the inode of the current directory (.) matches the inode for /home found in the root directory file, and the inode for the parent directory (..) is the same as that of the root directory.
</P>
<P>Linux navigates its file system by chaining up and down the directory file system. If you want to move a file to a directory on another physical disk, Linux detects this by reading the inode table. In such a case, the file is physically moved to the new disk and assigned a new inode on that disk before being deleted from its original location.</P>
<P>As with the <TT>mv</TT> command, when you delete a file with the <TT>rm</TT> command, you never touch the file itself. Instead, Linux marks that inode as free and returns it to the pool of available inodes. The file’s entry in the directory is erased.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>• <B>See</B> “Moving and Renaming Files,” <B>p. 323</B><HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">Links</FONT></H4>
<P><I>Ordinary links</I> aren’t really files at all; they’re actually directory entries that point to the same inode. The inode table keeps track of how many links there are to a file, and only when the last directory reference is deleted is the inode finally released back to the free pool. Obviously, ordinary links can’t cross device boundaries because all the directory references point to the same inode.</P>
<P>To create a link you use the <TT>ln</TT> command, which has the following form:</P>
<!-- CODE SNIP //-->
<PRE>
ln [<I>options</I>] <I>source destination</I>
</PRE>
<!-- END CODE SNIP //-->
<P>For example to create a link between a file named mainfile.txt and a file named tempfile.txt, you would enter the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
ln mainfile.txt tempfile.txt
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="303-306.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="308-310.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 + -