zoukankan      html  css  js  c++  java
  • Linux 系统管理 第二章第三章

    1、分别用cat ac l三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处?

    Cat:

    [root@localhost ~]# cat /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

    tac:

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

    # ForceCommand cvs server

    # PermitTTY no

    # AllowTcpForwarding no

    # 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、分别用moreless查看/etc/ssh/sshd_config里面的内容,请用总结moreless两个命令的相同和不同之处?

    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

    :

    总结:相同的是moreless都需要翻页,一次性出不来完,

    不同的是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

    5、练习使用grepegrep

    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 分别用grepegrep过滤出/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文件第1510行。

    [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.7new_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

    元数据缓存已建立

    11、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

  • 相关阅读:
    C语言 · 选择排序
    C语言 · 生物芯片
    C语言 · 猜灯谜
    C语言 · x的x次幂结果为10
    C语言 · LOG大侠
    C语言 · 成绩查询系统
    C语言 · C++中map的用法详解
    C语言 · 方程的解
    斯坦福大学公开课:监督学习应用,梯度下降
    斯坦福大学公开课:机器学习的动机与应用
  • 原文地址:https://www.cnblogs.com/shao123-/p/11252990.html
Copyright © 2011-2022 走看看