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

📄 ch23_12.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 23] 23.12 Using Wildcards to Delete Files with Strange Names </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:41:09Z"><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="ch23_01.htm"TITLE="23. Removing Files"><LINKREL="prev"HREF="ch23_11.htm"TITLE="23.11 Deleting Files with Odd Names "><LINKREL="next"HREF="ch23_13.htm"TITLE="23.13 Deleting Files with the Null Name "></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="ch23_11.htm"TITLE="23.11 Deleting Files with Odd Names "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 23.11 Deleting Files with Odd Names "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 23<BR>Removing Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch23_13.htm"TITLE="23.13 Deleting Files with the Null Name "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 23.13 Deleting Files with the Null Name "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-5960">23.12 Using Wildcards to Delete Files with Strange Names </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-25651"></A>Filenames can be hard to handle if their names include controlcharacters or characters that are special to the shell.Here's a directory with three oddball filenames:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls</B></CODE>What nowa$fileprog|.cprogram.c</PRE></BLOCKQUOTE></P><PCLASS="para">When you type those filenames on the command line, the shell interprets thespecial characters (space, dollar sign, and vertical bar) instead ofincluding them as part of the filename.There are<SPANCLASS="link">several ways (<ACLASS="linkend"HREF="ch23_11.htm"TITLE="Deleting Files with Odd Names ">23.11</A>)</SPAN>to handle this problem.One is with<SPANCLASS="link">wildcards (<ACLASS="linkend"HREF="ch15_02.htm"TITLE="Filename Wildcards in a Nutshell ">15.2</A>)</SPAN>.Type a part of the filename without the weird characters and use a wildcardto match the rest.As article<ACLASS="xref"HREF="ch08_05.htm"TITLE="Command-Line Evaluation ">8.5</A>explains, the shell doesn't scan the filenames for other special charactersafter itinterprets the wildcards, so you're (usually) safe if you can get a wildcardto match.For example, here's how to rename <EMCLASS="emphasis">What&nbsp;now</EM> to <EMCLASS="emphasis">Whatnow</EM>,remove <EMCLASS="emphasis">a$file</EM>, and rename <EMCLASS="emphasis">prog|.c</EM> to <EMCLASS="emphasis">prog.c</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>mv What* Whatnow</B></CODE>% <CODECLASS="userinput"><B>rm -i a*</B></CODE>rm: remove a$file? <CODECLASS="userinput"><B>y</B></CODE>% <CODECLASS="userinput"><B>mv prog?.c prog.c</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Filenames with control characters are just another version ofthe same problem. Use a wildcard to match the part of the namethat's troubling you. The real problem with control characters withfilenames is that some control characters do weird things to yourscreen. Once I accidentally got a file with a CTRL-L in its name.Whenever I ran <EMCLASS="emphasis">ls</EM>, it erased the screen before I could see whatthe filename was!Article<ACLASS="xref"HREF="ch16_14.htm"TITLE="Showing Non-Printable Characters in Filenames ">16.14</A>explains that on a BSD-based UNIX system, you can use<EMCLASS="emphasis">ls -q</EM> instead of a plain <EMCLASS="emphasis">ls</EM>;on System&nbsp;V, use <EMCLASS="emphasis">ls -b</EM>.It should be easy tospot the offensive file and construct a wildcard expression to rename ordelete it.(<EMCLASS="emphasis">ls -q</EM> is the default on many modern BSD UNIXimplementations. So if you're a BSD user, you may never see this problem.)</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</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="ch23_11.htm"TITLE="23.11 Deleting Files with Odd Names "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 23.11 Deleting Files with Odd 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="ch23_13.htm"TITLE="23.13 Deleting Files with the Null Name "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 23.13 Deleting Files with the Null Name "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">23.11 Deleting Files with Odd 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">23.13 Deleting Files with the Null Name </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 + -