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?;A用法

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.www58058.com/94591

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

相關推薦

  • 一些練習(4)

    一些練習(4) 1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 復制/etc/skel目錄為/home/tuser1 改權限 2、編輯/etc/group文件,添加組hadoop。 vim直接添加hadoop組 3、手動編輯/etc/passwd文件新增一行,添加用戶ha…

    2018-07-16
  • LINUX基礎–組及用戶

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 2、編輯/etc/group文件,添加組hadoop。 3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。 4、復制/etc/sk…

    2018-03-27
  • rpm包管理

    相關知識 接口 API:二進制接口 ABI:應用層接口, 包的組成: 二進制文件;庫文件;配置文件;幫助文檔 程序包管理器 debian: deb,dpt apt-agt包管理前段工具 rehat:rpm;rpm yum包管理前段工具 fedora dnf包管理前段工具 安裝過的rpm包數據庫 /var/lib/rpm/* 管理查看二進制程序依賴的庫文件 l…

    Linux筆記 2018-04-22
  • 進程和計劃任務

    進程間的狀態轉化、以及與進程相關的配置命令和文件;作業管理和任務計劃

    2018-05-04
  • Nginx認證模塊與狀態監測模塊使用示例

    Nginx認證模塊與狀態監測模塊使用示例 一、環境準備 1. 軟件版本 CentOS7.4 httpd-tools.x86_64??????? 2.4.6-67.el7.centos.6 nginx.x86_64????????????????? 1:1.12.2-2.el7 2. 軟件安裝 nginx的安裝需要epel源,沒有配置epel可以直接yum安裝…

    2018-06-29

評論列表(1條)

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

    筆記寫的不錯。

欧美性久久久久