chapter02 - 03 做業

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

[root@localhost ~]# cat -n /etc/ssh/sshd_configweb

     1 # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $apache

     2vim

     3 # This is the sshd server system-wide configuration file.  See緩存

     4 # sshd_config(5) for more information.bash

     5less

     6 # This sshd was compiled with PATH=/usr/local/bin:/usr/binssh

     7ide

8 # The strategy used for options in the default sshd_config shipped with工具

cat:將該文件下的內容以正向的形式顯示出來,文件中的空白行也會標記行號。

[root@localhost ~]# tac  /etc/ssh/sshd_config

# ForceCommand cvs server

# PermitTTY no

# AllowTcpForwarding no

# X11Forwarding no

#Match User anoncvs

# Example of overriding settings on a per-user basis

 

Subsystem sftp /usr/libexec/openssh/sftp-server

# override default of no subsystems

 

AcceptEnv XMODIFIERS

tac:將該文件下的內容反向顯示出來,與cat相反

[root@localhost ~]# nl /etc/ssh/sshd_config

     1 # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

       

     2 # This is the sshd server system-wide configuration file.  See

     3 # sshd_config(5) for more information.

       

     4 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin

       

5 # The strategy used for options in the default sshd_config shipped with

nl:正向顯示文件內容,但空白行不標行號

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

[root@localhost ~]# more /etc/ssh/sshd_config

[root@localhost ~]# less /etc/ssh/sshd_config

相同之處:moreless都是全屏方式分頁顯示內容,命令的用法同樣,均可以上下翻動,退出都是按q

不一樣之處:

MoreEnter鍵向上翻動一行,Shift+PgUp/PgDn鍵上下翻動一行,空格鍵向下翻動一頁。

LessPgUp/PgDn上下翻行;/鍵查找內容,n尋找查找出的下一個,N尋找查找出的上一個

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

[root@localhost ~]# cat /root/20_pass.txt | wc -l

20

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

[root@localhost ~]# cat /root/pass_15.txt | wc -l

15

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

5、練習使用grepegrep

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

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

        inet 192.168.100.104  netmask 255.255.255.0  broadcast 192.168.100.255

        inet6 fe80::20c:29ff:fe97:eb45  prefixlen 64  scopeid 0x20<link>

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

5.2./etc/passwd文件中的前20行重定向保存到/root下名稱爲pass

[root@localhost ~]# head -20 /etc/passwd > /root/pass

[root@localhost ~]# cat /root/pass | wc -l

20

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

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

5

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

[root@localhost ~]# grep "sh$" /etc/passwd | grep "^root" | 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 "^$"

 

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

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

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

/etc/passwd

[root@localhost ~]# ls

20_pass.txt      is the sshd server system-wide configuration file. See  公共  圖片  音樂

anaconda-ks.cfg  pass                                                    模板  文檔  桌面

file.tar.gz      pass_15.txt  

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

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

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

/etc/passwd

[root@localhost ~]# ls

20_pass.txt      file.tar.gz                                             pass_15.txt  視頻  下載

anaconda-ks.cfg  is the sshd server system-wide configuration file. See  公共         圖片  音樂

file.tar.bz2     pass     

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

[root@localhost ~]# mkdir -p /web/test1

[root@localhost ~]# ls /web/

test1

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

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

etc

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

:% s/root/benet/g

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

:set nu   //顯示行號

1     定位到第一行按dd刪除

5     定位到第一行按dd刪除

10    定位到第一行按dd刪除

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

:set nu   //顯示行號

將光標移動到第二行按 3yy 就把包括光標所在行的三行復制到剪貼板

/lp  //查找包含Ip開頭的行

將光標移動到第五行按 p 粘貼到該行下

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

:set nu   //顯示行號

/mail 查找mail字符串所在的行:9

/var  查找var字符串所在的行:18

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

2  //將光標移動到第二行

r /etc/hosts  //讀取/etc/hosts的文件到第二行下

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

:w /root/new_pass

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

[root@localhost ~]# gzip /root/new_pass

gzip: /root/new_pass: No such file or directory

[root@localhost ~]# ls

20_pass.txt      is the sshd server system-wide configuration file. See  v     圖片  桌面

anaconda-ks.cfg  new_pass.gz                                             公共  文檔

file.tar.bz2     pass                                                    模板  下載

file.tar.gz      pass_15.txt     

[root@localhost ~]# mv new_pass.gz npass.gz

[root@localhost ~]# ls

20_pass.txt      is the sshd server system-wide configuration file. See  pass_15.txt  圖片  桌面

anaconda-ks.cfg  mv                                                      公共         文檔

file.tar.bz2     npass.gz                                                模板         下載

file.tar.gz      pass         

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

[root@localhost ~]# ls -al /dev | grep -v "^d" | wc -l

142

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

[root@localhost ~]# ls -a /boot | grep "^vmlinuz"

vmlinuz-0-rescue-838f26c3e2384f26aae18f06e79bf4bb

vmlinuz-3.10.0-229.el7.x86_64

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

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

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

/boot/vmlinuz-0-rescue-838f26c3e2384f26aae18f06e79bf4bb

/boot/initramfs-3.10.0-229.el7.x86_64.img

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

umount  /etc/sr0  //卸載光盤

mount  /etc/sr0 /media/   //掛載光盤

ls  /media/   //查看

 

cd  /etc/yum.r*    //構建本地yum倉庫

mkdir  a/    //建立文件夾

mv  C*  a/

vi  ./local.repo   //建立本地yum倉庫文檔

[cdrom]    //倉庫名稱

name=cdrom

bareurl=file:///media    //指定rap包安裝

enabled=1     //啓用本地yum倉庫

gpgcheck=0   //禁用pgp校驗

 

yum  -y  clean  all   //清除yum緩存

yum  makecache    //重建yum緩存

rpm  -q  vsftpd    //查詢是否安裝vsftpd

yum  -y  install  vsftpd    //yum安裝vsftpd

rpm  -q  vsftpd      //查詢是否安裝vsftpd

yum  -y  remove  vsftpd   //yum卸載vsftpd

rpm  -q  vsftpd

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-9.el7 將被 安裝

--> 解決依賴關係完成

[root@localhost yum.repos.d]# rpm -q vsftpd

vsftpd-3.0.2-9.el7.x86_64

[root@localhost yum.repos.d]# yum -y remove vsftpd

已加載插件:fastestmirror, langpacks

正在解決依賴關係

--> 正在檢查事務

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

--> 解決依賴關係完成

[root@localhost yum.repos.d]# rpm -q vsftpd

未安裝軟件包 vsftpd

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

[root@localhost Packages]# rpm -vih vsftpd-3.0.2-9.el7.x86_64.rpm 

警告:vsftpd-3.0.2-9.el7.x86_64.rpm: V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY

準備中...                          ################################# [100%]

正在升級/安裝...

   1:vsftpd-3.0.2-9.el7               ################################# [100%]

[root@localhost Packages]# rpm -q vsftpd

vsftpd-3.0.2-9.el7.x86_64

[root@localhost Packages]# rpm -e vsftpd

[root@localhost Packages]# rpm -q vsftpd

未安裝軟件包 vsftpd

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

1、將軟件包導入(直接拖過去)

2、查看gccgcc-c++make是否安裝

gcc  --version

yum  -y  install  gcc

gcc-c++  --version

yum  -y  install  gcc-c++

make  --version

yum  -y  install  make

三、將源碼解壓到/usr/src/目錄下

tar  -xf  httpd-2.2.17.tar.gz  -C  /usr/src/

cd  /usr/src/

ls

cd  httpd-2.2.17  

./configure --prefix=/usr/local/apache/

5、編譯(源碼包目錄下)

make

六、安裝(源碼包目錄下)

make  install

7、修改配置文件

[root@localhost httpd-2.2.17]# cd /usr/local/apache/conf

[root@localhost conf]# ls

extra  httpd.conf  magic  mime.types  original

ServerName打開

[root@localhost conf]# vi httpd.conf 

/ServerName

n

Yy

p     

8、啓動

[root@localhost conf]# /usr/local/apache/bin/apachectl start

9、安裝lynx

[root@localhost conf]# lynx 127.0.0.1

bash: lynx: 未找到命令...

[root@localhost conf]# yum -y install lynx

已加載插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

正在解決依賴關係

--> 正在檢查事務

---> 軟件包 lynx.x86_64.0.2.8.8-0.3.dev15.el7 將被 安裝

--> 解決依賴關係完成

[root@localhost conf]# lynx 127.0.0.1

相關文章
相關標籤/搜索