chapter02 - 03 做業linux
一、分別用cat \tac\nl三個命令查看文件/etc/ssh/sshd_config文件中的內容,並用本身的話總計出這三個文檔操做命令的不一樣之處?web
[root@localhost ~]# cat /etc/ssh/sshd_config apache
#$OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $vim
# This is the sshd server system-wide configuration file. See緩存
# sshd_config(5) for more information.bash
...架構
#PermitTTY noless
#ForceCommand cvs serverssh
[root@localhost ~]# tac /etc/ssh/sshd_config ide
#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給顯示的內容加行號,空行不加行號。
二、分別用more和less查看/etc/ssh/sshd_config裏面的內容,請用總結more和less兩個命令的相同和不一樣之處?
[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
答:相同點:more和less都是分頁顯示
不一樣點:more和less在快捷鍵上不一樣,less的擴展功能更多,例如:less中能夠按「/」鍵查找內容,「n」下一個,「N」上一個。
三、將/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、練習使用grep和egrep
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 分別用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 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文件第1、5、10行。
[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
?var
7.5 經過vi編輯 快速跳轉到文件的第二行,經過r 讀取 /etc/hosts 文件的內容到第二行下。
2G :r /etc/hosts
7.6將更改後的文件使用vim另存爲/root/new_pass。
:w /root/new_pass
7.7將new_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
元數據緩存已創建
十一、用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 ~]#
十二、用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