ch04_05.htm
来自「unix基础教程」· HTM 代码 · 共 134 行
HTM
134 行
<html><head><title>Command History (UNIX in a Nutshell: System V Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Arnold Robbins" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="1-56592-427-4" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="UNIX in a Nutshell: System V Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Book Title" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch04_04.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch04_06.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">4.5. Command History</h2><p><a name="IXT-4-122798" /><a name="IXT-4-122799" /><a name="IXT-4-122800" />The Korn shell lets you display or modify previous commands.Commands in the history list can be modified using:</p><ul><li><p>Line-edit mode</p></li><li><p>The <tt class="literal">fc</tt> and <tt class="literal">hist</tt> commands</p></li></ul><a name="unut-ch-4-sect-5.1" /><div class="sect2"><h3 class="sect2">4.5.1. Line-Edit Mode</h3><p><a name="IXT-4-122801" />Line-edit mode emulates many features ofthe <tt class="literal">vi</tt> and <tt class="literal">emacs</tt> editors.The history list is treated like a file. When the editoris invoked, you type editing keystrokes to move tothe command line you want to execute. You can alsochange the line before executing it. When you're readyto issue the command, press the Return key.</p><p>Line-edit mode can be started in several ways. For example, these areequivalent:</p><blockquote><pre class="code">$ <tt class="userinput"><b>VISUAL=vi</b></tt>$ <tt class="userinput"><b>EDITOR=vi</b></tt>$ <tt class="userinput"><b>set -o vi</b></tt> <i class="lineannotation">Overrides value of VISUAL or EDITOR</i></pre></blockquote><p>Note that <tt class="literal">vi</tt> starts in input mode;to type a <tt class="literal">vi</tt> command, press the Escape key first.</p><a name="unut-ch-4-sect-5.1.1" /><div class="sect3"><h3 class="sect3">4.5.1.1. Common editing keystrokes</h3><table border="1" cellpadding="3"><tr><th><p><em class="emphasis">vi</em></p></th><th><p><em class="emphasis">emacs</em></p></th><th><p><em class="emphasis">Result</em></p></th></tr><tr><td><p><tt class="literal">k</tt></p></td><td><p><tt class="literal">CTRL-p</tt></p></td><td><p>Get previous command.</p></td></tr><tr><td><p><tt class="literal">j</tt></p></td><td><p><tt class="literal">CTRL-n</tt></p></td><td><p>Get next command.</p></td></tr><tr><td><p><tt class="literal">/</tt><em class="replaceable"><tt>string</tt></em></p></td><td><p><tt class="literal">CTRL-r</tt> <em class="replaceable"><tt>string</tt></em></p></td><td><p>Get previous command containing <em class="emphasis">string</em>.</p></td></tr><tr><td><p><tt class="literal">h</tt></p></td><td><p><tt class="literal">CTRL-b</tt></p></td><td><p>Move back one character.</p></td></tr><tr><td><p><tt class="literal">l</tt></p></td><td><p><tt class="literal">CTRL-f</tt></p></td><td><p>Move forward one character.</p></td></tr><tr><td><p><tt class="literal">b</tt></p></td><td><p><tt class="literal">ESC-b</tt></p></td><td><p>Move back one word.</p></td></tr><tr><td><p><tt class="literal">w</tt></p></td><td><p><tt class="literal">ESC-f</tt></p></td><td><p>Move forward one word.</p></td></tr><tr><td><p><tt class="literal">X</tt></p></td><td><p><tt class="literal">DEL</tt></p></td><td><p>Delete previous character.</p></td></tr><tr><td><p><tt class="literal">x</tt></p></td><td><p><tt class="literal">CTRL-d</tt></p></td><td><p>Delete character under cursor.</p></td></tr><tr><td><p><tt class="literal">dw</tt></p></td><td><p><tt class="literal">ESC-d</tt></p></td><td><p>Delete word forward.</p></td></tr><tr><td><p><tt class="literal">db</tt></p></td><td><p><tt class="literal">ESC-h</tt></p></td><td><p>Delete word backward.</p></td></tr><tr><td><p><tt class="literal">xp</tt></p></td><td><p><tt class="literal">CTRL-t</tt></p></td><td><p>Transpose two characters.</p></td></tr></table><p></div></div><a name="unut-ch-4-sect-5.2" /><div class="sect2"><h3 class="sect2">4.5.2. The fc and hist Commands</h3><p><a name="IXT-4-122802" />Use <tt class="literal">fc -l</tt> to list history commandsand <tt class="literal">fc -e</tt> to edit them. See the entry under "Built-in Commands" for more information.</p><p>In <tt class="literal">ksh93</tt>, the <tt class="literal">fc</tt>command has been renamed <tt class="literal">hist</tt>, and<tt class="literal">alias fc=hist</tt> is predefined.</p><a name="unut-ch-4-sect-5.2.1" /><div class="sect3"><h3 class="sect3">4.5.2.1. Examples</h3><blockquote><pre class="code">$ <tt class="userinput"><b>history</b></tt> <i class="lineannotation">List the last 16 commands</i> $ <tt class="userinput"><b>fc -l 20 30</b></tt> <i class="lineannotation">List commands 20 through 30</i>$ <tt class="userinput"><b>fc -l -5</b></tt> <i class="lineannotation">List the last five commands</i>$ <tt class="userinput"><b>fc -l cat</b></tt> <i class="lineannotation">List the last command beginning with cat</i>$ <tt class="userinput"><b>fc -ln 5 > doit</b></tt> <i class="lineannotation">Save command 5 to file doit.</i> $ <tt class="userinput"><b>fc -e vi 5 20</b></tt> <i class="lineannotation">Edit commands 5 through 20 using vi</i>$ <tt class="userinput"><b>fc -e emacs</b></tt> <i class="lineannotation">Edit previous command using emacs</i>$ <tt class="userinput"><b>r</b></tt> <i class="lineannotation">Reexecute previous command</i>$ <tt class="userinput"><b>r cat</b></tt> <i class="lineannotation">Reexecute last cat command</i>$ <tt class="userinput"><b>r doc=Doc</b></tt> <i class="lineannotation">Substitute, then reexecute last command</i>$ <tt class="userinput"><b>r chap=doc c</b></tt> <i class="lineannotation">Reexecute last command that begins with c, but change string chap to doc</i></pre></blockquote></div></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch04_04.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch04_06.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">4.4. Arithmetic Expressions</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">4.6. Job Control</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2003</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,88,96" href="../index.htm"><area shape="rect" coords="90,0,165,96" href="../upt/index.htm"><area shape="rect" coords="168,1,253,107" href="../mac/index.htm"><area shape="rect" coords="255,0,335,97" href="../korn/index.htm"><area shape="rect" coords="337,0,415,109" href="../unixnut/index.htm"><area shape="rect" coords="417,0,512,122" href="../sedawk/index.htm"><area shape="rect" coords="514,0,605,105" href="../lunix/index.htm"><area shape="rect" coords="611,2,694,121" href="../vi/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?