chapter02 - 03 作业
1、分别用cat ac l三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处?
[root@localhost ~]# cat /etc/ssh/sshd_config
[root@localhost ~]# tac /etc/ssh/sshd_config
[root@localhost ~]# nl /etc/ssh/sshd_config
Tac是倒序显示、cat-n显示行号以及空白行 nl空白行跳过,空白行里不加行号
2、分别用more和less查看/etc/ssh/sshd_config里面的内容,请用总结more和less两个命令的相同和不同之处?
[root@localhost ~]# more /etc/ssh/sshd_config
[root@localhost ~]# less /etc/ssh/sshd_config
1、操作
more不可以回去,就是不可以向前,只能向后,况且只能使用Enter和Space向后翻动。
less使用vim中的j,k键盘可以上下翻动,还可以使用上下箭头。
2、速度
less不必读整个文件,加载速度会比more更快。
3、内容
less退出后shell不会留下刚显示的内容,而more退出后会在shell上留下刚显示的内容。
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 ~]# tail -15 /etc/passwd > /root/pass_15.txt
4、请用一个命令统计/etc/hosts文件包含有多少行?多少字节?多少单词数?
[root@localhost ~]# wc /etc/hosts
2 10 158 /etc/hosts
两行 10字节 158单词数
5、练习使用grep和egrep
5.1.通过grep管道工具过滤出ifconfig命令显示信息中的IP字段?
[root@localhost ~]# grep "^inet"| ifconfig
5.2.将/etc/passwd文件中的前20行重定向保存到/root下名称为pass?
[root@localhost ~]# head -20 /etc/passwd > /root/pass
5.3.过滤/etc/passwd文件中含有/sbin/nologin 的行并统计行数?
[root@localhost ~]# wc -l grep /sbin/nologin /etc/passwd
0 grep
8 /sbin/nologin
39 /etc/passwd
47 总用量
5.4 过滤/etc/passwd文件中以sh结尾的行,及以 root开头的行,不显示包含login的行?
[root@localhost ~]# egrep "^root|sh&" /etc/passwd egrep -v "^login" /etc/passwd
5.5 分别用grep和egrep过滤出/etc/ssh/sshd_config文件中不包含“#”开头和空白的行?
[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config | grep -v "^$"
6.1 通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz
[root@localhost ~]# tar zcf /root/file.tar.gz /etc/passwd
tar: 从成员名中删除开头的“/”
6.2通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.bz2
[root@localhost ~]#
[root@localhost ~]# tar jcf /root/file.tar..bz2 /etc/passwd/
tar: 从成员名中删除开头的“/”
6.3创建空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?
Xf解压并释放
[root@localhost ~]# tar xf file.tar.bz2 -C /web/test1
7.1 通过vi编辑/web/test1/passwd文件将文件里为root单词全部替换成benet。
[root@localhost ~]#
[root@localhost ~]# vi /web/test1/etc/passwd
:% s/root/benet/g
7.2 通过vi编辑 删除pass文件第1、5、10行。
[root@localhost ~]#
[root@localhost ~]# vi /web/test1/etc/passwd
1dd 5dd 10dd
:del "1,5,10'
7.3 在vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。
[root@localhost ~]# vi pass
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin yyy
p
7.4 通过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。
[root@localhost ~]# vi /web/test1/etc/passwd
/mail /var
:set num
7.5 通过vi编辑 快速跳转到文件的第二行,通过r 读取 /etc/hosts 文件的内容到第二行下。
[root@localhost ~]# vi /web/test1/etc/passwd
光标放在第二行然后:r /etc/hosts
meile
7.6将更改后的文件使用vim另存为/root/new_pass。
[root@localhost ~]# vi /web/test1/etc/passwd
:w /root/new_pass
"~/new_pass" [New] 37L, 1967C written
7.7将new_pass文件压缩成gz格式并改名为npass.gz文件。
[root@localhost ~]# gzip new_pass >npass.gz
[root@localhost ~]# ls -a
8统计/dev 目录下的文件数量。
[root@localhost ~]# ls -l /dev
总用量 0
[root@localhost ~]# ls -l /dev |wc -l
155
9.1在/boot下查找文件名以vmlinuz开头的文件?
[root@localhost ~]# find /boot -name "vmlinuz*"
/boot/vmlinuz-3.10.0-229.el7.x86_64
/boot/vmlinuz-0-rescue-9a65ea9ec3044d628dc501909195e94f
9.2在/boot下查找文件大小大于3M 小于 20M 的文件
[root@localhost ~]# find /boot -size +3M -a -size -20M
/boot/vmlinuz-3.10.0-229.el7.x86_64
/boot/vmlinuz-0-rescue-9a65ea9ec3044d628dc501909195e94f
/boot/initramfs-3.10.0-229.el7.x86_64.img
10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用自己的话做上中文注释?
[root@localhost dev]# cd
[root@localhost ~]#
[root@localhost ~]# umount /dev/sr0 //卸载光盘
umount: /dev/sr0:未挂载
[root@localhost ~]# mou
mount mount.nfs4
mount.cifs mountpoint
mount.fuse mountstats
mount.glusterfs mousetweaks
mount.nfs
[root@localhost ~]# mount /dev/sr0 /media/ //挂载光盘
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /media/ //查看media目录下的文件
CentOS_BuildTag
EFI
EULA
GPL
images
isolinux
LiveOS
Packages
repodata
RPM-GPG-KEY-CentOS-7
RPM-GPG-KEY-CentOS-Testing-7
TRANS.TBL
[root@localhost ~]# cd /etc/yum.e*
-bash: cd: /etc/yum.e*: 没有那个文件或目录
[root@localhost ~]# cd /etc/yum.r* //创建本地yum仓库文件
[root@localhost yum.repos.d]# mkdir a/ //创建一个a目录
[root@localhost yum.repos.d]# mv C* a/ //以C开头的目录移到a目录下
[root@localhost yum.repos.d]# vi ./local.repo //创建本地yum仓库文档
[root@localhost yum.repos.d]# vi ./local.repo
[root@localhost yum.repos.d]# yum -y clean all //清除yum缓存
已加载插件:fastestmirror, langpacks
正在清理软件源: cdrom
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
cdrom | 3.6 kB 00:00
(1/4): cdrom/group_gz | 155 kB 00:00
(2/4): cdrom/primary_db | 3.0 MB 00:00
(3/4): cdrom/filelists_db | 3.0 MB 00:00
(4/4): cdrom/other_db | 1.3 MB 00:00
Determining fastest mirrors
11、用yum命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?
元数据缓存已建立
[root@localhost yum.repos.d]# rpm -qvsftpd
rpm: -qvsftpd: 未知的选项
[root@localhost yum.repos.d]# rpm -q vsftpd
未安装软件包 vsftpd
12、用rpm命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?
[root@localhost yum.repos.d]# yum -y remove vsftpd
已加载插件:fastestmirror, langpacks
参数 vsftpd 没有匹配
不删除任何软件包
[root@localhost yum.repos.d]# rpm -q vsftpd
未安装软件包 vsftpd
[root@localhost yum.repos.d]#
13、通过源码方式通过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试?
[root@localhost ~]# yum -y install gcc-c++ gcc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 gcc-c++-4.8.5-11.el7.x86_64 已安装并且是最新版本
软件包 gcc-4.8.5-11.el7.x86_64 已安装并且是最新版本
无须任何处理
[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]# make
[root@localhost httpd-2.2.17]# make install
[root@localhost httpd-2.2.17]# cd/usr/local/apache/conf/
[root@localhost httpd-2.2.17]# make
[root@localhost conf]# cp httpd.conf httpd.conf.bak
[root@localhost conf]# vi httpd.conf
[root@localhost conf]# /usr/local/apache/bin/apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName.
[root@localhost ~]# yum -y install lynx -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 lynx.x86_64.0.2.8.8-0.3.dev15.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================
Package 架构 版本 源 大小
================================================================
正在安装:
lynx x86_64 2.8.8-0.3.dev15.el7 cdrom 1.4 M
事务概要
================================================================
安装 1 软件包
总下载量:1.4 M
安装大小:5.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : lynx-2.8.8-0.3.dev15.el7.x86_64 1/1
验证中 : lynx-2.8.8-0.3.dev15.el7.x86_64 1/1
已安装:
lynx.x86_64 0:2.8.8-0.3.dev15.el7
完毕!
[root@localhost ~]# lynx 127.0.0.1