chapter02 - 03

一、  分別用cat \tac\nl三個命令查看文件/etc/ssh/sshd_config文件中的內容,並用本身的話總計出這三個文檔操做命令的不一樣之處?web

[root@localhost /]# cat /etc/ssh/sshd_configvim

[root@localhost /]# tac /etc/ssh/sshd_config緩存

[root@localhost /]# nl /etc/ssh/sshd_configbash

cat命令是查詢文件內容session

tac 命令是倒敘查詢文件內容架構

nl不顯示文件空行內容less

二、  分別用moreless查看/etc/ssh/sshd_config裏面的內容,請用總結moreless兩個命令的相同和不一樣之處?ssh

 

[root@localhost /]# more /etc/ssh/sshd_config工具

[root@localhost /]# less /etc/ssh/sshd_config測試

moreless 相同之處是都是全屏翻頁查看文件內容,空格鍵翻一頁,q退出

moreless不一樣之處是lessmore擴展功能多 moreenter向下翻一行,而lesspguppgdn上下翻頁並且less還有/查找功能,‘n’下一個‘N’上一個

 

三、  /etc/passwd文件中的前20行重定向保存到/root下更名爲20_pass.txt,/etc/passwd文件中的後15行重定向保存到/root下更名爲:pass_15.txt

 

[root@localhost /]# head -20 /etc/hosts > /root/20_pass.txt

[root@localhost /]# cd

[root@localhost ~]# ls

20_pass.txt  anaconda-ks.cfg  initial-setup-ks.cfg

[root@localhost ~]# tail -15 /etc/hosts > /root/pass_15.txt

[root@localhost ~]# ls

20_pass.txt  anaconda-ks.cfg  initial-setup-ks.cfg  pass_15.txt

 

四、  請用一個命令統計/etc/hosts文件包含有多少行?多少字節?多少單詞數?

 

[root@localhost ~]# wc /etc/hosts

  2  10 158 /etc/hosts

 

5、練習使用grepegrep

5.1.經過grep管道工具過濾出ifconfig命令顯示信息中的IP字段?

[root@localhost ~]# ifconfig | grep "inet*"

        inet 192.168.100.156  netmask 255.255.255.0  broadcast 192.168.100.255

        inet6 fe80::2587:2767:783c:e820  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 > /root/pass

[root@localhost ~]# ls

20_pass.txt      initial-setup-ks.cfg  pass_15.txt

anaconda-ks.cfg  pass

 

5.3.過濾/etc/passwd文件中含有/sbin/nologin 的行並統計行數?

[root@localhost ~]# grep "/sbin/nologin"  /etc/passwd | wc -l

 

5.4 過濾/etc/passwd文件中以sh結尾的行,及以 root開頭的行,不顯示包含login的行?

[root@localhost ~]# egrep "^root" /etc/passwd | grep "sh$" | grep -v "login"

root:x:0:0:root:/root:/bin/bash

 

5.5 分別用grepegrep過濾出/etc/ssh/sshd_config文件中不包含「#」開頭和空白的行?

 

[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config | grep -v "^$"

[root@localhost ~]# egrep -v "^#" /etc/ssh/sshd_config | egrep -v "^$"

 

6.1 經過tar命令將/etc/passwd文件打包壓縮成/root/file.tar.gz  

 

[root@localhost ~]# tar zcfv /root/file.tar.gz /etc/passwd

tar: 從成員名中刪除開頭的「/

/etc/passwd

[root@localhost ~]# ls

20_pass.txt      file.tar.gz           pass

anaconda-ks.cfg  initial-setup-ks.cfg  pass_15.txt

 

6.2經過tar命令將/etc/passwd文件打包壓縮成/root/file.tar.bz2

 

[root@localhost ~]# tar jcfv /root/file.tar.bz2 /etc/passwd

tar: 從成員名中刪除開頭的「/

/etc/passwd

[root@localhost ~]# ls

20_pass.txt      file.tar.bz2  initial-setup-ks.cfg  pass_15.txt

anaconda-ks.cfg  file.tar.gz   pass

 

6.3建立空文件夾/web/test1,並將file.tar.bz2 解包並釋放到/web/test1目錄下?

 

[root@localhost ~]# tar jxfv /root/file.tar.bz2 -C /web/test1/

etc/passwd

[root@localhost ~]# ls /web/test1/

etc

 

7.1 經過vi編輯/web/test1/passwd文件將文件裏爲root單詞所有替換成benet

 

 


 

7.2 經過vi編輯 刪除pass文件第1510行。

dd

 

7.3 vi中顯示pass文件行號複製文件2 3 4行粘貼到以lp開頭的行下。

 

將光標移動到第二行在命令模式下輸入3yy複製從光標起一下三行代碼

在命令模式下輸入/lp 將光標定位到lp行後 而後再命令模式下輸入p

 

7.4 經過vi編輯 查找文件內包含mail var等字符串,並記錄所在行號。

 /mail 5

/var  7

7.5 經過vi編輯 快速跳轉到文件的第二行,經過r 讀取 /etc/hosts 文件的內容到第二行下。

 

 


7.6將更改後的文件使用vim另存爲/root/new_pass

:w /root/new_pass

 


7.7new_pass文件壓縮成gz格式並更名爲npass.gz文件。

 

 


8統計/dev 目錄下的文件數量。

 

[root@localhost ~]# find /dev* | wc -l

355

9.1/boot下查找文件名以vmlinuz開頭的文件?

 

[root@localhost ~]# find /boot/ -name "vmlinuz*"

/boot/vmlinuz-3.10.0-862.el7.x86_64

/boot/vmlinuz-0-rescue-d33425ee638340c1961b31007b0c3a12

 

9.2/boot下查找文件大小大於3M 小於 20M 的文件

 

[root@localhost ~]# find /boot/ -size +3M | find -size -20M

.

./.bash_logout

./.bash_profile

./.bashrc

./.cshrc

./.tcshrc

./anaconda-ks.cfg

./.cache

./.cache/dconf

./.cache/dconf/user

./.cache/abrt

./.cache/abrt/lastnotification

./.dbus

./.dbus/session-bus

./.dbus/session-bus/d33425ee638340c1961b31007b0c3a12-9

./initial-setup-ks.cfg

./.config

./.config/abrt

./.bash_history

./.xauthgqjOrg

./.xauthR6pIRq

./.viminfo

./20_pass.txt

./pass_15.txt

./.Xauthority

./pass

./file.tar.gz

./file.tar.bz2

./napass.gz

 

10 請詳細寫出構建本地yum倉庫的步驟?並在每行命令後面用本身的話作上中文註釋?

[root@localhost /]# cd /etc/yum.r*  //構建本地YUM倉庫文檔

[root@localhost yum.repos.d]# mkdir a/ 

[root@localhost yum.repos.d]# ls

a CentOS-Debuginfo.repo  CentOS-Sources.repo

CentOS-Base.repo  CentOS-fasttrack.repo  CentOS-Vault.repo

CentOS-CR.repo    CentOS-Media.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倉庫

[root@localhost yum.repos.d]# yum -y clean all  //清除yum緩存

已加載插件:fastestmirror, langpacks

正在清理軟件源: cdeom

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

Determining fastest mirrors

cdeom                                      | 3.6 kB     00:00    

(1/4): cdeom/group_gz                        | 166 kB   00:00    

(2/4): cdeom/filelists_db                    | 3.1 MB   00:00    

(3/4): cdeom/primary_db                      | 3.1 MB   00:00    

(4/4): cdeom/other_db                        | 1.3 MB   00:00    

元數據緩存已創建

11、用yum命令安裝vsftpd,查詢安裝狀況,最後卸載vsftpd,並再次查詢卸載狀況?

[root@localhost yum.repos.d]# 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         cdeom       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.repos.d]# yum -y remove vsftpd  

已加載插件:fastestmirror, langpacks

正在解決依賴關係

--> 正在檢查事務

---> 軟件包 vsftpd.x86_64.0.3.0.2-22.el7 將被 刪除

--> 解決依賴關係完成

 

依賴關係解決

 

==================================================================

 Package      架構         版本                            大小

==================================================================

正在刪除:

 vsftpd       x86_64       3.0.2-22.el7        @cdeom       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 yum.repos.d]# rpm -q vsftpd

未安裝軟件包 vsftpd

12、用rpm命令安裝vsftpd,查詢安裝狀況,最後卸載vsftpd,並再次查詢卸載狀況?

 

[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

 

13、經過源碼方式經過解包、配置、編譯、安裝四個步驟安裝源碼軟件httpd-2.2.17.tar.gz?並進行測試?

 

相關文章
相關標籤/搜索