Unix体验中心
介绍一个Unix的体验中心:http://www.unix-center.net/
他们提供了Solaris的系统,并且有C、C++等语言的编译环境。对于想用Unix的人来说,还是不错的。不过没有X。
目前提供几个服务器:
- x4100.unix-center.net
- solaris.unix-center.net
推荐使用Putty使用SSH方式访问。
今天的Ubuntu出了问题
上次不记得修改了什么,今天启动Ubuntu的时候突然无法直接进入X Window了(不直接也进不去)。不仅如此,即使使用Console进入系统,很多命令也都无法使用,包括startx、vi等。
这样的话,我几乎什么也做不了。我首先想到的是看看日志文件,开始没留意什么,却发现一个log中写着:The directory “/usr/share/…” does not exist。觉得很奇怪,进入/usr,却发现里面什么都没有。/usr里面的内容凭空消失了?觉得问题出在/etc/fstab文件上,查看这个文件,偶然发现,在/dev/hda1的记录上写着:
- # Engry for /dev/hda1 :
- UUID=a80b3122-dd44-46b7-8fc5-00262a486e32 / reiserfs otail 0 1
注意那个otail了吗?实际上应该是notail。不知道上次在改什么的时候把它给删除了。却发现现在没有vi,没法编辑阿,为了一个字符写个教本也不值当的。
这时我想起了之前介绍的SystemRescueCD, 启动之后,mount /dev/hda1,修改文件,重新启动,搞定!
SystemRescueCD 0.3.3
SystemRescueCD是一个基于Linux的系统紧急工具包。支持Linux各种分区类型(ext3,ext3,reiserfs4等),也通过NTFS-3G支持NTFS分区的读写。包含磁盘分区(Gparted),内存硬盘检测(testdisk、memtest+),FireFox等多种工具。

SystemRescueCd 的 ISO 映像文件的大小为121MB,非常适合刻录为小CD盘片,可从下面下载。
Download SystemRescueCd 0.3.3
10 things you should know about every Linux installation
November 18, 2005
Update - 11/18/2005: This article is also available as a TechRepublic download.
Takeaway:
There are numerous common features with every Linux installation. This document lists 10 of the more important ones you should know about.
By Jeffrey G. Thomas
Linux is not Windows, and although there are some similarities, you must realize that there may be a few “new ways of doing things” to learn before you can be comfortable in Linux. Linux is an open-source clone of UNIX, a secure operating system (OS) that predates DOS and Windows and is designed for multiple users. The items in the following list generally apply to any UNIX-based *nix system, such as Linux and the various BSD’s. For the purposes of this article, assume that it’s all Linux.
重回Linux(2)——Post-installation
第一步把基本系统装好了,进入系统,X Window已经将我的nVidia的显卡配置好了。默认分辨率1600×1200@60Hz,看着实在是费劲。去Admin里面把Screen Solution重新设置为1280×1024@85Hz。
Ubuntu的确是汲取了很多Windows中优秀的东西,包括Automatic Update。刚刚装好的系统,右上角的Notification Area就提示了有更新的package要装。更是简单到只要点一下更新的图标,再点一下OK,就可以自动完成更新了。
这里有个不是很爽的东西,Ubuntu(包括Debian)的aptitude,如果他正在工作(下载或安装package),就不能同时开启另一个进程工作。也就是说,如果你在更新系统,那么无论是apt-get还是aptitude,还是Ubuntu的Package Manager都是无法工作。
当然,如果是tarball的package还是可以安装的。
花了将近1个小时下载并安装了全部的更新,其中包括一个linux-kernel-i386-2.6.17-11-generic的package。这里着重说一下,在后面的过程中,正式因为这个新的内核导致了其他的问题。
更新完成重新启动系统,却发现显示分辨率变成了800×600@60Hz了,而且只能从800×600和640×480中进行选择。这其实就是已经存在的nvidia-glx的package和新的内核不兼容。(当初装Debian的时候,就遇到过类似的问题)。
作为暂时的处理方法,先把老内核作为GRUB的默认选项了。至于新内核,我想了一下,-10和-11估计也没什么太大的差距,先凑合用了。
Update 2/23 20:43:翻了翻网上的方法,其实简单的要命。装一下nvidia-glx(如果显卡在“列表”中的最下面部分,就要装nvidia-glx legacy)。然后修改/etc/X11/xorg.conf文件:1、在Module中添加Load “glx”;2、在显卡配置中,将Driver “nv”换成Driver “nvidia”。重启,搞定。
接下来安装en-us环境下的中文支持。Ubuntu在中文支持上和早期的Debian相比,已经有了很大的提高了。想当初早期的Debian Woody默认安装后,是无法显示中文的,所有的中文字符都显示为1个方框,方框的4个角上分别写着1个数字。而现在的Ubuntu Edgy默认就可以显示所有的字符了,虽然看起来并不是那么漂亮。
我打算用文泉驿的字体(当然,用simsun或者Windows Vista中的微软雅黑都可以,只是复制不同的文件而已)。这里有个脚本,可以直接从文泉驿网站上下载nightly build的字体问题,并且自动安装。
- #!/bin/sh
- sudo apt-get install build-essential bdftopcf
- mkdir temp
- cd temp
- wget http://wenq.org/daily
- tar xzf wqy*
- cd wqy*
- make
- sudo rm *b.pcf
- if [ ! -d /usr/share/fonts/wqy-bitmapfont ]
- then
- sudo mkdir /usr/share/fonts/wqy-bitmapfont
- fi
- sudo mv *.pcf /usr/share/fonts/wqy-bitmapfont
- cd ../..
- rm -r temp
- sudo fc-cache -fv
- if [ -f /etc/fonts/conf.d/30-debconf-no-bitmaps.conf ]
- then
- sudo unlink /etc/fonts/conf.d/30-debconf-no-bitmaps.conf
- fi
chmod到755,然后run一下就行了。
仅仅这样做还是不够的,还要修改字体的配置文件/etc/fonts/fonts.conf:
- <!--
- Provide required aliases for standard names
- -->
- <alias>
- <family>serif</family>
- <prefer>
- <family>DejaVu Serif</family>
- <family>Bitstream Vera Serif</family>
- <family>Times New Roman</family>
- <family>Thorndale AMT</family>
- <family>Luxi Serif</family>
- <family>Nimbus Roman No9 L</family>
- <family>Times</family>
- <family>Frank Ruehl</family>
- <family>FreeSerif</family>
- <family>MgOpen Canonica</family>
- <family>Wenquanyi Bitmap Song</family>
- <family>Kochi Mincho</family>
- <family>AR PL SungtiL GB</family>
- <family>AR PL Mingti2L Big5</family>
- <family>MS 明朝</family>
- <family>Baekmuk Batang</family>
- </prefer>
- </alias>
- <alias>
- <family>sans-serif</family>
- <prefer>
- <family>DejaVu Sans</family>
- <family>Bitstream Vera Sans</family>
- <family>Verdana</family>
- <family>Arial</family>
- <family>Albany AMT</family>
- <family>Luxi Sans</family>
- <family>Nimbus Sans L</family>
- <family>Helvetica</family>
- <family>Nachlieli</family>
- <family>FreeSans</family>
- <family>MgOpen Moderna</family>
- <family>Wenquanyi Bitmap Song</family>
- <family>Kochi Gothic</family>
- <family>AR PL KaitiM GB</family>
- <family>AR PL KaitiM Big5</family>
- <family>MS ゴシック</family>
- <family>Baekmuk Dotum</family>
- <family>SimSun</family>
- </prefer>
- </alias>
- <alias>
- <family>monospace</family>
- <prefer>
- <family>DejaVu Sans Mono</family>
- <family>Bitstream Vera Sans Mono</family>
- <family>Andale Mono</family>
- <family>Courier New</family>
- <family>Cumberland AMT</family>
- <family>Luxi Mono</family>
- <family>Nimbus Mono L</family>
- <family>Courier</family>
- <family>Miriam Mono</family>
- <family>FreeMono</family>
- <family>Wenquanyi Bitmap Song</family>
- <family>Kochi Gothic</family>
- <family>AR PL KaitiM GB</family>
- <family>Baekmuk Dotum</family>
- </prefer>
- </alias>
最后安装输入法:
sudo apt-get install im-switch scim-pinyinim-switch -s scim-pinyin
基本搞定。。
重回Linux(1)——Ubuntu
已经装过好几次Linux了,从Slackware到Redhat,再到XTeam、Debian;但每次都是因为很多原因,恢复了Windows。这次决定重回Linux,改用Ubuntu Edgy Eft (v6.10)。
这次之所以选择Ubuntu,首先是因为Ubuntu是基于Debian的一个Open Source的Linux系统,与Debian的“大家投票”的更新形式不同,Ubuntu是有专人(Triage?)决定他采用或者不采用哪些功能或者包。
要安装Ubuntu非常简单,如果是全新系统,而且只安装一个系统,甚至比Windows的安装更加简单。
直接从Ubuntu首页(http://www.ubuntu.com/)上下载最新的版本就行了(到目前为止,Ubuntu的最新版本是Edgy Eft,也就是Version 6.10)。
Ubuntu的版本号比较奇怪,6.10表示它是在2006年10月发布的。上一个版本Dapper Drake是6.06。
如果想得到更多的支持,可以试试看Dapper,因为Dapper是LTS(Long Term Support)的。不过也无所谓,Open Source的最大优点就是有广泛的人使用和支持。
Ubuntu的最近几个版本如下:
- Warty Warthog (4.10)
- Hoary Hedgehog (5.04)
- Breezy Badger (5.10)
- Dapper Drake (6.06)
- Edgy Eft (6.10)
我在下载到Ubuntu光盘镜像后,遇到了个比较棘手的问题。Ubuntu CD是715MB的,而我手里的CDR都是650MB的。没辙,既然先决定要装了,就凑合一下吧。找了张DVD-R给刻了。
Ubuntu CD是个Live CD,意味着即使不安装,也可以直接在光盘上运行。安装更是简单到点击Install图标就可以了。
安装过程还是非常简单的,却在分区中遇到了问题。我因为以前装过Debian,所以就决定用类似的方法手工分区。计划是这样的:
| 分区 | 加载点 | 容量 | 文件系统 |
| hda1 | /boot | 32MB | ReiserFS |
| hda2 | / | 10GB | ReiserFS |
| hda3 | swap | 1GB | Swap |
| hda5 | /var | 4GB | ReiserFS |
| hda6 | /home | 60GB | ReiserFS |
| hda7 | /usr | 40GB | ReiserFS |
结果有问题,安装都快结束了,提示了一个Install GRUB failed! (fatal error: ‘grub-install’ failed)。想了半天也没感觉有问题啊,然后进入一个Terminal,手工安装GRUB,却提示Can’t find /boot。很怪异。
想来想去,还是暂时放弃了。除了swap,/usr,/home外,都使用一个分区了。结果就变成这样了:
| 分区 | 加载点 | 容量 | 文件系统 |
| hda1 | / | 14GB | ReiserFS |
| hda2 | Swap | 1GB | Swap |
| hda5 | /home | 60GB | ReiserFS |
| hda6 | /usr | 40GB | ReiserFS |
暂时是搞定了。接下来升级系统,发现Edgy居然也有这么多安全更新和包的更新。接下来就是该处理了中文支持了(其实默认情况下,中文已经可以显示了。)
Debian的Windows Installer
最为搞笑的是,该Installer的下载地址是:http://goodbye-microsoft.com/。

Is Debian Dying?
By Steven J. Vaughan-Nichols
For a while, Debian was the community Linux darling. In its heyday, Debian was known for its strong moral point of view and its outstanding code. Numerous important distributions, such as Linspire, Knoppix, and today’s most popular distribution, Ubuntu, have sprung from it. Things have changed.
Today, Debian is a troubled distribution. In order to get Debian GNU/Linux 4.0, codenamed etch, out the door by its scheduled date of December 4, 2006, Dunc-Tank.org, a group of Debian developers and fans, was formed.
Historically, Debian has been notoriously late ever since Debian 1.2 was released almost a decade ago in 1997. So, Dunc-Tank was created to accelerate Debian’s development.
Dunc-Tank’s membership includes Anthony Towns, the Debian Leader, Steve McIntyre, the assistant to the Debian Leader, prominent Debian developers Raphael Hertzog and Joey Hess, and well-known Debian and Linux kernel developer Ted Ts’o
Dunc-Tank plans to accomplish its mission by raising funds to be used for “financially supporting the volunteers working on managing the release process, allowing them to devote their full attention to that task.” Specifically, the group’s goal is to be able to raise enough funds to pay “both release managers enough to work exclusively on the release of etch for a month each, having Steve Langasek available full-time during October and Andreas Barth available full-time during November, with the release expected to follow soon after in the first week of December.”
Simple, straightforward, practical, and it has led to calls for the head of the Debian Project, Anthony Towns , to be recalled because he’s a member of the Dunc-Tank board.
Why? Because Denis Barbier, a relatively new Debian developer, claims that Towns has confused people into thinking that Dunc-Tank is officially supported by the Debian Project. Therefore, Barbier urged via the Debian voting mailing list that Debian developers “make this confusion vanish, and I would like to propose that we answer to the valid question quoted in the second paragraph above by recalling our Project Leader … and am seeking seconds for this proposal.”
Barbier immediately received numerous seconds for his motion.
There were other objections behind this recall movement. One developer, Lucas Nussbaum, said that “experiments have shown that sometimes, paying volunteers decreases the overall participation.”
Another concern is that paying developers will be bad for Debian. As T’so comments, though, in a Linux.com story on the controversy, “If money were among anybody’s primary motivators,” then “they probably wouldn’t be accepting a grant from Dunc-Tank; they could probably make more money by applying for a job with Google — or Microsoft.”
Others within the Debian community also wonder what all the fuss is about. Matthew R. Dempsky wants to know , for example, “What’s so scandalous about the DPL encouraging a timely release?”
Still other developers are fighting back against the recall movement. Loic Minier, a French Debian developer, said “I am pissed enough by the attitude of some developers that I want to reaffirm support for the elected DPL whatever he does to suppose Debian outside of the project.”
He then proposed the following counter-proposal : “The Debian Project reaffirms its support to its DPL. The Debian Project does not object to the experiment named ‘Duck Tank’, lead by Anthony Towns, the current DPL, and Steve McIntyre, the Second in Charge. However, this particular experiment is not the result of a decision of the Debian Project. The Debian Project wishes success to projects funding Debian or helping towards the release of Etch.”
Interestingly, Towne has seconded the motion for his own recall, to bring the matter to a decision.
He wrote, “I’m seconding this because I do think it’s a fair question for the project to consider, and to make it clear I don’t personally have any problem with being recalled if that’s what the project thinks is right and proper. If I’m not DPL, I expect I’ll continue doing what I have been: working on dunc-tank.org, working on helping the release team get the release out, poking at the security infrastructure to make sure it keeps behaving itself, and continuing to support other folks who’ve approached me in the past year where they still want that support. Frankly, I think we’re doing great, and I’m not remotely interested in quitting.”
This battle continues to rage on in the Debian lists, but I’m going to leave recording the details of that to others.
Here’s my point: The Debian community, instead of rejoicing in a perfectly sensible idea to help get the next version out the door, has instead fallen into a snake-pit of online politics. The result of all this infighting will, of course, be that less attention will be paid to the Etch code.
As Towne points out, “Given two weeks of discussion for this, two weeks of voting, and the nine week election process, the earliest we’d have a DPL would be the end of December by my count; so assuming this resolution passed and we released on time, we’d be doing so without a DPL [Debian Project Leader].”
If this were an isolated incident, I’d be inclined to dismiss it. It’s not, though.
On August 28, well-regarded Debian developer Matthew Garrett resigned from Debian because “Debian doesn’t really seem to know who or what it’s for. Arguments erupt over whether something is a deeply held principle or an accident of phrasing on the website; whether we should release more often or less often; whether free software is more important than our users having functional hardware. And, depressingly, these debates generally seem to turn into pedantic point scoring and insults and yes, I’m probably as guilty as many others in this respect. But it’s got to the point where social interaction with Debian-the-distribution makes me want to stab people.”
He’s not the only developer to get sick of Debian politics coming before Debian development. Scott James Remnant, another Debian developer who has left the fold, recently explained on his blog why he has gone to Ubuntu.
Remnant said, “I think that the end of my love-affair with Debian started at Debconf last year where several developers treated those of us who also worked on Ubuntu quite rudely. Someone was attacked for wearing an Ubuntu t-shirt at the conference, while someone else was applauded for wearing a “Fuck Ubuntu” t-shirt. That’s where I realized that maybe I didn’t have as much in common with these people as I thought I did.”
Once more, we see ugly, juvenile politics rearing its ugly head.
It was more than that, though. Remnant also objects to “Debian considering removing documentation and firmware from the distribution, especially the documentation, was another point I started wondering whether I shared anything in common with the project anymore.”
Remnant continued, “Call me strange, but I think that one of the fundamental purposes of a Linux distribution is to be useful to its users. If nobody can use the distribution because it doesn’t support their hardware, and even if it did, all the documentation has been stripped out; I started to wonder what its aims are. It became increasingly apparent that the only users Debian was considering a priority were its own developer.”
So, here we are. We have a Linux “community” at war with itself.
This is a community that in August of 2005 objected to its own founder, Ian Murdock, creating a group of Debian-based companies, the DCC Alliance, to further the operating system because it was at first named the Debian Alliance.
Enough.
Debian has become a distribution whose supporters are clearly more interested in scoring points off each other than creating a serious Linux distribution. It is a group where far too many of its people are far more concerned with moronic minutiae than they are with development.
Is it any wonder that Ubuntu took Debian’s old and great code and produced a wonderful distribution from it, when Debian’s own developers couldn’t cut the mustard?
I think it’s clear why Ubuntu rules. Debian’s best and brightest left for Ubuntu because there, with a formal organization and a focus on coding instead of petty personal politics, development gets done. In Debian, everything becomes a subject for debate and delay.
It’s possible that Debian may yet rise off its death-bed. Dunc-Tank is part of the medicine it needs to get well. But, unless the patient stops fighting with itself, Debian will continue its decline and die.
If it does die, we’ll miss it — but in Ubuntu and the other Linux distributions that have been based on the best of it, its DNA will live on.
我最终决定暂时放弃Linux
我今天痛下决心暂时放弃使用了近2个月的Linux系统。不是因为我用不惯,也不是无法工作在Linux下,更不是因为我不喜欢;只是因为,过多的应用系 统,尤其是我很喜欢的很多金融系统,比如工行、招行、福汇、MT等,都只有建立在Windows和Mac系统的软件(尤其是国内产品,更是酷爱 Windows)。
我曾经不止1次和招行软件中心的人提到Open Source,其实金融产品被Open Source后,必然涉及安全问题了。而且对于Dev的要求过高。
另外看到,福汇、MT这种东西居然也只支持Windows。唉,没办法。而且目前和比别人谈论外汇的时候,最好的方式还是QQ,因为有即时贴图(Linux版就没有),方便讨论。
所 以,鉴于此,我决定暂时舍弃Linux平台,回归Windows。但这并不意味着我将放弃Linux。在有朝一日,我有超过1台电脑的时候(LapTop +DeskTop或者DeskTop+DeskTop),我会为了我自己装一个Linux;为了金融,装个Windows的。
不仅如此,VI、Emacs等Open Source的工具,仍将成为我工作的不可或缺的部分,即便我工作在Windows平台。
Bash readline使用技巧
很多人会用 Bash,但是很少有人知道 readline 是怎么回事。readline 是一个强大的库,只要使用了它的程序,都可以用同一个配置文件配置,而且用同样的方法操作命令行,让你可以方便的编辑命令行。使用 readline 的程序现在主要有 Bash, GDB,ftp 等。readline 付予这些程序强大的 Emacs 似的命令行编辑方式,你可以随意绑定你的键盘。
术语解释
在 下文中,我们经常提到 “C-x r” 这类键操作。”C-x r” 其实就是按Ctrl-x,然后按 r。同理 “C-M-@” 就是按 ctrl-alt-@(M表示meta, 在 PC 上就是 Alt 键),但是其实 @ 是shift-2 (看看你的键盘)。所以 “C-M-@” 实际上要你按 ctrl-alt-shift-2。
但是在配置文件里的键序列中,我们把 “C-x r” 表示为 “\C-xr”, 把 “C-M-@” 表示为 “\C-\M-@”,你自己看看就知道怎么回事了。同理 “Esc a” 别表示成 “\ea”。
这就是 Emacs 里的按键的通常标记方法。EMACS = Esc Meta Alt Ctrl Shift
技巧篇
在自己配置命令行之前,我们先来看看利用缺省的键绑定能够进行的一些巧妙的用法:
第一招:使用以前的命令行参数
你是否经常出现这种情况?你想把 ~/text-browser/ 目录下的3个.tar.gz文件搬到/usr3/software/,于是你输入:
$mv ~/text-browser/*.tar.gz /usr3/software/
我想你一定已经知道,打入 ~/text 之后按 TAB 就可以补全text-browser这个长文件名吧?这是Bash 的基本功能。我废话?好了,就当你知道吧。不过今天我要讲的东西比这个复杂一些。
Go on! 刚刚输入到这里,你突然想起,应该在 /usr3/software/ 下先建立一个目录叫browsers,这样放进去的文件比较好管理。
于是你 Ctrl-u,删掉了这行命令。唉呀,这么长的命令一下就没了。是不是有点可惜?这还不算麻烦。然后你
mkdir /usr3/software/browser mv ~/text-browser/*.tar.gz /usr3/software/browser
嗯。TAB 是帮了你不少忙。可是你实际上有更好的办法来完成这项工作。好吧,看看 readline 怎样神奇的完成你的任务:我们回到这种情况:
$mv ~/text-browser/*.tar.gz /usr3/software/
你 刚才是按了 Ctrl-u 删除了所有输入的东西。可惜啊!你要是按 M-#(也就是按住 PC 机的 Alt 键,再按 #,实际上就是 Alt-Shift-3),那么 Bash 就会在这样最开头插入一个 “#”,然后输入这行。这样命令就被作为一行注释载入了历史。这有什么好处?这样你的这行命令里的内容就可以被再次利用。看着:你接着输入:
mkdir ...
等 等,你是不是想输入 /usr3/software/?你不用再敲一遍了!直接按 M-.(Alt 加句号),看看, /usr3/software/ 是不是出现在命令行上了?M-. 就是调用了 yank-last-arg 函数,把上一条命令的最后一个参数放在命令行上。好了,回车吧!你接着输入:
mv ...
等等,这下是该输入 ~/text-browser/*.tar.gz 了。烦不烦啊?换一种方式吧。请按:”M-1 M-.”(把上一条命令的第一个参数放在命令行上)。这样命令行成为了:
mv /usr3/software/browser
怎么成这样了?看看你的“上一条命令”是什么吧?是……你自己看。所以这个参数不是你想要的。那么继续再按一次 “M-.”。看到了吧?你的命令行已经成为:
mv ~/text-browser/*.tar.gz
好。打一个空格。再按一下 “M-.”。命令行变成了:
mv ~/text-browser/*.tar.gz /usr3/software/browser
这就是你想要的!是不是看起来你还是花了不少工夫?但是想一想,如果你是要执行这样一个命令呢?
mv /data/ftp/pub/TUG/texmf/tex/latex/CJK/GB/GB.cap \ /usr/local/texlive/texmf-local/tex/latex/CJK/GB/
嗯。记住这个有用命令:M-. , 它的前面可以用 M-0, … 作为数字参数。
第二招:补全命令名,文件名和变量名
你知道 TAB 可以补全命令行上很多东西。可是你遇到这种情况的时候怎么办?
man a-very-very-long-command-name
你 输入了 man a-ver… 之后,按 TAB,什么反应也没有。因为 TAB 执行的是 “按情况补全”(complete),它看到 man,知道这应该是一个命令,那么它认为: “后面应该是一个文件名参数。” 但是你想要的是命令的名字怎么办?答案:按 “M-!”.再来看:你需要设置 XMODIFIERS=”@im=fcitx”。你输入了
export XM...
按 TAB? 没有反应。为什么呢?因为 TAB 的补全想要一个文件名,而当前目录没有开头是 “XM…” 的文件。那么你怎么补全?答案:”M-$”。其实 readline 的补全方式被 Bash 扩充了很多。看看有多少吧!
"TAB": complete "\M-!": complete-command "\M-/": complete-filename "\M-@": complete-hostname "\M-~": complete-username "\M-$": complete-variable
自己试试吧!
第三招:扩展命令行
你 的一个目录里有很多类似的文件,名字叫 T12.txt, T12.log, T23.txt, T23.log, T13.txt, T13.log…… 有后缀 txt 的,也有后缀 log 的。… 你想把其中的某些 T*.txt 都移动到另外一个目录,而T*.log都不动。但是T*.txt 也不是全部都要移动。所以你想把T*.txt 都放在命令行上,然后选择其中一些。你输入:
mv T...
接着按 “M-*”(insert-completions)。结果 T 开头的文件都被放到命令行上了。嗯。这在某些时候是有用的,可是现在它把 T*.log 的文件也放上去了。不行。我们于是继续输入:
mv T*.txt
好了,现在我们可以使用 “C-x*”(先按ctrl-x,然后按*)。结果所有名字T*.txt 的文件都被放到了命令行上面。”C-x*” 执行的函数叫做 glob-expand-word.
配置篇
你是不是觉得那些命令很难记住?不顺手?别怕!它们都是可以改变的,就像Emacs的键绑定那样,可以被任意的改变!
所有使用readline的程序,都使用一个配置文件来决定它的行为和键绑定。这个文件一般是 INPUTRC 环境变量确定的。如果这个环境变量没有值,那么缺省使用 ~/.inputrc。
~/.inputrc 文件很简单,只有4种语句:
- 注释
- 变量设置语句(set variable value)
- 键绑定(”keyseq”:function)
- 条件语句($if … $endif)
我们先不说其它的,先来看看键绑定吧!
键绑定
- 绑定语句。你 现在就可以动手设置你喜欢的控制方式。比如,我发现有些时候我需要在命令行上做上 mark(Emacs 术语),然后把mark 和光标之间的 region(Emacs术语) 删掉,这个操作在 Emacs 里叫做kill-region. 但是我们发现这个函数在 Bash 里缺省是没有绑定的。如果我希望得到跟 Emacs 一样的绑定 C-w 的话,就把这行插入到 ~/.inputrc:
"\C-w":kill-region
- 使绑定生效。为了使这个键绑定生效,你需要执行 re-read-init-file 函数。这个函数缺省绑定在了 “C-x C-r”。你修改 ~/.inputrc 之后在 Bash 里输入 “C-x C-r” 就可以使新的配置生效了。
- 列出可用的函数。不过你怎么知道那些函数可以被绑定呢?readline 的 info 页列出了很多函数,可是你不会每次都去info里查询吧,很麻烦啊。其实你可以使用bash的 bind 命令来得到所有的键绑定:
$bind -p
可以显示所有现有的已经绑定和没有绑定的函数。没有被绑定的函数被显示为 “(not bound)”,并被加上了注释。就像这样:
"\C-g": abort "\C-x\C-g": abort "\M-\C-g": abort "\C-j": accept-line "\C-m": accept-line # alias-expand-line (not bound) # arrow-key-prefix (not bound) # backward-byte (not bound) "\C-b": backward-char "\M-OD": backward-char "\C-h": backward-delete-char "\C-?": backward-delete-char
你可以把这个命令的输出作为一个模板,嵌入到 ~/.inputrc 文件。把你喜欢的函数绑定到方便的按键。其实 readline 有三个函数可以让你方便的查询函数,变量和宏的绑定情况,它们是:
dump-functions dump-variables dump-macros
可是它们缺省都没有被绑定到任何按键。你可以为它们分别设置类似 “C-xf”, “C-xv”, “C-xm” 这样容易记忆的绑定。
- 如果忘了绑定……这样你就可以设置你需要的绑定啦!但是你还是有可能在需要的时候突然记不起哪些键绑定可以补全。这时候你输入:
$bind -p | grep compl
得到结果:
"\C-i": complete "\M-\e": complete "TAB": complete "\M-!": complete-command "\M-/": complete-filename "\M-@": complete-hostname "\M-{": complete-into-braces "\M-~": complete-username "\M-$": complete-variable "\M-\C-i": dynamic-complete-history "\M-g": glob-complete-word "\M-*": insert-completions .......这样你记不住一个键的时候就可以方便的查询,这样几次之后,你就会把自己需要的按键都记住了。
配置变量
- 体验:Bash 的 readline 有一些变量可以控制它的行为。比如:
bell-style 可以控制出错时是 audible(发出响声),visible(闪动屏幕),还是none(什么都不做);editing-mode 可以控制你是用 Emacs 的输入方式还是用 vi 的;
completion-query-times 的值控制在补全的个数超过多少N时,bash 提示: “Display all N possibilities? (y or n)”;
如果我设置 expand-tilde 为 on,当输入“ls ~/doc”,按 TAB 时,命令行会自动变成 “ls /home/wy/doc”.
如果把 visible-stats 设置为 on,那么列出补全的时候,目录,可执行文件,符号连接,会被分别使用 /, *, @ 来标记,就像 ls -F 的到的结果。
- 设置:设置的方法极其简单,就在 ~/.inputrc 文件里写入类似语句:
set visible-stats on
然后 “C-x C-r” 使设置生效。
- 怎样知道有哪些设置?可以设置的参数是很多的。使用命令
$bind -v
就可以得到所有这些可以设置的变量和它们的值了。

