linux--第一次作业

本文详细介绍了如何在VMware上创建Linux虚拟机并使用SSH进行远程连接。接着展示了Linux文件管理命令,如在/opt下创建tmp目录及a.txt文件。此外,还讲解了VI/VIM编辑器的使用,包括创建newfile文件,插入日期时间,读取grub.cfg内容,删除包含#号的行以及开启行号显示功能。
摘要由CSDN通过智能技术生成

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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值