第三周作业

1、使用sed命令打印出/etc/passwd文件在中的奇数行内容

答:

[root@centos8 script]#sed -n '1~2p' /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:2:2:daemon:/sbin:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
下文省略

2、使用sed命令将/etc/passwd文件从2到10行中的bin替换成linux?

答:

[root@centos8 script]#sed -n '2,10s/bin/linux/gp' /etc/passwd
linux:x:1:1:linux:/linux:/slinux/nologin
daemon:x:2:2:daemon:/slinux:/slinux/nologin
adm:x:3:4:adm:/var/adm:/slinux/nologin
lp:x:4:7:lp:/var/spool/lpd:/slinux/nologin
sync:x:5:0:sync:/slinux:/linux/sync
shutdown:x:6:0:shutdown:/slinux:/slinux/shutdown
halt:x:7:0:halt:/slinux:/slinux/halt
mail:x:8:12:mail:/var/spool/mail:/slinux/nologin
operator:x:11:0:operator:/root:/slinux/nologin

3、使用sed命令显示/etc/passwd文件中最后一行信息内容

答:

[root@centos8 script]#sed -n '$p' /etc/passwd
zhang:x:1002:1002::/home/zhang:/bin/bash

4、使用sed命令删除/etc/fstab文件中所有以‘#’为注释的行和其后面紧挨着的空白字符,达到去除注释的目的

答:

[root@centos8 script]#sed -r 's/^#[[:space:]]*(.*)$/1/' /etc/fstab


/etc/fstab
Created by anaconda on Mon May 25 19:03:41 2020

Accessible filesystems, by reference, are maintained under '/dev/disk/'.
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.

After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.

UUID=fe92b43e-e98f-4784-bd8c-5cd60cc81e41 /                       xfs     defaults        0 0
UUID=a8d32f1a-dc93-4ffa-8f50-3dc6a9cfa04a /boot                   ext4    defaults        1 2
UUID=0e15bd13-618e-4c69-9ff2-7e8abcc1cd2c /data                   xfs     defaults        0 0
UUID=bf15e2eb-d89a-4527-9a6d-d2675ee7c8c6 swap                    swap    defaults        0 0

5、使用sed命令将/etc/passwd前三行信息保存至/root/file.txt文件中

答:

[root@centos8 script]#sed -n '1,3w /root/file.txt' /etc/passwd
[root@centos8 script]#cat /root/file.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin

6、使用rpm命令安装、卸载、更新ntp-0.7.12x86_64.rpm软件包

安装:rpm -ivh ntp-0.7.12x86_64.rpm

卸载:rpm -e ntp-0.7.12x86_64.rpm

更新:rpm -uvh ntp-0.7.12x86_64.rpm

7、哪个命令可查看安装openssl.x86.rpm包的依赖关系,查询会安装哪几个文件,分别到哪个目录,而不实际安装?如何查询openssl安装的时间?如何查询/usr/lib/libssl.so.6属于哪个包安装的?

答:

依赖关系:rpm -qR openssl

安装文件:rpm -ql openssl

安装时间:rpm -qi openssl | grep "Build Date"

查询文件由哪个包提供:rpm -qf /usr/lib/libssl.so.6

8、实现开机启动挂载光盘

答:

yun install autofs -y

systemctl enable --now autofs

cd /misc/cd

9、查看系统是否安装reids软件

答:

rpm -q reids

原文地址:https://www.cnblogs.com/jojohyj/p/13138703.html