1、在VMware上创建虚拟机以及安装Linux操作系统,使用ssh进行远程连接:
ssh root@192.168.103.1
2、文件管理命令练习:
(1)在/opt日录下创建一个临时日录tmp:
[root@localhost ~]# mkdir -p /opt/tmp
[root@localhost ~]# tree /opt/
/opt/
└── tmp
(2)在临时目录下创建一个文件,文件名为 a.txt:
[root@localhost ~]# touch /opt/tmp/a.txt
[root@localhost ~]# ll /opt/tmp/
总用量 0
-rw-r--r--. 1 root root 0 3月 28 21:32 a.txt
3、vi/vim练习:完成如下步骤
(1)应用vi命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间:
1.查看/tmp目录是否存在:
[root@localhost ~]# ls -ld /tmp
drwxrwxrwt. 15 root root 4096 3月 28 21:45 /tmp
2.创建文件newfile:(使用vim编辑文件然后直接保存退出:wq)
[root@localhost ~]# vim /tmp/newfile
[root@localhost ~]# ll /tmp/newfile
-rw-r--r--. 1 root root 0 3月 28 21:50 /tmp/newfile
[root@localhost ~]# date > /tmp/newfile
[root@localhost ~]# cat /tmp/newfile
2023年 03月 28日 星期二 21:51:36 CST
[root@localhost ~]# touch /tmp/newfile
[root@localhost ~]# ll /tmp/newfile
-rw-r--r--. 1 root root 43 3月 28 21:53 /tmp/newfile
[root@localhost ~]# date "+%F %T" > /tmp/newfile
[root@localhost ~]# cat /tmp/newfile
2023-03-28 21:54:30
(2)将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第2行):
1.使用vim打开/tmp/newfile,然后输入:r /boot/grub2/gurb.cfg,最后:wq保存退出:
[root@localhost ~]# vim /tmp/newfile
2.[root@localhost ~]# cat /boot/grub2/grub.cfg >> /tmp/newfile
3.使用vim打开文件输入:/g/#/d最后再:wq保存退出
4.使用vim打开文件输入:set nu 查看序号
(3)查找文档中包含#号字符的行,将整行删除:
[root@bogon~]# grep^#/tmp/newfile
[root@bogon~]#vim/tmp/newfile
:g/#/d
(4)开启vi的行号提示功能:
[root@bogon~]#vim/tmp/newfile
: set nu