📄 882.html
字号:
<TD rowSpan=2><IMG src="images/header_r1_c7.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c7.gif" width=26 border=0 name=header_r1_c7></TD>
<TD><IMG height=83 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 border=0></TD></TR>
<TR>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"><IMG height=22
src="images/header_r2_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r2_c1.gif" width=296 border=0
name=header_r2_c1></TD>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>提高linux命令行的工作效率</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:lfree(zwsqyy0483@sina.com.cn)<br>来自:Linux知识宝库<br>联系方式:无名<br><br> 本文介绍一些配置技巧,使你更好地操纵linux命令行,提高工作效率。<br>
虽然最近几年个人计算机的潮流已经从命令行方式转向图形界面方式,大量的采用鼠标操作,但是shell 在linux中依然有很强的生命力。shell有好几种, 主要有bash、ksh、tcsh、zsh、ash,用得最多的是bash,它几乎是各种linux发布版的标准配置。同时在linux 操作系统中,即使在X Window下,系统管理员经 常也要与命令行打交道,使用键盘次数要明显高于鼠标,本文通过介绍合理地定制与修改INPUTRC环境变量,以及利用bash 2.05以上版本中增加的complete命令,可以更好地提高linux命令行使用的工作效率,减少键盘的敲打以及拼写错误。<br>
<br>
一.定制/etc/inputrc文件:<br>
通过设置INPUTRC环境变量(参见/etc/profile文件),其作用主要定义或者改变一些功能键的定义,从而更好地使用命令行,通常情况下INPUTRC环境变量指向 /etc/inputrc文件,只要编辑/etc/inputrc文件,以及利用Tab键的命令补全功能,就可以实现类似于MSDOS的DOSKEY的功能。<br>
以Redhat 7.3为例来说明,使用的bash shell版本号为2.0.5。你可以根据自己的需要定制与修改此文件,如想了解更多的内容,可以参阅man bash文档。<br>
例子:/etc/inputrc文件内容如下:<br>
<br>
set bell-style none<br>
set meta-flag on<br>
set input-meta on<br>
set convert-meta off<br>
set output-meta on<br>
<br>
set show-all-if-ambiguous On<br>
<br>
"e[1~": beginning-of-line # home<br>
"e[2~": insert-last-argument # insert<br>
"e[3~": delete-char # delete<br>
"e[4~": end-of-line # end<br>
"e[5~": backward-kill-word # page up<br>
"e[6~": kill-word # page down<br>
<br>
# (F1 .. F5) are "e[[A" ... "e[[E"<br>
"e[18~": history-search-forward # F7<br>
"e[19~": history-search-backward # F8<br>
<br>
具体修改说明如下(注以下[]中的内容为所按的键):<br>
set bell-style none <br>
<br>
关闭计算机小喇叭发出的声音。<br>
<br>
set meta-flag on<br>
set input-meta on<br>
set convert-meta off<br>
set output-meta on<br>
<br>
这几行主要是实现命令行上实现汉字的输入以及显示。 比如想输入汉字的文件名等等。<br>
<br>
<br>
set show-all-if-ambiguous On<br>
<br>
这一行主要是使命令补全的功能更好的发挥。许多linux初学者并不知道这个功能,就是使用[Tab]键,能够减少键盘的敲打以及拼写错误。比如当前你想执行ifconfig命名,你输入if后按[Tab]键两次,就会出现所有以if开头的命令,文件名和目录名也可以使用这个方法输入,当打开上述命令后可以使用[Tab]键,仅仅需要按一次,这样更加方便与快捷。<br>
<br>
"e[1~": beginning-of-line # home<br>
"e[2~": insert-last-argument # insert<br>
"e[3~": delete-char # delete<br>
"e[4~": end-of-line # end<br>
"e[5~": backward-kill-word # page up<br>
"e[6~": kill-word # page down<br>
<br>
这几行主要是使命令行编辑方便,[home]、[delete]、[end]键保持原意,意指移动到命令行的开始、删除一个字符、移动到命令行尾。[insert] 键被定义为插入上一个命令的最后一个参数。比如执行如下命令:<br>
<br>
<br>
$ mount /mnt/cdrom<br>
$ cd[space][insert] <br>
# 相当于 执行 cd /mnt/cdrom<br>
<br>
可以试着按[insert]键几次看看会有什么出现内容?<br>
<br>
[Pageup]和[PageDown]键定义为向前和向后删除单词。<br>
<br>
"e[18~": history-search-forward # F7<br>
"e[19~": history-search-backward # F8<br>
<br>
[F7]和[F8]定义为命令历史查找功能,有点向MSDOS的DOSKEY功能类似,比如前面使用过mount命令,再次输入mount后按[F8]会调出先前使用的命令,特别是当命令非常长参数非常多的时候。<br>
<br>
二.安装bash-completion:<br>
如果经常你使用[tab]键命令补全功能,就会发现它的不足之处,你可以发现它不能根据具体的需要或者命令补全所需要的参数与文件或者目录。例如你执行cd [tab],系统会将文件与目录一起显示出来,而实际上这时你仅仅需要显示文件类型为目录。bash从2.05版开始,已经加入命令complete内部命令,从而能够使用复杂的命令行接口,通过一个复杂的脚本bash_completion实现可编程的补全程序,减少系统管理员日常维护工作,减少差错提高工作效率。<br>
具体操作如下:<br>
<br>
1. 下载最新的bash-completiton脚本,检查bash的版本号【执行bash --version】,如果版本低于2.0.5最好升级bash.<br>
http://www.caliban.org/files/bash/bash-completion-latest.tar.gz<br>
http://www.caliban.org/files/redhat/RPMS/i386/bash-2.05-51.i386.rpm<br>
<br>
2. 安装<br>
# rpm -Uvh bash-2.05-12.i386.rpm <br>
# tar xzvf bash-completion-latest.tar.gz -C /tmp<br>
<br>
3. 仔细阅读bash_completetion目录下的README文件,修改/etc/bashrc文件,在行尾加入如下命令:<br>
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}<br>
if [ "$PS1" ] && [ $bmajor -eq 2 ] && [ $bminor '>' 04 ] <br>
&& [ -f /etc/bash_completion ]; then # interactive shell<br>
# Source completion code<br>
. /etc/bash_completion<br>
fi<br>
unset bash bmajor bminor<br>
<br>
4. 拷贝bash_completion文件:<br>
# cp /tmp/bash_completion/bash_completion /etc<br>
注销再重新进入后,你就会发现许多命令在使用命令补全时都会发生一些变化。<br>
通过以上的修改,你会发现在命令行上使用linux,同样高效与快捷,减少了许多不必要的错误。<br>
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -