rhl12.htm
来自「linux的初学电子书」· HTM 代码 · 共 1,692 行 · 第 1/3 页
HTM
1,692 行
<P>The history editing commands enable you to replace words and letters in previously entered commands as well as add words to the end of previously entered commands. More information on these editing commands can be found by referring to the tcsh man
page. You can view this man page by entering the following command at the shell prompt:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">man tcsh</FONT></PRE>
<BR>
<A NAME="E68E81"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Aliases</B></FONT></CENTER></H3>
<BR>
<P>Command aliases are commands that you can specify and execute. Alias commands are usually abbreviations of other Linux commands. You tell tcsh to execute a Linux command whenever it encounters the alias. For example, if you entered the following alias
command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">alias ls 'ls -F'</FONT></PRE>
<P>the ls -F command would be substituted for the ls command each time the ls command was used.
<BR>
<P>If you decide after you enter an alias that you don't need or want that alias to exist any longer, you can use the tcsh unalias command to delete that alias:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">unalias cd</FONT></PRE>
<P>After you use the unalias command to remove an alias, the alias will no longer exist, and trying to execute that alias will cause tcsh to return a command not found error message.
<BR>
<P>Some aliases that you might want to define are:
<BR>
<UL>
<LI>alias ll 'ls -l'
<BR>
<BR>
<LI>alias ls 'ls -F'
<BR>
<BR>
</UL>
<P>If you are a DOS user and are accustomed to using DOS file commands, you might also want to define the following aliases:
<BR>
<UL>
<LI>alias dir 'ls'
<BR>
<BR>
<LI>alias copy 'cp'
<BR>
<BR>
<LI>alias rename 'mv'
<BR>
<BR>
<LI>alias md 'mkdir'
<BR>
<BR>
<LI>alias rd 'rmdir'
<BR>
<BR>
</UL>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>When you define aliases, quotation marks are necessary only if the command within them contains spaces or other special characters.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>If you enter the alias command without any arguments, it will print to the screen all of the aliases that are already defined. The following listing illustrates sample output from the alias command:
<BR>
<PRE>
<FONT COLOR="#000080">alias ls 'ls -F'
alias dir 'ls'
alias ll 'ls -l'
alias md 'mkdir'
alias rd 'rmdir'</FONT></PRE>
<BR>
<A NAME="E68E82"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Input and Output Redirection</B></FONT></CENTER></H3>
<BR>
<P>The standard input and output of a command can be redirected using the same syntax that is used by bash and pdksh. The < character is used for input redirection, and the > character is used for output redirection. The following command redirects
the standard input of the cat command to the .cshrc file:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">cat < .cshrc</FONT></PRE>
<P>In practice, input redirection isn't used very often because most commands that require input from a file support passing the filename as an argument to the command.
<BR>
<P>Output redirection is used much more frequently. The following command redirects the standard output of the cat command to the file named cshenv (which has the effect of storing the contents of the .cshrc and .login files in one file named cshenv):
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">cat .cshrc .login > cshenv</FONT></PRE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>The file to which output is being redirected is created if it does not exist and is overwritten without warning if it already exists.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E83"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Pipelines</B></FONT></CENTER></H3>
<BR>
<P>tcsh pipelines, just like bash and pdksh pipelines, are a way to string together a series of Linux commands. This means that the output from the first command in the pipeline is used as the input to the second command in the pipeline. The output from
the second command in the pipeline is used as input to the third command in the pipeline, and so on. The output from the last command in the pipeline is the output that the user will actually see. This output will be displayed to the screen (or put into a
file if output redirection was specified on the command line).
<BR>
<P>You can tell tcsh to create a pipeline by typing two or more commands separated by the | character. The following command illustrates an example of using a tcsh pipeline:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">cat file1 file2 | wc -l</FONT></PRE>
<P>The cat command in this pipeline appends file2 to the end of file1 and passes the resulting file to the wc command. The wc command prints to the screen the total number of lines contained in the resulting file.
<BR>
<BR>
<A NAME="E68E84"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Prompts</B></FONT></CENTER></H3>
<BR>
<P>tcsh has three levels of user prompts. The first-level prompt is what you see when tcsh is waiting for you to type a command. The default prompt is the % character. This prompt can be customized by assigning a new value to the prompt tcsh variable:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">set prompt="%t$"</FONT></PRE>
<P>This example would change the first-level prompt to the current time followed by a dollar sign.
<BR>
<P>The second-level prompt is displayed when tcsh is waiting for input when in a while or for loop (used in shell programming, discussed in <A HREF="rhl13.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl13.htm">Chapter 13</A>, "Shell Programming"). The default for the second-level prompt is %R?,
where %R is a special character sequence that displays the status of the parser. You can change the second-level prompt by setting the value of the prompt2 tcsh variable. For example:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">set prompt2="?"</FONT></PRE>
<P>changes the second-level prompt to a question mark.
<BR>
<P>The third-level prompt is used when tcsh displays the corrected command line when automatic spelling correction is in effect. This prompt is set using the prompt3 variable, and it has a default value of CORRECT>%R (y|n|e)?. See the "Correcting
Spelling Errors" section for more information on this feature.
<BR>
<P>tcsh supports special character codes in its prompt variables. These codes are similar to the codes that bash supports in its prompts. The main difference between the two is that the syntax for using them is different. Table 12.1 lists the most commonly
used special character codes.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 12.1. </B><B>tcsh</B><B> prompt special character codes.</B></FONT></CENTER>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Character Code</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Meaning</I></FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%/
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays the current working directory.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%h, %!, !
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
These codes all display the current history number.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%t, %@
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
These codes both display the time of day.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%n
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays the username.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%d
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays the current day of the week.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%w
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays the current month.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
%y
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays the current year.</FONT>
</TABLE><P>The following is an example of setting the prompt variable:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080"><A NAME="I2"></A>set prompt="%h %/"</FONT></PRE>
<P>This command sets the prompt to display the history number of the current command, followed by the current working directory.
<BR>
<BR>
<A NAME="E68E85"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Job Control</B></FONT></CENTER></H3>
<BR>
<P>Job control refers to the ability to control the execution behavior of a currently running process. Specifically, you can suspend a running process and cause it to resume running at a later time. tcsh keeps track of all the processes that it starts as a
result of user input. You can suspend a running process or restart a suspended one at any time during the life of that process.
<BR>
<P>Pressing the Ctrl-Z key sequence suspends a running process. The bg command restarts a suspended process in the background, and the fg command restarts a process in the foreground.
<BR>
<P>These commands are most often used when you want to run a command in the background but by accident start it in the foreground. When a command is started in the foreground, it locks the shell from any further user interaction until the command completes
execution. This is usually fine because most commands take only a few seconds to execute. If the command you're running is going to take a long time, you would typically start the command in the background so that you could continue to use tcsh to enter
other commands.
<BR>
<P>For example, if you started a command that was going to take a long time in the foreground, such as
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">find / -named "test" > find.out</FONT></PRE>
<P>your shell will be tied up for several minutes. If you have done this and want to cause the find command to continue executing in the background, you could enter the following:
<BR>
<PRE>
<FONT COLOR="#000080">control-z
bg</FONT></PRE>
<P>This would suspend the find command and then restart it in the background. The find command would continue to execute, and you would regain control of tcsh.
<BR>
<BR>
<A NAME="E68E86"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Key Bindings</B></FONT></CENTER></H3>
<BR>
<P>Like the pdksh, tcsh provides the ability to change and add key bindings. The tcsh implementation of key bindings is more powerful than the way key bindings are done in pdksh.
<BR>
<P>With tcsh you can bind to things other than the built-in editor commands. This means that you can bind a key to a UNIX command, for example. tcsh also enables you to bind vi editing commands, whereas pdksh only allows the binding of emacs editing
commands.
<BR>
<P>Key bindings can be very useful, especially if you're using a favorite editor other than emacs or vi. The basic syntax for defining key bindings is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">bindkey [option] <instring or keyname> <outstring or command></FONT></PRE>
<P>The options that bindkey supports are not discussed in this book. If you want to learn about the bindkey options, refer to the tcsh man page. The basic function of the bindkey command is to bind the key sequence contained in the first argument to the
command contained in the second argument.
<BR>
<P>The following list gives some of the most useful editing commands that you can bind key sequences to, along with the default key binding for that command. You can list all the bindings that are defined in tcsh by typing the bindkey command without any
arguments.
<BR>
<UL>
<LI>beginning-of-line (^A): Moves the cursor to the beginning of the command line.
<BR>
<BR>
<LI>backward-char (^B): Moves the cursor back one character.
<BR>
<BR>
<LI>end-of-line (^E): Moves the cursor to the end of the command line.
<BR>
<BR>
<LI>forward-char (^F): Moves the cursor forward one character.
<BR>
<BR>
<LI>backward-delete-char (^H): Deletes the character to the left of the cursor.
<BR>
<BR>
<LI>kill-line (^K): Deletes all of the characters to the right of the cursor.
<BR>
<BR>
<LI>clear-screen (^L): Removes all of the text from the shell window.
<BR>
<BR>
<LI>down-history (^N): Moves down one command in the history list.
<BR>
<BR>
<LI>up-history (^P): Moves up one command in the history list.
<BR>
<BR>
<LI>kill-whole-line (^U): Deletes all of the characters on the current line.
<BR>
<BR>
</UL>
<P>All of these commands are the same whether you're in emacs or vi insert mode. tcsh supports many more editing commands than are listed here. To see what these commands are, refer to the tcsh man page.
<BR>
<P>The following are examples of setting key bindings:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?