一、分別用cat \tac\nl三個命令查看文件/etc/ssh/sshd_config文件中的內容,並用本身的話總計出這三個文檔操做命令的不一樣之處?linux
Cat:web
[root@localhost ~]# cat /etc/ssh/sshd_configvim
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $緩存
# This is the sshd server system-wide configuration file. See架構
tac:less
[root@localhost ~]# tac /etc/ssh/sshd_configssh
# ForceCommand cvs serveride
# PermitTTY no工具
# AllowTcpForwarding noui
# X11Forwarding no
nl:
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
總結:cat是目錄正着看;tac是目錄反着看;nl是自帶序列號
2、分別用more和less查看/etc/ssh/sshd_config裏面的內容,請用總結more和less兩個命令的相同和不一樣之處?
more:
[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
AuthorizedKeysFile .ssh/authorized_keys
--More--(32%)
less:
[root@localhost ~]# less /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
#ListenAddress 0.0.0.0
:
總結:相同的是more和less都須要翻頁,一次性出不來完,
不一樣的是more不能查找而less能夠查找還有翻頁的鍵位不同
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 ~]# tail -15 /etc/passwd > pass_15.txt
4、請用一個命令統計/etc/hosts文件包含有多少行?多少字節?多少單詞數?
[root@localhost ~]# wc /etc/hosts
2 10 158 /etc/hosts
五、練習使用grep和egrep
5.1.經過grep管道工具過濾出ifconfig命令顯示信息中的IP字段?
[root@localhost ~]# ifconfig |grep "inet"
inet 192.168.18.131 netmask 255.255.255.0 broadcast 192.168.18.255
inet6 fe80::b2d:c34d:301e:d541 prefixlen 64 scopeid 0x20<link>
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
5.2.將/etc/passwd文件中的前20行重定向保存到/root下名稱爲pass?
[root@localhost ~]# head -20 /etc/passwd >pass
5.3.過濾/etc/passwd文件中含有/sbin/nologin 的行並統計行數?
[root@localhost ~]# grep -c "/sbin/nologin" /etc/passwd
5.4 過濾/etc/passwd文件中以sh結尾的行,及以 root開頭的行,不顯示包含login的行?
[root@localhost ~]# egrep -v "sh$|^root|login" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
[root@localhost ~]#
5.5 分別用grep和egrep過濾出/etc/ssh/sshd_config文件中不包含「#」開頭和空白的行?
egrep:
[root@localhost ~]# egrep -v "^$|#" /etc/ssh/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
grep:
[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config |grep -v "^$"
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
6.1 經過tar命令將/etc/passwd文件打包壓縮成/root/file.tar.gz
[root@localhost ~]# tar cjvf file.tar.gz /etc/passwd -C /root
6.2經過tar命令將/etc/passwd文件打包壓縮成/root/file.tar.bz2
[root@localhost ~]# tar cjvf file.tar.bz2 /etc/passwd -C /root
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 /wed/test/etc/passwd
:% s/root/benet/g
7.2 經過vi編輯 刪除pass文件第1、5、10行。
[root@localhost ~]# vi pass
1 G dd
5 G dd
10 G dd
7.3 在vi中顯示pass文件行號複製文件2 3 4行粘貼到以lp開頭的行下。
[root@localhost ~]# vi pass
Set nu
2G yy
/lp p
3G yy
/lp p
4G yy
/lp p
7.4 通過vi編輯 查找文件內包含mail var等字符串,並記錄所在行號。
[root@localhost ~]# vi pass
Set nu
:/mail var
7.5 經過vi編輯 快速跳轉到文件的第二行,經過r 讀取 /etc/hosts 文件的內容到第二行下。
2 G : 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 | grep "^d" | wc -l
17
9.1在/boot下查找文件名以vmlinuz開頭的文件?
[root@localhost ~]# find /boot -name "vmlinuz*"
/boot/vmlinuz-3.10.0-693.el7.x86_64
/boot/vmlinuz-0-rescue-a88cce67b72b4ea5850db7b28e5936b2
9.2在/boot下查找文件大小大於3M 小於 20M 的文件
[root@localhost ~]# find /boot -size +3M -a -size -20M
/boot/System.map-3.10.0-693.el7.x86_64
/boot/vmlinuz-3.10.0-693.el7.x86_64
/boot/initrd-plymouth.img
/boot/vmlinuz-0-rescue-a88cce67b72b4ea5850db7b28e5936b2
/boot/initramfs-3.10.0-693.el7.x86_64kdump.img
10 請詳細寫出構建本地yum倉庫的步驟?並在每行命令後面用本身的話作上中文註釋?
[root@localhost ~]# umount /dev/sr0 卸載光盤
[root@localhost ~]# mount /dev/sr0 /media/ 掛載光盤
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@localhost ~]# ls /media 查看
CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
EFI images Packages RPM-GPG-KEY-CentOS-Testing-7
EULA isolinux repodata TRANS.TBL
[root@localhost ~]# cd /etc/yum.r* 構建本地yum倉庫文檔
[root@localhost yum.repos.d]# mkdir a/
mkdir: 沒法建立目錄"a/": 文件已存在
[root@localhost yum.repos.d]# mkdir s/
[root@localhost yum.repos.d]# mv C* s/
mv: 沒法獲取"C*" 的文件狀態(stat): 沒有那個文件或目錄
[root@localhost yum.repos.d]# mv a* s/
[root@localhost yum.repos.d]# vi ./jie.repo 建立本地yum倉庫文檔
[cdrom] 倉庫名稱
name=cdrom
baseurl=file:///media //指定rpm包的位置
enabled=1 啓用本地yum倉庫
gpgcheck=0 禁用gpg校驗
"./jie.repo" [New] 6L, 63C 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:00
(1/4): cdrom/group_gz | 156 kB 00:00:00
(2/4): cdrom/primary_db | 5.7 MB 00:00:00
(3/4): cdrom/filelists_db | 6.7 MB 00:00:00
(4/4): cdrom/other_db | 2.5 MB 00:00:00
Determining fastest mirrors
元數據緩存已創建
十一、用yum命令安裝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
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 ~]# yum -q remove vsftpd
=====================================================================================
Package 架構 版本 源 大小
=====================================================================================
正在刪除:
vsftpd x86_64 3.0.2-22.el7 @cdrom 348 k
事務概要
=====================================================================================
移除 1 軟件包
是否繼續?[y/N]:y
查詢:
[root@localhost ~]# rpm -q vsftpd
未安裝軟件包 vsftpd
12、用rpm命令安裝vsftpd,查詢安裝狀況,最後卸載vsftpd,並再次查詢卸載狀況?
安裝:
root@localhost ~]# cd /media/Packages/
[root@localhost Packages]# find -name vsftpd
[root@localhost Packages]# find -name vsftpd*
vsftpd-sysvinit-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]# rpm -q vsftpd
vsftpd-3.0.2-22.el7.x86_64
卸載:
[root@localhost Packages]# rpm -e vsftpd
查詢:
[root@localhost Packages]# rpm -q vsftpd
未安裝軟件包 vsftpd