⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18_04.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<EMCLASS="emphasis">file</EM> and <EMCLASS="emphasis">hardlink</EM> is the same;that's because they both refer to exactly the same file, with two links (names).</P><PCLASS="para">A symbolic link has an <CODECLASS="literal">l</CODE> at the start ofthe permissions field.Its i-number isn't the same as the file it points tobecause a symbolic link takes a separateinode; so, it also takes disk space (which an extra hard link doesn't).The name has two parts: the name of the link (here, <EMCLASS="emphasis">symlink</EM>) followedby an arrow and the name the link points to (in this case, to <EMCLASS="emphasis">file</EM>).The symlink takes just 4 characters, which is exactly enough to store thepathname (<CODECLASS="literal">file</CODE>) that the link points to.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-7944-SECT-1.2">18.4.2 Links to a Directory </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-20311"></A><ACLASS="indexterm"NAME="AUTOID-20314"></A>While we're at it, here's a section that isn't aboutlinking to files or making symbolic links.Let's look at the first two entries in the previous sample directoryin terms of links and link counts.This should help to tie the filesystem together (both literally and in yourmind!).</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-20318"></A><ACLASS="indexterm"NAME="AUTOID-20321"></A>You've seen <CODECLASS="literal">.</CODE> and <CODECLASS="literal">..</CODE> in<SPANCLASS="link">pathnames (<ACLASS="linkend"HREF="ch01_21.htm"TITLE="Making Pathnames ">1.21</A>)</SPAN>;you might also have read an<SPANCLASS="link">explanation of what's in a directory (<ACLASS="linkend"HREF="ch18_02.htm"TITLE="What's Really in a Directory ">18.2</A>)</SPAN>.The <CODECLASS="literal">.</CODE> entry is a link to the current directory; notice that itslink count is 2.Where's the other link?It's in the parent directory:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">$ <CODECLASS="userinput"><B>ls -li ..</B></CODE>total 2 140330 drwxr-xr-x   2 jerry    ora      1024 Aug 18 10:11 sub  85524 drwxr-xr-x   2 jerry    ora      1024 Aug 18 10:47 sub2</PRE></BLOCKQUOTE></P><PCLASS="para">Look at the i-numbers for the entries in the parent directory.Which entry is for our current directory?The entry for <EMCLASS="emphasis">sub</EM> has the i-number 140330, and so doesthe <CODECLASS="literal">.</CODE> listing in the current directory.So the current directory is named <EMCLASS="emphasis">sub</EM>.</P><PCLASS="para">Now you should be able see why every directory has at least two links.One link, named <CODECLASS="literal">.</CODE>, is to the directory itself.The other link, in its parent, gives the directory its name.(Article<ACLASS="xref"HREF="ch14_04.htm"TITLE="How Does UNIX Find Your Current Directory? ">14.4</A>has a picture of this.)</P><PCLASS="para">Every directory has a <CODECLASS="literal">..</CODE> entry, which isa link to its parent directory.If you look back at the listing of our current directory,you can see that the parent directory has four links.Where are they?Think for a minute.(No fair peeking ahead!)</P><PCLASS="para">Bzzzzzzt... time's up.<ACLASS="indexterm"NAME="AUTOID-20342"></A>When a directory has subdirectories, it will also have a hard link named<CODECLASS="literal">..</CODE> in each subdirectory.You can see above, in the output from <CODECLASS="literal">ls&nbsp;-li&nbsp;..</CODE>, that the parentdirectory has two subdirectories:<EMCLASS="emphasis">sub</EM> and <EMCLASS="emphasis">sub2</EM>.That's two of the four links.The other two links arethe <CODECLASS="literal">.</CODE> entry in the parent directory,and the entry for the parent directory (which is named <EMCLASS="emphasis">test</EM>)in <EMCLASS="emphasis">its</EM> parent directory:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch16_08.htm"TITLE="16.8 The ls -d Option ">-d</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls -dli ../. ../../test</B></CODE>  85523 drwxr-xr-x   4 jerry    ora      1024 Aug 18 10:47 ../.  85523 drwxr-xr-x   4 jerry    ora      1024 Aug 18 10:47 ../../test</PRE></TD></TR></TABLE></P><PCLASS="para">As they should, all the links have the same i-number: 85523.Make sense?This concept can be a little abstract and hard to follow at first.Understanding it will help you, though&nbsp;- especially if you're a systemadministrator who has to use strong medicine like <SPANCLASS="link"><EMCLASS="emphasis">clri</EM> (<ACLASS="linkend"HREF="ch23_13.htm"TITLE="Deleting Files with the Null Name ">23.13</A>)</SPAN>.For more practice, make a subdirectory and experiment in it the waywe've shown in this article.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-20361"></A>By the way, directories and their hard links <CODECLASS="literal">.</CODE> and <CODECLASS="literal">..</CODE>are added by the <EMCLASS="emphasis">mkdir</EM>(2) system call.That's the only way that normal users can create a directory (and thelinks to it).Article<ACLASS="xref"HREF="ch23_18.htm"TITLE="How Making and Deleting Directories Works ">23.18</A>has even more low-level details.</P></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN>, <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="ch18_03.htm"TITLE="18.3 Files with Two or More Names"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 18.3 Files with Two or More Names"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="ch18_05.htm"TITLE="18.5 Creating and Removing Links "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 18.5 Creating and Removing Links "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">18.3 Files with Two or More Names</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">18.5 Creating and Removing Links </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 &amp; 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 + -