一、vi编辑器必备知识
1、vi的三种模式特点、切换方式
i 进入插入模式
esc 进入命令模式
: 进入末行模式
2、vi <文件名> 打开文件
:q 结束编辑
:q! 强制退出
:w 保存后退出
:wq 强制保存后退出
3、vi基本编辑
dd 删除光标所在行
yy 复制光标所在行
nyy 复制光标所在n行
p 粘贴
/600 查找具有600 的关键字 n 下一个 N 上一个
o 换行后,进入插入状态
:set nu 带行号显示
G 光标快速定位到最后一行
g 光标快速定位到文档开头
二、vi编辑器使用示例
1、在/root建立目录temp,把/bin目录下所有字母a开头的文件拷贝到/root/temp

2、查找ifcfg-eth0文件,并拷贝到/root/temp

3、把/var/log/messages文件拷贝到/root/temp,并查看文件的内容的最后20行

4、使用grep命令查找messages文件中包含net字符串的行,并写入到messages.net文件中

5、 使用grep、awk命令以及管道和重定向,截取shadow文件的第1行第2段的内容输出到root.pass文件中

6、 使用tar命令打包压缩/root/temp中的所有文件,命名为temp.tar.gz,放到/root目录下

网友评论