要对linux的基础知识作一个基本的学习

  既然我打算把linux系统作为我的个人日常使用平台,我就得把学习linux操作系统当一回事。

  在解决我的sedY890手机在redhat linux9.0下认不到的过程中,我感觉到了自己的linux操作系统基础知识的缺乏。例如:各个主要配置文件的作用,内核的编译、内核编译过程中选项的意思,linux的启动与日常的软件维护。

  我发现单单靠去心里没底的实践来掌握linux的使用可能要走弯路。那么,就让我掌握那20%的基础知识,来获得80%的使用效果吧!

  我发现在http://www.matrix.org.cn上的linux知识比较对我的口味,这段时间就以这个论坛的浏览为主、再结合我买的那本盗版的linux书为辅来进行基础知识的补充吧。

  今天,认真读了一篇入门文章:Linux爱好者入门教程(随时更新)!! ,不错。本想转载的,太长了。列一个特征段,保证以后可以在网上找到这篇文章:

  


为了保证文章的完整性,简单说说目录吧,其实大家都很清楚的。如果我们把数以万计的水果扔在一个箩筐里面是不是很难找?但是如果我们把苹果放在叫做苹果的箩筐里面,把梨放在叫做梨的箩筐里面……这样是不是大大简化了我们寻找指定水果的速度?这些水果如果是我们的文件,那么我们用的箩筐就叫目录。新的问题出现了,即使把桃子扔在叫做桃子的箩筐中,我们仍然很难从好几千个桃子里面找出来自四川成都龙泉驿的桃子啊。聪明的你一定想到在桃子的箩筐中再放入很多叫做四川啊,河北啊,广州啊这些名字的箩筐,把不同产地的桃子放进去。对!就这样!我们在一个文件目录下面可以再建立新的文件目录,把文件进行非常细致的管理。到这里你明白了什么叫做目录,还明白了目录是可以嵌套的,这就可以了。目录技术是从软件的基础上对资源进行管理的方法。

 

  嘿嘿,作者好像是四川的老乡呢。

  从今天的浏览我得出一个结论,要想掌握linux,必须先从文本模式开始学习。就像我学java从ultraedit文本编辑器开始同样的道理。我要拿出初学java时的态度来掌握linux。能力是其次的,态度才是关键所在!

疑问:eclipse中的work目录的所有者怎么为root?

  今天,在eclipse2.1中启动Tomcat5.0后总是不能启动eclipse中的learndiary工程,报告找不到wok目录下的一些文件,可是我明明加了work目录啊。想到linux的权限控制,可能这个目录我没有写权限,一看,果然如此,所有者是root,其它人没有写权限,那些工作文件当然就不能写入了。

  但是我不明白为什么我用非root用户登录在eclipse中用add jsp work folder创建的work目录的所有者会是root,成了我这个真正的创建者倒不能控制我自己创建的目录了,是为什么呢?

linux下的java反编译器

命令行的,用起来感觉还可以。

相关页面地址:http://www.kpdus.com/jad.html#download

我下载的是:http://www.kpdus.com/jad/linux/jadlx158.zip

以root权限进行如下操作:

1、把下载的文件解压至/opt/jad目录。

2、然后在/etc/profile文件里的export path=""里加入/opt/jad ,如我的这行为:export PATH="$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin:$ANT_HOME/bin:/opt/rar:/opt/firefox:/opt/jad"

3、在命令行中输入:jad -sjava User.class

显示为:Parsing User.class... Generating User.java

这样就把User.class反编译为了:User.java

其它更多的选项和用法见其中的Readme.txt或者输入jad --help查查看帮助。

安装windows怎样删除linux的引导程序

  单位上的那台k6-2 450老机使用redhat linux9.0太慢了,简直不能正常工作,使用windows2000还能继续做点事,于是格式化硬盘后重新分区,准备安装win2000,但是grep的引导程序总是存在,以至不能继续安装。后来,在网上查了一下,是linux安装时把引导程序写入了主引导分区记录。在dos下用fdisk /mbr重写主引导分区记录就行了。

  这时,我想起原来在redhat linux9.0上直接安装windows2000没有覆盖linux的引导记录我想大概也是同样的原因吧。见:在linux的基础上重新安装windows2000不会覆盖启动菜单

  我感觉我对linux渐渐的有些好感了。

Linux 使用技巧集锦(转载)

Linux 使用技巧集锦(转载)

极光苏键 | 2006-04-23 12:45

初用Linux时可能有处处不方便的感觉, 可是等使用一段时间掌握了一些技巧后就会感到越来越顺手了. 以下就是我使用Linux以来积累的一些经验与技巧, 相信对初学者会有所帮助的.

1. 使用虚拟控制台

  登录后按Alt+F2键这时又可以看到"login:"提示符, 这个就是第二个虚拟控制台. 一般新安装的Linux有四个虚拟控制台, 可以用Alt+F1~Alt+F4来访问. 虚拟控制台最有用的时候是当一个程序出错锁住输入时可以切换到其他虚拟控制台登录进入后杀掉这个出错的进程.

2. 拷贝与粘贴

  字符界面: 不管是Slackware 还是RedHat 安装后每次启动时都会自动运行一个叫gpm的程序, 该程序运行后就可以用鼠标来拷贝与粘贴了. 具体做法是按住鼠标左键拖动使要拷贝的地方反白, 这时反白的区域已经被拷贝, 再按鼠标右键拷贝的内容就会被粘贴在光标所在位置了.

X-Window下: 拷贝的操作与字符界面下一样, 三键鼠标的话按中键粘贴, 两键鼠标的话同时按左右键粘贴(须在配置XF86时在鼠标的设置里选择 Emulate 3 Button).

3. 快速进入某些目录

键入 cd ~ 可进入用户的home目录.

键入 cd - 可进入上一个进入的目录.

4. 软驱的使用

如果是Linux 的ext2文件系统用如下命令:

#mount -t ext2 /dev/fd0 /mnt

dos格式的软盘则用命令:

#mount -t msdos /dev/fd0 /mnt

然后就可以在/mnt里访问软盘的内容了, 注意在取出软盘之前要先卸掉软盘上的文件系统,

#umount /mnt 否则会导致信息丢失.

在软盘上建立文件系统可用如下命令:

#mke2fs /dev/fd0 1440

5. RedHat下显示彩色目录列表

打开/etc/bashrc, 加入如下一行:

alias ls="ls --color"

下次启动bash时就可以像在Slackware里那样显示彩色的目录列表了, 其中颜色的含义如下:

蓝色-->目录

绿色-->可执行文件

红色-->压缩文件

浅蓝色-->链接文件

灰色-->其他文件

6. 显示文件的类型

  用命令 file 可以使你知道某个文件究竟是ELF格式的可执行文件, 还是shell script文件或是其他的什么格式 例如:

#file startx

7 .命令文件的路径

当你键入一些命令如find, shutdown, mount, startx时是否想过要知道这些文件究竟放在哪个目录里? 用命令

whereis 可以实现,如

#whereis startx

8. 查找文件

find 命令要加一些参数才能查到文件, 如:

#find /usr -name XF86Setup -print

在/usr里查找文件XF86Setup.

9. 删除无用的core文件

程序运行出后有时候会产生一个名为core的文件, 这个文件一般很大而且没什么用, 可以删除掉以释放空间.

10. 一次解开.tar.gz文件

解开.tar.gz文件一般要先用gunzip解压再用tar解包, 在Linux下可以一次完成, 如:

#tar zxpvf sample.tar.gz

11. 显示win95分区里的长文件名

  如果你发现win95分区里的长文件命不能显示, 可以重新用vfat方式来mount. 对于启动时就mount的分区可以修改文件/etc/fstab, 将里面的msdos字样改为vfat. 如果无法用vfat mount, 则要重新编译一下核心, 加入对vfat的支持.

12. Linux 里的Norton Commander

  在提示符下键入命令mc后你就会看到一个与Norton Commander很相似的界面, 实际上功能也很相似甚至更强大, 比如可以直接对.tar.gz 压缩包里的文件进行操作(有点像ZipMagic).

13. 启动后直接进入X

  编辑/etc/inittab文件, 把id:3:initdefautl改为 id:4:initdefautl. 不过搜索路径可能会有些问题, 关机时你得直接进入/sbin 里去执行 shutdown.

14. 后台运行 X 程序

  执行一个X程序时别忘了在后面加一个&号,如 #netscape & 否则的话在你推出执行的程序之前再无法在那个终端窗口里输入命令了.

15. 强行退出 X

  有时候在 X 里由于程序出错鼠标键盘都不起作用, 这时候不用着急, 因为在Linux下几乎不会像在Win95里那样恶性死机, 你只须键入Ctrl+Alt+BackSpace键就可以回到字符界面下了。

16. 重装Win9x后lilo失效无法启动Linux

  只须先用软盘启动Linux然后运行一次lilo即可。对于RedHat可以用命令mkbootdisk来制作启动盘,例如:

mkbootdisk --devices /dev/fd0 2.0.34-1

其中2.0.34-1是 /lib/modules下的一个目录。

17. 把dos/windows改为缺省启动的OS

  RedHat把Linux作为lilo缺省启动的OS,即出现 boot: 提示符后直接回车启动Linux。如果想改为dos/Windows,修改文件/etc/lilo.conf,把有关启动dos的部分放在前面,再运行一次lilo即可。例如把lilo.conf从:

boot=/dev/hda

map=/boot/map

install=/boot/boot.b

prompt

timeout=50

image=/boot/vmlinuz-2.0.34-1

label=linux

root=/dev/hdc5

read-only

other=/dev/hda1

label=dos

table=/dev/hda

改为:

boot=/dev/hda

map=/boot/map

install=/boot/boot.b

prompt

timeout=50

other=/dev/hda1

label=dos

table=/dev/hda

image=/boot/vmlinuz-2.0.34-1

label=linux

root=/dev/hdc5

read-only

18. 去掉引导区内的lilo信息

  安装lilo后如果硬盘数量或分区情况有改变的话将导致硬盘不能启动,这时只须用软盘启动dos再运行 fdisk/mbr 即可。(这个方法还可清除任何引导区病毒)

19. 让 X 支持 AGP 显卡

  下载一个 AX 4.1 即 AcceleratedX 4.1 , 一个商业版的 X Server 。除 AGP 显卡外 AX 还支持很多牌号的显卡。另外还可以用AX 带的设置程序 Xsetup 方便的对分辨率,刷新率等参数进行设置。不过我也不知道用AGP卡效果如何,因为我现在还在用老掉牙的 S3 765 。

20. 把 man 或 info 的信息存为文本文件

以 tcsh 为例: man tcsh | col -b > tcsh.txt

info tcsh -o tcsh.txt -s

21. 用当前路径作提示符

对 bash 来说,在 .bashrc 里加一行:

PS1="$PWD$"

对 tcsh 来说,在 .tcshrc 里加一行:

set prompt="%/>"

22. 压缩可执行文件

  Linux 下有一个类似 dos 里的 pklite 和 lzexe 的命令 -- gzexe 。而且压缩率一般都可以超过 50% ,在空间紧张时很有用。比如:

/dosc/temp# ls -al

total 148

-rwxr-xr-x 1 root root 149564 Dec 8 15:33 gawk

/dosc/temp# gzexe gawk

gawk: 54.5%

/dosc/temp# ls -al

total 216

-rwxr-xr-x 1 root root 68710 Dec 8 15:36 gawk

-rwxr-xr-x 1 root root 149564 Dec 8 15:33 gawk~

/dosc/temp#

23. 查看 Linux 启动时的信息

  Linux 启动时屏幕显示的信息来不及看清就一闪而过,如果对这些信息感兴趣的话可以在启动完后用命令 dmesg 查看。

24. 处理文件名内含有特殊字符的文件

  如果有一个文件名叫 -file 如果想删除它,键入 rm -file 会显示 invalid option ,原来由于文件名的第一个字符为 - , Linux 把文件名当作选项了,可以加 -- 解决这个问题, 如 rm -- -file 。如果是其他特殊字符的话可以在特殊字符前加一个 ,或者用双引号把整个文件名括起来。

25. 一次处理一整个目录

  Linux/UNIX 的很多常用命令如 rm , cp 等都有一个参数---- -r , 是递归的意思, 命令里加了参数 -r 就可以对目标目录及其下所有子目录进行操作,如:

rm -rf /test (f 是 force 意为强行) , 该命令完全删除根目录下的子目录 test ,作用类似于 dos 下的 deltree ,当然使用这个命令时要特别小心。再如:

cp -r /test /test1 有类似 dos 下 xcopy /s 的作用。

26. 修改登录画面

对本机:

先修改文件 /etc/issue 改为相要显示的内容, 再修改文件 /etc/rc.d/rc.local(RedHat) 或 /etc/rc.d/rc.S(Slackware) 把下面几句注释掉:

# This will overwrite /etc/issue at every boot. So, make any changes you

# want to make to /etc/issue here or you will lose them when you reboot.

echo "" > /etc/issue

echo "Red Hat Linux $R" >> /etc/issue

echo "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue

cp -f /etc/issue /etc/issue.net

echo >> /etc/issue

不然的话每次重新启动 /etc/issue 都会被更改。

对 telnet 的远地机器:

先把文件 /etc/usr/sbin/in.telnetd 改名,如改为 in.telnetd.exe ,再编一个名为 in.telnetd 的 shell 脚本, 在显示完需要的内容后再调用 in.telnetd.exe 。如:

#!/bin/sh

cat /etc/login.banner #需要在登录提示符前显示的内容

echo -n ""

exec /usr/sbin/in.telnetd.exe

27. 几个有用的别名

几个能方便操作和减少误操作的别名,建议把它们放到启动文件里, 如 /etc/bashrc 。

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

#前三个别名的作用是在删除、覆盖文件之前先提示确认,RedHat已经自动

#加上了,强烈建议Slackware的用户也加上,因为Linux/UNIX下文件一旦删

#除就再也无法恢复了。

alias l='ls -l'

alias cd..='cd ..'

alias utar='tar xvfz' #解 *.tar.gz 文件

alias inforpm='rpm -qpi' #显示rpm包的信息

alias instrpm='rpm -Uhv' #安装rpm包

alias listrpm='rpm -qpl' #列rpm包内的文件

alias uistrpm='rpm -e' #反安装rpm包

28. 使用命令补齐

  所谓命令补齐(Command-Line Completion)是指当键入的字符足以确定目录下一个唯一的文件时只须按 Tab 键就可以自动补齐该文件名的剩下部分,例如要把目录 /freesoft 下的文件 gcc-2.8.1.tar.gz 解包,当键入到 tar xvfz /freesoft/g 时如果该文件是该目录下唯一以 g 起头的文件的话就可以按下 Tab 键,这时命令会被自动补齐为:tar xvfz /freesoft/gcc-2.8.1.tar.gz ,非常方便。

29. 最后一条技巧

  有时间的话多看看系统提供的FAQ文件,因为通常遇到的问题大多数都能在里面找到答案。

30.取消^M字符

当你FTP一些DOS文件到unix下时,你经常会看见每行文件后面有个讨 厌的^M 字符,有两个简单的方法可以取消它。用"vi"打开此文件,在Command mode下敲入: s/^V^M//g 或者,在UNIX SHELL下敲入: sed 's/^V^M//g' foo > foo.new

31.使用nohup命令

如果你想进程在你退出系统后还能执行,可以使用NOHUP命令 如: % nohup tar -cf /dev/tape /home & 你退出后再重新登录的话,使用'ps'命令可以看到进程还在执行

32.查看文件的方法

如果你只想看文件的前5行,可以使用head命令,如: head -5 /etc/passwd 如果你想查看文件的后10行,可以使用tail命令,如: tail -10 /etc/passwd 你知道怎么查看文件中间一段吗?你可以使用sed命令 如: sed -n '5,10p' /etc/passwd 这样你就可以只查看文件的第5行到第10行。

33.计算文件数和目录数下面的语句可以帮你计算有多少个文件和多少个目录..

# ls -l * |grep "^-"|wc -l ---- to count files

# ls -l * |grep "^d"|wc -l ----- to count dir

还可以将以上的语句变成script或做个alias

34.只列子目录的方法:

ls -F | grep /$ 或者

alias sub = "ls -F | grep /$"(linux)

ls -l | grep "^d" 或者

ls -lL | grep "^d" (Solaris)

35.利用Find命令改变所有权

想要改变当前目录下所有文件的所有权,可以这样:

find . -exec chown OWNER.[GROUP] {} ; (Solaris)

find . -exec chown -R OWNER.[GROUP] {} ; (Linux)

36.列出除了某些类型文件的当前目录所有文件

使用Ksh,用ls !(*.Z)可以显示所有文件,除了*.Z文件。 这个命令在一个目录里有许多种类型的文件的时候很有用。

37、处理特殊的文件名

假设Linux系统中有一个文件名叫“-aaa”,如果我们想对它进行操作,例如现在要删除它,如果我们按照一般的删除方法在命令行中输入rm -aaa命令,界面将会提示我们是无效选项(invalid option),原来由于文件名的第一个字符为 - ,Linux把文件名当作选项了,我们可以使用“--”符号来解决这个问题,例如我们可以输入rm -- -aaa命令来删除-aaa文件。如果是其他特殊字符的话可以在特殊字符前加一个“”符号,或者用双引号把整个文件名括起来。

38、修复Linux下超级用户的密码

如果超级用户将密码忘记,就无法进入系统,也无法管理和使用系统。本来这种事不太可能发生,但是在一些Linux单机使用者,尤其是初学者中,却是比较容易发生。一般的解决方法就是格式化硬盘来重新安装系统,但这有点儿小题大作了。准备好bootdisk和rootdisk两张软盘,从软驱启动,启动到 root盘并出现shell提示符。将Linux根目录分区mount至/mnt目录,比如你的Linux在硬盘第一分区,就在命令行中输入mount /dev/hda1 /mnt,然后进入mnt目录,将其中的etc/passwd文件改名,输入mv /mnt/etc/passwd /mnt/etc/passwd.bak就可以了;接着使用命令cp /etc/passwd /mnt/etc/passwd将软盘上的/etc/passwd文件复制到硬盘中的etc目录下,这样重新由硬盘启动,登录时就不会询问超级密码;最后使用mv/etc/passwd.bak passwd命令将passwd文件改回,再运行passwd命令重新设定密码就可以了。

39、直接进行Linux的安装工作

  通常我们在安装某个操作系统软件时,需要该系统的引导盘启动才能安装。但我们在安装Linux操作系统时,可以利用该系统光盘中的一个名为 loadlin.exe的DOS软件,将Linux核心直接调入内存,并由Linux核心代替当前操作系统来接管计算机,并进入Linux的安装界面。在安装Linux时,我们只要在运行对话框中输入loadlin E:imagesvmlinuz root=/dev/ram initrd=E:imagesinitrd.img这个命令就可以直接安装Linux了;其中E是光驱盘符,E:imagesvmlinuz为 Linux核心名。

40、快速启动Linux系统

  随着个人计算机配置的日益提高,在自己的计算机上安装Linux系统已经不是什么新鲜的事了。假设我们的计算机上同时装有windows和Linux两个操作系统,应该如何启动Linux呢?是否每次都需要重启计算机,通过LiLo引导?其实如果我们在dos下,有一种简单快速启动Linux的方法,那就是load Linux。loadlin.exe是在dos下的可执行程序,它可以在纯dos环境下迅速启动Linux,而且无需重启计算机,通常我们可以在光盘的 /kernels目录下可以找到这个程序。如果不知这个程序被放置于安装盘的何处,可以使用“find -name loadlin*”命令来寻找。找到之后将其复制到dos分区中,同时还需要复制一份你所使用的Linux内核文件。可以通过windows直接从光盘复制,也可在Linux环境下使用mcopy命令将文件copy到dos分区;接着再编写一个Linux.bat的批处理文件,文件内容如下:c: loadlin c:vmlinuz root=/dev/hda1 ro

其中我们假设loadlin.exe和vmlinuz这两个内核文件都在c盘根目录,而root为Linux根设备,而且Linux处于硬盘第一分区,所以设备名为/dev/hda1,ro意为readonly。以后在dos下要启动Linux时,运行Linux.bat就可以了。这样启动Linux快速高效,大大的减少了系统自检时等待的时间。

41、消除Xwindows下的死机现象

  如果我们在Xwindows状态下运行Linux时,由于硬件本身的问题或者自己操作上的不当,有时侯可能会导致系统突然失去响应,也就是我们常见到的一种死机现象,其实此时系统并没有死机。我们可以用两个常用的方法来消除这种现象:第一,用键盘上的复合键Ctrl+Alt+Backspace来关闭当前正在运行的任务;第二,首先按住键盘上的Ctrl+Alt+F2复合键,让系统切换到另一个操作台,然后登陆到系统,再执行#ps -ax|grep startx命令,这将会列出你的Xserver的进程标识(PID),接着在命令行中输入如下命令就能消除Xwindows下的死机现象:#kill -9 PID_Number,最后通过Alt+F1复合键返回原来的平台。

42、快速关闭Linux系统

  旧版本的的Linux/UNIX系统必须先运行shutdown命令,然后才能关闭电源,但最新版本的Linux/UNIX系统已经在这个方面作了很大的改进,再也没有必要象以前那样关机了。因为新版本的系统借鉴了大型机的技术,采用了抗掉电的日志式文件系统,可以自动跟踪保存用户数据、自动同步刷新文件系统,用户完全可以随手关闭电源,从而达到快速关闭系统的目的了。

43、巧妙使用rm命令

  我们知道在Linux字符界面中,要删除一个文件的话可以使用rm命令,删除一个目录可以使用rmdir命令。但由于rmdir命令只能删除空白的目录,假使某个目录下面有文件,就只能先用rm命令来把目录中的文件删除掉才可以,所以通常需要rmdir与rm这两个命令配合使用才能彻底删除一个完整的目录。但用这种方法来对付几级子目录还能凑合,如果一个目录中含有若干个子目录,而且这若干子目录中又包含了若干级子目录,再使用这种方法不把你累死才怪。现在我们可以使用带-r参数的rm命令来删除一个非空目录,例如我们在命令行中输入rm -r bbb这样的命令,表示系统将把bbb目录中包含的所有文件和子目录全部删除掉。

44、善用虚拟操作台

  当我们登录进Linux系统后,如果再按一下键盘上的Alt+F2键,这时我们又可以看到一个Shell提示符,其实这个就是第二个虚拟操作台。通常,新安装的Linux系统共有四个虚拟操作台,我们可以分别用复合键Alt+F1、Alt+F2、Alt+F3、Alt+F4来访问它们。使用虚拟操作台频率最多的地方就是,当某一个程序出错锁住输入时或者Linux系统突然失去响应时,就可以切换到其他虚拟操作台登录进入后杀掉这个出错的进程任务。

45、增加虚拟缓存

  如果计算机上的SWAP(交换空间)不够了,只要我们的硬盘上还有空余的空间,我们就可以把这些剩余空间利用起来,我们可以直接使用命令:mkswap /dev/hda(假设Linux的驱动器是/dev/hda),swapon /dev/hda;要自动启动Swap,可以把新的分区加入到etc/fstab中去,照着原来swap的写就行了。用"free"检查swap的大小, Linux支持最多16个交换分区,每个交换分区最大128M,没有空闲分区的时候,可以用个大文件来建立。下面是执行的一系列命令:

   #dd if=/dev/zero of=swapfile bs=1024 count=8192

   #mkswap swapfile 8192

   #sync

   #swapon swapfile

46、巧妙使用Tab键

  大家知道在Linux字符界面中输入命令时,有时需要输入很多字符,如果经常这样逐个逐个地输入字符,比较烦琐。假设键入的字符足以确定目录下一个唯一的文件时,我们只须按键盘上的 Tab 键就可以自动补齐该文件名的剩下部分,例如要把目录 /ccc 下的文件 ddddddd-1.2.3.tar.gz 解包时,当我们在命令行中键入到tar xvfz /ccc/d时,如果该文件是该目录下唯一以d起头的文件的话就可以直接按下键盘上的Tab键,这时命令会被自动补齐为:tar xvfz /ccc/ddddddd-1.2.3.tar.gz ,从而提高了输入效率。

47、多用拷贝与粘贴来提高操作速度

   Linux系统安装后,每次启动到字符界面时都会自动运行一个叫gpm的程序, 该程序运行后就可以用鼠标来拷贝与粘贴了。具体做法是按住鼠标左键拖动让要拷贝的地方突出显示, 这时突出显示的区域已经被拷贝, 再按鼠标右键拷贝的内容就会被粘贴在光标所在位置了。如果我们在Xwindow下运行Linux系统,拷贝与粘贴的操作与在普通的Win9x系统下一样。

48、加快Linux存取数据

  如果我们想快速提高Linux下的硬盘读取数据,可以在Linux下进行一些设置,让Linux在32位输入输出方式和DMA通道方式下进行工作。设置时,在Linux命令界面中输入命令/sbin/hdparm -cl /dev/hda来打开32bit传输方式,输入命令/sbin/hdparm -dl /dev/hda来打开DMA传输方式,接着再输入命令/sbin/hdparm -kl /dev/hda来使硬盘在Reset之后仍然保持上述的设置,通过这些设置,我们就能提高Linux的读盘速度到1倍以上

49.禁止启动时进入其它操作系统

当计算机上有多个操作系统时,我们可以调整多重启动管理器的配置,让计算机在启动时只能进入Linux,禁止别人进入其它操作系统。

大多Linux系统使用的都是LILO多重启动管理器,也有使用其它启动管理器的(蓝点LINUX 2.0使用的就是grub启动管理器)。

对于LILO启动管理器,可以编辑/etc/lilo.conf文件,其中文字行以“image=”开头的部分引导Linux系统,以“other=”开头的部分引导其它操作系统。只要将以“other=”开头描述引导其它操作系统的部分删除,重新启动,计算机就只能进入LINUX系统了。如果想恢复计算机可以引导其它操作系统的状态,只要重新编辑/etc/lilo.conf文件,恢复以“other=”开头的描述部分即可。

对于grub启动管理器,可以编辑/boot/grub/menu.lst文件,其中以“title”开头的文字行就是计算机启动时出现的菜单选项,将描述引导其它操作系统的部分删除,只保留引导Linux系统的部分,重新启动,计算机将只显示引导Linux系统的选项,计算机只能进入Linux系统。恢复计算机能引导其它操作系统的状态可以重新编辑/boot/grub/menu.lst文件,添加以“title”开头描述引导其它操作系统的部分即可。

50.启动时直接进入KDE环境

要想让Linux启动时直接进入KDE环境,可对文件/etc/inittab进行修改。用文本编辑器打开文件/etc/inittab,找到如下的一行文字: id: 3: initdefault: 把它改为: id: 5: initdefault: 再次启动时就可以直接进入KDE环境了。

TAR命令参数详解(转帖)

TAR命令参数详解

极光苏键 | 2006-04-28 17:30

每次使用都要查帮助,只怪自己记不住。发上来方便查。

TAR

命令名

tar - tar 档案文件管理程序的 GNU 版本。下面将逐个介绍其含义

总览

tar [ - ] A --catenate --concatenate | c --create | d --diff --compare | r --append | t --list | u --update | x -extract --get [ --atime-preserve ] [ -b, --block-size N ] [ -B, --read-full-blocks ] [ -C, --directory DIR ] [ --checkpoint ]

[ -f, --file [HOSTNAME:]F ] [ --force-local ]

[ -F, --info-script F --new-volume-script F ] [ -G, --incremental ] [ -g, --listed-incremental F ] [ -h, --dereference ] [ -i, --ignore-zeros ] [ -I, --bzip ] [ --ignore-failed-read ] [ -k, --keep-old-files ] [ -K, --starting-file F ] [ -l, --one-file-system ] [ -L, --tape-length N ] [ -m, --modification-time ] [ -M, --multi-volume ] [ -N, --after-date DATE, --newer DATE ] [ -o, --old-archive, --portability ] [ -O, --to-stdout ] [ -p, --same-permissions, --preserve-permissions ] [ -P, --absolute-paths ] [ --preserve ]

[ -R, --record-number ] [ --remove-files ] [ -s, --same-order, --preserve-order ] [ --same-owner ] [ -S, --sparse ] [ -T, --files-from F ] [ --null ]

[ --totals ]

[ -v, --verbose ] [ -V, --label NAME ] [ --version ]

[ -w, --interactive, --confirmation ] [ -W, --verify ]

[ --exclude FILE ] [ -X, --exclude-from FILE ] [ -Z, --compress, --uncompress ] [ -z, --gzip, --ungzip ]

[ --use-compress-program PROG ] [ --block-compress ] [ -[0-7][lmh] ]

filename1 [ filename2, ... filenameN ]

directory1 [ directory2, ...directoryN ]

描述

tar 程序用于储存或展开 tar 存档文件。存档文件可放在磁盘中 ,也可以存为普通文件。 tar是需要参数的,可选的参数是A、c、d、r、t、u、x,您在使用tar时必须首先为 tar 指定至少一个参数;然后,您必须指定要处理的文件或目录。如果指定一个目录则该目录下的所有子目录都将被加入存档。

应用举例:

1)展开 abc.tar.gz 使用命令: tar xvzf abc.tar.gz 展开 abc.tar 使用命令: tar xvf abc.tar

2)将当前目录下的 man 目录及其子目录存成存档 man.tar tar cf man.tar ./man

参数说明

运行tar时必须要有下列参数中的至少一个才可运行

-A, --catenate, --concatenate

将一存档与已有的存档合并

-c, --create

建立新的存档

-d, --diff, --compare

比较存档与当前文件的不同之处

--delete

从存档中删除

-r, --append

附加到存档结尾

-t, --list

列出存档中文件的目录

-u, --update

仅将较新的文件附加到存档中

-x, --extract, --get

从存档展开文件

其他参数

--atime-preserve

不改变转储文件的存取时间

-b, --block-size N

指定块大小为 Nx512 字节(缺省时 N=20)

-B, --read-full-blocks

读取时重组块(???!!!)

-C, --directory DIR

转到指定的目录

--checkpoint

读取存档时显示目录名

-f, --file [HOSTNAME:]F

指定存档或设备 (缺省为 /dev/rmt0)

--force-local

强制使用本地存档,即使存在克隆

-F, --info-script F --new-volume-script F

在每个磁盘结尾使用脚本 F (隐含 -M)

-G, --incremental

建立老 GNU 格式的备份

-g, --listed-incremental F

建立新 GNU 格式的备份

-h, --dereference

不转储动态链接,转储动态链接指向的文件。

-i, --ignore-zeros

忽略存档中的 0 字节块(通常意味着文件结束)

--ignore-failed-read

在不可读文件中作 0 标记后再退出???

-k, --keep-old-files

保存现有文件;从存档中展开时不进行覆盖

-K, --starting-file F

从存档文件 F 开始

-l, --one-file-system

在本地文件系统中创建存档

-L, --tape-length N

在写入 N*1024 个字节后暂停,等待更换磁盘

-m, --modification-time

当从一个档案中恢复文件时,不使用新的时间标签

-M, --multi-volume

建立多卷存档,以便在几个磁盘中存放

-N, --after-date DATE, --newer DATE

仅存储时间较新的文件

-o, --old-archive, --portability

以 V7 格式存档,不用 ANSI 格式

-O, --to-stdout

将文件展开到标准输出

-p, --same-permissions, --preserve-permissions

展开所有保护信息

-P, --absolute-paths

不要从文件名中去除 '/'

--preserve

like -p -s

与 -p -s 相似

-R, --record-number

显示信息时同时显示存档中的记录数

--remove-files

建立存档后删除源文件

-s, --same-order, --preserve-order

???

--same-owner

展开以后使所有文件属于同一所有者

-S, --sparse

高效处理

-T, --files-from F

从文件中得到要展开或要创建的文件名

--null

读取空结束的文件名,使 -C 失效

--totals

显示用 --create 参数写入的总字节数

-v, --verbose

详细显示处理的文件

-V, --label NAME

为存档指定卷标

--version

显示 tar 程序的版本号

-w, --interactive, --confirmation

每个操作都要求确认

-W, --verify

写入存档后进行校验

--exclude FILE

不把指定文件包含在内

-X, --exclude-from FILE

从指定文件中读入不想包含的文件的列表

-y, --bzip2, --bunzip2

用 bzip2 对存档压缩或解压

-Z, --compress, --uncompress

用 compress 对存档压缩或解压

-z, --gzip, --ungzip

用 gzip 对存档压缩或解压

--use-compress-program PROG

用 PROG 对存档压缩或解压 ( PROG 需能接受 -d 参数)

--block-compress

为便于磁盘存储,按块记录存档

-[0-7][lmh]

指定驱动器和密度[高中低]

--------------------------

压缩目录

压缩: tar -xf soft.tar soft

解压: tar -cf soft.tar soft

压缩文件

压缩:zip good.zip good1 good2

解压:unzip good.zip

Linux 查看磁盘分区、文件系统、使用情况的命令(转帖)

Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍

作者:北南南北

来自:LinuxSir.Org

提要:Linux 磁盘分区表、文件系统的查看、统计的工具很多,有些工具是多功能的,不仅仅是查看磁盘的分区表,而且也能进行磁盘分区的操作;但在本文,我们只讲磁盘分区的查看,以及分区的使用情况的查看;本文只是给新手上路之用;关于分区工具的操作,我将在以后做专门介绍;

此文目的:主要是向初学者介绍一下入门必备的一点基础知识,有了基础知识才能进阶;如果把所有的磁盘操作工具都放在一个文档里,大家看了也累;基于这种想法,所以我写文档的时候,就想让新手弟兄一目了解,能轻松点就轻松点;生活、工作和学习无不是如此;

操作环境:Fedora core 4.0 i686 & Slackware 10.1

+++++++++++++++++++++++++++++++++++++++

正文

+++++++++++++++++++++++++++++++++++++++

一、df 命令;

df 是来自于coreutils 软件包,系统安装时,就自带的;我们通过这个命令可以查看磁盘的使用情况以及文件系统被挂载的位置;

举例:

[root@localhost beinan]# df -lh

Filesystem            容量  已用 可用 已用% 挂载点

/dev/hda8              11G  6.0G  4.4G  58% /

/dev/shm              236M     0  236M   0% /dev/shm

/dev/sda1              56G   22G   35G  39% /mnt/sda1

我们从中可以看到,系统安装在/dev/hda8 ;还有一个56G的磁盘分区/dev/sda1挂载在 /mnt/sda1中;

其它的参数请参考 man df

二、fdsik

fdisk 是一款强大的磁盘操作工具,来自util-linux软件包,我们在这里只说他如何查看磁盘分区表及分区结构;参数 -l ,通过-l 参数,能获得机器中所有的硬盘的分区情况;

[root@localhost beinan]# fdisk -l

Disk /dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System

/dev/hda1 * 1 765 6144831 7 HPFS/NTFS

/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)

/dev/hda3 2806 7751 39728745 5 Extended

/dev/hda5 2806 3825 8193118+ 83 Linux

/dev/hda6 3826 5100 10241406 83 Linux

/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris

/dev/hda8 5199 6657 11719386 83 Linux

/dev/hda9 6658 7751 8787523+ 83 Linux

在上面Blocks中,表示的是分区的大小,Blocks的单位是byte ,我们可以换算成M,比如第一个分区/dev/hda1的大小如果换算成M,应该是6144831/1024=6000M,也就是6G左右,其实没有这么麻烦,粗略的看一下把小数点向前移动三位,就知道大约的体积有多大了;

System 表示的文件系统,比如/dev/hda1 是NTFS格式的;/dev/hda2 表示是fat32格式的文件系统;.

在此例中,我们要特别注意的是/dev/hda3分区,这是扩展分区;他下面包含着逻辑分区,其实这个分区相当于一个容器;从属于她的有 hda5,hda6,hda7,hda8,hda9 ;

我们还注意到一点,怎么没有hda4呢?为什么hda4没有包含在扩展分区?一个磁盘最多有四个主分区; hda1-4算都是主分区;hda4不可能包含在扩展分区里,另外扩展分区也算主分区;在本例中,没有hda4这个分区,当然我们可以把其中的一个分区设置为主分区,只是我当时分区的时候没有这么做而已;

再仔细统计一下,我们看一看这个磁盘是不是还有空间?hda1+hda2+hda3=实际已经分区的体积,所以我们可以这样算 hda1+hda2+hda3=6144831+16386300+39728745 = 62259876 (b),换算成M单位,小数点向前移三位,所以目前已经划分好的分区大约占用体积是62259.876(M),其实最精确的计算 62259876/1024=60800.67(M);而这个磁盘大小是80.0 GB (80026361856byte),其实实际大小也就是78150.744(M);通过我们一系列的计算,我们可以得出这个硬盘目前还有使用的空间;大约还有18G未分区的空间;

fdisk -l 能列出机器中所有磁盘的个数,也能列出所有磁盘分区情况;比如:

[root@localhost beinan]# fdisk -l

Disk /dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System

/dev/hda1 * 1 765 6144831 7 HPFS/NTFS

/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)

/dev/hda3 2806 7751 39728745 5 Extended

/dev/hda5 2806 3825 8193118+ 83 Linux

/dev/hda6 3826 5100 10241406 83 Linux

/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris

/dev/hda8 5199 6657 11719386 83 Linux

/dev/hda9 6658 7751 8787523+ 83 Linux

Disk /dev/sda: 60.0 GB, 60011642880 bytes

64 heads, 32 sectors/track, 57231 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot Start End Blocks Id System

/dev/sda1 1 57231 58604528 83 Linux

通过上面我们可以知道此机器有两块硬盘,我们也可以指定fdisk -l 来查看其中一个硬盘的分区情况;

[root@localhost beinan]# fdisk -l /dev/sda

Disk /dev/sda: 60.0 GB, 60011642880 bytes

64 heads, 32 sectors/track, 57231 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot Start End Blocks Id System

/dev/sda1 1 57231 58604528 83 Linux

通过上面情况可以知道,在/dev/sda 这个磁盘中,只有一个分区;使用量差不多是百分百了;

我们还可以来查看 /dev/hda的

[root@localhost beinan]# fdisk -l /dev/hda

自己试试看?

三、cfdisk 来自于util-linux的软件包;

cfdisk 也是一款不错的分区工具;在有些发行版中,此工具已经从util-linux包中剔除;cfdisk 简单易用是他的特点;和DOS中的fdisk 相似;在本标题中,我们只来解说如何查看机器的中的磁盘分区状况及所用的文件系统等;

查看磁盘分区的用法 cfdisk -Ps 磁盘设备名;

比如

[root@localhost beinan]cfdisk -Ps

[root@localhost beinan]cfdisk -Ps /dev/hda

[root@localhost beinan]cfdisk -Ps

Partition Table for /dev/hda

               First Last

 # Type Sector Sector Offset Length Filesystem Type (ID) Flag

-- ------- ----------- ----------- ------ ----------- -------------------- ----

 1 Primary 0 23438834 63 23438835 Linux (83) Boot

 2 Primary 23438835 156296384 0 132857550 Extended (05) None

 5 Logical 23438835 155268224 63 131829390 Linux (83) None

 6 Logical 155268225 156296384 63 1028160 Linux swap (82) None

我们只用的参数 -Ps,就列出了磁盘的分区情况;目前在Slackware Debian Mandrake 等主流发行版中存在cfdisk ,而fedora 4.0把这个小工具剔除了;有点可惜;这是我在Slackware中操作的;

如果您这样操作,就更直观了;

[root@localhost beinan]cfdisk 磁盘设备名

举例:

[root@localhost beinan]cfdisk /dev/hda

您所看到的是如下的模式:

                                        cfdisk 2.12a

                                    Disk Drive: /dev/hda

                              Size: 80026361856 bytes, 80.0 GB

                    Heads: 255 Sectors per Track: 63 Cylinders: 9729

    Name Flags Part Type FS Type [Label] Size (MB)

 -------------------------------------------------------------------------------------------

    hda1 Boot Primary Linux ReiserFS 12000.69

    hda5 Logical Linux ReiserFS 67496.65

    hda6 Logical Linux swap 526.42

     [Bootable] [ Delete ] [ Help ] [Maximize] [ Print ] [ Quit ]

     [ Type ] [ Units ] [ Write ]

                        Toggle bootable flag of the current partition

您进入了cfdisk 的操作界面;用键盘移动指针到[Quit]就可以退出;

四、parted 功能不错的分区工具;在Fedora 4.0中有带,可以自己安装上;在此主题中,我们只说如何查看磁盘的分区情况;

调用方法简单,parted 默认是打开的设备是/dev/hda ,也可以自己指定;比如 parted /dev/hda 或/dev/sda 等;退出的方法是 quit

[root@localhost beinan]# parted

使用 /dev/hda

(parted) p

/dev/hda 的磁盘几何结构:0.000-76319.085 兆字节

磁盘标签类型:msdos

Minor 起始点 终止点 类型 文件系统 标志

1 0.031 6000.842 主分区 ntfs 启动

2 6000.842 22003.088 主分区 fat32 lba

3 22003.088 60800.690 扩展分区

5 22003.119 30004.211 逻辑分区 reiserfs

6 30004.242 40005.615 逻辑分区 reiserfs

7 40005.646 40774.350 逻辑分区 linux-swap

8 40774.381 52219.094 逻辑分区 ext3

9 52219.125 60800.690 逻辑分区 reiserfs

我们在partd 的操作面上,用p就可以列出当前磁盘的分区情况,如果想要查看其它磁盘,可以用 select 功能,比如 select /dev/sda ;

五、qtparted ,与parted 相关的软件还有qtparted ,也能查看到磁盘的结构和所用的文件系统,是图形化的;

[beinan@localhost ~]# qtparted

图形化的查看,一目了然;

六、sfdisk 也是一个分区工具,功能也多多;我们在这里只说他的列磁盘分区情况的功能;

[root@localhost beinan]# sfdisk -l

自己看看吧;

sfdisk 有几个很有用的功能;有兴趣的弟兄不妨看看;

七、partx 也简要的说一说,有些系统自带了这个工具,功能也简单,和fdisk 、parted、cfdisk 来说不值一提;不用也罢;

用法: partx 设备名

[root@localhost beinan]# partx /dev/hda

# 1: 63- 12289724 ( 12289662 sectors, 6292 MB)

# 2: 12289725- 45062324 ( 32772600 sectors, 16779 MB)

# 3: 45062325-124519814 ( 79457490 sectors, 40682 MB)

# 4: 0- -1 ( 0 sectors, 0 MB)

# 5: 45062388- 61448624 ( 16386237 sectors, 8389 MB)

# 6: 61448688- 81931499 ( 20482812 sectors, 10487 MB)

# 7: 81931563- 83505869 ( 1574307 sectors, 806 MB)

# 8: 83505933-106944704 ( 23438772 sectors, 12000 MB)

# 9: 106944768-124519814 ( 17575047 sectors, 8998 MB)

八、查看目前机器中的所有磁盘及分区情况:

[beinan@localhost ~]$ cat /proc/partitions

major minor #blocks name

   3 0 78150744 hda

   3 1 6144831 hda1

   3 2 16386300 hda2

   3 5 8193118 hda5

   3 6 10241406 hda6

   3 7 787153 hda7

   3 8 11719386 hda8

   3 9 8787523 hda9

   8 0 58605120 sda

   8 1 58604528 sda1

九、mac-fdisk 这个工具主要是用在Powerpc版本的Linux中,咱们常用X86版本中没有这个工具;这个只是介绍一下;

相关文档

《在Linux系统中存储设备的两种表示方法》

《合理规划您的硬盘分区》

《系统引导过程及硬盘分区结构论述》

《Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍》

《实例解说 fdisk 使用方法》

《在Fedora core 4.0 加载NTFS和FAT32分区详述》

《Fedora Core 4.0 HAL配置即插即用移动存储(USB及1394)的实践》

Emacs Tutorial(即Emacs 教程中文版的英文原文)

(中文版:Emacs 教程中文版http://www.123go.org.cn/disDiaryContentAction.do?goalID=1980

Emacs Tutorial

NOTE: It is suggested that you start up Emacs before continuing. To bring up this tutorial in Emacs, hit the ESC key following by "x" then type help-with-tutorial followed by hitting the RETURN key.

Copyright (c) 1985 Free Software Foundation, Inc; See end for conditions.

Emacs commands generally involve the CONTROL key (sometimes labelled CTRL or CTL) or the META key (sometimes labelled EDIT). Rather than write out META or CONTROL each time we want you to prefix a character, we'll use the following abbreviations:

C-<chr> means hold the CONTROL key while typing the character <chr> Thus, C-f would be: hold the CONTROL key and type f.

M-<chr> means hold the META or EDIT key down while typing <chr>. If there is no META or EDIT key, type <ESC>, release it, then type the character <chr>. "<ESC>" stands for the key labelled "ALT" or "ESC".

Important note: to end the Emacs session, type C-x C-c. (Two characters.)

The characters ">>" at the left margin indicate directions for you to try using a command. For instance:

>> Now type C-v (View next screen) to move to the next screen. (go ahead, do it by depressing the control key and v together). From now on, you'll be expected to do this whenever you finish reading the screen. Note that there is an overlap when going from screen to screen; this provides some continuity when moving through the file.

The first thing that you need to know is how to move around from place to place in the file. You already know how to move forward a screen, with C-v. To move backwards a screen, type M-v (depress the META key and type v, or type v if you don't have a META or EDIT key). >> Try typing M-v and then C-v to move back and forth a few times.

Summary

The following commands are useful for viewing screenfuls:

C-v Move forward one screenful

M-v Move backward one screenful

C-l Clear screen and redisplay everything

putting the text near the cursor at the center.

(That's control-L, not control-1.)

>> Find the cursor and remember what text is near it. Then type a C-l. Find the cursor again and see what text is near it now.

Basic Cursor Control

Getting from screenful to screenful is useful, but how do you reposition yourself within a given screen to a specific place? There are several ways you can do this. One way (not the best, but the most basic) is to use the commands previous, backward, forward and next. As you can imagine these commands (which are given to Emacs as C-p, C-b, C-f, and C-n respectively) move the cursor from where it currently is to a new place in the given direction. Here, in a more graphical form are the commands:

  Previous line, C-p

  :

  :

   Backward, C-b .... Current cursor position .... Forward, C-f

  :

  :

  Next line, C-n

>> Move the cursor to the line in the middle of that diagram and type C-l to see the whole diagram centered in the screen.

You'll probably find it easy to think of these by letter. P for previous, N for next, B for backward and F for forward. These are the basic cursor positioning commands and you'll be using them ALL the time so it would be of great benefit if you learn them now.

>> Do a few C-n's to bring the cursor down to this line.

>> Move into the line with C-f's and then up with C-p's. See what C-p does when the cursor is in the middle of the line.

Lines are separated by Newline characters. For most applications there should normally be a Newline character at the end of the text, as well, but it is up to you to make sure of this. A file can validly exist without a Newline at the end.

>> Try to C-b at the beginning of a line. Do a few more C-b's. Then do C-f's back to the end of the line and beyond.

When you go off the top or bottom of the screen, the text beyond the edge is shifted onto the screen so that your instructions can be carried out while keeping the cursor on the screen.

>> Try to move the cursor off the bottom of the screen with C-n and see what happens.

If moving by characters is too slow, you can move by words. M-f (Meta-f) moves forward a word and M-b moves back a word.

>> Type a few M-f's and M-b's. Intersperse them with C-f's and C-b's.

Notice the parallel between C-f and C-b on the one hand, and M-f and M-b on the other hand. Very often Meta characters are used for operations related to English text whereas Control characters operate on the basic textual units that are independent of what you are editing (characters, lines, etc). There is a similar parallel between lines and sentences: C-a and C-e move to the beginning or end of a line, and M-a and M-e move to the beginning or end of a sentence.

>> Try a couple of C-a's, and then a couple of C-e's.

Try a couple of M-a's, and then a couple of M-e's.

See how repeated C-a's do nothing, but repeated M-a's keep moving farther. Do you think that this is right?

Two other simple cursor motion commands are M-< (Meta Less-than), which moves to the beginning of the file, and M-> (Meta Greater-than), which moves to the end of the file. You probably don't need to try them, since finding this spot again will be boring. On most terminals the "<" is above the comma and you must use the shift key to type it. On these terminals you must use the shift key to type M-< also; without the shift key, you would be typing M-comma. The location of the cursor in the text is also called "point". To paraphrase, the cursor shows on the screen where point is located in the text. Here is a summary of simple moving operations including the word and sentence moving commands:

C-f Move forward a character

C-b Move backward a character

M-f Move forward a word

M-b Move backward a word

C-n Move to next line

C-p Move to previous line

C-a Move to beginning of line

C-e Move to end of line

M-a Move back to beginning of sentence

M-e Move forward to end of sentence

M-< Go to beginning of file

M-> Go to end of file

Like all other commands in Emacs, these commands can be given arguments which cause them to be executed repeatedly. The way you give a command a repeat count is by typing C-u and then the digits before you type the command. If you have a META or EDIT key, you can omit the C-u if you hold down the META or EDIT key while you type the digits. This is easier, but we recommend the C-u method because it works on any terminal.

For instance, C-u 8 C-f moves forward eight characters.

>> Try giving a suitable argument to C-n or C-p to come as close as you can to this line in one jump.

The only apparent exception to this is the screen moving commands, C-v and M-v. When given an argument, they scroll the screen up or down by that many lines, rather than screenfuls. This proves to be much more useful.

>> Try typing C-u 8 C-v now.

Did it scroll the screen up by 8 lines? If you would like to scroll it down you can give an argument to M-v.

If you are using X Windows, there is probably a rectangular area called a scroll bar at the right hand side of the Emacs window. You can scroll the text by clicking the mouse in the scroll bar.

>> Try pressing the middle button at the top of the highlighted area within the scroll bar, then moving the mouse while holding that button down.

>> Move the mouse to a point in the scroll bar about three lines from the top, and click the left button a couple of times. Then try the right button a couple of times.

When Emacs is hung

If Emacs gets into an infinite (or simply very long) computation which you don't want to finish, you can stop it safely by typing C-g. You can also use C-g to discard a numeric argument or the beginning of a command that you don't want to finish.

>> Type C-u 100 to make a numeric arg of 100, then type C-g. Now type C-f. How many characters does it move? If you have typed an <ESC> by mistake, you can get rid of it with a C-g.

If you type <ESC> <ESC>, you get a new window appearing on the screen, telling you that M-ESC is a "disabled command" and asking whether you really want to execute it. The command M-ESC is marked as disabled because you probably don't want to use it until you know more about Emacs, and we expect it would confuse you if it were allowed to go ahead and run. If you really want to try the M-ESC command, you could type a Space in answer to the question and M-ESC would go ahead. Normally, if you do not want to execute M-ESC, you would type "n" to answer the question.

>> Type <ESC> <ESC>, then type n.

Windows

Emacs can have several windows, each displaying its own text. At this stage it is better not to go into the techniques of using multiple windows. But you do need to know how to get rid of extra windows that may appear to display help or output from certain commands. It is simple:

C-x 1 One window (i.e., kill all other windows).

That is Control-x followed by the digit 1. C-x 1 makes the window which the cursor is in become the full screen, by getting rid of any other windows.

>> Move the cursor to this line and type C-u 0 C-l.

>> Type Control-h k Control-f. See how this window shrinks, while a new one appears to display documentation on the Control-f command.

>> Type C-x 1 and see the documentation listing window disappear.

Inserting and Deleting

If you want to insert text, just type it. Characters which you can see, such as A, 7, *, etc. are taken by Emacs as text and inserted immediately. Type <Return> (the carriage-return key) to insert a Newline character.

You can delete the last character you typed by typing <Rubout>. <Rubout> is a key on the keyboard, which might be labelled "Delete" instead of "Rubout" on some terminals. More generally, <Rubout> deletes the character immediately before the current cursor position.

>> Do this now, type a few characters and then delete them by typing <Rubout> a few times. Don't worry about this file being changed; you won't affect the master tutorial. This is just a copy of it.

>> Now start typing text until you reach the right margin, and keep typing. When a line of text gets too big for one line on the screen, the line of text is "continued" onto a second screen line. The backslash at the right margin indicates a line which has been continued.

>> Use <Rubout>s to delete the text until the line fits on one screen line again. The continuation line goes away.

>> Move the cursor to the beginning of a line and type <Rubout>. This deletes the newline before the line and merges the line onto the previous line. The resulting line may be too long to fit, in which case it has a continuation line.

>> Type <Return> to reinsert the Newline you deleted.

Remember that most Emacs commands can be given a repeat count; this includes characters which insert themselves.

>> Try that now -- type C-u 8 * and see what happens.

You've now learned the most basic way of typing something in Emacs and correcting errors. You can delete by words or lines as well. Here is a summary of the delete operations:

<Rubout>     delete the character just before the cursor

C-d        delete the next character after the cursor

M-<Rubout>   kill the word immediately before the cursor

M-d      kill the next word after the cursor

C-k      kill from the cursor position to end of line

M-k      kill to the end of the current sentence

Notice that <Rubout> and C-d vs M-<Rubout> and M-d extend the parallel started by C-f and M-f (well, <Rubout> isn't really a control character, but let's not worry about that). C-k and M-k are like C-e and M-e, sort of, in that lines are opposite sentences.

Now suppose you kill something, and then you decide that you want to get it back? Well, whenever you kill something bigger than a character, Emacs saves it for you. To yank it back, use C-y. You can kill text in one place, move elsewhere, and then do C-y; this is a good way to move text around. Note that the difference between "Killing" and "Deleting" something is that "Killed" things can be yanked back, and "Deleted" things cannot. Generally, the commands that can destroy a lot of text save it, while the ones that attack only one character, or nothing but blank lines and spaces, do not save.

For instance, type C-n a couple times to position the cursor at some line on this screen.

>> Do this now, move the cursor and kill that line with C-k.

Note that a single C-k kills the contents of the line, and a second C-k kills the line itself, and make all the other lines move up. If you give C-k a repeat count, it kills that many lines AND their contents.

The text that has just disappeared is saved so that you can retrieve it. To retrieve the last killed text and put it where the cursor currently is, type C-y.

>> Try it; type C-y to yank the text back.

Think of C-y as if you were yanking something back that someone took away from you. Notice that if you do several C-k's in a row the text that is killed is all saved together so that one C-y will yank all of the lines.

>> Do this now, type C-k several times.

Now to retrieve that killed text:

>> Type C-y. Then move the cursor down a few lines and type C-y again. You now see how to copy some text.

What do you do if you have some text you want to yank back, and then you kill something else? C-y would yank the more recent kill. But the previous text is not lost. You can get back to it using the M-y command. After you have done C-y to get the most recent kill, typing M-Y replaces that yanked text with the previous kill. Typing M-y again and again brings in earlier and earlier kills. When you have reached the text you are looking for, you can just go away and leave it there. If you M-y enough times, you come back to the starting point (the most recent kill).

>> Kill a line, move around, kill another line. Then do C-y to get back the second killed line. Then do M-y and it will be replaced by the first killed line. Do more M-y's and see what you get. Keep doing them until the second kill line comes back, and then a few more. If you like, you can try giving M-y positive and negative arguments.

Undo

Any time you make a change to the text and wish you had not done so, you can undo the change (return the text to its previous state) with the undo command, C-x u. Normally, C-x u undoes one command's worth of changes; if you repeat the C-x u several times in a row, each time undoes one more command. There are two exceptions: commands that made no change (just moved the cursor) do not count, and self-inserting characters are often lumped together in groups of up to 20. This is to reduce the number of C-x u's you have to type.

C-_ is another command for undoing; it is just the same as C-x u but easier to type several times in a row. The problem with C-_ is that on some keyboards it is not obvious how to type it. That is why C-x u is provided as well. On some DEC terminals, you can type C-_ by typing / while holding down CTRL. Illogical, but what can you expect from DEC?

Giving a numeric argument to C-_ or C-x u is equivalent to repeating it as many times as the argument says.

Files

In order to make the text you edit permanent, you must put it in a file. Otherwise, it will go away when your invocation of Emacs goes away. You put your editing in a file by "finding" the file. What finding means is that you see the contents of the file in your Emacs; and, loosely speaking, what you are editing is the file itself. However, the changes still don't become permanent until you "save" the file. This is so you can have control to avoid leaving a half-changed file around when you don't want to. Even then, Emacs leaves the original file under a changed name in case your changes turn out to be a mistake.

If you look near the bottom of the screen you will see a line that begins and ends with dashes, and contains the string "Emacs: TUTORIAL". Your copy of the Emacs tutorial is called "TUTORIAL". Whatever file you find, that file's name will appear in that precise spot.

The commands for finding and saving files are unlike the other commands you have learned in that they consist of two characters. They both start with the character Control-x. There is a whole series of commands that start with Control-x; many of them have to do with files, buffers, and related things, and all of them consist of Control-x followed by some other character.

Another thing about the command for finding a file is that you have to say what file name you want. We say the command "reads an argument from the terminal" (in this case, the argument is the name of the file). After you type the command

C-x C-f Find a file

Emacs asks you to type the file name. It echoes on the bottom line of the screen. You are using the minibuffer now! this is what the minibuffer is for. When you type <Return> to end the file name, the minibuffer is no longer needed, so it disappears.

>> Type C-x C-f, then type C-g. This cancels the minibuffer, and also cancels the C-x C-f command that was using the minibuffer. So you do not find any file.

In a little while the file contents appear on the screen. You can edit the contents. When you wish to make the changes permanent, issue the command

C-x C-s Save the file

The contents of Emacs are written into the file. The first time you do this, the original file is renamed to a new name so that it is not lost. The new name is made by appending "~" to the end of the original file's name.

When saving is finished, Emacs prints the name of the file written. You should save fairly often, so that you will not lose very much work if the system should crash.

>> Type C-x C-s, saving your copy of the tutorial. This should print "Wrote .../TUTORIAL" at the bottom of the screen. On VMS it will print "Wrote ...[...]TUTORIAL."

To make a new file, just find it "as if" it already existed. Then start typing in the text. When you ask to "save" the file, Emacs will really create the file with the text that you have inserted. From then on, you can consider yourself to be editing an already existing file.

Buffers

If you find a second file with C-x C-f, the first file remains inside Emacs. You can switch back to it by finding it again with C-x C-f. This way you can get quite a number of files inside Emacs.

The object inside Emacs which holds the text read from one file is called a "buffer." Finding a file makes a new buffer inside Emacs. To see a list of the buffers that exist in Emacs, type

C-x C-b List buffers

>> Try C-x C-b now.

See how each buffer has a name, and it may also have a file name for the file whose contents it holds. Some buffers do not correspond to files. For example, the buffer named "*Buffer List*" does not have any file. It is the buffer which contains the buffer list that was made by C-x C-b. ANY text you see in an Emacs window has to be in some buffer.

>> Type C-x 1 to get rid of the buffer list.

If you make changes to the text of one file, then find another file, this does not save the first file. Its changes remain inside Emacs, in that file's buffer. The creation or editing of the second file's buffer has no effect on the first file's buffer. This is very useful, but it also means that you need a convenient way to save the first file's buffer. It would be a nuisance to have to switch back to it with C-x C-f in order to save it with C-x C-s. So we have

C-x s Save some buffers

C-x s goes through the list of all the buffers you have and finds the ones that contain files you have changed. For each such buffer, C-x s asks you whether to save it.

Extending the Command Set

There are many, many more Emacs commands than could possibly be put on all the control and meta characters. Emacs gets around this with the X (eXtend) command. This comes in two flavors:

C-x Character eXtend.  Followed by one character.

M-x Named command eXtend.  Followed by a long name.

These are commands that are generally useful but used less than the commands you have already learned about. You have already seen two of them: the file commands C-x C-f to Find and C-x C-s to Save. Another example is the command to tell Emacs that you'd like to stop editing and get rid of Emacs. The command to do this is C-x C-c. (Don't worry; it offers to save each changed file before it kills the Emacs.)

C-z is the usual way to exit Emacs, because it is always better not to kill the Emacs if you are going to do any more editing. On systems which allow it, C-z exits from Emacs to the shell but does not destroy the Emacs; if you use the C shell, you can resume Emacs with the `fg' command (or, more generally, with `%emacs', which works even if your most recent job was some other). On systems where suspending is not possible, C-z creates a subshell running under Emacs to give you the chance to run other programs and return to Emacs afterward, but it does not truly "exit" from Emacs. In this case, the shell command `exit' is the usual way to get back to Emacs from the subshell.

You would use C-x C-c if you were about to log out. You would also use it to exit an Emacs invoked under mail handling programs and other random utilities, since they may not believe you have really finished using the Emacs if it continues to exist.

There are many C-x commands. The ones you know are:

C-x C-f Find file.

C-x C-s Save file.

C-x C-b List buffers.

C-x C-c Quit Emacs.

C-x u Undo.

Named eXtended commands are commands which are used even less frequently, or commands which are used only in certain modes. These commands are usually called "functions". An example is the function replace-string, which globally replaces one string with another. When you type M-x, Emacs prompts you at the bottom of the screen with M-x and you should type the name of the function you wish to call; in this case, "replace-string". Just type "repl s<TAB>" and Emacs will complete the name. End the command name with <Return>. Then type the two "arguments"--the string to be replaced, and the string to replace it with--each one ended with a Return.

>> Move the cursor to the blank line two lines below this one. Then type M-x repl s<Return>changed<Return>altered<Return>.

Notice how this line has changed: you've replaced the word c-h-a-n-g-e-d with "altered" wherever it occurred after the cursor.

Mode Line

If Emacs sees that you are typing commands slowly it shows them to you at the bottom of the screen in an area called the "echo area." The echo area contains the bottom line of the screen. The line immediately above it is called the MODE LINE. The mode line says something like

--**-Emacs: TUTORIAL          (Fundamental)--58%----------------------

This is a very useful "information" line.

You already know what the filename means--it is the file you have found. What the --NN%-- means is that NN percent of the file is above the top of the screen. If the top of the file is on the screen, it will say --Top-- instead of --00%--. If the bottom of the file is on the screen, it will say --Bot--. If you are looking at a file so small it all fits on the screen, it says --All--.

The stars near the front mean that you have made changes to the text. Right after you visit or save a file, there are no stars, just dashes.

The part of the mode line inside the parentheses is to tell you what modes you are in. The default mode is Fundamental which is what you are in now. It is an example of a "major mode". There are several major modes in Emacs for editing different languages and text, such as Lisp mode, Text mode, etc. At any time one and only one major mode is active, and its name can always be found in the mode line just where "Fundamental" is now. Each major mode makes a few commands behave differently. For example, there are commands for creating comments in a program, and since each programming language has a different idea of what a comment should look like, each major mode has to insert comments differently. Each major mode is the name of an extended command, which is how you get into the mode. For example, M-x fundamental-mode is how to get into Fundamental mode.

If you are going to be editing English text, such as this file, you should probably use Text Mode.

>> Type M-x text-mode<Return>.

Don't worry, none of the commands you have learned changes Emacs in any great way. But you can observe that apostrophes are now part of words when you do M-f or M-b. Major modes are usually like that: commands don't change into completely unrelated things, but they work a little bit differently.

To get documentation on your current major mode, type C-h m.

>> Use C-u C-v once or more to bring this line near the top of screen.

>> Type C-h m, to see how Text mode differs from Fundamental mode.

>> Type C-x 1 to remove the documentation from the screen.

Major modes are called major because there are also minor modes. They are called minor because they aren't alternatives to the major modes, just minor modifications of them. Each minor mode can be turned on or off by itself, regardless of what major mode you are in, and regardless of the other minor modes. So you can use no minor modes, or one minor mode, or any combination of several minor modes.

One minor mode which is very useful, especially for editing English text, is Auto Fill mode. When this mode is on, Emacs breaks the line in between words automatically whenever the line gets too long. You can turn this mode on by doing M-x auto-fill-mode<Return>. When the mode is on, you can turn it off by doing M-x auto-fill-mode<Return>. If the mode is off, this function turns it on, and if the mode is on, this function turns it off. This is called "toggling".

>> Type M-x auto-fill-mode<Return> now. Then insert a line of "asdf " over again until you see it divide into two lines. You must put in spaces between them because Auto Fill breaks lines only at spaces.

The margin is usually set at 70 characters, but you can change it with the C-x f command. You should give the margin setting you want as a numeric argument.

>> Type C-x f with an argument of 20. (C-u 2 0 C-x f). Then type in some text and see Emacs fill lines of 20 characters with it. Then set the margin back to 70 using C-x f again.

If you makes changes in the middle of a paragraph, Auto Fill mode does not re-fill it for you. To re-fill the paragraph, type M-q (Meta-q) with the cursor inside that paragraph.

>> Move the cursor into the previous paragraph and type M-q.

Searching

Emacs can do searches for strings (these are groups of contiguous characters or words) either forward through the file or backward through it. To search for the string means that you are trying to locate it somewhere in the file and have Emacs show you where the occurrences of the string exist. This type of search is somewhat different from what you may be familiar with. It is a search that is performed as you type in the thing to search for. The command to initiate a search is C-s for forward search, and C-r for reverse search. BUT WAIT! Don't do them now. When you type C-s you'll notice that the string "I-search" appears as a prompt in the echo area. This tells you that Emacs is in what is called an incremental search waiting for you to type the thing that you want to search for. <RET> terminates a search.

>> Now type C-s to start a search. SLOWLY, one letter at a time, type the word 'cursor', pausing after you type each character to notice what happens to the cursor.

>> Type C-s to find the next occurrence of "cursor".

>> Now type <Rubout> four times and see how the cursor moves.

>> Type <RET> to terminate the search.

Did you see what happened? Emacs, in an incremental search, tries to go to the occurrence of the string that you've typed out so far. To go to the next occurrence of 'cursor' just type C-s again. If no such occurrence exists Emacs beeps and tells you that it is a failing search. C-g would also terminate the search.

If you are in the middle of an incremental search and type <Rubout>, you'll notice that the last character in the search string is erased and the search backs up to the last place of the search. For instance, suppose you currently have typed 'cu' and you see that your cursor is at the first occurrence of 'cu'. If you now type <Rubout>, the 'u' on the search line is erased and you'll be repositioned in the text to the occurrence of 'c' where the search took you before you typed the 'u'. This provides a useful means for backing up while you are searching.

If you are in the middle of a search and type a control or meta character (with a few exceptions--characters that are special in a search, such as C-s and C-r), the search is terminated.

The C-s starts a search that looks for any occurrence of the search string AFTER the current cursor position. But what if you want to search for something earlier in the text? To do this, type C-r for Reverse search. Everything that applies to C-s applies to C-r except that the direction of the search is reversed.

Multiple Windows

One of the nice features of Emacs is that you can display more than one window on the screen at the same time.

>> Move the cursor to this line and type C-u 0 C-l.

>> Now type C-x 2 which splits the screen into two windows. Both windows display this tutorial. The cursor stays in the top window.

>> Type C-M-v to scroll the bottom window.

>> Type C-x o ("o" for "other") to move the cursor to the bottom window.

>> Use C-v and M-v in the bottom window to scroll it. Keep reading these directions in the top window.

>> Type C-x o again to move the cursor back to the top window. The cursor is still just where it was in the top window before.

You can keep using C-x o to switch between the windows. Each window has its own cursor position, but only one window actually shows the cursor. All the ordinary editing commands apply to the window that the cursor is in.

The command C-M-v is very useful when you are editing text in one window and using the other window just for reference. You can keep the cursor always in the window where you are editing, and edit there as you advance through the other window.

>> Type C-x 1 (in the top window) to get rid of the bottom window.

(If you had typed C-x 1 in the bottom window, that would get rid of the top one. Think of this command as "Keep just one window--the window I am already in.")

You don't have to display the same buffer in both windows. If you use C-x C-f to find a file in one window, the other window doesn't change. You can pick a file in each window independently.

Here is another way to use two windows to display two different things:

>> Type C-x 4 C-f followed by the name of one of your files. End with <RETURN>. See the specified file appear in the bottom window. The cursor goes there, too.

>> Type C-x o to go back to the top window, and C-x 1 to delete the bottom window.

Recursive Editing Levels

Sometimes you will get into what is called a "recursive editing level". This is indicated by square brackets in the mode line, surrounding the parentheses around the major mode name. For example, you might see [(Fundamental)] instead of (Fundamental).

To get out of the recursive editing level, type

M-x top-level<Return>.

>> Try that now; it should display "Back to top level" at the bottom of the screen.

In fact, you were ALREADY at top level (not inside a recursive editing level) if you have obeyed instructions. M-x top-level does not care; it gets out of any number of recursive editing levels, perhaps zero, to get back to top level.

You can't use C-g to get out of a recursive editing level because C-g is used for discarding numeric arguments and partially typed commands WITHIN the recursive editing level.

Getting More Help

In this tutorial we have tried to supply just enough information to get you started using Emacs. There is so much available in Emacs that it would be impossible to explain it all here. However, you may want to learn more about Emacs since it has numerous desirable features that you don't know about yet. Emacs has a great deal of internal documentation. All of these commands can be accessed through the character Control-h, which we call "the Help character" because of the function it serves.

To use the HELP features, type the C-h character, and then a character saying what kind of help you want. If you are REALLY lost, type C-h ? and Emacs will tell you what kinds of help it can give. If you have typed C-h and decide you don't want any help, just type C-g to cancel it.

The most basic HELP feature is C-h c. Type C-h, a c, and a command character or sequence, and Emacs displays a very brief description of the command.

>> Type C-h c Control-p. The message should be something like C-p runs the command previous-line

This tells you the "name of the function". That is important in writing Lisp code to extend Emacs; it also is enough to remind you of what the command does if you have seen it before but did not remember.

Multi-character commands such as C-x C-s and (if you have no META or EDIT key) <ESC>v are also allowed after C-h c.

To get more information on the command, use C-h k instead of C-h c.

>> Type C-h k Control-p.

This displays the documentation of the function, as well as its name, in an Emacs window. When you are finished reading the output, type C-x 1 to get rid of the help text. You do not have to do this right away. You can do some editing while referring to the help text and then type C-x 1.

Here are some other useful C-h options:

   C-h f Describe a function.  You type in the name of the

function.

   C-h a Command Apropos.  Type in a keyword and Emacs will list

all the commands whose names contain that keyword.

These commands can all be invoked with Meta-x.

For some commands, Command Apropos will also list a one

or two character sequence which has the same effect.

>> Type C-h a file<Return>.

This displays in another window a list of all M-x commands with "file" in their names. You will also see commands like C-x C-f and C-x C-w, listed beside the command names find-file and write-file.

Conclusion

Remember, to exit Emacs permanently use C-x C-c. To exit to a shell temporarily, so that you can come back in, use C-z.

This tutorial is meant to be understandable to all new users, so if you found something unclear, don't sit and blame yourself - complain!

Copying

This tutorial descends from a long line of Emacs tutorials starting with the one written by Stuart Cracraft for the original Emacs.

This version of the tutorial, like GNU Emacs, is copyrighted, and comes with permission to distribute copies on certain conditions:

Copyright (c) 1985 Free Software Foundation

Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the copyright notice and permission notice are preserved, and that the distributor grants the recipient permission for further redistribution as permitted by this notice.

Permission is granted to distribute modified versions of this document, or of portions of it, under the above conditions, provided also that they carry prominent notices stating who last altered them.

The conditions for copying Emacs itself are slightly different but in the same spirit. Please read the file COPYING and then do give copies of GNU Emacs to your friends. Help stamp out software obstructionism ("ownership") by using, writing, and sharing free software!

Press here to return to the Editors Menu

Emacs中强大的搜索功能(转帖)

(转自:http://www.80x86.cn/blog/blogview.asp?logID=569)

Emacs入门指南(3)   [ Date: 2006-03-15 12:04:44 AM | Author: 80x86 | From: Original | Sunny | Emotion Index: +2 ] 

通过前两篇文章的学习,您已经可以把Emacs当作一个Better-Notepad来使用了。今天我们要学习的是Emacs中强大的搜索功能。

  默认情况下,Emacs采用了一种很待殊的"增量搜索"的功能,虽然它与我们常用的搜索方法在操作习惯上有很大的不同,但习惯后确实是十分的方便。

  要让Emacs开始执行搜索,可以按C-s或C-r,前者是从光标位置往后查找,后者则是往前查找。我们以C-s为例。按动C-s后,Emacs在 Minibuffer中提示: I-Search:,这时您便可以输入要搜索的关键字了,现在学习试验的阶段建议您输入时手脚慢一点,看看Emacs是如何来执行您的搜索请求的。

  比如,要搜索“search”一词,您输入s,这时Emacs会把光标移动到最近一个s字母上,这里如果您暂停输入一会儿,Emacs就会把所有的s字母进行高亮。您继续输入e,这时Emacs就找到了最近的se字母组合。一直输入下去,直到Emacs找到您要找的内容,这时按回车键即可结束查找。

  在查找过程中,您可以反复按动C-s或C-r来执行向后或向前的查找。如果您已经找到一了一个匹配的内容,并且按了回车键结束了查找,这时如要继续查找这个内容,您只需按两次C-s或C-r即可,第一次按动用于激活查找功能,而第二次按动则表示要继续查找。

  在输入查找关键字时,如果不小心输错了,可以按动<DEL>键来清除前一个字符,请注意,在Emacs术语中,<DEL>键是指我们通常所说的<BackSpace>键,而<delete>键才表示我们键盘上的<delete>或<Del>键。

  输入关键词时也有一个细节的问题,如果您输入的关键字全部是英文小字母,则Emacs会进行不区分大小写的查找。但如果输入的关键字中包含有大写字母, Emacs就会进行区分大小写的查找。另外在查找的过程中,可以通过M-c快捷键来切换区分大小字模式,可以用它来强行指定是否区分大小写。

  如果不想用Emacs的增量搜索功能,也可以让Emacs进行传统的搜索,在按下C-s或C-r后,直接打一个回车键,这时Emacs就将进行非增量搜索,您可以输入你的关键字,再按回车键来执行搜索。

  下面要介绍的是更为强大的正则表达式搜索功能。您可以通过按动C-M-s或C-M-r来启动正向或反向的正则表达式搜索功能,Emacs会在Minibuffer中提示Regexp I-search:,这时您便可以输入正要匹配的正则表达式了。

  在正则表达式中可以使用很多的控制符号,这里我挑选几个常用的作一个简单的介绍,更全面复杂的解释可以在Emacs的手册中查到。

  '.' (句号): 正则表达式的中句号可以用于匹配一个任意的字符。比如正则式'a.b'就可以匹配abb,acb,adb。。。等等以a开头以b结尾的三个字符的字符串。

  '*': 正则表达式中的*号可以用于表示把它前面的字符重复0次或多次。比如'ff*'可以匹配一个或多个相连的f的字符串。

  '+': 正则表达式中的+号与*号的作用基本相同,区别在于它表示把它前面的字符重复1次或多次,所以可知正则式'ff*'等价与'f+'。

  Emacs的正则表达式语法十分复杂与强大,请您阅读Emacs手册来对它们进行全面的学习,一定会给您的工作带来巨大的便捷,作为一篇入门教程,这里我就不再作更全面的叙述了。