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

📄 ch16_28.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 16] 16.28 oldlinks: Find Unconnected Symbolic Links </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:38:07Z"><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="ch16_01.htm"TITLE="16. Where Did I Put That?"><LINKREL="prev"HREF="ch16_27.htm"TITLE="16.27 newer: Print the Name of the Newest File "><LINKREL="next"HREF="ch16_29.htm"TITLE="16.29 sls: Super ls with Format You Can Choose "></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="ch16_27.htm"TITLE="16.27 newer: Print the Name of the Newest File "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 16.27 newer: Print the Name of the Newest File "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 16<BR>Where Did I Put That?</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch16_29.htm"TITLE="16.29 sls: Super ls with Format You Can Choose "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 16.29 sls: Super ls with Format You Can Choose "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-4500">16.28 oldlinks: Find Unconnected Symbolic Links </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-17991"></A><ACLASS="indexterm"NAME="AUTOID-17994"></A>One problem with symbolic links is that they're relatively<SPANCLASS="link">&quot;fragile&quot; (<ACLASS="linkend"HREF="ch18_06.htm"TITLE="Stale Symbolic Links ">18.6</A>)</SPAN>.The link and the file itself are different kinds of entities; the linkonly stores the name of the &quot;real&quot; file. Therefore, if you delete orrename the real file, you can be left with a &quot;dead&quot; or &quot;old&quot; link: alink that points to a file that doesn't exist.</P><PCLASS="para">This causes no end of confusion, particularly for new users. Forexample, you'll see things like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls nolink</B></CODE>nolink% <CODECLASS="userinput"><B>cat nolink</B></CODE>cat: nolink: No such file or directory</PRE></BLOCKQUOTE></P><PCLASS="para">The file's obviously there, but <EMCLASS="emphasis">cat</EM> tells you that it doesn'texist.</P><PCLASS="para">There's no real solution to this problem, except to be careful. Oneway to be careful is to write a script that checks links to seewhether or not they exist. Here's one such script from Tom Christiansen;it uses <EMCLASS="emphasis">find</EM> to track down all links, and then uses<SPANCLASS="link"><EMCLASS="emphasis">perl</EM> (<ACLASS="linkend"HREF="ch37_01.htm#UPT-ART-5560"TITLE="What We Do and Don't Tell You About Perl ">37.1</A>)</SPAN>to print the names of links that point to nonexistent files.<ACLASS="indexterm"NAME="AUTOID-18009"></A></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">&#13;#!/bin/shfind . -type l -print | perl -nle '-e || print'</PRE></BLOCKQUOTE></P><PCLASS="para">The script only lists &quot;dead&quot; links; it doesn't try to delete them ordo anything drastic. If you want to take some other action (likedeleting these links automatically),you can use the output of the script in<SPANCLASS="link">backquotes (<ACLASS="linkend"HREF="ch09_16.htm"TITLE="Command Substitution ">9.16</A>)</SPAN>.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>rm `oldlinks`</B></CODE></PRE></BLOCKQUOTE></P><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="ch16_27.htm"TITLE="16.27 newer: Print the Name of the Newest File "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 16.27 newer: Print the Name of the Newest File "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="ch16_29.htm"TITLE="16.29 sls: Super ls with Format You Can Choose "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 16.29 sls: Super ls with Format You Can Choose "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">16.27 newer: Print the Name of the Newest File </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">16.29 sls: Super ls with Format You Can Choose </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 + -