📄 ch01_19.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.19 The Tree Structure of the Filesystem </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:31:23Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch01_01.htm"TITLE="1. Introduction"><LINKREL="prev"HREF="ch01_18.htm"TITLE="1.18 Who Handles Wildcards? "><LINKREL="next"HREF="ch01_20.htm"TITLE="1.20 Your Home Directory "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_18.htm"TITLE="1.18 Who Handles Wildcards? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.18 Who Handles Wildcards? "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 1<BR>Introduction</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_20.htm"TITLE="1.20 Your Home Directory "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.20 Your Home Directory "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1018">1.19 The Tree Structure of the Filesystem </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-1018-IX-TREE-STRUCTURED-FILESYSTEM"></A><ACLASS="indexterm"NAME="UPT-ART-1018-IX-FILESYSTEMS-STRUCTURE-OF"></A><ACLASS="indexterm"NAME="UPT-ART-1018-IX-HIERARCHICAL-FILESYSTEMS"></A>A multiuser system needs a way to let different users have differentfiles with the same name. It also needs a way to keep files inlogical groups. With thousands of system files and hundreds of filesper user, it would be disastrous to have all of the files in onebig heap. Even single-user operating systems have found it necessaryto go beyond "flat" filesystem structures.</P><PCLASS="para">Almost every operating system solved this problem by implementinga tree-structured, or <EMCLASS="emphasis">hierarchical</EM>, filesystem. UNIX is noexception. A hierarchical filesystem is not much different from a setof filing cabinets at the office. Your set of cabinets consists ofmany individual cabinets. Each individual cabinet has severaldrawers; each drawer may have several partitions in it; each partitionmay have several hanging (Pendaflex) folders; and each hanging folder may haveseveral files. You can specify an individual file by naming thefiling cabinet, the drawer, the partition, the group of folders, andthe individual folder. For example, you might say to someone:"Get me the `meeting of July 9' file from the Kaiser folder inthe Medical Insurance Plans partition in the Benefits drawer of thePersonnel file cabinet." This is backwards from the way you'd specify afilename, because it starts with the most specific part,but the idea is essentially the same.</P><PCLASS="para">You could give a complete path like this to any file in any of yourcabinets, as shown in<ACLASS="xref"HREF="ch01_19.htm#UPT-ART-1018-FIG-0"TITLE="A Hierarchical Filesystem">Figure 1.2</A>.The concept of a "path" lets you distinguish your July 9meeting with Kaiser from yourJuly 9 interview with a job applicant or your July 9 policyplanning meeting. It also lets you keep related topics together: it'seasy to browse through the "Medical Insurance" section of one draweror to scan all your literature and notes about the Kaiser plan.The UNIX filesystem works in exactly the same way (as do most otherhierarchical filesystems). Rather than having a heap of assorted<ACLASS="indexterm"NAME="AUTOID-1859"></A>files, files are organized into <EMCLASS="emphasis">directories</EM>. A directory isreally nothing more than a special kind of file that lists a bunch ofother files (see article<ACLASS="xref"HREF="ch18_02.htm"TITLE="What's Really in a Directory ">18.2</A>).A directory can contain any number of files (althoughfor performance reasons, it's a good idea to keep the number of filesin one directory relatively small - under 100, when you can). A directory canalso contain other directories. Because a directory is nothing more than aspecial kind of file, directories also have names. At the top (thefilesystem "tree" is really upside down) is a directory called the"root," which has the<ACLASS="indexterm"NAME="AUTOID-1864"></A><ACLASS="indexterm"NAME="AUTOID-1866"></A>special name <CODECLASS="literal">/</CODE> (pronounced "slash,"but never spelled out).</P><H4CLASS="figure"><ACLASS="title"NAME="UPT-ART-1018-FIG-0">Figure 1.2: A Hierarchical Filesystem</A></H4><IMGCLASS="graphic"SRC="figs/1018a.gif"ALT="Figure 1.2"><PCLASS="para">To locate any file, we can give a sequence of names, starting from thefilesystem's root, that shows its exact position in the filesystem: westart with the root and then list the directories you go through tofind the file, separating them by slashes. This is called a <EMCLASS="emphasis">path</EM>.For examples, let's look at the simple filesystem represented by<ACLASS="xref"HREF="ch01_19.htm#UPT-ART-1018-FIG-1"TITLE="A UNIX Filesystem Tree">Figure 1.3</A>.The names <EMCLASS="emphasis">/home/mkl/mystuff/stuff</EM> and<EMCLASS="emphasis">/home/hun/publick/stuff</EM> both refer to files named <EMCLASS="emphasis">stuff</EM>.However, these files are in different directories, so they aredifferent files. The names <EMCLASS="emphasis">home</EM>, <EMCLASS="emphasis">hun</EM>, and so on are allnames of directories. Complete paths like these are called"absolute paths." There are shorter ways to refer to a file called <SPANCLASS="link">relative paths (<ACLASS="linkend"HREF="ch01_21.htm"TITLE="Making Pathnames ">1.21</A>)</SPAN>. </P><H4CLASS="figure"><ACLASS="title"NAME="UPT-ART-1018-FIG-1">Figure 1.3: A UNIX Filesystem Tree</A></H4><IMGCLASS="graphic"SRC="figs/1018b.gif"ALT="Figure 1.3"><ACLASS="indexterm"NAME="AUTOID-1885"></A><ACLASS="indexterm"NAME="AUTOID-1886"></A><ACLASS="indexterm"NAME="AUTOID-1887"></A><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_18.htm"TITLE="1.18 Who Handles Wildcards? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.18 Who Handles Wildcards? "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_20.htm"TITLE="1.20 Your Home Directory "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.20 Your Home Directory "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.18 Who Handles Wildcards? </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">1.20 Your Home Directory </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -