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