RHCSA第三天总结与练习

总结
在这里插入图片描述

1、创建文件命令练习:
(1) 在/目录下创建一个临时目录test;

[root@localhost ~]# mkdir  /test
[root@localhost ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  test  tmp  usr  var

(2)在临时目录test下创建五个文件,文件名分别为passwd,group,bashrc,profile,sshd_config;

[root@localhost ~]# cd /test
[root@localhost test]# touch passwd group bashrc profile sshd_config
[root@localhost test]# ls /test
bashrc  group  passwd  profile  sshd_config

(3)在/test创建/etc/motd的软链接,文件名为motd.soft;创建/etc/motd的硬链接为motd.hard

[root@localhost ~]# ln -s /etc/motd /test/motd.soft
[root@localhost ~]# ln  /etc/motd /test/motd.hard
[root@localhost ~]# ls /test
bashrc  group  motd.hard  motd.soft  passwd  profile  sshd_config
[root@localhost ~]# ll /test
total 0
-rw-r--r--. 1 root root 0 Oct 21 13:01 bashrc
-rw-r--r--. 1 root root 0 Oct 21 13:01 group
-rw-r--r--. 2 root root 0 Sep 10  2018 motd.hard
lrwxrwxrwx. 1 root root 9 Oct 21 13:04 motd.soft -> /etc/motd
-rw-r--r--. 1 root root 0 Oct 21 13:01 passwd
-rw-r--r--. 1 root root 0 Oct 21 13:01 profile
-rw-r--r--. 1 root root 0 Oct 21 13:01 sshd_config
[root@localhost ~]# ll -i  /etc/motd /test/motd.hard
33652948 -rw-r--r--. 2 root root 0 Sep 10  2018 /etc/motd
33652948 -rw-r--r--. 2 root root 0 Sep 10  2018 /test/motd.hard

2、重定向练习:
(1)将系统内核版本信息,发行版本信息,写入到/test/motd.soft文件中

[root@localhost ~]# cat /etc/redhat-release      //查看发行版本
Red Hat Enterprise Linux release 8.4 (Ootpa)
[root@localhost ~]# cat /etc/redhat-release > /test/motd.soft
[root@localhost ~]# cat /test/motd.soft
Red Hat Enterprise Linux release 8.4 (Ootpa)
[root@localhost ~]# uname -r                    //查看内核版本
4.18.0-305.el8.x86_64
[root@localhost ~]# uname -r >> /test/motd.soft  //追加到/motd.soft文件
[root@localhost ~]# cat /test/motd.soft
Red Hat Enterprise Linux release 8.4 (Ootpa)
4.18.0-305.el8.x86_64

(2)将当前主机主机名,当前用户使用的shell信息追加到/test/motd.hard文件中

[root@localhost ~]# hostname      //查看主机名
localhost.localdomain            
[root@localhost ~]# hostname > /test/motd.hard     //将主机名写入到文件
[root@localhost ~]# cat /test/motd.hard
localhost.localdomain
[root@localhost ~]# echo $SHELL           //查看当前默认的shell
/bin/bash
[root@localhost ~]# echo $SHELL >> /test/motd.hard  //将shell信息追加到文件
[root@localhost ~]# cat /test/motd.hard
localhost.localdomain
/bin/bash

(3)将根目录下的文件的文件名写入/test/file文件中

[root@localhost ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  test  tmp  usr  var
[root@localhost ~]# ls / > /test/file
[root@localhost ~]# cat /test/file
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var

(4)查看当前工作目录是否为/test目录,将当前工作目录的详细信息追加到/test/file文件中

[root@localhost ~]# pwd          //查看当前工作目录
/root
[root@localhost ~]# pwd >> /test/file
[root@localhost ~]# cat /test/file
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var
/root

3、tee命令练习:
(1)将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中

[root@localhost ~]# date | tee /test/passwd /test/group /test/bashrc /test/profile /test/sshd_config
Fri Oct 21 13:25:32 CST 2022
[root@localhost ~]# cat /test/passwd
Fri Oct 21 13:25:32 CST 2022
[root@localhost ~]# cat /test/group
Fri Oct 21 13:25:32 CST 2022
[root@localhost ~]# cat /test/bashrc
Fri Oct 21 13:25:32 CST 2022
[root@localhost ~]# cat /test/profile
Fri Oct 21 13:25:32 CST 2022
[root@localhost ~]# cat /test/sshd_config
Fri Oct 21 13:25:32 CST 2022

(2)将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件

[root@localhost ~]# hostname | tee -a /test/passwd /test/group /test/bashrc /test/profile /test/sshd_config
localhost.localdomain
[root@localhost ~]# cat /test/passwd
Fri Oct 21 13:25:32 CST 2022
localhost.localdomain
[root@localhost ~]# cat /test/sshd_config
Fri Oct 21 13:25:32 CST 2022
localhost.localdomain

4、vim命令练习:
(1)将/etc/passwd文件内容读入/test/passwd,并修改文件里的root字符为admin

[root@localhost ~]# vim /test/passwd

进入到/test/passwd文件里,输入 :r /etc/passwd
这个命令是在/test/passwd文件读入/etc/passwd 文件的内容

[root@localhost ~]# vim /test/passwd

进入文件,输入 /需要查找的字符 可查找到所有的root字符
这里我查找root字符,所以需要输入 /root
在这里插入图片描述
查找到后,输入 :% s/原字符/替换的字符/g
这是将所有字符进行替换
我需要将root替换成admin,所以我需要输入 :% s/root/admin/g
在这里插入图片描述

(2)将/etc/group文件内容读入/test/group,只保留root开头的行内容
查看/etc/group文件

进入到/test/group文件,读入/etc/group的内容

[root@localhost ~]# vim /test/group    //进入文件

输入 :r /etc/group
在这里插入图片描述
删除除root字段的其他字段
:v/root/d
在这里插入图片描述

(3)将/root/.bashrc文件内容读入/test/bashrc,删除#号开头的行内容
进入到/test/bashrc里面,继续使用 :r /root/.bashrc 读入/root/.bashrc的内容
在这里插入图片描述
然后输入 :g/#/d
或者是 :%s/#.*\n 删除以#开头的字段
在这里插入图片描述

(4)将/etc/ssh/sshd_config文件内容读入/test/sshd_config,在该文件的第17行后添加一行内容Port 22

读入内容
在这里插入图片描述
输入 :set nu 显示行数
在这里插入图片描述
找到17行,输入一行内容Port22
在这里插入图片描述

(5)将/test/sshd_config文件中的第40-50行的yes改为no
原本内容
在这里插入图片描述
对其进行替换,输入 :40,50 s/yes/no/g
在这里插入图片描述

(6)将/test/sshd_config文件另存为/test/sshd.conf
在/test/sshd_config文件中输入 :w /test/sshd.conf 即可另存文件
在这里插入图片描述

(7)将/test目录下的passwd,group,bashrc文件中的第一行内容复制至文档最后一行
在文件里输入 :1 co 最后一行行号
group文件
在这里插入图片描述

(8)将/test目录下的profile,sshd_config文件中前两行内容复制至文档倒数第二行
profile文件
在这里插入图片描述

输入 :1,2 co 1
在这里插入图片描述
sshd_config文件
在这里插入图片描述
输入 :1,2 co 149
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值