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手册来对它们进行全面的学习,一定会给您的工作带来巨大的便捷,作为一篇入门教程,这里我就不再作更全面的叙述了。

Emacs 教程中文版(转帖)

(注:这篇文章即是在emacs环境下用:CTRL-h t命令调出的emacs的tutorial的翻译)

(转自:http://www.linuxmine.com/3947.html)

Emacs 教程中文版

2005-08-24 10:00 am

作者:linux宝库 (http://www.linuxmine.com)

来自:linux宝库 (http://www.linuxmine.com)

现存:http://www.linuxmine.com/3947.html

联系:linuxmine#gmail.com

不明白?欢迎到 linux论坛 (http://bbs.linuxmine.com) 参加讨论!

Emacs 的命令通常包括控制键(就是上面标有 Ctrl或Ctl的那个)或者 是META键(上面标

有EDIT或ALT)。为了方便起见我们将用下面的缩写来 代替这些键的全称:

C-<chr> 意思是当敲入字符<chr>时同时按住控制键,因此,C-f表 示:按住控

制键并且按 f 。

M-<chr> 表示当键入<chr>时按住META或ALT或EDIT键。如果没有META 或ALT或

EDIT键,则用ESC键代替。<ESC>表示ESC键

注意:退出Emacs,按C-x C-c(两个字符)。在文本左边区域的“>>”符号 表示让你试着

使用一个命令。比如:

>> 现在键入C-v(观看下一屏)移动到下一屏。(就象前面说的,按v的同时 也按住控制键

)。从现在开始,每当你读完一屏的时候都可以用它来翻屏。

注意在翻屏后会保留上屏的最后一行;这是为你继续阅读文本提供某些连 贯性。

你所需要知道的第一件事是如何把光标从一个地方移动到另一个地方。你 已经知道了如

何向前翻一屏--用 C-v。要向后翻一屏,键入M-v。

>> 试着键入 M-v 和 C-v 几次。

* 摘要(SUMMARY)

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

下面几个命令对整屏观看时有用:

C-v 向前翻一整屏。

M-v 向后翻一整屏。

C-l 清除屏幕并重新显示所有的文本,然后把光标移动到屏幕的中

央。 (注意是Control-L,而不是 Control-1)。

>> 寻找光标,并且注意它在文本里的位置。然后键入C-l。再寻找光标你会 注意到光标

现在会出现在同样的文本附近。

* 基本光标控制(BASIC CURSOR CONTROL)

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

整屏整屏的移动是很有用的,可是如何把光标移动到屏幕上文本里的一个指定 的地方呢



有好几个方法可以实现。最基本的方法是用命令 C-p,C-b,C-f,和C-n。这些 命令每

个都使光标在屏幕上往特定的方向移动一行或者一列。下面是一个图表 显示了这四个命

令和它们所移动的方向:

上一行,C-p

:

:

向前,C-b ...... 当前光标的位置 ...... 向后,C-f

:

:

下一行,C-n

>> 用C-n或C-p把光标移动到图表中间。然后键入C-l会看到整个图表出现在屏 幕的中央



你也许会发现这些字母很容易记住:P 代表上面的(previous),N 代表下一个 (next),

B 代表向前(backward),F 代表向后(forward)。这些是基本的光标位 置命令,你将经

常会用到它们。所以现在学习它们很有好处〕

>> 用几次 C-n 把光标向下移动到这一行。

>> 用 C-f 把光标移动到行里,再用C-p把光标上移。观察当光标在行的中间时 C-p做了

些什么。

每一个文本行都以一个换行符结尾,它用来当作行与行之间的分格。你的文件的 最后一

行的尾部应该有一个换行符(但Emacs并不要求一定要有一个)。

>> 试着在行的开头使用C-b。它将会把光标移到上一行的末尾。这是因为它向后 移的时

候穿过了换行符。

C-f 也能象 C-b一样穿过换行符。

>> 使用几次C-b,使您能知道光标在哪。然后用C-f移动到行的末尾。然后再用 一次C-

f,使光标移动到下一行。

当你移动超过屏幕的顶部或底部,光标回移动到下一屏的中间,这叫做“滚屏 (scroll

ing)”。它使得Emacs滚屏移动到文本上指定的部位而不是移出屏幕。

>> 试着用C-n把光标移过屏幕的底部,看看回发生什么。

如果觉得一个一个字符的移动太缓慢,可以一个单词一个单词的移动。M-f(Meta-f) 向

前移一个单词,M-b向后移一个单词。

>> 键入几个M-f和M-b。

当光标在一个单词的中间,M-f移动到单词的末尾。当光标在两个单词间的空白部分 M-

f移动到后一个单词的末尾。M-b与M-f一样,只是移动的方向相反。

>> 键入M-f和M-b几次,中间穿插一些C-f和C-b以使你能观察到M-f和M-b在单词中和 单

词间的不同行为。

注意比较C-f,C-b与M-f,M-b。通常情况下Meta键用于有关语言单位(词,句,段落) 的

操作;而控制键用于编辑时的基本单位(字符,行等)。

这是句与行的比较:C-a和C-e移动到一行的开头和末尾,M-a和M-e移动到一个句子 的开

头和末尾。

>> 键入一对C-a,再键入一对C-e。 键入一对M-a,再键入一对M-e。

你会看到重复键入的C-a什么也不做,而重复键入的M-a则会移动一个以上的句子。

光标在文本中的位置也叫“点(point)”。在段落里,光标标示出了点在屏幕上文本 里

的位置。

下面是简单的光标移动命令的总结,包括单词和句子的移动命令:

C-f 向前移动一个字符。

C-b 向后移动一个字符。

M-f 向前移动一个单词。

M-b 向后移动一个单词。

C-n 移动到下一行。

C-p 移动到上一行。

C-a 移动到行首。

C-e 移动到行尾。

M-a 向前移动到句子的开头。

M-e 向后移动到句子的末尾。

>> 试着对每一个命令都实践几次,它们都是经常要用到的命令。

另外两个重要的光标移动命令是M-<(Meta小于),它移动光标到整个文本的开头,M-> (

Meta大于)它移动光标到整个文本的末尾。

在多数终端上,“<”在逗号的上面,所以你必须用Shift键来输入它。在这些终端 上,

你也必须用Shift键来输入M-<;没有Shift键,你可以输入M-逗号。

>> 现在就试试M-<,移动到本教程的开头,然后再用C-v移回这里。 现在就试试M->,移

动到本教程的末尾,然后再用M-v移回这里。

你也可以用方向键来移动光标,如果你的终端有方向键的话。我们建议学习C-b, C-f,

C-n和C-p有三个原因。第一,它们能在所有类型的终端上工作。第二,你获得 了使用E

macs的锻炼,你将会发现输入这些CTRL加字符比按方向键要快(因为你不必 把你的手从

键盘上移开)。第三,一旦你养成了使用这些CTRL加字符的命令的习惯, 你就能一样容

易的学习其他高级的光标移动命令。

大多数Emacs命令接收一个数字参数;对大多数命令来说,这表示命令重复的次数。 输

入重复命令次数的方法是在输入命令之前按C-u和数字。如果你有META(或EDIT或 ALT)键

,则有另一种方法输入数字参数:在按住META键的时候输入数字,我们建议 学习C-u方

法,因为它能在任何终端上工作。

例如,C-u 8 C-f 向前移动8个字符。

>> 试着使用带数字参数的C-n或C-p,只用一个命令就把光标移动到与本行相邻的 行上



绝大多数命令把数字参数当作重复次数,但也有几个例外。C-v和M-v就是。当给出 一个

参数,只是上滚或下滚数字指定的行数而不是屏数。比如,C-u 4 C-v滚动4行 屏幕。

>> 现在试试 C-u 8 C-v。

这将使屏幕滚动8行,如果你想往回滚动的话,键入一个带参数的M-v。

如果你正在使用X窗口,在Emacs窗口的左手边有一个叫做滚动条的矩形区域。你能 通过

用鼠标点击滚动条来滚动文本。

>> 试着在滚动条顶部的高亮区域点击中键。这将使文本滚动,滚动的位置取决于 你点

击的长短。

>> 试着按住鼠标中键上移或下移鼠标,你将看到当你移动鼠标时文本会上下滚动。

* 当EMACS挂起时(WHEN EMACS IS HUNG)

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

当Emacs停止响应你的命令时,你能用C-g把它安全的停止。当一个命令执行了太长的 时

间时你可以用C-g把它终止。

你也可以用C-g来取消数字参数和输入后又不想执行的命令。

>> 键入C-u 100 产生一个值为100的数字参数,然后按C-g。再按C-f。它只会移动 一个

字符,因为你用C-g取消了参数。

如果错误的输入了一个<ESC>,你能用C-g消掉它。

* 禁止命令(DISABLED COMMAND)

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

一些Emacs命令是“禁止”的,所以新手不会因偶然而执行它。

如果你键入了一个禁止命令,Emacs会显示一条消息说明这条命令是干什么的,并且问

你是否需要执行它。

如果你真的想要执行,敲空格键继续。通常,如果你不想执行禁止命令,用“n”来回

答。

>> 输入<ESC>一条禁止命令),然后用n来回答。

* 窗口(WINDOWS)

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

Emacs 能有好几个窗口,每一个显示自己的文本。我们将在后面解释怎样对多窗口 操作

。现在我们要解释怎样去除多余的窗口屏回到基本的单窗口编辑状态。 这是一个例子:

C-x 1 一个窗口(也就是除去其他所有的窗口)。

因为Control-x跟了数字1。C-x 1使包含光标的窗口占满整个屏幕,屏删除其他所有 窗

口。

>> 把光标移动本行并输入 C-u 0 C-l。

>> 键入Control-h k Control-f。 看这个窗口如何缩小,并在按Control-f的时候出现

了一个新的文档窗口。

>> 键入C-x 1 并且看到那个文档窗口消失了。

* 插入和删除(INSERTING AND DELETING)

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

如果你要插入文本,只须输入文本。输入的字符你能见到,比如A,7,*等等。Emacs 会

立即把它们插入。键入<Return>(回车键)插入一个换行符。

你能用<Delete>删除你输入的最后一个字符。<Delete>就是键盘上标着“Del”的键。

在某些情况下,“Backspace”键作用和<Delete>一样,但不总是这样!

通常,<Delete>立即删除光标前面的那个字符。

>> 输入几个字符,然后用<Delete>删除它们。不必担心这个文件回被改变;你不会 替

换主教程。这只是你的个人拷贝。

当一行文本太长而超过屏幕宽度时,这一行会在屏幕的下一行被“继续”。文本的右 边

会有一个反斜杠“\”表示它被继续。

>> 插入文本直到最右边,然后再插入。你将看到一个继续了的行。

>> 使用<Delete>删除文本直到行的长度在屏幕的宽度以内。继续的行将会消失。

你能像删除其他任何字符一样删除换行符。删除两个行间的换行符会使它们合并为一 行

。如果这一行很长屏幕显示不下的话,将会用一个继续的行来表示。

>> 把光标移动到一行的开头按<Delete>这将使本行和上一行合为一行。

>> 按<Return>重新插入你删除的换行符。

记住大多数的Emacs命令能接收一个重复次数。这包括文本字符,把一个文本字符重复

的插入几次。

>> 键入这个-- C-u 8 * 来插入 ********

你现在已经学习了Emacs的大多数输入和排错的方法。你也能一样的删除单词或行。这

是删除操作的摘要:

<Delete> 删除光标前面的字符

C-d 删除光标后面的字符

M-<Delete> 除去光标前面的单词

M-d 除去光标后面的单词

C-k 除去从光标位置到行尾的内容

M-k 除去到当前句子的末尾

注意比较<Delete>,C-d与M<Delete>,M-d和C-f,M-f(<Delete>不是一个控制字符, 但

不用担心)。C-k和M-k就象C-e,M-e。

当你一次除去不止一个字符时,Emacs将保存着这些文本,所以你可以恢复它们。 恢复

那些被除去的文本称作“拉(yanking)”。你能在除去文本的同一地方拉回它们, 或是

在文本的其他地方。你能对文本拉上几次以产生它们的多个拷贝,拉的命令是 C-y。

注意“除去(killing)”与“删除(Deleting)”之间的区别,被除去的东西能被拉回 来

,而被删除的不能。通常除去能除去很多的文本屏保存,而删除只能除去一个字 符,或

是空行或空格,并且不保存。

>> 把光标移到一个空行的开头,键入C-k除去这一行。

>> 按第二次C-k,你将看到剩下的空行也被除去了。

注意单个的C-k除去行的内容,第二个C-k除去行本身,并且使后面的所有行上移。 特别

要注意数字参数:它除去很多行和它们的内容,这不仅仅是重复。C-u 2 C-k 除去两行

和它们剩下的空行;而按两次C-k并不会这样做。

要在当前光标处找回上次被除去的文本;按C-y

>> 试一试,用C-y把文本拉回来。

把C-y考虑为你把某人从你这里拿走的东西再拿回来。注意你如果在一行上按了几次 C-

y,所有被除去的文本是存在一起的,所以按一次C-y将拉回全部的行。

>> 现在就试一下,按几次C-k。 现在找回被除去的文本;

>> 按C-y。然后把光标下移几行再按一次C-y,你现在会看到怎样拷贝这些文本。

当你要拉回一些被除去的文本该怎样做呢?C-y只能拉回最近被除去的文本。但以前 的

文本并没有消失。你能用M-y来恢复它。当你用C-y拉回最近被除去的文本后,换成 M-y

可以拉回以前被除去的文本。键入一次又一次的M-y可以拉回更早以前被除去的文 本。

当你找到要寻找的文本,不必做任何事来保持它,只须离开拉文本的地方继续你 的编辑



如果你M-y了足够多的次数,你会回到开始点(最近被除去的)。

>> 除掉一行,移开,再除掉另一行。 然后用C-y拉回第二行。 然后换成M-y拉回被除掉

的第一行。 再按一次M-y看看得到了什么。继续按直到拉回被除去的第二行;然后再做

几次。 如果原意的话,你可以给M-y加正的或负的数字参数。

* 撤销(UNDO)

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

如果你对文本作了一些改动,然后又发现这样做是错误的,你能用撤销命令,C-x u 撤

销这些改变。

通常,一次C-x u撤销一个改变;如果你在一行上重复几次C-x u,就会重复几次撤销 操

作。

但有两个例外:不改变文本的操作(包括光标移动和滚屏命令)不算在内;只能处理20 次



>> 用C-k除去这一行,然后按C-x u 它将重现出来。

C-_是一个可选择的撤销命令;它所作的工作和C-x u 完全一样,只是更容易输入。 C-

_的缺点是有些键盘上没有它,这就是为什么还提供C-x u的原因。在某些终端上 你可以

按住CTRL的时候再敲/来输入C-_。C-_或C-x u把数参数字当作重复次数。

* 文件(FILES)

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

为了永久保存你编辑的文本,你必须把它放到一个文件里。否则当你退出Emacs的时候

它就会消失。你通过“查找(finding)”文件,把你编辑的内容放到文件里。(也称为 “

访问(visiting)文件”)。

(译注:为了保持与原文的一致性,把find译为“查找”,但是这里和后面出现的 “查

找文件”指的都是打开文件的意思。)

查找(finding)一个文件意味着你在Emacs里看文件的内容,在多数情况下,也就是你 在

编辑它。但是,你用Emacs对它作的改变并不是永久行的,除非你“保存(saving)” 它

。所以你可以避免把一个改了一半的文件留在系统上。甚至你保存了文件,Emacs也 会

把原始文件换个名字保留下来,以防过后你发现对文件的改动是错误的。

如果你观察屏幕的你将看见一个开始和结尾都是破折号的行,并且以“--:**-- TUTORI

AL”或之类的东西开始。屏幕的这部分通常显示你正在访问的文件的名字。 现在,一个

叫做“TUTORAL”的文件,它是你的Emacs教程的个人拷贝。当你用Emacs 查找一个文件

,文件名会出现在同样的位置。

查找和保存文件命令不像前面学的那些命令。它们都以字符Control-x开始。以 Contro

l-x起头的是一个完整的命令系列;它们中的许多都是对文件,缓冲,和相关的 东西进

行操作的。这些命令有两个,三个或四个字符长。

关于查找文件命令的另一件事是你必须给出你需要的文件的文件名。我们说这个命令 “

从终端读取一个参数”。(在这种情况下,参数是文件的名字);当你键入命令C-x C-f后

,Emacs会提示你输入文件的名字。你输入的文件名会出现在屏幕底部的行上。 这个底

部的行称为微型缓冲(minibuffer)用于这类较短的输入。你能用Emacs本身的 编辑命令

来编辑文件名。

当你正在输入文件名(或其他任何微型缓冲区输入),你能用命令C-g来取消。

>> 键入命令C-x C-f,然后输入C-g。这将取消微型缓冲,也取消了C-x C-f命令所使 用

的微型缓冲,所以你不查找任何文件。

当你输完文件名后用<Return>来结束。然后C-x C-f开始工作,并开始寻找你所选择的

文件。当C-x C-f命令结束后微型缓冲区也消失了。

过一小会儿文件的内容就会显示在屏幕上,然后你就能对它进行编辑了。当想永久保留

你的改动时用命令:

C-x C-s 保存文件(save the file)。

这个操作会把Emacs里的文本拷贝到文件里。在你第一次作的时候,Emacs把原始文 件改

为一个新名字以使它不至于丢失。新名字是在原来名字的后面加一个“~”。

保存结束后,Emacs打印出被写的文件的文件名。你应当经常的保存,万一系统崩溃 的

话你不至于丢失太多的工作。

>> 键入C-x C-s来保存你的教程的拷贝。屏幕的底部会打印出“Wrote.....TUTORIAL”



注意:在某些系统上,输入C-x C-s 会把屏幕冻结住使你从Emacs看不到更多的输出。这

表示这个操作系统的“特性”叫做“控制流程”,它拦截了C-x不让它到达Emacs那里。

要使屏幕解冻,输入C-q,然后看Emacs手册里的“Spontaneous Entry to Incrementa

l Search”一节,按上面的建议来对付这种“特性”。

你能查找一个已存在的文件,来查看它或编辑它。你也可以查找一个尚未存在的文件。

这是 Emacs:里创建文件的方法:查找文件,将会出现一个空白,然后插入文件的文本

。当你 “保存(saving)”的时候,Emacs将会用你插入的文本创建文件。从那时候起,

你可以认为 你在编辑一个存在的文件了。

* (缓冲)BUFFERS

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

如果你用C-x C-f查找第二个文件,第一个文件仍然留在Emacs里。你可以再用C-x C-f查

找 一次来切换回去。用这种方法你在Emacs里有很多文件。

>> 输入C-x C-f foo <Return>来建立一个名为foo的文件。然后插入一些文本,编辑它

,并 用C-x C-s来保存“foo”。 最后输入C-x C-f TUTORIAL<Return>以回到本教程。

Emacs把每个文件的文本都保存在一个叫“缓冲(buffer)”的东西里。查找(打开)一个文

件 就会在Emacs里产生一个新的缓冲。要看你当前运行的Emacs里存在的缓冲列表,输入



C-x C-b 列出缓冲(list buffers)

>> 输入 C-x C-b

观察每个缓冲都有一个名字,它可能也有一个它所保存的文件的文件名。一些缓冲不对

应 文件。比如,叫“*Buffers List*”的缓冲没有任何文件。这个缓冲只包含由C-x C

-b产生的 缓冲列表。你在Emacs窗口里看到的任何文本都是某个缓冲的一部分。

>> 输入 C-x 1 消除缓冲列表。

如果你对一个文件的文本作了改动,然后查找另一个文件,第一个文件并不保存。它的

改变 保存在Emacs里,在那个文件的缓冲里。被建立或编辑的第二个文件的缓冲并不影

响第一个 的。这一点很有用,但这也意味着要有一个便捷的方法来保存第一个文件的缓

冲。如果要用 C-x C-f切换回去只是为了按C-x C-s保存它将会是一件令人讨厌的事。所

以我们用

C-x s 保存缓冲(save the buffer)

C-x s 向你询问每个改动过但未存盘的缓冲,对每个这样的缓冲都询问是否保存。

>> 插入一行文本,然后按C-x s。 将会问你是否保存叫TUTORIAL的缓冲。 输入“y”来

回答是。

* 扩展命令集(EXTENDING THE COMMAND SET)

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

有太多的Emacs命令,大大超过了Contorl和meta加上字符所能表示的数量。Emacs用X(扩

展 eXtand)命令来解决这个问题。有两种风格:

C-x 字符扩展,后跟一个字符。

M-x 名字命令扩展,后跟一个长名字。

这些命令通常有用,但不如你已经学过的那些命令使用的频繁。你已经见过了它们中的

两个: 文件命令C-x C-f 用于查找和C-x C-s用于保存。

另一个例子是结束Emacs的命令C-x C-c(不必担心你所作的改动会丢失,在退出Emacs 之

前,C-x C-c会提示你保存每一个改动过的文件)。

C-z命令用于*临时*退出Emacs,所以你能回到原来运行的Emacs里。在允许这样做的 系

统上,C-z把Emacs“挂起”;就是说回到外壳(shell)下,但并不破坏运行的Emacs。 在

大多数外壳上,你能用‘fg’命令或‘%emacs’来继续Emacs。

在不支持挂起的系统上,C-z建立一个子外壳(subshell)运行于Emacs下以使你能运行 其

他程序然后回到Emacs;这并不是真正的“退出”Emacs。在这种情况下,通常从 子外壳

回到Emacs的外壳命令是‘exit’。 有很多C-x 命令,这是已学过的一个列表:

C-x C-f 查找文件

C-x C-s 保存文件

C-x C-b 缓冲列表

C-x C-c 退出Emacs

C-x u 撤销操作

被称作扩展命令的命令的使用频率都不太高。或者是只在某些模式下使用。一个例子是

替换 字符串的命令,它在全文里把字符串替换为其他的。当你键入M-x, Emacs会在屏

幕的底部 提示你输入命令;在这种情况下,是“replace-string”。比如输入“repl

s<TAB>”, Emacs会把命令补全。用<Return>来结束命令。

替换字符串命令要求两个参数--要被替换的字符串和用来替换的字符串。你必须用<Ret

urn> 来结束两个参数。

>> 把光标移上两行,然后输入M-x repl s<TAB><Return>changed<Return>altered <Re

turn>。 注意现在这一行改变了:你把光标初始位置后的所有单词c-h-a-n-g-e-d替换为

了 “altered”

* 自动保存(AUTO SAVE)

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

当你改动了一个文件还未存盘的话,所作的改动也许会由于系统崩溃而丢失。为防止 这

种情况发生,Emacs在编辑时为每个文件提供了“自动保存(auto save)”。自动保存 的

文件的文件名前后都有一个#号;例如,如果你编辑的文件名叫“hello.c”,自动保 存

的文件的文件名就叫“#hello.c#”。当你正常的保存了文件后,Emacs会删除这个自 动

保存的文件。如果遇到死机,你能打开那个文件后按M-x recover file<Return>来恢复

你的编辑,(是你编辑的文件而不是自动保存的文件)。当提示确认时,输入yes<Retur

n> 来继续恢复自动保存的数据。

* 回显区域(ECHO AREA)

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

如果Emacs发现你输入命令的速度很慢的话它会在屏幕底部为你显示出来,这个区域叫

“回显区域”。

* 模式行(MODE LINE)

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

回显区域上面的一行称为“模式行(mode line)”。模式行显示与下面类似的东西:

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

这一行给出了有关你在编辑的文件和Emacs状态的有用信息。

你已经知道了文件名意味着什么。--NN%--指出你现在在文本里的位置;它意味着上面还

有NN%的文本。如果是在文件的开头,会用--Top-- 来代替--0%--。如果是在行的末尾

, 会显示--Bot--。如果你正在看的文本内容很少,可以全部显示在屏幕上,模式行会

说 --All--。

前面的星号表示你已经改动过文本了。一旦你保存了文件或打开了一个新文件,模式行

的 这部分就不是星号而是破折号了。

模式行上括号里的部分是现在的编辑模式。现在是缺省的基本(Fundamental)模式。它是

“主模式(major mode)”的一种。

Emacs有很多不同的主模式。有些意味着不同的语言或不同的文本。如Lisp模式(Lisp m

ode), 文本模式(text mode)等等。在任何时候有且只能有一种主模式被激活。并且它

的名字会出 现在现在显示“Fundamental”的位置上。

每一个主模式都有些自己的命令。就象不同的编程语言的注释看起来不同一样。每种主

模式 插入的注释也不同。可以用扩展命令切换进某种主模式。例如,M-x fundamental

-mode 是切 换进基本模式。

>> 输入 M-x text-mode<Return>

不必担心,没有命令会给Emacs带来很大改变。但是你可以看到现在M-f和M-b把省略号当

作 单词的一部分。而先前,在基本模式里,M-f 和M-b把省略号当成当成分隔符。

主模式通常作诸如此类微小的变化:大多数命令在每个主模式里作“同样的工作”,但

又有 些微小的不同。

要观看关于你现在的主模式的文档,按C-h m。

>> 键入C-u C-v一次和多次使本行接近屏幕的顶端。

>> 输入C-h m ,看看文本模式和基本模式有些什么不同。

>> 按C-x 1 从屏幕上关掉这个文档。

主模式之所以叫做主模式是因为也存在从模式,从模式与主模式完全不同。每个从模式

可以自 己打开或者关闭,独立于所有其他从模式,也独立于你的主模式。所以你可以不

用从模式或者 同时用很多种从模式。

有一种从模式很有用,特别是在编辑英文文本时。它是自动填充模式(auto fill mode)

。当这个 模式打开的时候,当输入的文本过宽的时候就会自动折行。

你能用M-x auto-fill-mode<Return>来打开自动填充模式。如果此模式已经打开M-x au

to- fill-mode<Return>则把它关闭。我们把这叫做切换开关。

>> 输入M-x auto-fill-mode<Return>。然后插入一些“asdf”直到看到这行被分为两行

。你 必须在中间放一些空格,只有到空格的时候才会换行。

通常边界宽度是70,但你能用带数字参数的C-x f 命令来改变它。

>> 键入带参数20的C-x。(C-u 20 C-x f) 然后输入一些文本看现在每行只有20个字符了

。然后用C-x f把它改回70。

如果你在一个段落的中间产生了改变,自动填充模式将不会重新填充。要想重新填充段

落, 当光标在段落里的时候按M-q。

>> 把光标移到上一段按 M-q。

* 搜索(SEARCHING)

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

Emacs 能朝前和朝后搜索字符串(指相邻的一些字符或单词)。搜索是一个移动光标的操

作, 它把光标移动到字符串出现的下一个地方。

Emacs 的搜索命令和其他大多数编辑器不同,它是“增量式(incremental)”的,这意味

着搜索在你键入字符串时就开始了。

开始一个向前搜索的命令是C-s,C-r是往回搜索。但等等,先别忙。

当你输入C-s是你将注意到在回显区域会出现一个字符串“I-search”。这告诉你Emacs

开始 了一个增量搜索,并在等待你输入要搜索的东西。<RET>结束查询。

>> 现在键入C-s开始一个搜索。慢慢的输入单词‘cousor’,在输入每一个字母的时候

停顿一 下,注意看光标发生了什么。

>> 再输入一次C-s,来搜索“cursor”出现的下一个地方。

>> 现在输入<Delete>四次看看光标移到了哪里。

>> 输入<RET>结束搜索。

看到发生什么了吗?在Emacs的增量搜索里,你输入多少字符串它就试着搜索这些字符出

现的 地方。到字符串出现的下一个地方,只须再按一次C-s。要搜索的字符串不存在的

话,Emacs 会发出蜂鸣并告诉你当前的搜索“失败(failing)”,按 C-g 也是终止搜索



注意:在某些系统上,输入 C-s 会把屏幕冻结住使你从Emacs看不到更多的输出。这 表

示这个操作系统的“特性”叫做“控制流程”,它拦截了C-s不让它到达Emacs那里。 要

使屏幕解冻,输入C-q,然后看Emacs手册里的“Spontaneous Entry to Incremental S

earch”一节,按上面的建议来对付这种“特性”。

如果你在搜索的过程里按了<Delete>,你将注意到要搜索的字符串的最后一个字符会被

删除 并且光标会回到上一个被搜索到的地方。比如,假设你键入了“c”,将会搜索“

c”第一次出 现的地方。然后如果你键入“u”,光标将移到“ cu”第一次出现的地方

。现在键入<Delete>。 这将从搜索的字符串里把“u”删掉,这时光标回到“c”第一次

出现的地方。

如果你在搜索时按了Control或meta键加字符(少数几个少数命令例外,如C-s和C-r),搜

索将被 终止。

C-s向当前光标的后面搜索字符串出现的地方。如果你需要搜索前面文本里的东西,用C

-r来代替。 我们所介绍的C-s的每个特性C-r也支持,除了方向相反。

* 多窗口(MULTIPLE WINDOWS)

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

Emacs有一个非常好的特性是能同时在屏幕上显示不止一个的窗口。

>> 把光标移到本行上按C-u 0 C-l。

>> 现在按C-x 2,它把屏幕分裂成两个窗口,每个窗口都显示本教程。光标在上面的窗

口里。

>> 按C-M-v 滚动到下面的窗口里。(如果你没有一个真正的Meta键,那么按ESC C-v)

>> 按 C-x o (“o” 指 “其他(other)”) 把光标移到到下面的窗口里。

>> 用 C-v 和 M-v 滚动下面窗口里的文本。 在上面的窗口里看本教程。

>> 再次按 C-x o 使光标回到上面的窗口里。 现在光标象以前一样在上面的窗口里了。

你能一直用C-x o在窗口间切换。每个窗口都有它自己的光标位置,但仅有一个窗口能显

示活动 的光标。所有的编辑命令都发生在那个显示光标的窗口上。我们把这个窗口叫做

“选中窗口( selected window)”。

当你在一个窗口里编辑文本,而用另一个窗口作参考时命令C-M-v非常有用。你总是能把

光标留 在所编辑的地方,而用C-M-v来翻阅另一窗口。

C-M-v 是 CONTROL-META 加字符的一个例子。 如果你有一个真正的META 键,你能同时

按住 CTRL 和 META 再按“v”来输入C-M-v。CTRL 和 META 谁先按谁后按无所谓。

如果你没有一个真正的META 键, 你可以用 ESC 来代替。这时候次序是有关系的: 你

必须让 ESC 跟在 CTRL-v后面; 否则 CTRL-ESC v 将不工作。 这是因为 ESC 是一个有

意义的字符而不 是一个修饰字符。

>> 输入 C-x 1 (在上面的窗口里) 以消除下面的窗口。

(如果你在下面的窗口里键入C-x 1,将会把上面的窗口去掉。可以把这个命令看作是“

只保留你 现在在的那个窗口。)

你不必一定要在两个窗口里显示同样的缓冲。如果你在一个窗口里键入C-x C-f查找文件

,另一个 窗口的内容不会改变。你能独立的在每个窗口里查找文件。

这是让两个窗口显示不同内容的另一种方法:

>> 在你输入的文件名后再输入C-x 4 C-f,然后用<Return>结束。会看到指定的文件出

现在下面 的窗口里。光标也在那里面。

>> 键入C-x o 回到上面的窗口,然后输入C-x 1删掉下面的窗口。

* 递归编辑层(RECURSIVE EDITING LEVELS)

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

有时候你会进入“递归编辑层(recursive editing level)”。由模式行上的方括号指示

。它在主模式 名的括号外面。例如你也许会看到(Fundamental)变成了[(Fundamental)

]。

要退出递归编辑层,按ESC ESC ESC。这是一个通用的退出命令,你也可以用它除去额外

的窗 口,或者退出微型缓冲。

>> 输入 M-x 进入一个微型缓冲; 然后用 ESC ESC ESC 离开。

你不能用C-g来退出递归编辑层。这是因为C-g只能取消在递归编辑层里面的命令。

* 获取更多的帮助(GETTING MORE HELP)

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

在本教程里我们试着为你开始使用Emacs提供了足够多的信息。但是有关Emacs的信息实

在是太 多以至于不能全部都在这里说明。但是,你还应该学习更多有关Emacs的东西,

因为它另外还有 很多有用的特性。Emacs提供了很多读取有关命令的文档的命令。这些

“帮助”命令都以 Control-h开头,叫做“帮助字符”。

为了使用帮助特性,输入字符C-h,然后再输入一个字符来说明你需要哪种帮助。如果你

真的不知 道,输入C-h ? 然后 Emacs会告诉你它能给你什么样的帮助。如果你输入了C

-h 又觉得不需要任 何帮助,你可以用C-g来取消它。

(在有的地方,C-h的作用被改变了。如果按C-h在屏幕的底部没有出现有关帮助的信息的

话,试试 用F1和M-x help RET来代替。)

最基本的帮助特性是C-h c。输入C-h,然后是字符 c,然后输入一个命令字符和序列;

然后 Emacs 会显示这个命令的简洁的描述。

>> 输入 C-h c Control-p.

显示的消息看起来会象这样:

C-p runs the command previous-line

这告诉你“功能的名字”。功能的名字主要用于对Emacs的功能扩充和定制。但因为功能

的名字 指出了命令的用途,所以最好不要改动它。

C-h c后面可跟多字符命令,比如 C-x C-s 和 (如果你没有 META 或者 EDIT 或者 ALT

键) <ESC>v 。

要获取有关命令的更多信息,用C-h k 代替 C-h c。

>> 输入 C-h k Control-p.

这将在一个Emacs窗口里显示命令的文档。当你读完后可以用C-x 1除去帮助文本。如果

不想马上 离开,你可以一边编辑一边参考帮助文本,然后再按C-x 1。

这是一些有用的 C-h 选项:

C-h f 描述一个功能,在你输入了这个功能的名字后。

>> 输入 C-h f previous-line<Return>。 将打印出C-p命令所实现的所有功能。

C-h a 命令查找。输入一个关键字,Emacs将列出所有名字里有这个关

键字的命令。 包括所有以Meta-x开始的命令。对有些命令,C-h a 也将列出实现同一功

能的 几个命令序列。

>> 输入 C-h a file<Return>.

这将在窗口里显示所有名字里有单词“file”的M-x命令。

>> 输入 C-M-v 来滚动帮助窗口,做上几次。

>> 输入 C-x 1 来删除帮助窗口。

* 总结(CONCLUSION)

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

记住,永远都用C-x C-c来退出Emacs。用C-z来退到一个临时的外壳里,以使你过后还能

回到 Emacs。

不明白?欢迎到 linux论坛 (http://bbs.linuxmine.com) 参加讨论!

全文结束

在Linux环境中使用USB接口的存储设备(转帖)

在Linux环境中使用USB接口的存储设备

(转自:(赛迪网社区Linux俱乐部)http://bbs.ccidnet.com/showthread.php?threadid=211409)

如何在Linux环境中使用USB接口的存储设备?这是各大电脑论坛上出现得比较多的一个问题,同此可见这也是摆在许多电脑玩家面前的一道难题。本文就为您提供一套完美的解决方案,通过下面的方法,您仅可以在Linux环境中方便地使用U盘、USB硬盘盒,而且还能将数码相机作为USB大容量存储器。这里就以Red  Hat  Linux  7.2为例,来一步一步地介绍如何在Linux环境中使用USB存储器。

  1.在X-Windows环境中打开“控制中心”,展开“信息→USB设备”控制台树,查看Linux是否已经正确识别您的USB存储器,如果没有看到USB设备信息,那么您就应该要检查USB端口是否已经在BIOS中打开,或USB存储器与电脑的物理连接有没有连接好了。图1所示为笔者的 FinePix数码相机信息。


图1

  2.在控制台状态下输入如下命令:

  fdisk  -l  /dev/sda

  注意:不要在sda后面加通配符“*”或“?”,否则运行命令后返回的信息将不正常。如果您有多个USB设备话,则设备名在Linux下分别表示为sda、sdb、sdc等。

  运行上面的命令后,笔者的电脑上返回如图2所示信息,表示系统已经找到笔者的USB设备,设备名称为/dev/sda1、可启动(Boot下面的那个*表示是活动分区),容量8MB、文件系统为FAT12。


图2

  3.在/mnt目录下建立一个挂装USB存储器的目录:

  mkdir  /mnt/usb

  4.然后再运行装载设备命令,将USB设备挂装到/mnt/usb目录下:

  mount  -t  msdos  /dev/sda1  /mnt/usb 

  注意:如果在图2中显示您的USB设备的文件系统为FAT32,请使用mount  -t  vfat  /dev/sda1  /mnt/usb命令装载USB设备。

  5.运行如下命令即可查看USB存储器中的文件信息:

  ls  /mnt/usb

  然后您就可以像对待硬盘一样对USB存储器中的数据进行拷贝、删除等操作了。

  如果您不习惯于在控制台下敲敲打打,还可以在KDE桌面上建立一个指向USB存储器的快捷方式,用鼠标完成所有的文件操作,就像在Windows中一样简单,建立快捷方式的操作非常简单:用鼠标在桌面空白处单击鼠标,从弹出的快捷菜单中选择“新建/硬盘”,右键单击新创建的快捷方式,选择“属性”菜单命令,切换到“设备”选项卡,分别输入USB存储器的设备名称、安装点和文件系统类型,如图3所示。以后只需要单击该快捷方式即可方便地访问USB存储器了。


图3

奇怪的硬盘错误

  今天,帮同事安装一个win xp,用克隆的方法到80%左右停止,报告硬盘错误;用安装的光盘也不行。格式化,查错均没有发现错误。

  后来,试着把硬盘格式化成fat格式(原来为fat32),安装成功。搞不懂是怎么一回事?

  以后,碰到类似的情况可以试着改变一下硬盘格式。