7.26上机作业

chapter02 - 03 作业

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

[root@localhost ~]# cat /etc/ssh/sshd_config

#$OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

 

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

...

#PermitTTY no

#ForceCommand cvs server

[root@localhost ~]# tac /etc/ssh/sshd_config

#ForceCommand cvs server

#PermitTTY no

#AllowTcpForwarding no

#X11Forwarding no

#Match User anoncvs

# Example of overriding settings on a per-user basis

...

#$OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

[root@localhost ~]# nl /etc/ssh/sshd_config

     1#$OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

       

     2# This is the sshd server system-wide configuration file.  See

     3# sshd_config(5) for more information.

...

 114#PermitTTY no

   115#ForceCommand cvs server

答:cat使文件中的内容正着显示,tac使文件中的内容倒着显示,nl给显示的内容加行号,空行不加行号。

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

[root@localhost ~]# more /etc/ssh/sshd_config

#$OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

 

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

...

#ListenAddress ::

--More--(17%)

[root@localhost ~]# less /etc/ssh/sshd_config

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

 

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

...

/etc/ssh/sshd_config

答:相同点:moreless都是分页显示

不同点:moreless在快捷键上不同,less的扩展功能更多,例如:less中可以按“/”键查找内容,“n”下一个,“N”上一个。

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

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

[root@localhost ~]# wc -l 20_pass.txt

20 20_pass.txt

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

[root@localhost ~]# wc -l pass_15.txt

15 pass_15.txt

 

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

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

  2  10 158 /etc/hosts

5、练习使用grepegrep

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

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

 

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

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

 

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

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

36

 

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

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

root:x:0:0:root:/root:/bin/bash

5.5 分别用grepegrep过滤出/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 czvf file.tar.gz /etc/passwd

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

[root@localhost ~]# tar cjvf file.tar.bz2 /etc/passwd

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

[root@localhost ~]# tar -xf file.tar.bz2 -C /web/test1/

 

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

[root@localhost ~]# vi /web/test1/etc/passwd

% s/root/benet/g

 

7.2 通过vi编辑 删除pass文件第1510行。

[root@localhost ~]# vi pass

1dd

5dd

10dd

:wq

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

 [root@localhost ~]# vi pass

2yy

P

3yy

P

4yy

p

:wq

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

:set nu

/mail

?var

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

2G    :r /etc/hosts

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

:w /root/new_pass

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

[root@localhost ~]# gzip new_pass > npass.gz

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

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

158

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

[root@localhost ~]# cd /boot

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

./vmlinuz-3.10.0-693.el7.x86_64

./vmlinuz-0-rescue-e6955c9ba7dd4a36a57fab3f6acb1bd6

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

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

 

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

[root@localhost ~]# umount /media/              //卸载/medie/下挂载光盘

umount: /media/:未挂载

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

[root@localhost ~]# mount /dev/sr0/ /media/       //将一张光盘挂载到media目录下

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

[root@localhost ~]# ls /media/                   //再次查询media

CentOS_BuildTag  images    repodata

EFI              isolinux  RPM-GPG-KEY-CentOS-7

EULA             LiveOS    RPM-GPG-KEY-CentOS-Testing-7

GPL              Packages  TRANS.TBL

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

[root@localhost yum.repos.d]# mkdir a/           //建立文件夹a

[root@localhost yum.repos.d]# ls                 //查询

a                      CentOS-fasttrack.repo

CentOS-Base.repo       CentOS-Media.repo

CentOS-CR.repo         CentOS-Sources.repo

CentOS-Debuginfo.repo  CentOS-Vault.repo

[root@localhost yum.repos.d]# mv C* a/           //移动以C开头的文件到文件夹a

[root@localhost yum.repos.d]# ls                 //查询

a

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

[cdrom]                                      

name=cdrom                                 //仓库名称

baseurl = file:///media                          //制定rpm包位置

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

gpgcheck=0                                   //禁用gpg校验

                                            

"./local.repo" [New] 5L, 64C written

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

已加载插件:fastestmirror, langpacks

正在清理软件源: 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, langpacks

cdrom                             | 3.6 kB     00:00     

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

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

(3/4): cdrom/other_db               | 1.2 MB   00:00     

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

Determining fastest mirrors

元数据缓存已建立

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

[root@localhost ~]# rpm -q vsftpd

未安装软件包 vsftpd

[root@localhost ~]# yum -y install vsftpd

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

正在解决依赖关系

--> 正在检查事务

---> 软件包 vsftpd.x86_64.0.3.0.2-22.el7 将被 安装

 

 

--> 解决依赖关系完成

 

依赖关系解决

 

=========================================================

 Package    架构       版本              源         大小

=========================================================

正在安装:

 vsftpd     x86_64     3.0.2-22.el7      cdrom     169 k

 

事务概要

=========================================================

安装  1 软件包

 

总下载量:169 k

安装大小:348 k

Downloading packages:

Running transaction check

Running transaction test

rpmTransaction test succeeded

Running transaction

  正在安装    : vsftpd-3.0.2-22.el7.x86_64           1/1

  验证中      : vsftpd-3.0.2-22.el7.x86_64           1/1

 

已安装:

  vsftpd.x86_64 0:3.0.2-22.el7                           

 

完毕!

[root@localhost ~]# rpm -q vsftpd

vsftpd-3.0.2-22.el7.x86_64

[root@localhost ~]# yum -y remove vsftpd

已加载插件:fastestmirror, langpacks

正在解决依赖关系

--> 正在检查事务

---> 软件包 vsftpd.x86_64.0.3.0.2-22.el7 将被 删除

--> 解决依赖关系完成

 

依赖关系解决

 

=========================================================

 Package    架构       版本             源          大小

=========================================================

正在删除:

 vsftpd     x86_64     3.0.2-22.el7     @cdrom     348 k

 

事务概要

=========================================================

移除  1 软件包

 

安装大小:348 k

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在删除    : vsftpd-3.0.2-22.el7.x86_64           1/1

  验证中      : vsftpd-3.0.2-22.el7.x86_64           1/1

 

删除:

  vsftpd.x86_64 0:3.0.2-22.el7                           

 

完毕!

[root@localhost ~]# rpm -q vsftpd

未安装软件包 vsftpd

[root@localhost ~]#

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

[root@localhost ~]# rpm -q vsfted

未安装软件包 vsfted

[root@localhost ~]# ls /media/Packages/

 

[root@localhost ~]# cd /media/Packages/

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

./vsftpd-3.0.2-22.el7.x86_64.rpm

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

警告:vsftpd-3.0.2-22.el7.x86_64.rpm: V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

准备中...                          ################################# [100%]

正在升级/安装...

   1:vsftpd-3.0.2-22.el7              ################################# [100%]

[root@localhost Packages]# cd

[root@localhost ~]# rpm -e vsftpd

[root@localhost ~]# rpm -q vsftpd

未安装软件包 vsftpd

[root@localhost ~]#

13、通过源码方式通过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试?

[root@localhost ~]# tar xf httpd-2.2.17.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/httpd-2.2.17/
[root@localhost httpd-2.2.17]# ./configure --prefix=/usr/local/apache
[root@localhost httpd-2.2.17]# vi /usr/local/apache/conf/httpd.conf
第97行开头#号删除 serverName www.example.com:80, wq退出保存
[root@localhost httpd-2.2.17]# /usr/local/apache/bin/apachectl start
[root@localhost httpd-2.2.17]# yum -y install lynx

[root@localhost httpd-2.2.17]# lynx 127.0.0.1

原文地址:https://www.cnblogs.com/sun0917/p/11252978.html