• Linux系统管理----目录与文件管理作业习题


    chapter02 - 03 作业

    1、  分别用cat ac l三个命令查看文件/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

  • 相关阅读:
    升级python
    python内置函数整理
    import 搜索路径
    webpy 解决中文出现UnicodeDecodeError: 'ascii' codec can't decode byte 问题
    未预期的符号 `$'{ '' 附近有语法错误
    python引入模块时import与from ... import的区别
    "Native table 'performance_schema'.'session_variables' has the wrong structure") [SQL: "SHOW VARIABLES LIKE 'sql_mode'"]
    git命令
    Redis简介
    MongoDB基本操作
  • 原文地址:https://www.cnblogs.com/chenxi123/p/11251549.html
Copyright © 2020-2023  润新知