RHCSA练习作业

目录

文件管理命令练习

vi/vim练习


文件管理命令练习

题目如下:

(1)在/opt目录下创建一个临时目录tmp;

先查看是否存在/opt:
[redhat@localhost ~]# ls -d /opt
解答:
[redhat@localhost ~]# mkdir -p /opt/tmp
[redhat@localhost ~]# tree /opt/

(2)在临时目录下创建一个临时文件,文件名为:a.txt;

解答:
[redhat@localhost ~]# touch /opt/tmp/a.txt
[redhat@localhost ~]# ll /opt/tmp/

vi/vim练习

需要完成以下步骤:

 (1)应用vi命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间

解答:
先查看/tmp目录是否存在
    [redhat@localhost ~]# ls -ld /tmp
    drwxrwxrwt. 24 root root 4096 3月 27 19:32 /tmp
创建文件newfile

方法一:【使用vim编辑文件然后直接保存退出(:wq)】
    [redhat@localhost ~]# vim /tmp/newfile
    [redhat@localhost ~]# ll /tmp/newfile
    -rw-r--r--. 1 root root 0 3月 27 19:32 /tmp/newfile
    [redhat@localhost ~]# date > /tmp/newfile
    [redhat@localhost ~]# cat  /tmp/newfile
    2023年 03月 27日 星期一 19:10:22 CST

方法二:
    [redhat@localhost ~]# touch /tmp/newfile
    [redhat@localhost ~]# ll /tmp/newfile
    -rw-r--r--. 1 root root 0 3月 27 19:34 /tmp/newfile    
    [redhat@localhost ~]# date  "+%F %T" > /tmp/newfile
    [redhat@localhost ~]# cat /tmp/newfile
    2023-03-27 19:38:18

    

  (2)将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第二行)

解答:
方法一:
    使用vim打开/tmp/newfile,然后输入:r /boot/grub2/grub.cfg,最后输入:wq进行保存退出
[redhat@localhost ~]# vim /tmp/newfile

方法二:
    [redhat@localhost ~]# cat /boot/grub2/grub.cfg  >> /tmp/newfile

 (3)查找文档中包含#号字符的行,将整行删除

解答:
    使用vim打开文件输入:
        g/#/d
    最后再输入:wq 进行保存退出

 (4)开启VI的行号提示功能

解答:
    使用vim打开文件输入
        set nu    便可以查看行号

开启行号提示之后:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值