zoukankan      html  css  js  c++  java
  • Linux RPM、TAR包管理

    一.RPM软件包命令的使用

     RPM主要有5种基本操作模式:安装、卸载、刷新、升级及查询。下面分别介绍。

    1.安装软件包

    命令语法:

    rpm -ivh [RPM包文件名称]

    命令中各参数的含义如下:

    -i:表示安装软件包。

    -v:表示在安装过程中显示详细的信息。

    -h:表示显示水平进度。

    例1:安装 sqldeveloper-4.0.1.14.48-1.noarch.rpm软件包。

    [root@redhat2 ~]# rpm -ivh sqldeveloper-4.0.1.14.48-1.noarch.rpm

    Preparing...                                                            (100########################################### [100%]

       1:sqldeveloper                                                       (  1########################################### [100%]

    [root@redhat2 ~]#

    如果某软件包的同一版本已经安装,系统会显示如下信息。

    [root@redhat2 ~]# rpm -ivh sqldeveloper-4.0.1.14.48-1.noarch.rpm

    Preparing...                                                            (100########################################### [100%]

            package sqldeveloper-4.0.1.14.48-1.noarch is already installed

    例2:在软件包  sqldeveloper-4.0.1.14.48-1.noarch.rpm 已安装的情况下仍旧安装该软件包。

       如果在软件包已安装的情况下仍打算安装同一本版本的软件包,可以使用“--replacepkgs”选项忽略错误。

    [root@redhat2 ~]# rpm -ivh --replacepkgs sqldeveloper-4.0.1.14.48-1.noarch.rpm

    Preparing...                                                            (100########################################### [100%]

       1:sqldeveloper                                                       (  1########################################### [100%]

    [root@redhat2 ~]#

    2.卸载软件包

    命令语法:

    rpm -e [RPM包名称]

    命令中参数的含义如下。

    -e:表示卸载软件包。

    [root@redhat2 ~]# rpm -e sqldeveloper

    [root@redhat2 ~]#

    注意:在卸载软件包时使用软件包名称sqldeveloper,而不是软件包名称sqldeveloper-4.0.1.14.48-1.noarch.rpm

    在卸载软件包时也会遇到依赖关系错误。当另一个已安装的软件包依赖于用户试图删除软件包时,依赖关系错误就会发生。

    要使RPM忽略这个错误并强制删除该软件包,可以使用“--nodeps”选项,但是依赖于它的软件包可能无法正常运行。

    3.查询软件包

    使用"rpm -q" 命令可以查询软件包安装的相关信息。

    (1).查询指定软件包的详细信息。

    命令语法:

    Rpm -q [RPM包名称]

    例1:查sqldeveloper软件包是否安装

    [root@redhat2 ~]# rpm -q sqldeveloper

    sqldeveloper-4.0.1.14.48-1.noarch

    [root@redhat2 ~]#

    //说明已经安装

    (2)查询系统中所有已安装的RPM软件包

    命令语法:

    Rpm -qa

    例1:查询系统内所有已安装的yun软件包。

    [root@redhat2 ~]# rpm -qa yum*

    yum-plugin-security-1.1.30-14.el6.noarch

    yum-plugin-aliases-1.1.30-14.el6.noarch

    yum-rhn-plugin-0.9.1-40.el6.noarch

    yum-metadata-parser-1.1.2-16.el6.x86_64

    yum-plugin-changelog-1.1.30-14.el6.noarch

    yum-plugin-verify-1.1.30-14.el6.noarch

    yum-3.2.29-30.el6.noarch

    yum-plugin-downloadonly-1.1.30-14.el6.noarch

    yum-plugin-versionlock-1.1.30-14.el6.noarch

    yum-utils-1.1.30-14.el6.noarch

    yum-presto-0.6.2-1.el6.noarch

    yum-plugin-tmprepo-1.1.30-14

    (3)查询指定已安装软件包的描述信息

    命令语法:

    Rpm -qi [RPM包名称]

    例:查询sqldeveloper 软件包的描述信息。

    [root@redhat2 ~]# rpm -qi sqldeveloper

    Name        : sqldeveloper                 Relocations: (not relocatable)

    Version     : 4.0.1.14.48                       Vendor: (none)

    Release     : 1                             Build Date: Tue 18 Feb 2014 03:15:58 PM PST

    Install Date: Wed 21 Jan 2015 05:56:15 AM PST      Build Host: slc04qag.us.oracle.com

    Group       : Developer                     Source RPM: sqldeveloper-4.0.1.14.48-1.src.rpm

    Size        : 299716358                        License: Oracle

    Signature   : (none)

    Summary     : Oracle SQL Developer

    Description :

    Oracle SQL Developer is a new, free graphical tool that enhances productivity and simplifies database development tasks. With SQL Developer, you can browse database objects, run SQL statements and SQL scripts, and edit and debug PL/SQL statements. You can also run any number of provided reports, as well as create and save your own.

    [root@redhat2 ~]#

    (4).查询某已安装软件包所含的文件列表

    命令语法:

    Rpm -ql [软件包名称]

    (5).查询软件包的依赖要求。

    命令语法:

    Rpm -qR [RPM包名称]

    例:查询软件包的依赖关系。

    [root@redhat2 ~]# rpm -qR sqldeveloper

    /bin/sh 

    rpmlib(CompressedFileNames) <= 3.0.4-1

    rpmlib(FileDigests) <= 4.6.0-1

    rpmlib(PayloadFilesHavePrefix) <= 4.0-1

    rpmlib(PayloadIsXz) <= 5.2-1

    [root@redhat2 ~]#

    (6).查询系统中指定文件属于哪个软件包。

    命令语法:

    Rpm -qf [文件名]

    例:查询/usr/local/bin/sqldeveloper文件属于那个软件包。

    [root@redhat2 ~]# rpm -qf /usr/local/bin/sqldeveloper

    sqldeveloper-4.0.1.14.48-1.noarch

    [root@redhat2 ~]#

    //当指定文件时,必须指定文件的完整路径(如/usr/local/bin/sqldeveloper)

    二.tar包管理

     使用tar命令可以将文件和目录进行打包或压缩以做备份用。

    在Windows系统下最常见的压缩文件是zip和rar,Linux系统就不同了,它有.gz、.tar.gz、tgz、bz2、.Z、.tar等众多的压缩文件名,此外Windows系统下的.zip和.rar也可以在Linux下使用。

     Linux系统下最常用的打包程序是tar,使用tar程序打出来的包称为tar包,tar包文件的命令通常都是以.tar结尾的。生成tar包后,就可以用其他的程序来进行压缩了。

    1.tar包使用和管理

    命令语法:

    [root@redhat2 ~]# tar --help

    Usage: tar [OPTION...] [FILE]...

    GNU `tar' saves many files together into a single tape or disk archive, and can

    restore individual files from the archive.

    Examples:

      tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.

      tar -tvf archive.tar         # List all files in archive.tar verbosely.

      tar -xf archive.tar          # Extract all files from archive.tar.

     Main operation mode:

      -A, --catenate, --concatenate   append tar files to an archive

      -c, --create               create a new archive

      -d, --diff, --compare      find differences between archive and file system

          --delete               delete from the archive (not on mag tapes!)

      -r, --append               append files to the end of an archive

    ------------------------------------

    ------------------------------------

    ------------------------------------

    例1:备份/root目录下的全部文件,备份文件名为root.bak.tar。

    [root@redhat2 ~]# tar cvf root.bak.tar /root/*

    tar: Removing leading `/' from member names

    /root/a

    /root/anaconda-ks.cfg

    /root/b/

    /root/b/ccc

    /root/Desktop/

    /root/Desktop/gnome-terminal.desktop

    /root/Documents/

    /root/Downloads/

    /root/install.log

    /root/install.log.syslog

    /root/Music/

    /root/Pictures/

    /root/Public/

    /root/sqldeveloper-4.0.1.14.48-1.noarch.rpm

    /root/Templates/

    /root/Videos/

    /root/yang

    [root@redhat2 ~]#

    [root@redhat2 ~]# ls

    a                install.log         sqldeveloper-4.0.1.14.48-1.noarch.rpm

    anaconda-ks.cfg  install.log.syslog  Templates

    b                Music               Videos

    Desktop          Pictures            yang

    Documents        Public

    Downloads        root.bak.tar

    [root@redhat2 ~]#

    //可以看到 root.bak.tar就是打包后生成的文件。

    例2:查看root.bak.tar备份文件的内容,并显示在显示器上。

    [root@redhat2 ~]# tar tvf root.bak.tar

    -r--r--r-- root/newuser      0 2015-01-19 05:19 root/a

    -rw------- root/root      2623 2014-06-02 14:28 root/anaconda-ks.cfg

    drwxr-xr-x newuser/newuser   0 2015-01-20 05:52 root/b/

    -rw-r--r-- newuser/newuser   0 2015-01-20 05:52 root/b/ccc

    drwxr-xr-x root/root         0 2014-06-03 17:39 root/Desktop/

    -rwxr-xr-x root/root      6333 2014-06-03 17:39 root/Desktop/gnome-terminal.desktop

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Documents/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Downloads/

    -rw-r--r-- root/root     40730 2014-06-02 14:27 root/install.log

    -rw-r--r-- root/root      9272 2014-06-02 14:19 root/install.log.syslog

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Music/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Pictures/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Public/

    -rw-r--r-- root/root 230725684 2014-04-02 20:18 root/sqldeveloper-4.0.1.14.48-1.noarch.rpm

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Templates/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Videos/

    -rw-r--r-- root/root        28 2014-12-15 05:12 root/yang

    //可以看到该打包文件由root目录下的所有文件打包而成。

    例3:将打包文件解压出来。

    [root@redhat2 ~]# tar xvf root.bak.tar

    root/a

    root/anaconda-ks.cfg

    root/b/

    root/b/ccc

    root/Desktop/

    root/Desktop/gnome-terminal.desktop

    root/Documents/

    root/Downloads/

    root/install.log

    root/install.log.syslog

    root/Music/

    root/Pictures/

    root/Public/

    root/sqldeveloper-4.0.1.14.48-1.noarch.rpm

    root/Templates/

    root/Videos/

    root/yang

    [root@redhat2 ~]#

    例4:将文件/root/a添加到root.bak.tar包里面去。

    [root@redhat2 ~]# tar rvf root.bak.tar a

    a

    [root@redhat2 ~]# tar tvf root.bak.tar

    -r--r--r-- root/newuser      0 2015-01-19 05:19 root/a

    -rw------- root/root      2623 2014-06-02 14:28 root/anaconda-ks.cfg

    drwxr-xr-x newuser/newuser   0 2015-01-20 05:52 root/b/

    -rw-r--r-- newuser/newuser   0 2015-01-20 05:52 root/b/ccc

    drwxr-xr-x root/root         0 2014-06-03 17:39 root/Desktop/

    -rwxr-xr-x root/root      6333 2014-06-03 17:39 root/Desktop/gnome-terminal.desktop

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Documents/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Downloads/

    -rw-r--r-- root/root     40730 2014-06-02 14:27 root/install.log

    -rw-r--r-- root/root      9272 2014-06-02 14:19 root/install.log.syslog

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Music/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Pictures/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Public/

    -rw-r--r-- root/root 230725684 2014-04-02 20:18 root/sqldeveloper-4.0.1.14.48-1.noarch.rpm

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Templates/

    drwxr-xr-x root/root         0 2014-06-02 06:42 root/Videos/

    -rw-r--r-- root/root        28 2014-12-15 05:12 root/yang

    -r--r--r-- root/newuser      6 2015-01-21 06:49 a

    [root@redhat2 ~]#

    三.tar包的特殊使用

       tar   可以在打包或解包的同时调用其他的压缩程序,比如调用gzip,bzip等。

    1.tar调用gzip

      gzip是GNU组织开发的一个压缩程序,以.gz结尾的文件就是gzip压缩的结果。与gzip相对应的解压程序是gunzip,tar中使用参数“z”来调用gzip,下面举例说明。

    例1:把/root/abc目录包括其子目录全部做备份文件,并进行压缩,文件名为abc.tar.gz。

    [root@redhat2 ~]# tar zcvf abc.tar.gz /root/a

    tar: Removing leading `/' from member names

    /root/a

    [root@redhat2 ~]#

    例2:查看压缩文件abc.tar.gz的内容,并显示在显示器上。

    [root@redhat2 ~]# tar ztvf abc.tar.gz

    -r--r--r-- root/newuser      6 2015-01-21 06:49 root/a

    [root@redhat2 ~]#

    //可以看到该压缩文件由一个目录和该目录下的3个文件压缩而成。

    例3:将压缩文件abc.tar.gz解压出来。

    [root@redhat2 ~]# tar zxvf abc.tar.gz

    root/a

    [root@redhat2 ~]#

    2.tar调用bzip2

      bzip2是一个压缩能力更强的压缩程序,以.bz2结尾的文件就是bzip2压缩的结果。与bzip2相对应的解压程序是bunzip2。tar中使用参数“j”来调用gzip,下面举例说明。

    例1:将目录/root/a及该目录所有文件压缩成abc.tar.bz2文件。

    [root@redhat2 ~]# tar cjf abc.tar.bz2 /root/a

    tar: Removing leading `/' from member names

    [root@redhat2 ~]# ls

    a                Downloads           root

    abc.tar.bz2      install.log         root.bak.tar

    anaconda-ks.cfg  install.log.syslog  sqldeveloper-4.0.1.14.48-1.noarch.rpm

    b                Music               Templates

    Desktop          Pictures            Videos

    Documents        Public              yang

    [root@redhat2 ~]#

    例2:查看压缩文件abc.tar.bz2的内容,并显示在显示器上。

    [root@redhat2 ~]# tar tjf abc.tar.bz2

    root/a

    [root@redhat2 ~]

  • 相关阅读:
    记录下python学习中,容易弄混和实用的知识点
    操作系统简史
    计算机结构
    计算机结构
    电脑简史
    电脑简史
    为什么学Python
    为什么学Python
    树莓派更换更新国内源
    树莓派更换更新国内源
  • 原文地址:https://www.cnblogs.com/numberone/p/4242850.html
Copyright © 2011-2022 走看看