zoukankan      html  css  js  c++  java
  • Linux2

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

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

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

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

    cat命令是正序查看文件内容

    tac命令是倒序查看文件内容

    nl命令是对查看的内容添加行号,空白行直接跳过,不显示行号

    2、分别用moreless查看/etc/ssh/sshd_config里面的内容,请用总结moreless两个命令的相同和不同之处?

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

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

    相同之处more命令与less命令都可以用来查看文件内容

    不同之处less命令可以按条件查找 输入/(后面跟查找内容)可以搜索查找,按Nn 上下查找

    2、/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 ~]# ls

    20_pass.txt      initial-setup-ks.cfg  模板  图片  下载  桌面

    anaconda-ks.cfg  公共                  视频  文档  音乐

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

    [root@localhost ~]# ls

    20_pass.txt      initial-setup-ks.cfg  公共  视频  文档  音乐

    anaconda-ks.cfg  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.116.128  netmask 255.255.255.0  broadcast 192.168.116.255

            inet6 fe80::da33:9fda:beb9:743e  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.255If

    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 "sh$|^root" /etc/passwd | grep -v "login"

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

    elin:x:1000:1000:elin:/home/elin:/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

    6.1 通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz

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

    tar: 从成员名中删除开头的“/

    [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 jcf /root/file.tar.bz2 /etc/passwd

    tar: 从成员名中删除开头的“/

    [root@localhost ~]# ls

    20_pass.txt      file.tar.gz           pass_15.txt  视频  下载

    anaconda-ks.cfg  initial-setup-ks.cfg  公共         图片  音乐

    file.tar.bz2     pass                  模板         文档  桌面

    6.3创建空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?

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

    mkdir: 已创建目录 "/web"

    mkdir: 已创建目录 "/web/test1"

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

    7.1 通过vi编辑/web/test1/passwd文件将文件里为root单词全部替换成benet

    [root@localhost ~]# vi /web/test1/etc/passwd

    :% s/root/benet/g

    7.2 通过vi编辑 删除pass文件第1510行。

    10dd

    5dd

    1dd

    7.3 vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。

    将光标放置第2行执行以下操作

    3yy

    p

    7.4 通过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。

    /mail    12

    /var   12 15 21 22 23 26 27 28 29 33 36 38 40 41 42

     7 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    7.5 通过vi编辑 快速跳转到文件的第二行,通过r 读取 /etc/hosts 文件的内容到第二行下。

    在末行模式中输入以下内容

    :2

    :r /etc/hosts

    7.6将更改后的文件使用vim另存为/root/new_pass

    :w /root/new_pass

    7.7new_pass文件压缩成gz格式并改名为npass.gz文件。

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

    8统计/dev 目录下的文件数量。

    [root@localhost dev]# ls -l | wc -l

    9.1/boot下查找文件名以vmlinuz开头的文件?

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

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

    /boot/vmlinuz-0-rescue-d6b1971c9cfe4d5cac8ca7357e569311

    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/vmlinuz-0-rescue-d6b1971c9cfe4d5cac8ca7357e569311

    /boot/initrd-plymouth.img

    /boot/initramfs-3.10.0-693.el7.x86_64kdump.img

    10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用自己的话做上中文注释?

    umount /dev/sr0     //将光盘卸载

    mount /dev/sr0 /media/   //挂载光盘到media目录下面

    ls /media/      //查看media目录下的文件是否有dev镜像文件

    cd /etc/yum.r*  //进入yum.repos.d文件里面(构建仓库文档)

    mkdir a/        //创建一个名字为a的文件夹

    mv C* a/       //yum.repos.d文件中以C开头的文件移动到a文件夹中

    vi ./local.repo   //创建llocal.repo 文件并对其进行配置添加

    点击i进入编辑模式在里面添加如下信息

    [cdrom]       //仓库文档名称

    name=cdrom   //名字为cdrom

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

    enabled=1         //启用本地yum仓库 1为启动,0为停止

    gpgchack=0        //禁用gpg 校验验证

    输入:wq保存并退出

    yum -y clean all //清除yum内部缓存

    yum makecache //重建yum缓存

    11、yum命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

    yum -y install vsftpd  //安装vsftpd

    rpm -q vaftpd    //查看是否安装

    yom -y remove vsftpd   //卸载vsftpd

    rpm -q vsftpd  //查看是否卸载

    12、用rpm命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

    首先先查找vsftpd 是在哪个文件下面的,也即安装源在哪里,在使用此命令时候后面的压缩文件包必须是全称才能成功安装。

    cd /media/Packages/  

    ls  

    [root@localhost Packages]# rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm

    rpm -q vsftpd  //检查是否安装

    rpm -e vsftpd //卸载软件

    12、通过源码方式通过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试?

    [root@localhost ~]# yum -y install gcc-c++ gcc

    [root@localhost ~]# tar xf httpd-2.2.17.tar.gz -C /usr/src

    [root@localhost ~]# cd /usr/src/httpd-2.2.17/

    [root@localhost ~]# ./configure --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]# cd /usr/local/apache/conf/

    [root@localhost conf]# cp httpd.conf httpd.conf.bak

    root@localhost conf]# vi httpd.conf

    ServerName www.example.com:80

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

    [root@localhost conf]# cd

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

    已加载插件:fastestmirror, langpacks

    Loading mirror speeds from cached hostfile

    ...................................

    已安装:

      lynx.x86_64 0:2.8.8-0.3.dev15.el7                                                                                                                                        

     

    完毕!

    [root@localhost ~]# lynx 127.0.0.1

     

  • 相关阅读:
    解决:The content of element type "web-app" must match "(icon?display
    [转]实体类与数据库字段不匹配问题,java.sql.SQLSyntaxErrorException: Unknown column 'xxx' in 'field list'
    IDEA中导入其它由Maven管理的java web项目并运行,提示“Error:(3, 38) java: 程序包org.springframework.stereotype不存在”问题的解决
    动态规划题目汇总
    数组题目汇总
    c++11 push_back与emplace_back之间的区别
    字符串题目汇总
    链表题目汇总
    C++ stringstream与getline()
    二叉树题目汇总
  • 原文地址:https://www.cnblogs.com/elin989898/p/11252879.html
Copyright © 2011-2022 走看看