?? _chapter 9.htm
字號(hào):
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<p class="docText">The history list is displayed in reverse order.</td>
</tr>
</table>
<h5 id="ch09list17" class="docExampleTitle">Example 9.17 </h5>
<pre>% <span class="docEmphStrong">history 5</span> <span class="docEmphasis"># Prints the last 5 events on the history list</span>
<span class="docEmphasis">7 echo $USER</span>
<span class="docEmphasis">8 cd</span>
<span class="docEmphasis">9 set</span>
<span class="docEmphasis">10 history 杗</span>
<span class="docEmphasis">11 history 5</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<p class="docText">The last five commands on the history list are displayed.</td>
</tr>
</table>
<p class="docText"><b>Reexecuting Commands.</b> To reexecute a command from the
history list, the exclamation point (bang) is used. If you type two exclamation
points (!!), the last command is reexecuted. If you type the exclamation point
followed by a number, the number is associated with the command from the history
list and the command is executed. If you type an exclamation point and a letter,
the last command that started with that letter is executed. The caret (^) is
also used as a shortcut method for editing the previous command.</p>
<h5 id="ch09list18" class="docExampleTitle">Example 9.18 </h5>
<pre>1 % <span class="docEmphStrong">date</span>
<span class="docEmphasis">Mon Feb 8 12:27:35 PST 2001</span>
2 % <span class="docEmphStrong">!!</span>
<span class="docEmphasis">date</span>
<span class="docEmphasis">Mon Feb 8 12:28:25 PST 2001</span>
3 % <span class="docEmphStrong">!3</span>
<span class="docEmphasis">date</span>
<span class="docEmphasis">Mon Feb 8 12:29:26 PST 2001</span>
4 % <span class="docEmphStrong">!d</span>
<span class="docEmphasis">date</span>
<span class="docEmphasis">Mon Feb 8 12:30:09 PST 2001</span>
5 % <span class="docEmphStrong">dare</span>
<span class="docEmphasis">dare: Command not found.</span>
6 % <span class="docEmphStrong">^r^t</span>
<span class="docEmphasis">date</span>
<span class="docEmphasis">Mon Feb 8 12:33:25 PST 2001</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The UNIX <span class="docEmphasis">date</span> command
is executed at the command line. The history list is updated. This is the
last command on the list.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">!!</span> (bang bang)
gets the last command from the history list; the command is reexecuted.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The third command on the history list is reexecuted.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The last command on the history list that started with
the letter <span class="docEmphasis">d</span> is reexecuted.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The command is mistyped.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The carets are used to substitute letters from the last
command on the history list. The first occurrence of an
<span class="docEmphasis">r</span> is replaced with a
<span class="docEmphasis">t.</span></span></li>
</ol>
</span></td>
</tr>
</table>
<h5 id="ch09list19" class="docExampleTitle">Example 9.19 </h5>
<pre>1 % <span class="docEmphStrong">cat file1 file2 file3</span>
<span class="docEmphasis"><Contents of files displayed here></span>
% <span class="docEmphStrong">vi !:1</span>
<span class="docEmphasis">vi file1</span>
2 % <span class="docEmphStrong">cat file1 file2 file3</span>
<span class="docEmphasis"><Contents of file, file2, and file3 are displayed here></span>
% <span class="docEmphStrong">ls !:2</span>
<span class="docEmphasis">ls file2</span>
<span class="docEmphasis">file2</span>
3 % <span class="docEmphStrong">cat file1 file2 file3</span>
% <span class="docEmphStrong">ls !:3</span>
<span class="docEmphasis">ls file3</span>
<span class="docEmphasis">file3</span>
4 % <span class="docEmphStrong">echo a b c</span>
<span class="docEmphasis">a b c</span>
% <span class="docEmphStrong">echo !$</span>
<span class="docEmphasis">echo c</span>
<span class="docEmphasis">c</span>
5 % <span class="docEmphStrong">echo a b c</span>
<span class="docEmphasis">a b c</span>
% <span class="docEmphStrong">echo !^</span>
<span class="docEmphasis">echo a</span>
<span class="docEmphasis">a</span>
6 % <span class="docEmphStrong">echo a b c</span>
<span class="docEmphasis">a b c</span>
% <span class="docEmphStrong">echo !*</span>
<span class="docEmphasis">echo a b c</span>
<span class="docEmphasis">a b c</span>
7 % <span class="docEmphStrong">!!:p</span>
<span class="docEmphasis">echo a b c</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">cat</span> command
displays the contents of <span class="docEmphasis">file1</span> to the
screen. The history list is updated. The command line is broken into
words, starting with word number zero. If the word number is preceded by a
colon, that word can be extracted from the history list. The
<span class="docEmphasis">!:1</span> notation means,
<span class="docEmphasis">get the first argument from the last command on
the history list and replace it in the command string.</span> The first
argument from the last command is <span class="docEmphasis">file1.</span>
(Word <span class="docEmphasis">0</span> is the command itself.)</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">!:2</span> is replaced
with the second argument of the last command, <span class="docEmphasis">
file2,</span> and given as an argument to <span class="docEmphasis">ls.
file2</span> is printed. (<span class="docEmphasis">file2</span> is the
third word.)</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList"><span class="docEmphasis">ls !:3</span> reads,
<span class="docEmphasis">go to the last command on the history list and
get the fourth word (words start at zero) and pass it to the</span> ls
<span class="docEmphasis">command as an argument</span> (<span class="docEmphasis">file3</span>
is the fourth word).</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The bang (<span class="docEmphasis">!</span>) with the
dollar sign (<span class="docEmphasis">$</span>) refers to the last
argument of the last command on the history list. The last argument is
<span class="docEmphasis">c.</span></span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The caret (<span class="docEmphasis">^</span>)
represents the first argument after the command. The bang (<span class="docEmphasis">!</span>)
with the <span class="docEmphasis">^</span> refers to the first argument
of the last command on the history list. The first argument of the last
command is <span class="docEmphasis">a.</span></span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The asterisk (<span class="docEmphasis">*</span>)
represents all arguments after the command. The bang (<span class="docEmphasis">!</span>)
with the <span class="docEmphasis">*</span> refers to all of the arguments
of the last command on the history list.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The last command from the history list is printed but
not executed. The history list is updated. You could now perform caret
substitutions on that line.</span></li>
</ol>
</span></td>
</tr>
</table>
<h4 class="docSection2Title" id="ch09lev2sec5">9.1.5 Aliases</h4>
<p class="docText">An <span class="docEmphasis">alias</span> is a C shell
user-defined abbreviation for a command. Aliases are useful when a command has a
number of options and arguments or the syntax is difficult to remember. Aliases
set at the command line are not inherited by subshells. Aliases are normally set
in the <span class="docEmphasis">.cshrc</span> file. Since the
<span class="docEmphasis">.cshrc</span> is executed when a new shell is started,
any aliases set there will get reset for the new shell. Aliases may also be
passed into shell scripts, but will cause potential portability problems unless
they are directly set within the script.</p>
<p class="docText"><b>Listing Aliases.</b> The <span class="docEmphasis">alias</span>
built-in command lists all set aliases. The alias is printed first, followed by
the real command or commands it represents.</p>
<h5 id="ch09list20" class="docExampleTitle">Example 9.20 </h5>
<pre>% <span class="docEmphStrong">alias</span>
<span class="docEmphasis">co compress</span>
<span class="docEmphasis">cp cp 杋</span>
<span class="docEmphasis">ls1 enscript 朆 杛 朠orange 杅 Courier8 !* &</span>
<span class="docEmphasis">mailq /usr/lib/sendmail 朾p</span>
<span class="docEmphasis">mroe more</span>
<span class="docEmphasis">mv mv 杋</span>
<span class="docEmphasis">rn /usr/spool/news/bin/rn3</span>
<span class="docEmphasis">uc uncompress</span>
<span class="docEmphasis">uu uudecode</span>
<span class="docEmphasis">vg vgrind 杢 杝11 !:1 | lpr 杢</span>
<span class="docEmphasis">weekly (cd /home/jody/ellie/activity; ./weekly_report; echo Done)</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<p class="docText">The <span class="docEmphasis">alias</span> command lists
the alias (nickname) for the command in the first column and the real
command the alias represents in the second column.</td>
</tr>
</table>
<p class="docText"><b>Creating Aliases.</b> The <span class="docEmphasis">alias</span>
command is used to create an alias. The first argument is the name of the alias,
the nickname for the command. The rest of the line consists of the command or
commands that will be executed when the alias is executed. Multiple commands are
separated by a semicolon, and commands containing spaces and metacharacters are
surrounded by single quotes.</p>
<h5 id="ch09list21" class="docExampleTitle">Example 9.21 </h5>
<pre>1 % <span class="docEmphStrong">alias m more</span>
2 % <span class="docEmphStrong">alias mroe more</span>
3 % <span class="docEmphStrong">alias lF 'ls -alF'</span>
4 % <span class="docEmphStrong">alias cd 'cd \!*; set prompt = "$cwd >"'</span>
% <span class="docEmphStrong">cd ..</span>
/home/jody > <span class="docEmphBoldItalic">cd /</span> <span class="docEmphasis"># New prompt displayed</span>
<span class="docEmphStrong">/ ></span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The nickname for the <span class="docEmphasis">more</span>
command is set to <span class="docEmphasis">m.</span></span></li>
<li><span style="FONT-WEIGHT: normal">
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -