1.重定向练习题
(1)新建一个文件redirect.txt,并在其中写入20210804RHCSA,保存并退出
先输入命令
XML
[root@localhost ~]# vim redirect.txt
进入vim编辑器后,按快捷键"i"进入编辑模式,再写入数据,写完之后按"esc"键退出编辑模式,最后再输入"wq"保存并退出。

(2)将cat redirect.txt 的输出结果重定向到 redirect1.txt中
XML
[root@localhost ~]# cat redirect.txt >redirect1.txt
[root@localhost ~]# cat redirect1.txt
20210804RHCSA
(3)将cat redirect.txt noexist.txt的标准输出重定向到redirect2.txt,标准错误输出重定向到error1.txt
XML
[root@localhost ~]# cat redirect.txt noexist.txt 1>redirect2.txt 2>error1.txt
[root@localhost ~]# cat redirect2.txt
20210804RHCSA
[root@localhost ~]# cat error1.txt
cat: noexist.txt: No such file or directory
(4)将cat redirect.txt noexisttxt的标准输出和错误输出都从定向到redirect3.txt中
XML
[root@localhost ~]# cat redirect.txt noexist.txt 1>redirect3.txt 2<&1
[root@localhost ~]# cat redirect3.txt
20210804RHCSA
cat: noexist.txt: No such file or directory
2.vim练习题
(1)应用vi命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间
先输入命令,进入vi编译器后,输入i开启编辑模式,写入数据后按esc键退出编译模式,确认信息无误后,输入":wq"保存并退出。
XML
[root@localhost ~]# vim /tmp/newfile
[root@localhost ~]# cat /tmp/newfile
2023-09-17 8:00

(2)将/etc/group文档的内容读入到newfile文档中 (在日期的下-行即第2行)
XML
[root@localhost ~]# ll /etc/group
-rw-r--r--. 1 root root 811 Sep 10 21:56 /etc/group
[root@localhost ~]# cat /tmp/newfile
2023-09-17 8:00
-rw-r--r--. 1 root root 811 Sep 10 21:56 /etc/group

(3)查找文档中包含#号字符的行,将整行删除
XML
[root@localhost ~]# vim /tmp/newfile :g/#/d
2 files to edit
(4)开启VI的行号提示功能
进入newfile中,进入编辑模式输入"set no"回车后即可显示行号,成功开启行号提示功能
XML
[root@localhost ~]# vim /tmp/newfile

