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

📄 ch11_01.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 11] The Lessons of History</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:36:03Z"><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="part02.htm"TITLE="II. Let the Computer Do the Dirty Work "><LINKREL="prev"HREF="ch10_10.htm"TITLE="10.10 Simulated Bourne Shell Functions and Aliases "><LINKREL="next"HREF="ch11_02.htm"TITLE="11.2 History in a Nutshell "></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="ch10_10.htm"TITLE="10.10 Simulated Bourne Shell Functions and Aliases "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 10.10 Simulated Bourne Shell Functions and Aliases "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 11</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch11_02.htm"TITLE="11.2 History in a Nutshell "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 11.2 History in a Nutshell "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="CHAPTER"><H1CLASS="chapter"><ACLASS="title"NAME="UPT-CHP-11">11. The Lessons of History</A></H1><DIVCLASS="htmltoc"><P><B>Contents:</B><BR><ACLASS="sect1"HREF="#UPT-ART-4920"TITLE="11.1 The Lessons of History ">The Lessons of History </A><BR><ACLASS="sect1"HREF="ch11_02.htm"TITLE="11.2 History in a Nutshell ">History in a Nutshell </A><BR><ACLASS="sect1"HREF="ch11_03.htm"TITLE="11.3 My Favorite Is !$ ">My Favorite Is !$ </A><BR><ACLASS="sect1"HREF="ch11_04.htm"TITLE="11.4 My Favorite Is !:n* ">My Favorite Is !:n* </A><BR><ACLASS="sect1"HREF="ch11_05.htm"TITLE="11.5 My Favorite Is ^^ ">My Favorite Is ^^ </A><BR><ACLASS="sect1"HREF="ch11_06.htm"TITLE="11.6 Using !$ for Safety with Wildcards ">Using !$ for Safety with Wildcards </A><BR><ACLASS="sect1"HREF="ch11_07.htm"TITLE="11.7 History Substitutions ">History Substitutions </A><BR><ACLASS="sect1"HREF="ch11_08.htm"TITLE="11.8 Repeating a Cycle of Commands ">Repeating a Cycle of Commands </A><BR><ACLASS="sect1"HREF="ch11_09.htm"TITLE="11.9 Running a Series of Commands on a File ">Running a Series of Commands on a File </A><BR><ACLASS="sect1"HREF="ch11_10.htm"TITLE="11.10 Check Your History First with :p ">Check Your History First with :p </A><BR><ACLASS="sect1"HREF="ch11_11.htm"TITLE="11.11 Picking Up Where You Left Off ">Picking Up Where You Left Off </A><BR><ACLASS="sect1"HREF="ch11_12.htm"TITLE="11.12 Pass History to Another Shell ">Pass History to Another Shell </A><BR><ACLASS="sect1"HREF="ch11_13.htm"TITLE="11.13 Shell Command-Line Editing ">Shell Command-Line Editing </A><BR><ACLASS="sect1"HREF="ch11_14.htm"TITLE="11.14 More Ways to Do Interactive History Editing ">More Ways to Do Interactive History Editing </A><BR><ACLASS="sect1"HREF="ch11_15.htm"TITLE="11.15 Changing C Shell History Characters with histchars ">Changing C Shell History Characters with histchars </A><BR><ACLASS="sect1"HREF="ch11_16.htm"TITLE="11.16 Instead of Changing History Characters ">Instead of Changing History Characters </A></P><P></P></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-4920">11.1 The Lessons of History </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-4920-IX-HISTORY-OF-COMMAND-HISTORY-SUBSTITUTIONS"></A><ACLASS="indexterm"NAME="UPT-ART-4920-IX-HISTORY-OF-COMMAND"></A>It has been said that &quot;the only thing we learn from history is thatpeople don't learn from history.&quot;</P><PCLASS="para">Fortunately, the original maxim that &quot;history repeats itself&quot; is moreappropriate to UNIX.</P><PCLASS="para">Most shells include a powerful history mechanism thatlets you recall and repeat past commands, potentially editingthem before execution.This can be a godsend, especially when typinga long or complex command.</P><PCLASS="para">All that is needed to set C shell history in motion is a command like thisin your <EMCLASS="emphasis">.cshrc</EM> file: </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">set history=<CODECLASS="replaceable"><I>n</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-12312"></A><ACLASS="indexterm"NAME="AUTOID-12314"></A>where <CODECLASS="replaceable"><I>n</I></CODE> is the number of pastcommands that you want to save.In <EMCLASS="emphasis">ksh</EM> and <EMCLASS="emphasis">bash</EM>, the variable is <EMCLASS="emphasis">HISTSIZE</EM>, and it'salready set for you; the default values are 128 and 500, respectively.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-12321"></A>The <EMCLASS="emphasis">history</EM> command lists the saved commands, each with anidentifying number.[In <EMCLASS="emphasis">csh</EM> and <EMCLASS="emphasis">bash</EM>,you can show just the last few commands by typing a number, too.For instance, <EMCLASS="emphasis">history&nbsp;20</EM> shows your last 20 commands. <EMCLASS="emphasis">-JP</EM>&nbsp;](It's also possible to configure the shellsto print the history number of each command<SPANCLASS="link">as part of your prompt (<ACLASS="linkend"HREF="ch07_02.htm"TITLE="Basics of Setting the Prompt ">7.2</A>)</SPAN>.)</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-12330"></A><ACLASS="indexterm"NAME="AUTOID-12333"></A>In <EMCLASS="emphasis">csh</EM> and <EMCLASS="emphasis">bash</EM>,you can repeat a past command by typing itsnumber (or its name) preceded by an exclamation point (<CODECLASS="literal">!</CODE>).You can also select onlyparts of the command to be repeated, and use various editingoperators to modify it.Articles<ACLASS="xref"HREF="ch11_07.htm"TITLE="History Substitutions ">11.7</A>and<ACLASS="xref"HREF="ch09_06.htm"TITLE="String Editing (Colon) Operators ">9.6</A>give quick tutorial summaries of some of the wonderful things you can do.Most of the rest of the chapter gives a miscellanyof tipsfor using and abusing the shells' history mechanism.</P><PCLASS="para">Most shells&nbsp;- except the original Bourne and C shells&nbsp;- also have<ACLASS="indexterm"NAME="AUTOID-12342"></A><SPANCLASS="link">interactive command-line editing (<ACLASS="linkend"HREF="ch11_13.htm"TITLE="Shell Command-Line Editing ">11.13</A>)</SPAN>.[Interactive editing might seem to be better than typing<CODECLASS="literal">!vi</CODE> or <CODECLASS="literal">lpr&nbsp;!$</CODE>.If you learn both systems, though, you'll find plenty of cases where the<CODECLASS="literal">!</CODE> system is faster and more useful than interactive editing. <EMCLASS="emphasis">-JP</EM>]</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</SPAN></P></DIV></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="ch10_10.htm"TITLE="10.10 Simulated Bourne Shell Functions and Aliases "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 10.10 Simulated Bourne Shell Functions and Aliases "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="ch11_02.htm"TITLE="11.2 History in a Nutshell "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 11.2 History in a Nutshell "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">10.10 Simulated Bourne Shell Functions and Aliases </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">11.2 History in a Nutshell </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 + -