linux下rpm、yum、sed基础用法介绍

一、RPM包管理介绍

RPM是radhat系列和suse系列等的包管理系统,主要管理系统上软件包的安装、卸载和查询

rpm安装语法:rpm [install options] [programname…]

常用安装option:-i,表示安装程序包

          -v,表示输出详细安装过程
          -h,安装过程输出进度条
          -U,升级程序包
          -c,查看程序包的配置文件路劲
          --force,忽略程序包的冲突关系
          --nodeps,忽略程序包的依赖关系强制安装
          -e,卸载程序包

常用安装升级组合:

1、安装程序包

    rpm -ivh [程序包路劲]  用来安装程序包并显示安装信息进度

2、升级程序包

    rpm -Uvh [程序包路劲]  用来升级程序包并显示安装信息进度

3、rpm -e [程序包名称] 用来卸载程序包

rpm查询语法: rpm [query ostions] [程序包名|程序文件]
常用查询option:-q,表示查询信息,执行查询必带的参数
              -a,查询所有已安装的程序包
              -f,查询程序包产生的文件
              -l,查询指包名的程序文件
              -d,查询程序包的安装文档
              -i,查询程序包的相关信息
              -R,查询程序包的依赖关系

常用组合示例:

1、查询指定程序包的相关信息

        [root@suyiwen01 ~]# rpm -qi httpd
        Name        : httpd
        Version     : 2.4.6
        Release     : 67.el7.centos.6
        Architecture: x86_64
        Install Date: Wed 28 Mar 2018 11:37:25 AM CST
        Group       : System Environment/Daemons
        Size        : 9827789
        License     : ASL 2.0
        Signature   : RSA/SHA256, Fri 20 Oct 2017 08:31:20 PM CST, Key ID 24c6a8a7f4a80eb5
        Source RPM  : httpd-2.4.6-67.el7.centos.6.src.rpm
        Build Date  : Fri 20 Oct 2017 04:41:19 AM CST
        Build Host  : c1bm.rdu2.centos.org
        Relocations : (not relocatable)
        Packager    : CentOS BuildSystem <http://bugs.centos.org>
        Vendor      : CentOS
        URL         : http://httpd.apache.org/
        Summary     : Apache HTTP Server
        Description :
        The Apache HTTP Server is a powerful, efficient, and extensible
        web server.

2、查询程序包产生的文件

        [root@suyiwen01 ~]# rpm -ql httpd
        /etc/httpd
        /etc/httpd/conf
        /etc/httpd/conf.d
        /etc/httpd/conf.d/README
        ......

3、查询程序包的依赖关系

        [root@suyiwen01 ~]# rpm -qR mariadb
        /bin/sh
        /usr/bin/perl
        /usr/sbin/update-alternatives
        /usr/sbin/update-alternatives
        bash
        config(mariadb) = 1:5.5.56-2.el7
        fileutils
        .....

4、查询指定文件由哪个程序产生

        [root@suyiwen01 ~]# rpm -qf /etc/hostname 
        systemd-219-42.el7.x86_64
        [root@suyiwen01 ~]# 

二、CentOS系统yum详解

yum是基于rpm的包管理系统,可以自动为程序包解决依赖关系,简化对软件包的安装、升级、查询和卸载

语法格式 yum [options] [program name] [subcommand] [程序包]

常用option:

    -y,对所有回答为yes
    -q,静默模式

常用子命令

    install,安装程序包
    remove,卸载chengxubao
    update,升级程序包
    list,查看程序包列表
    seach,搜索程序包
    info,查看软件包信息
    check-update,查看可以升级的程序包
    clean,清除yum repo缓存
    groupinstall,安装程序包组
    grouplist,查看程序包组列表
    localinstall,安装本地程序包
    deplist,显示软件包的依赖关系

常用示例:

1、安装指定软件包

        [root@suyiwen01 ~]# yum install ntp -y
        Loaded plugins: fastestmirror
        Loading mirror speeds from cached hostfile
         * base: mirrors.aliyun.com
         * epel: mirrors.aliyun.com
         * extras: mirrors.aliyun.com
         * updates: mirrors.aliyun.com
        Resolving Dependencies
        --> Running transaction check
        ---> Package ntp.x86_64 0:4.2.6p5-25.el7.centos.2 will be installed
        --> Processing Dependency: ntpdate = 4.2.6p5-25.el7.centos.2 for package: ntp-4.2.6p5-25.el7.centos.2.x86_64
        --> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-25.el7.centos.2.x86_64
        .....

2、查看指定软件包的信息

        [root@suyiwen01 ~]# yum info ntp
        Loaded plugins: fastestmirror
        Loading mirror speeds from cached hostfile
         * base: mirrors.aliyun.com
         * epel: mirrors.aliyun.com
         * extras: mirrors.aliyun.com
         * updates: mirrors.aliyun.com
        Available Packages
        Name        : ntp
        Arch        : x86_64
        Version     : 4.2.6p5
        Release     : 25.el7.centos.2
        Size        : 547 k
        Repo        : base/7/x86_64
        Summary     : The NTP daemon and utilities
        URL         : http://www.ntp.org
        License     : (MIT and BSD and BSD with advertising) and GPLv2
        Description : The Network Time Protocol (NTP) is used to synchronize a computer's
                    : time with another reference time source. This package includes ntpd
                    : (a daemon which continuously adjusts system time) and utilities used
                    : to query and configure the ntpd daemon.
                    : 
                    : Perl scripts ntp-wait and ntptrace are in the ntp-perl package,
                    : ntpdate is in the ntpdate package and sntp is in the sntp package.
                    : The documentation is in the ntp-doc package.

3、安装指定包组

        [root@suyiwen01 ~]# yum groupinstall "Development Tools"
        Loaded plugins: fastestmirror
        There is no installed groups file.
        Maybe run: yum groups mark convert (see man yum)
        Loading mirror speeds from cached hostfile
         * base: mirrors.aliyun.com
         * epel: mirrors.aliyun.com
        .....            

4、卸载指定程序包

        [root@suyiwen01 ~]# yum remove ntp -y
        Loaded plugins: fastestmirror
        Resolving Dependencies
        --> Running transaction check
        ---> Package ntp.x86_64 0:4.2.6p5-25.el7.centos.2 will be erased
        --> Finished Dependency Resolution

        Dependencies Resolved
        ......

5、升级指定程序包

        [root@suyiwen01 ~]# yum update systemd
        Loaded plugins: fastestmirror
        Loading mirror speeds from cached hostfile
         * base: mirrors.aliyun.com
         * epel: mirrors.aliyun.com
         * extras: mirrors.aliyun.com
         * updates: mirrors.aliyun.com
         ......

yum源配置

配置yum配置文件
    [base]                                        //yum源仓库名
    name=                                        //yum源名字信息
    baseurl=                                    //yum源路径
    enable=                                        //是否启用源
    gpgcheck=                                    //是否启用key检查
    gpgkey=                                        //key路径

三、文本处理三剑客之sed常基础用法

sed是一个流式的文本处理工具

语法:sed [OPTION]… {script-only-if-no-other-script} [input-file]…

常用option:

-n,静默模式,不输出内容至屏幕,经过sed特殊处理的那一行才会显示出来
-e script,根据script进行编辑
-r,使用扩展正则表达式匹配
-f,后跟script命令文件进行编辑
-i,直接编辑原文件

常用script命令:

a,新增一行内容
c,替换匹配到的字符串为指定字符串
d,删除匹配到的字符串
s,查找替换
i,在当前行前前插入一行内容

示例1:显示/etc/fstab的第5到第10行

[root@suyiwen01 ~]# sed -n "5,10p" /etc/fstab
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=add4bda5-b5b9-44c4-91ad-d0f55e313ae8 /boot                   xfs     defaults        0 0

示例2:删除/boot/grub/grub2.cfg文件中所有以空白字符开头的行的行首的所有空白字符

[root@localhost ~]# sed -e "s@^#[[:space:]]*@@" /etc/fstab


/etc/fstab
Created by anaconda on Mon Mar 26 17:26:06 2018

Accessible filesystems, by reference, are maintained under '/dev/disk'
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=83a1568a-0c24-4e08-bf70-f15cc8489bde /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

示例3:将/etc/inittab中的#号,替换为//

[root@localhost ~]# sed "s@#@//@" /etc/inittab 
// inittab is no longer used when using systemd.
//
// ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
//
// Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
//
// systemd uses 'targets' instead of runlevels. By default, there are two main targets:
//
// multi-user.target: analogous to runlevel 3
// graphical.target: analogous to runlevel 5
//
// To view current default target, run:
......

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/94591

(0)
落叶落叶
上一篇 2018-04-01 21:46
下一篇 2018-04-01 22:28

相关推荐

  • Tomcat介绍及相关实验(一)

    Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。

    2018-07-24
  • 第一周作业

    本周作业 1、描述计算机的组成及其功能。 2、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。 3、描述Linux的哲学思想,并按照自己的理解对其进行解释性描述。 4、说明Linux系统上命令的使用格式;详细介绍ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、rebo…

    Linux笔记 2018-05-12
  • 第四周

      sed的高级用法 安装包路径/misc/cd/Packages/ rpm 可以安装 卸载 软件包 rpm -i 跟软件包名称 (安装) -e 卸载软件包 (只有配置文件会自己备份 备份文件以.rpmsave结尾的文件)-v显示详细进度 -h显示百分条 –test 测试安装,但不是真的装–nodeps 忽略依赖性 (但安装…

    Linux笔记 2018-04-22
  • linux

    输入、输出重定向  >若文件不存在,则创建,并将正确的输出填充,若文件已存在,则覆盖原内容 >> 若文件不存在,则创建,并将正确的输出内容填充,若文件已存在,则追加内容 2> 若文件不存在,则创建,并将错误的输出填充,若文件已存在,则覆盖原内容2>> 若文件不存在,则创建,并将错误的输出内容填充,若文件已存在,则追加内容 …

    Linux笔记 2018-05-26
  • shell脚本编程基础——循环用法

    本节索引: 一、if、case条件判断 二、for、while及until循环 三、循环控制语句continue、break、shift及select菜单 四、信号捕捉trap   在前面的基础编程内容中,我们已经学习了shell脚本的顺序执行及选择执行,通过这两种方式,可 以帮我们解决一些简单需求,但要想在更复杂的场景中使用的话,就需要掌握循环执…

    2018-05-10

评论列表(1条)

  • 马哥教育
    马哥教育 2018-04-10 22:01

    笔记写的不错。