chapter02 - 03

chapter02 - 03 作业

1、分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处?

cat命令可同时显示多个文件的内容

tac倒着显示文件内容

nl命令文件加行号,对空白行不加行号

2、分别用more和less查看/etc/ssh/sshd_config里面的内容,请用总结more和less两个命令的相同和不同之处?

more命令是全屏方式分页显示文件内容

 

扫描二维码关注公众号,回复: 6874411 查看本文章

less命令功能多可以按/查找内容,按pguf、pgdn键上下翻页

3、将/etc/passwd文件中的前20行重定向保存到/root下改名为20_pass.txt,将/etc/passwd文件中的后15行重定向保存到/root下改名为:pass_15.txt

[root@localhost /]# head -20 /etc/passwd > /root/20_pass.txt

[root@localhost /]# ls /root

20_pass.txt  anaconda-ks.cfg

 

[root@localhost /]# tail -15 /etc/passwd > /root/pass_15.txt

 

4、请用一个命令统计/etc/hosts文件包含有多少行?多少字节?多少单词数?

[root@localhost /]# wc /etc/hosts

  2  10 158 /etc/hosts

 

包含两行,158字节,十个单词数

5、练习使用grep和egrep

5.1.通过grep管道工具过滤出ifconfig命令显示信息中的IP字段?

[root@localhost ~]# ifconfig | grep "inet"

        inet 192.168.100.199  netmask 255.255.255.0  broadcast 192.168.100.255

        inet6 fe80::36ec:28ae:8711:ba74  prefixlen 64  scopeid 0x20<link>

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

5.2.将/etc/passwd文件中的前20行重定向保存到/root下名称为pass?

[root@localhost ~]# head -20 /etc/passwd > /root/pass

[root@localhost ~]# ls

20_pass.txt  anaconda-ks.cfg  pass  pass_15.txt

 

5.3.过滤/etc/passwd文件中含有/sbin/nologin 的行并统计行数?

[root@localhost ~]# grep "/sbin/nologin" /etc/passwd  |wc -l

5.4 过滤/etc/passwd文件中以sh结尾的行,及以 root开头的行,不显示包含login的行?

[root@localhost ~]# grep "sh$" /etc/passwd | grep "^root" | grep -v "login"

 

5.5 分别用grep和egrep过滤出/etc/ssh/sshd_config文件中不包含“#”开头和空白的行?

[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config |grep -v "^$"

 

[root@localhost ~]# egrep -v "^#|^$" /etc/ssh/sshd_config

 

6.1 通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz

[root@localhost /]# tar -zcf /root/file.tar.gz /etc/passwd

 

6.2通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.bz2

[root@localhost /]# tar -jcf /root/file.tar.bz2 /etc/passwd    

 

6.3创建空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?

[root@localhost /]# mkdir -p /web/test1 | tar -xvjf /root/file.tar.bz2 -C /web/test1

 

7.1 通过vi编辑/web/test1/passwd文件将文件里为root单词全部替换成benet。

输入命令:vi /web/test1/passwd 进入文档编辑,在末行模式输入

:% s/root/benet/g

 

7.2 通过vi编辑 删除pass文件第1、5、10行。

在末行模式输入“1”定位到第一行,按两下dd删除第一行、

在末行模式输入“5”定位到第五行,按两下dd删除第五行、

在末行模式输入“10”定位到第五行,按两下dd删除第十行、

7.3 在vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。

在末行模式输入“2”快速定位到第二行,,按3yy进行复制2 3 4 行,找到lp所在行按p粘贴

 

7.4 通过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。

在末行模式输入/mail 按Enter查找mail在第十四行

在末行模式输入/var 按Enter查找var在第十七行

7.5 通过vi编辑 快速跳转到文件的第二行,通过r 读取 /etc/hosts 文件的内容到第二行下。

在末行模式输入2回车跳转到第二行,然后在末行模式输入

:r /etc/hosts

 

7.6将更改后的文件使用vim另存为/root/new_pass。

在末行模式输入:w /root/new_pass 按Enter

 

7.7将new_pass文件压缩成gz格式并改名为npass.gz文件。

[root@localhost /]# gzip /root/new_pass | mv /root/new_pass.gz /root/npass.gz

 

8统计/dev 目录下的文件数量。

[root@localhost /]# ls -l /dev | wc -l

 

9.1在/boot下查找文件名以vmlinuz开头的文件?

[root@localhost /]# find /boot/ -name  "vmlinuz*"

 

9.2在/boot下查找文件大小大于3M 小于 20M 的文件

[root@localhost /]# find /boot -size +3M -a -size -20M

 

10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用自己的话做上中文注释?

[root@localhost ~]# umount /dev/sr0   //卸载光盘

umount: /dev/sr0:未挂载

[root@localhost ~]# mount /dev/sr0 /media/   //挂载光盘

mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost ~]# ls /media/     //查看media

CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7

EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

[root@localhost ~]# cd /etc/yum.r*      //构建本地yum仓库

[root@localhost yum.repos.d]# mkdir a

[root@localhost yum.repos.d]# mv C* a

[root@localhost yum.repos.d]# vi ./local.repo   //创建本地yum仓库文档

[cdrom]    //仓库名称

name=cdrom

baseurl=file:///media   //指定rpm包的位置

enabled=1                      //启用本地yum仓库

gpgcheck=0                    //禁用gpg校验

[root@localhost yum.repos.d]# yum -y clean all           //清除yum缓存

已加载插件:fastestmirror

正在清理软件源: cdrom

Cleaning up everything

Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

Cleaning up list of fastest mirrors

[root@localhost yum.repos.d]# yum makecache          //重建yum缓存

已加载插件:fastestmirror

Determining fastest mirrors

cdrom                         | 3.6 kB     00:00    

(1/4): cdrom/group_gz           | 166 kB   00:00    

(2/4): cdrom/filelists_db       | 3.1 MB   00:00    

(3/4): cdrom/primary_db         | 3.1 MB   00:00    

(4/4): cdrom/other_db           | 1.3 MB   00:00    

元数据缓存已建立

11、用yum命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost yum.repos.d]# yum -y install vsftpd           //安装vsftpd

 

[root@localhost yum.repos.d]# rpm -q vsftpd               //查询安装

 

[root@localhost yum.repos.d]# rpm -e vsftpd      //卸载vsftpd

 

12、用rpm命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost Packages]# rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm

 

[root@localhost Packages]# rpm -q vsftpd            //查询安装

 

[root@localhost yum.repos.d]# rpm -e vsftpd      //卸载vsftpd

 

猜你喜欢

转载自www.cnblogs.com/wanghs8/p/11250159.html