rhl12.htm
来自「linux的初学电子书」· HTM 代码 · 共 1,692 行 · 第 1/3 页
HTM
1,692 行
<HTML>
<HEAD>
<TITLE>Red Hat Linux Unleashed rhl12.htm </TITLE>
<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/htindex.htm">
<LINK REL="Next" HREF="rhl13.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl13.htm">
<LINK REL="Previous" HREF="rhl11.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl11.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<A NAME="I0"></A>
<H2>Red Hat Linux Unleashed rhl12.htm</H2>
<P ALIGN=LEFT>
<A HREF="rhl11.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl11.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="rhl13.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl13.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E77" >An Introduction to tcsh</A>
<LI>
<A HREF="#E68E78" >Command Completion</A>
<LI>
<A HREF="#E68E79" >Wildcards</A>
<LI>
<A HREF="#E68E80" >Command History</A>
<LI>
<A HREF="#E68E81" >Aliases</A>
<LI>
<A HREF="#E68E82" >Input and Output Redirection</A>
<LI>
<A HREF="#E68E83" >Pipelines</A>
<LI>
<A HREF="#E68E84" >Prompts</A>
<LI>
<A HREF="#E68E85" >Job Control</A>
<LI>
<A HREF="#E68E86" >Key Bindings</A>
<LI>
<A HREF="#E68E87" >Other Neat Stuff</A>
<UL>
<LI>
<A HREF="#E69E182" >Correcting Spelling Errors</A>
<LI>
<A HREF="#E69E183" >Precommands</A>
<LI>
<A HREF="#E69E184" >Change Directory Commands</A>
<LI>
<A HREF="#E69E185" >Monitoring Logins and Logouts</A></UL>
<LI>
<A HREF="#E68E88" >Customizing tcsh</A>
<LI>
<A HREF="#E68E89" >tcsh Command Summary</A>
<LI>
<A HREF="#E68E90" >tcsh Variables</A>
<LI>
<A HREF="#E68E91" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E12"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>12</B></FONT></CENTER></H1>
<BR>
<A NAME="E67E12"></A>
<H2 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>Using </B><B>tcsh</B></FONT></CENTER></H2>
<BR>
<P>The last two chapters introduced you to the Bourne Again Shell (bash) and the Public Domain Korn Shell (pdksh). This chapter introduces a third shell, tcsh. This chapter shows you how tcsh supports the following:
<BR>
<UL>
<LI>Command-line completion
<BR>
<BR>
<LI>Command history and aliases
<BR>
<BR>
<LI>Input and output redirection
<BR>
<BR>
<LI>Pipelines
<BR>
<BR>
<LI>Changing your prompts
<BR>
<BR>
<LI>Job control
<BR>
<BR>
<LI>Key bindings
<BR>
<BR>
<LI>Spelling correction
<BR>
<BR>
</UL>
<P>In addition to these topics, we will see how you can customize tcsh to suit your tastes. You will also be introduced to several important tcsh commands and variables.
<BR>
<P>Rounding out the chapter is a section on neat little features that tcsh provides that are not available in any of the other shell programs we have discussed.
<BR>
<BR>
<A NAME="E68E77"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>An Introduction to </B><B>tcsh</B></FONT></CENTER></H3>
<BR>
<P>tcsh is a modified version of the C shell (csh). It is fully backward-compatible with csh, but it contains many new features that make user interaction much easier. The biggest improvements over the csh are in the areas of command-line editing and
history navigation.
<BR>
<BR>
<A NAME="E68E78"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Command Completion</B></FONT></CENTER></H3>
<BR>
<P>Just like pdksh and bash, tcsh supports command-line completion. You invoke command-line completion in tcsh exactly the same way as you do in bash: by pressing the Tab key at any point while you are typing a command.
<BR>
<P>When you press the Tab key, tcsh 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:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">emacs hello</FONT></PRE>
<P>Here, tcsh will try to match the letters hello with any file (or subdirectory) in the current directory. If there is a single file in the current directory that begins with the letters hello, tcsh fills in the rest of the filename for you. Now assume
that you typed the following command and then pressed the Tab key:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">emacs /usr/bin/hello</FONT></PRE>
<P>In this case, tcsh would try to match the letters hello with any file in the /usr/bin directory. From these examples, you can see that you must give tcsh something to go on before asking it to complete the command for you.
<BR>
<P>Another example of using command-line completion is as follows: Assume that the directory that you are currently in contains these files:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">News/ bin/ mail/ sample.txt testfile ttd.txt</FONT></PRE>
<P>If you want to print the sample.txt file, you could type the following command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">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:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">lpr s</FONT></PRE>
<P>At this point, tcsh attempts to complete the command and finds that the only file that can possibly match what was typed so far is the sample.txt file. tcsh would then complete the command by putting the following text on the command line:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">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.
<BR>
<BR>
<A NAME="E68E79"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Wildcards</B></FONT></CENTER></H3>
<BR>
<P>tcsh enables you to use wildcards in your commands. It supports the same three wildcards as bash and pdksh:
<BR>
<UL>
<UL>
<P>* matches any character or any number of characters.
<BR>
</UL></UL>
<UL>
<UL>
<P>? matches any single character.
<BR>
</UL></UL>
<UL>
<UL>
<P> [...] matches any single character contained within the brackets.
<BR>
</UL></UL>
<P>The * wildcard can be used to perform some of the same functions as command-line completion. If you entered a command like
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">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.
<BR>
<P>The * matches any character or any number of characters, so the shell will replace the t* with the file in the directory that matches the wildcard pattern.
<BR>
<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 t* with the list of filenames in the directory that match
the wildcard pattern, and the cd 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.
<BR>
<P>A case that is more suited to using the * 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:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">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 atc and end with the .stk extension, you could do so by typing
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">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 .stk extension.
<BR>
<P>Using the ? wildcard, the following command will accomplish the same thing:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">lpr atc?.stk</FONT></PRE>
<P>Using the [...] wildcard, you could enter the following command to get the same files to print:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">lpr atc[12].stk</FONT></PRE>
<BR>
<A NAME="E68E80"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Command History</B></FONT></CENTER></H3>
<BR>
<P>The tcsh shell provides a mechanism for accessing the command history that is similar to ones provided with bash and pdksh. The shell remembers the last history commands that have been entered into the shell (where history is a user-definable tcsh
variable).
<BR>
<P>tcsh 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 .history, but you can change it using the histfile
tcsh 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 -a or -A options of the ls command.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>In order for the history list to be saved in the history file, you must make sure that the savehist variable is set to the number of commands that you want to be saved. Refer to the .login file listing in the "Customizing tcsh" section of
this chapter for an example of setting this variable.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<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.
<BR>
<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, tcsh also supports a wide range of equivalent emacs and vi editing commands. See the "Key Bindings" section of this chapter for more information on vi and
emacs command-line editing.
<BR>
<P>Another method of using the history file is to display and edit the history list using a number of other editing commands that tcsh provides. The history command can be invoked by any one of three different methods. The first method has the following
command-line syntax:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">history [-hr] [n]</FONT></PRE>
<P>This form of the history command displays the history list to the screen. The n option is used to specify the number of commands to display. If the n option is not used, the history command will display the entire history list. The -h option causes
history to remove the command numbers and timestamps that are usually present in the output of the history command. The -r option tells history to display the commands in reverse order, starting with the most recent command. The following command displays
the last five commands that were entered:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">history 5</FONT></PRE>
<P>The second method of invoking the history command is used to modify the contents of the history file or the history list. It has the following command-line syntax:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">history -S | -L | -M [filename]</FONT></PRE>
<P>The -S option writes the history list to a file. The -L option appends a history file to the current history list. The -M 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.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>All of the options for the second form of the history command use the filename option as the name of the history file. If no filename is specified, the history command will use the value of the histfile variable. If the histfile variable isn't set,
it will use the ~/.history (home directory) file.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The history command using the -c option clears the current history list.
<BR>
<P>In addition to the history command and its options, tcsh also contains many history navigation and editing commands. The following commands are used to navigate through the history list:
<BR>
<UL>
<LI>!n re-executes the command with the history number of n.
<BR>
<BR>
<LI>!-n re-executes the command that is n commands from the end of the history list.
<BR>
<BR>
<LI>!! re-executes the last command that was entered.
<BR>
<BR>
<LI>!c re-executes the last command in the history list that begins with the letter c.
<BR>
<BR>
<LI>!?c? re-executes the last command in the history list that contains the letter c.
<BR>
<BR>
</UL>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?