Linux系統管理----目錄與文件管理作業習題


chapter02 - 03 作業

 

1、  分別用cat \tac\nl三個命令查看文件/etc/ssh/sshd_config文件中的內容,並用自己的話總計出這三個文檔操作命令的不同之處?

cat 命令可同時顯示多個文件的內容

tac 倒序顯示

nl 顯示行號,不現實空白行

[root@localhost chen]# cat /etc/ssh/sshd_config

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

……

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

#       ForceCommand cvs server

……

root@localhost chen]# 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

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

more命令是全屏方式分頁顯示文件內容

less命令功能多可以按/查找內容,按pguf、pgdn鍵上下翻頁,與more功能基本類似

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

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# Authentication:

--More--(24%)

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

[root@localhost chen]#

3、將/etc/passwd文件中的前20行重定向保存到/root下改名為20_pass.txt,將/etc/passwd文件中的后15行重定向保存到/root下改名為:pass_15.txt

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

[root@localhost chen]# ls /root/

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

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

[root@localhost chen]# ls /root/

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

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

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

  2  10 158 /etc/hosts

5、練習使用grep和egrep

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

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

        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 chen]# head -20 /etc/passwd > /root/pass

[root@localhost chen]# ls /root/

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

[root@localhost chen]#

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

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

38

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

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

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

chen:x:1000:1000:chen:/home/chen:/bin/bash

5.5 分別用grep和egrep過濾出/etc/ssh/sshd_config文件中不包含“#”開頭和空白的行?

[root@localhost chen]# grep -Ev "^#|^$" /etc/passwd

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

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

……

[root@localhost chen]# egrep -v "^#|^$" /etc/passwd

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

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

……

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

[root@localhost chen]# tar -czf /etc/passwd  /root/file.tar.gz

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

[root@localhost chen]# ls /root/

20_pass.txt  anaconda-ks.cfg  file.tar.gz  initial-setup-ks.cfg  pass  pass_15.txt

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

[root@localhost chen]# tar -cjf /etc/passwd  /root/file.tar.bz2

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

[root@localhost chen]# ls /root/

anaconda-ks.cfg  file.tar.bz2  initial-setup-ks.cfg

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

[root@localhost chen]# ls /root/

anaconda-ks.cfg  file.tar.bz2  initial-setup-ks.cfg

[root@localhost chen]# mkdir /web/test1 -pv

mkdir: 已創建目錄 "/web"

mkdir: 已創建目錄 "/web/test1"

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

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

passwd

7.1 通過vi編輯/web/test1/passwd文件將文件里為root單詞全部替換成benet。

% s/root/benet/g

benet:x:0:0:benet:/benet:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

 

7.2 通過vi編輯 刪除pass文件第1、5、10行。

1 daemon:x:2:2:daemon:/sbin:/sbin/nologin

2 adm:x:3:4:adm:/var/adm:/sbin/nologin

:1 d

1 adm:x:3:4:adm:/var/adm:/sbin/nologin

 2 lp:x4:7:lp:/var/spool/lpd:/sbin/nologin

:5 d

:10 d

 

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

/set nu(顯示行號)

:2    (光標移到第二行)

3yy (復制二三四行三行內容)

p   (粘貼)

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

/mail 8

/var 4.8.11.。。。。

 

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

#2

r /etc/hosts

2 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

3 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdoma        in4

4 ::1         localhost localhost.localdomain localhost6 localhost6.localdoma        in6

 5 sync:x:5:0:sync:/sbin:/bin/sync

7.6將更改后的文件使用vim另存為/root/new_pass。

:w /root/new_pass

[root@localhost chen]# ls /root/

anaconda-ks.cfg  initial-setup-ks.cfg  new_pass

7.7將new_pass文件壓縮成gz格式並改名為npass.gz文件。

[root@localhost chen]# gzip /root/new_pass /root/npass.gz

[root@localhost chen]# ls /root/

anaconda-ks.cfg  initial-setup-ks.cfg  new_pass.gz

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

[root@localhost chen]# find /dev* | wc

    355     355    5557

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

[root@localhost chen]# find /boot/vmlinuz*

/boot/vmlinuz-0-rescue-c437baa086514f01850a9178b54b456f

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

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

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

/boot/System.map-3.10.0-862.el7.x86_64

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

/boot/vmlinuz-0-rescue-c437baa086514f01850a9178b54b456

10 請詳細寫出構建本地yum倉庫的步驟?並在每行命令后面用自己的話做上中文注釋?

umount /dev/sr0                        //卸載光盤

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

ls /media/                            //查看

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

mkdir a/                        //創建本地yum倉庫文檔

mv C* a/

vi ./local.repo

[cdrom]                      //倉庫名稱

name=cdrom

baseurl=file:///media         //指定rpm包的位置

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

gpgcheck=0               //禁用gpg校驗

 

----------------

清除yum緩存

yum -y clean all

重建yum緩存

yum makecache

[root@localhost yum.repos.d]# yum -y clean all

已加載插件:fastestmirror, langpacks

正在清理軟件源: cal

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

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

已加載插件:fastestmirror, langpacks

Determining fastest mirrors

cal                                                         | 3.6 kB  00:00:00

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

(2/4): cal/primary_db                                       | 3.1 MB  00:00:00

(3/4): cal/filelists_db                                     | 3.1 MB  00:00:00

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

元數據緩存已建立

[root@localhost yum.repos.d]#

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             cal            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]# rpm -q vsftpd

vsftpd-3.0.2-22.el7.x86_64

[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            @cal            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

 

完畢!

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-3.0.2-22.el7.x86_64

[root@localhost Packages]# rpm -q vsftpd

未安裝軟件包 vsftp

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]#

配置

[root@localhost httpd-2.2.17]# ./config --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]# lynx 127.0.0.1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM