📄 ch12.htm
字号:
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<H1></H1>
<UL>
<LI><A HREF="#Heading1">- 12 -</A>
<UL>
<LI><A HREF="#Heading2">tcsh</A>
<UL>
<LI><A HREF="#Heading3">An Introduction to tcsh</A>
<LI><A HREF="#Heading4">Command Completion</A>
<LI><A HREF="#Heading5">Wildcards</A>
<LI><A HREF="#Heading6">Command History</A>
<LI><A HREF="#Heading7">NOTE</A>
<LI><A HREF="#Heading8">NOTE</A>
<LI><A HREF="#Heading9">Aliases</A>
<LI><A HREF="#Heading10">NOTE</A>
<LI><A HREF="#Heading11">Input and Output Redirection</A>
<LI><A HREF="#Heading12">CAUTION</A>
<LI><A HREF="#Heading13">Pipelines</A>
<LI><A HREF="#Heading14">Prompts</A>
<LI><A HREF="#Heading15">Job Control</A>
<LI><A HREF="#Heading16">Key Bindings</A>
<LI><A HREF="#Heading17">Other Neat Stuff</A>
<UL>
<LI><A HREF="#Heading18">Correcting Spelling Errors</A>
<LI><A HREF="#Heading19">Precommands</A>
<LI><A HREF="#Heading20">Change Directory Commands</A>
</UL>
<LI><A HREF="#Heading21">WARNING</A>
<UL>
<LI><A HREF="#Heading22">Monitoring Logins and Logouts</A>
</UL>
<LI><A HREF="#Heading23">Customizing tcsh</A>
<LI><A HREF="#Heading24">tcsh Command Summary</A>
<LI><A HREF="#Heading25">tcsh Variables</A>
<LI><A HREF="#Heading26">Summary</A>
</UL>
</UL>
</UL>
<P>
<HR SIZE="4">
<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 12 -</FONT></H2>
<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">tcsh</FONT></H2>
<P><I>by Rick McMullin</I></P>
<P>IN THIS CHAPTER</P>
<UL>
<LI>An Introduction to tcsh<TT> </TT>
<P>
<LI>Command Completion
<P>
<LI>Wildcards
<P>
<LI>Command History
<P>
<LI>Aliases
<P>
<LI>Input and Output Redirection
<P>
<LI>Pipelines
<P>
<LI>Prompts
<P>
<LI>Job Controls
<P>
<LI>Key Bindings
<P>
<LI>Other Neat Stuff
<P>
<LI>Customizing tcsh<TT> </TT>
<P>
<LI>tcsh Command Summary
<P>
<LI> tcsh Variables<TT> </TT>
</UL>
<P><BR>
The last two chapters introduced you to the Bourne Again Shell (<TT>bash</TT>) and
the Public Domain Korn Shell (<TT>pdksh</TT>). This chapter introduces a third shell,
<TT>tcsh</TT>. This chapter shows you how <TT>tcsh</TT> supports the following:
<UL>
<LI>Command-line completion
<P>
<LI>Command history and aliases
<P>
<LI>Input and output redirection
<P>
<LI>Pipelines
<P>
<LI>Changing your prompts
<P>
<LI>Job control
<P>
<LI>Key bindings
<P>
<LI>Spelling correction
</UL>
<P>In addition to these topics, we will see how you can customize <TT>tcsh</TT> to
suit your tastes. You will also be introduced to several important <TT>tcsh</TT>
commands and variables.</P>
<P>Rounding out the chapter is a section on neat little features that <TT>tcsh</TT>
provides that are not available in any of the other shell programs we have discussed.
<H3 ALIGN="CENTER"><A NAME="Heading3<FONT COLOR="#000077">An Introduction to
tcsh</FONT></H3>
<P><TT>tcsh</TT> is a modified version of the C shell (<TT>csh</TT>). It is fully
backward-compatible with <TT>csh</TT>, but it contains many new features that make
user interaction much easier. The biggest improvements over the <TT>csh</TT> are
in the areas of command-line editing and history navigation.
<H3 ALIGN="CENTER"><A NAME="Heading4<FONT COLOR="#000077">Command Completion</FONT></H3>
<P>Just like <TT>pdksh</TT> and <TT>bash</TT>, <TT>tcsh</TT> supports command-line
completion. You invoke command-line completion in <TT>tcsh</TT> exactly the same
way as you do in <TT>bash</TT>: by pressing the Tab key at any point while you are
typing a command.</P>
<P>When you press the Tab key, <TT>tcsh</TT> tries to complete the command by matching
what has been typed with any file in the directory that the command is referring
to. For example, assume that you typed the following command and then pressed the
Tab key:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">emacs hello
</FONT></PRE>
<P>Here, <TT>tcsh</TT> will try to match the letters <TT>hello</TT> with any file
(or subdirectory) in the current directory. If there is a single file in the current
directory that begins with the letters <TT>hello</TT>, <TT>tcsh</TT> fills in the
rest of the filename for you. Now assume that you typed the following command and
then pressed the Tab key:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">emacs /usr/bin/hello
</FONT></PRE>
<P>In this case, <TT>tcsh</TT> would try to match the letters <TT>hello</TT> with
any file in the <TT>/usr/bin</TT> directory. From these examples, you can see that
you must give <TT>tcsh</TT> something to go on before asking it to complete the command
for you.</P>
<P>Another example of using command-line completion is as follows: Assume that the
directory that you are currently in contains these files:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">News/ bin/ mail/ sample.txt testfile ttd.txt
</FONT></PRE>
<P>If you want to print the <TT>sample.txt</TT> file, you could type the following
command:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpr sample.txt
</FONT></PRE>
<P>Using command-line completion, you could get away with typing the following command
and then pressing the Tab key:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpr s
</FONT></PRE>
<P>At this point, <TT>tcsh</TT> attempts to complete the command and finds that the
only file that can possibly match what was typed so far is the <TT>sample.txt</TT>
file. <TT>tcsh</TT> would then complete the command by putting the following text
on the command line:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpr sample.txt
</FONT></PRE>
<P>You can now either confirm that this is the intended command by pressing the Enter
key, or you can edit the command if it isn't what you intended.
<H3 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Wildcards</FONT></H3>
<P><TT>tcsh</TT> enables you to use wildcards in your commands. It supports the same
three wildcards as <TT>bash</TT> and <TT>pdksh</TT>: <TT>*</TT> matches any character
or any number of characters.</P>
<P><TT>?</TT> matches any single character.
<BLOCKQUOTE>
<P><TT>[...]</TT> matches any single character contained within the brackets.
</BLOCKQUOTE>
<P>The <TT>*</TT> wildcard can be used to perform some of the same functions as command-line
completion. If you entered a command like<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">cd t*
</FONT></PRE>
<P>and only one subdirectory in the current directory begins with the letter t, this
command would behave the same as if you had used command-line completion by pressing
the Tab key.</P>
<P>The <TT>*</TT> matches any character or any number of characters, so the shell
will replace the <TT>t*</TT> with the file in the directory that matches the wildcard
pattern.</P>
<P>This will work reliably only if there is one file in the directory that starts
with the letter t. If more than one file in the directory starts with the letter
t, the shell will try to replace <TT>t*</TT> with the list of filenames in the directory
that match the wildcard pattern, and the <TT>cd</TT> command will make the first
directory in this list the working directory. This will end up being the file that
comes first alphabetically and may or may not be the intended file.</P>
<P>A case that is more suited to using the <TT>*</TT> wildcard is if you want to
perform the same operation on a number of files that have similar filenames. For
example, assume the current directory contains the following files:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">Mail/ atc1.stk atc2.stk bin/ borl.stk cdrom.txt lfi.stk temp/
</FONT></PRE>
<P>If you want to print both of the files that start with <TT>atc</TT> and end with
the <TT>.stk</TT> extension, you could do so by typing<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpr a*.stk
</FONT></PRE>
<P>This command will do the job, because there are no other files in the directory
that start with the letter a and have the <TT>.stk</TT> extension.</P>
<P>Using the <TT>?</TT> wildcard, the following command will accomplish the same
thing:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpr atc?.stk
</FONT></PRE>
<P>Using the <TT>[...]</TT> wildcard, you could enter the following command to get
the same files to print:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpr atc[12].stk
</FONT></PRE>
<H3 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">Command History</FONT></H3>
<P>The <TT>tcsh</TT> shell provides a mechanism for accessing the command history
that is similar to ones provided with <TT>bash</TT> and <TT>pdksh</TT>. The shell
remembers the last history commands that have been entered into the shell (where
history is a user-definable <TT>tcsh</TT> variable).</P>
<P><TT>tcsh</TT> stores the text of the last history commands in a history list.
When you log into your account, the history list is initialized from a history file.
The default filename for the history file is <TT>.history</TT>, but you can change
it using the <TT>histfile</TT> <TT>tcsh</TT> variable. This file is located in your
home directory. Notice that the file begins with a period. This means that the file
is a hidden file and will appear in a directory listing only if you use the <TT>-a</TT>
or <TT>-A</TT> options of the <TT>ls</TT> command.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading7<FONT COLOR="#000077"><B>NOTE: </B></FONT>In order for the
history list to be saved in the history file, you must make sure that the <TT>savehist</TT>
variable is set to the number of commands that you want to be saved. Refer to the
<TT>.login</TT> file listing in the "Customizing <TT>tcsh</TT>" section
of this chapter for an example of setting this variable.
<HR>
</DL>
<P>The simplest way of using the history list is to use the up and down arrow keys
to scroll through the commands that were entered earlier. Pressing the up arrow key
will cause the last command entered to appear on the command line. Pressing the up
arrow key again will put the command before that on the command line, and so on.
If you move up in the command buffer past the command that you wanted, you can move
down the history list one command at a time by pressing the down arrow key.</P>
<P>The command that is on the command line can be edited. You can use the left and
right arrow keys to move along the command line, and you can insert text at any point.
You can also delete text from the command line by using the Backspace or Delete keys.
Most users should find these simple editing commands sufficient, but for those who
do not, <TT>tcsh</TT> also supports a wide range of equivalent <TT>emacs</TT> and
<TT>vi</TT> editing commands. See the "Key Bindings" section of this chapter
for more information on <TT>vi</TT> and <TT>emacs</TT> command-line editing.</P>
<P>Another method of using the history file is to display and edit the history list
using a number of other editing commands that <TT>tcsh</TT> provides. The <TT>history</TT>
command can be invoked by any one of three different methods. The first method has
the following command-line syntax:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">history [-hr] [n]
</FONT></PRE>
<P>This form of the <TT>history</TT> command displays the history list to the screen.
The <TT>n</TT> option is used to specify the number of commands to display. If the
<TT>n</TT> option is not used, the history command will display the entire history
list. The <TT>-h</TT> option causes <TT>history</TT> to remove the command numbers
and timestamps that are usually present in the output of the <TT>history</TT> command.
The <TT>-r</TT> option tells <TT>history</TT> to display the commands in reverse
order, starting with the most recent command. The following command displays the
last five commands that were entered:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">history 5
</FONT></PRE>
<P>The second method of invoking the <TT>history</TT> command is used to modify the
contents of the history file or the history list. It has the following command-line
syntax:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">history -S | -L | -M [filename]
</FONT></PRE>
<P>The <TT>-S</TT> option writes the history list to a file. The <TT>-L</TT> option
appends a history file to the current history list. The <TT>-M</TT> option merges
the contents of the history file with the current history list and sorts the resulting
list by the timestamp contained with each command.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading8<FONT COLOR="#000077"><B>NOTE: </B></FONT>All of the options
for the second form of the <TT>history</TT> command use the filename option as the
name of the history file. If no filename is specified, the <TT>history</TT> command
will use the value of the <TT>histfile</TT> variable. If the <TT>histfile</TT> variable
isn't set, it will use the <TT>~/.history</TT> (home directory) file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -