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

📄 ch21_11.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 21] 21.11 Safer Removing, Moving, and Copying </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:40:13Z"><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="ch21_01.htm"TITLE="21. More About Managing Files"><LINKREL="prev"HREF="ch21_10.htm"TITLE="21.10 Keep a Directory Listing at Top of the Screen: dirtop "><LINKREL="next"HREF="ch21_12.htm"TITLE="21.12 Copying Files to a 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="ch21_10.htm"TITLE="21.10 Keep a Directory Listing at Top of the Screen: dirtop "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.10 Keep a Directory Listing at Top of the Screen: dirtop "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 21<BR>More About Managing Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch21_12.htm"TITLE="21.12 Copying Files to a Directory "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.12 Copying Files to a Directory "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0409">21.11 Safer Removing, Moving, and Copying </A></H2><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="rm">rm</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="AUTOID-23515"></A><ACLASS="indexterm"NAME="AUTOID-23518"></A><ACLASS="indexterm"NAME="AUTOID-23520"></A><ACLASS="indexterm"NAME="AUTOID-23524"></A><ACLASS="indexterm"NAME="AUTOID-23527"></A>By default, the UNIX utilities <EMCLASS="emphasis">rm</EM>, <EMCLASS="emphasis">mv</EM>, and <EMCLASS="emphasis">cp</EM>do what you tell them to without asking.If that means overwriting existing files or deleting all the filesin the directory, they'll do it.If you want more safety, you can add aliases like these to your<SPANCLASS="link">shell startup files (<ACLASS="linkend"HREF="ch02_02.htm"TITLE="Shell Setup Files-Which, Where, and Why ">2.2</A>)</SPAN>:</TD></TR></TABLE><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"><BCLASS="emphasis.bold">C shell</B>   <BCLASS="emphasis.bold">ksh</B>, <BCLASS="emphasis.bold">bash</B>alias rm /bin/rm -i   alias rm='/bin/rm -i'alias cp /bin/cp -i   alias cp='/bin/cp -i'alias mv /bin/mv -i   alias mv='/bin/mv -i'</PRE></BLOCKQUOTE></P><PCLASS="para">&#13;(The pathname <CODECLASS="literal">/bin/</CODE> may be different on your system.You may be able to omit it completely, but watch out for alias loops ifyou do.)Then, when you type <CODECLASS="literal">cp</CODE> or <CODECLASS="literal">mv</CODE> at the command line,the command will prompt you before destroying an existing file.And the <CODECLASS="literal">rm</CODE> command will always prompt you before every fileyou ask it to remove (with a wildcard, this can take some time!).<ACLASS="indexterm"NAME="AUTOID-23545"></A><ACLASS="indexterm"NAME="AUTOID-23548"></A><ACLASS="indexterm"NAME="AUTOID-23551"></A><ACLASS="indexterm"NAME="AUTOID-23554"></A><ACLASS="indexterm"NAME="AUTOID-23557"></A><ACLASS="indexterm"NAME="AUTOID-23560"></A>These aliases set the <EMCLASS="emphasis">-i</EM> (interactive) option; most versions of<EMCLASS="emphasis">cp</EM>, <EMCLASS="emphasis">mv</EM>, and <EMCLASS="emphasis">rm</EM> have it.</P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="cp">cp</A><BR><ACLASS="programreference"HREF="examples/index.htm"TITLE="mv">mv</A><BR></TH><TDVALIGN="TOP">&#13;The GNU versions of <EMCLASS="emphasis">cp</EM> and <EMCLASS="emphasis">mv</EM> have <EMCLASS="emphasis">-i</EM> options.They also have an alternative: the <EMCLASS="emphasis">-b</EM> option, which automaticallymakes a backup of any file that will be overwritten.</TD></TR></TABLE><BLOCKQUOTECLASS="note"><PCLASS="para"><STRONG>NOTE:</STRONG> These aliases can be dangerous when you <EMCLASS="emphasis">don't</EM> have them.If you change to a new shell or use another account without thesealiases, you can destroy files before you realize that the aliasesaren't there to protect you.So, I don't use any of these aliases on my account.Instead, I check what I type before I press RETURN.</P></BLOCKQUOTE><PCLASS="para">You can override the alias by typing:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>\rm *.o</B></CODE>   <EMCLASS="emphasis">C shells</EM>$ <CODECLASS="userinput"><B>command rm *.o</B></CODE>   <EMCLASS="emphasis">bash</EM>$ <CODECLASS="userinput"><B>/bin/rm *.o</B></CODE>   <EMCLASS="emphasis">Bourne shells</EM></PRE></BLOCKQUOTE></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="ch21_10.htm"TITLE="21.10 Keep a Directory Listing at Top of the Screen: dirtop "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.10 Keep a Directory Listing at Top of the Screen: dirtop "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="ch21_12.htm"TITLE="21.12 Copying Files to a Directory "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.12 Copying Files to a Directory "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">21.10 Keep a Directory Listing at Top of the Screen: dirtop </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">21.12 Copying Files to a 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 &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 + -