chapter02 - 03 做业c++
一、分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用本身的话总计出这三个文档操做命令的不一样之处?web
[root@localhost ~]# cat /etc/ssh/sshd_config 读取文件内容,按照顺序打出apache
[root@localhost ~]# tac /etc/ssh/sshd_config 读取文件内容,按照逆序打出vim
[root@localhost ~]# nl /etc/ssh/shd_config 读取文件内容时给没行加上序列号缓存
2、分别用more和less查看/etc/ssh/sshd_config里面的内容,请用总结more和less两个命令的相同和不一样之处?bash
[root@localhost ~]# more /etc/ssh/sshd_configless
[root@localhost ~]#dom
[root@localhost ~]# less /etc/ssh/sshd_configssh
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
-rw-r--r--. 1 root root 0 7月 26 14:18 root20_pass.txt
[root@localhost /]# tail -15 /etc/passwd > /root/pass_15.txt
[root@localhost /]# find /root -name 'pass_15.txt'
/root/pass_15.txt
4、请用一个命令统计/etc/hosts文件包含有多少行?多少字节?多少单词数?
[root@localhost ~]# wc -l /etc/hosts
2 /etc/hosts
[root@localhost ~]# wc -w /etc/hosts
10 /etc/hosts
[root@localhost ~]# wc -c /etc/hosts
158 /etc/hosts
[root@localhost ~]#
5、练习使用grep和egrep
5.1.经过grep管道工具过滤出ifconfig命令显示信息中的IP字段?
[root@localhost /]# ifconfig | grep 'inet' | grep -o 't.* n' | grep -o " .* "
192.168.100.114
127.0.0.1
192.168.122.1
[root@localhost /]#
5.2.将/etc/passwd文件中的前20行重定向保存到/root下名称为pass?
root@localhost /]# head -20 /etc/passwd > /root/pass
-rw-r--r--. 1 root root 0 7月 26 14:18 root20_pass.txt
5.3.过滤/etc/passwd文件中含有/sbin/nologin 的行并统计行数?
[root@localhost /]# grep 'sbin' /etc/passwd | grep 'nologin' | wc -l
39
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/bas
5.5 分别用grep和egrep过滤出/etc/ssh/sshd_config文件中不包含“#”开头和空白的行?
[root@localhost /]# grep -v '^#|^$' etc/ssh/sshd_config
[root@localhost /]# egrep -v '^#|^$' /etc/ssh/sshd_config |grep -v '^$'
6.1 经过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz
[root@localhost /]#
[root@localhost /]# cd /etc
[root@localhost etc]# tar -czf/root/file.tar.gz passwd
[root@localhost etc]# ll
6.2经过tar命令将/etc/passwd文件打包压缩成/root/file.tar.bz2
[root@localhost ~]# cd /etc
[root@localhost etc]# tar -czf/root/file.tar.bz2 passwd
[root@localhost etc]# ll
6.3建立空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?
[root@localhost web]# mkdir -pv /wed/twst1
mkdir: 已建立目录 "/wed"
mkdir: 已建立目录 "/wed/twst1"
[root@localhost web]# tar -xf /root/file.tar.bz2 -C /web/test1
[root@localhost web]# ls
test1
[root@localhost web]# ls test1
passwd
7.1 经过vi编辑/web/test1/passwd文件将文件里为root单词所有替换成benet。
[root@localhost test1]# vi /web/test1/passwd
:% s/root/benet/g
7.2 经过vi编辑 删除pass文件第1、5、10行。
[root@localhost ~]# vi pass
:set nu
:1d
:5d
:10d
7.3 在vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。
:2,4 so 5
7.4 经过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。
[root@localhost ~]# vi pass
:set nu
:/mail 11行号
[root@localhost ~]# vi pass
:set nu
:/var
7.5 经过vi编辑 快速跳转到文件的第二行,经过r 读取 /etc/hosts 文件的内容到第二行下。
[root@localhost ~]# vi pass
#2G
:r /etc/hosts
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
7.6将更改后的文件使用vim另存为/root/new_pass。
[root@localhost ~]# vi pass
:w / root/new_pass。
7.7将new_pass文件压缩成gz格式并更名为npass.gz文件。
[root@localhost ~]# tar -czf npass.gz new_pass
8统计/dev 目录下的文件数量。
[root@localhost ~]# ls /dev -l | wc -l
9.1在/boot下查找文件名以vmlinuz开头的文件?
[root@localhost boot]# find /boot -name "vmlinuz*"
9.2在/boot下查找文件大小大于3M 小于 20M 的文件
[root@localhost boot]# find /boot -size +1M -a -size -20M
10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用本身的话作上中文注释?
cd /etc/yum.r* 进入etc下yum文件夹
mkdir a/ 在yum文件夹中建立名字为a的文件夹
mv C* a/ 在yum文件夹中将开头带C的文件所有移动到文件夹a中
vi ./local.repo 建立本地yum仓库文档
[cdrom] 仓库名称
name=cdrom 仓库名称=cdrom
baseurl=file:///media //指定rpm包的位置
enabled=1 //启用本地yum仓库
gpgcheck=0 //禁用gpg校验
yum -y clean all 清除yum缓存
yum makecache 重建yum缓存
11、用yum命令安装vsftpd,查询安装状况,最后卸载vsftpd,并再次查询卸载状况?
[root@localhost yum.repos.d]# yum -y install vsftpd.x86_64 安装
[root@localhost yum.repos.d]# rpm -q vsftpd 查询
[root@localhost yum.repos.d]# yum -y remove vsftpd.x86_64 卸载
12、用rpm命令安装vsftpd,查询安装状况,最后卸载vsftpd,并再次查询卸载状况?
[root@localhost yum.repos.d]# rpm -ivh /media/Packages/vsftpd-3.0.2-25.el7.x86_64.rpm
[root@localhost yum.repos.d]# rpm -q vsftpd 查询
[root@localhost yum.repos.d]# rpm -e vsftpd 卸载
[root@localhost yum.repos.d]# rpm -q vsftpd 查询
13、经过源码方式经过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试?[root@localhost ~]# yum -y install gcc-c++ gcc
[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 conf]# cp httpd.conf httpd.conf.bak
[root@localhost conf]# vi httpd.conf
[root@localhost conf]# /usr/local/apache/bin/apachectl start
[root@localhost ~]# yum -y install lynx -y
[root@localhost conf]# lynx 127.0.0.1