实验二:vi基础操作
实验步骤
- 打开vi
a.使用上次实验创建的用户登录系统。
b.打开Terminal。
c.打开vi编辑器,观察其特征。
- 文件录入和修改
a.练习在命令模式和文本输入之间的切换。
b.在vi中输入以下内容:
The vi history The vi editor was developed at the University of california, berkeley as part of the berkeley unix system. |
c.保存文件,名称为vi_history_1,退出vi。
d.用vi打开文件vi_history_1。
e.将vi中的内容修改为以下内容:
The vi history The vi editor was developed at the University of california berkeley as part of the berkeley unix system. At the beginning the vi editor was part of another editor The vi part of the ex editor was often used and became very. This popularity forced the developers to come up with a separate vi editor. now the vi editor is independent of the ex editor and is available on most of the UNIX operating system. The vi editor is a good editor for every editing jobs. |
f.将以上内容保存到文件vi_history_2中。
g.继续修改vi中的内容,目标结果如下:
The vi history The vi editor was developed at the University of California Berkeley as part of the Berkeley UNIX system. At the beginning the vi (visual) editor was part of the ex editor and you had to be in the ex editor to use the vi editor. The vi part of the ex editor was often used and became very popular. This popularity forced the developers to come up with a separate vi editor. Now the vi editor is independent of the ex editor and is available on most of the UNIX operating systems. The vi editor is a good, efficient editor for every editing jobs although it could be more user friendly. |
h.将以上内容保存到文件vi_history_3中。
- 内容查找
a.使用斜线(/)在vi中查找单词vi,使用n遍历所有查找结果。
b.使用问号(?)在vi中查找单词vi,使用n遍历所有查找结果。
- 删除与替换
a.将光标移到文件头,删除前5行。然后再恢复删除。
b.将光标移到第二行开头,删除10个字符。然后再恢复删除。
- 使用r命令替换光标所在位置的字符,然后再恢复。
d.使用R命令将单词developers替换为creators。
- 退出vi
a.执行ZZ命令退出vi。
b.查找保存的三个文件。
- 目录与文件操作
a.使用ls / 命令查看根目录中都有哪些系统目录,说出这些目录的用途。
答案:
bin:存放可执行程序
sbin:存放系统可执行程序
home:存放普通用户主目录
device:存放设备文件
etc:存放配置文件
b.尝试在根目录下创建目录和删除目录,预测其结果并进行验证。
答案:
如果普通用户创建失败,root用户可以创建和删除。
c.执行如下linux命令序列,观察每步执行的结果,思考其原因($是提示符):
$ ls
$ pwd
$ cd ..
$ pwd
$ cd
$ pwd
$ cd ~
$ pwd
答案:
第一个pwd输出的是当前主目录
第二个pwd输出的是/home
第三个pwd输出的是当前主目录
第四个pwd输出的是当前主目录
d.在主目录下创建子目录xyz。
答案:
cd ~
mkdir xyz
e.在子目录xyz中创建文件xyz,其内容如下:
This is a test file.
答案:
方法1:
cd xyz
cat > xyz
This is a test file.
[Crtl-d]
方法2:
cd xyz
vi xyz
i(命令)
This is a test file.
[Esc]
:wq!
f.打印文件xyz,然后取消打印申请。(学生选做,可以不做)
g.以下面几种方式显示主目录的内容:
〉以长格式列出文件;
答案:ls -l
〉以多列格式显示;
答案:ls -C
〉列出所有文件,包括隐藏文件。
答案:ls -a
h.查看文件xyz的访问权限。
答案:ls -l 然后查看权限字段
i.删除目录xyz。
答案:
方法1:
cd xyz
rm xyz
cd ..
rmdir xyz
方法2:
rm -r xyz (此处xyz是目录)