next up previous contents
Next: YUM 線上升級機制 Up: RPM 套件下載安裝 Previous: RPM 套件移除   Contents

RPM 查詢

  1. 查詢已安裝套件資訊的選項以 -q 開頭。
    [root@linux ~]# rpm -qa
    [root@linux ~]# rpm -q[licdR] 已安裝的套件名稱
    [root@linux ~]# rpm -qf 存在於系統上面的某個檔案
    
    -q  :僅查詢,後面接的套件名稱是否有安裝;
    -qa :列出所有已經安裝在本機 Linux 系統上面的套件名稱;
    -qi :列出該套件的詳細資訊 (information),包含開發商、版本與說明等;
    -ql :列出該套件所有的檔案與目錄所在完整檔名 (list);
    -qc :列出該套件的所有設定檔 (僅找出在 /etc/ 底下的檔名)
    -qd :列出該套件的所有說明檔 (僅找出與 man 有關的檔案)
    -qR :列出與該套件有關的相依套件所含的檔案 (Required )
    -qf :由後面接的檔案名稱,找出該檔案屬於哪一個已安裝的套件;
    
  2. 查詢未安裝套件資訊的選項:
    [root@linux ~]# rpm -qp[licdR] 未安裝的某個檔案名稱
    -qp[icdlR]:後面接的所有參數以上面的說明一致。
    
  3. 找出是否有安裝套件 logrotate?
    [root@linux ~]# rpm -q logrotate  # 不必加上版本。
    logrotate-3.7.1-10
    [root@linux ~]# rpm -q logrotating
    package logrotating is not installed
    
  4. 列出套件 logrotate 的所有目錄與檔案:
    [root@linux ~]# rpm -ql logrotate
    /etc/cron.daily/logrotate
    /etc/logrotate.conf
    ......以下省略......
    
  5. 列出套件 logrotate 的相關說明資料:
    [root@linux ~]# rpm -qi logrotate
    Name        : logrotate     Relocations: (not relocatable)
    Version     : 3.7.1         Vendor: Red Hat, Inc.
    Release     : 10            Build Date: Fri Apr  1 03:54:42 2005
    Install Date: Sat Jun 25 08:28:26 2005  Build Host: tweety.build.redhat.com
    Group       : 系統環境/基礎   Source RPM: logrotate-3.7.1-10.src.rpm
    Size        : 47825         License: GPL
    Signature   : DSA/SHA1, Sat May 21 01:34:11 2005, Key ID b44269d04f2a6fd2
    Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
    Summary     : 循環、壓縮、移除以及郵寄系統紀錄檔案。
    Description :
    The logrotate utility is designed to simplify the administration of
    log files on a system which generates a lot of log files. Logrotate
    allows for the automatic rotation, compression, removal, and mailing of
    log files. Logrotate can be set to handle a log file daily, weekly,
    monthly, or when the log file gets to a certain size. Normally,
    logrotate runs as a daily cron job.
    
  6. 查詢 mplayer 的設定檔
    [root@dywHome2 ~]# rpm -qc mplayer
    /etc/mplayer/codecs.conf
    /etc/mplayer/input.conf
    /etc/mplayer/menu.conf
    /etc/mplayer/mplayer.conf
    
  7. 查詢 mplayer 的說明檔
    [root@dywHome2 ~]# rpm -qd mplayer
    /usr/share/doc/mplayer-1.0/AUTHORS
    /usr/share/doc/mplayer-1.0/ChangeLog
    /usr/share/doc/mplayer-1.0/Copyright
    /usr/share/doc/mplayer-1.0/HTML/cs/advaudio.html
    /usr/share/doc/mplayer-1.0/HTML/cs/aspect.html
    /usr/share/doc/mplayer-1.0/HTML/cs/audio-codecs.html
    /usr/share/doc/mplayer-1.0/HTML/cs/audio-formats.html
    ----以下省略----
    
  8. 查詢 logrotate 相依套件
    [root@linux ~]# rpm -qR logrotate
    /bin/sh
    config(logrotate) = 3.7.1-10
    libc.so.6
    ----以下省略----
    
  9. 查詢 /bin/sh 是由那個套件提供?
    [root@linux ~]# rpm -qf /bin/sh
    bash-3.0-31
    # 參數後面接的是『檔案』,不是接套件。
    
  10. 查詢套件 kplayer ( 未安裝 )之相依套件?
    [root@dywHome2 rpm]# rpm -qpR kplayer-0.5.3-5mdv2007.0.i586.rpm
    mplayer
    kdelibs-common
    /bin/sh
    /bin/sh
    rpmlib(PayloadFilesHavePrefix) <= 4.0-1
    rpmlib(CompressedFileNames) <= 3.0.4-1
    libDCOP.so.4
    libICE.so.6
    ----以下省略----
    
  11. 查詢套件 logrotate 設定檔
    [root@dywHome2 ~]# rpm -qc logrotate
    /etc/logrotate.conf
    /etc/logrotate.d/syslog
    
  12. 若查出 logrotate 的設定檔案已被改過,而要從網路直接重新安裝,該如何作?
    [root@dywHome2 ~]# rpm -ivh http://ftp.isu.edu.tw/pub/Linux/Mandriva\
    >/official/2007.0/i586/media/main/release/logrotate-3.7.3-4mdk.i586.rpm\
    > --replacepkgs
    
  13. 如果誤刪 /etc/crontab,如何查詢它屬於那個套件,以重新安裝?
    # 雖然檔案 /etc/crontab 已不存在,但 /var/lib/rpm 資料庫中有記錄:
    [root@dywHome2 ~]# rpm -qf /etc/crontab
    crontabs-1.10-6mdk
    
  14. 查詢系統中含 player 字串的套件?
    [root@dywHome2 rpm]# rpm -qa | grep player
    mplayer-1.0-1.pre8.13.2mdv2007.0
    kplayer-0.5.3-5mdv2007.0
    
  15. 如何知道系統中以 c 開頭的套件有幾個?
    [root@dywHome2 rpm]# rpm -qa | grep ^c | wc -l
    15
    
  16. 查詢 rpm 套件並以 -queryformat 選項指定輸出格式。以下例子是以輸出安裝時間的時間戳、日期、套件名稱顯示,並以時間戳排序,最後列出最後 10 行。
    [root@kvm7 ~]# rpm -qa  --queryformat '%{installtime} (%{installtime:date}) %{name}\n' | sort -n | tail 
    1408439342 (Tue 19 Aug 2014 05:09:02 PM CST) keyutils
    1408439342 (Tue 19 Aug 2014 05:09:02 PM CST) libevent
    1408439342 (Tue 19 Aug 2014 05:09:02 PM CST) quota
    1408439343 (Tue 19 Aug 2014 05:09:03 PM CST) libnfsidmap
    1408439344 (Tue 19 Aug 2014 05:09:04 PM CST) nfs-utils
    1408619268 (Thu 21 Aug 2014 07:07:48 PM CST) apr
    1408619269 (Thu 21 Aug 2014 07:07:49 PM CST) apr-util
    1408619269 (Thu 21 Aug 2014 07:07:49 PM CST) httpd-tools
    1408619270 (Thu 21 Aug 2014 07:07:50 PM CST) mailcap
    1408619271 (Thu 21 Aug 2014 07:07:51 PM CST) httpd
    
  17. 上面例子以單引號括起來的輸出格式是以 printf 函式運作,其中 %{} 大括號內的變數,大小寫不分,可以使用 -querytags 查詢所有的變數。
    [root@kvm7 ~]# rpm --querytags
    ARCH
    ARCHIVESIZE
    BASENAMES
    BUGURL
    BUILDARCHS
    BUILDHOST
    BUILDTIME
    C
    CHANGELOGNAME
    CHANGELOGTEXT
    CHANGELOGTIME
    CLASSDICT
    COLLECTIONS
    CONFLICTFLAGS
    CONFLICTNAME
    CONFLICTNEVRS
    CONFLICTS
    CONFLICTVERSION
    COOKIE
    DBINSTANCE
    DEPENDSDICT
    DESCRIPTION
    DIRINDEXES
    DIRNAMES
    DISTRIBUTION
    DISTTAG
    DISTURL
    DSAHEADER
    E
    EPOCH
    EPOCHNUM
    EVR
    EXCLUDEARCH
    EXCLUDEOS
    EXCLUSIVEARCH
    EXCLUSIVEOS
    FILECAPS
    FILECLASS
    FILECOLORS
    FILECONTEXTS
    FILEDEPENDSN
    FILEDEPENDSX
    FILEDEVICES
    FILEDIGESTALGO
    FILEDIGESTS
    FILEFLAGS
    FILEGROUPNAME
    FILEINODES
    FILELANGS
    FILELINKTOS
    FILEMD5S
    FILEMODES
    FILEMTIMES
    FILENAMES
    FILENLINKS
    FILEPROVIDE
    FILERDEVS
    FILEREQUIRE
    FILESIZES
    FILESTATES
    FILEUSERNAME
    FILEVERIFYFLAGS
    FSCONTEXTS
    GIF
    GROUP
    HDRID
    HEADERCOLOR
    HEADERI18NTABLE
    HEADERIMAGE
    HEADERIMMUTABLE
    HEADERREGIONS
    HEADERSIGNATURES
    ICON
    INSTALLCOLOR
    INSTALLTID
    INSTALLTIME
    INSTFILENAMES
    INSTPREFIXES
    LICENSE
    LONGARCHIVESIZE
    LONGFILESIZES
    LONGSIGSIZE
    LONGSIZE
    N
    NAME
    NEVR
    NEVRA
    NOPATCH
    NOSOURCE
    NVR
    NVRA
    O
    OBSOLETEFLAGS
    OBSOLETENAME
    OBSOLETENEVRS
    OBSOLETES
    OBSOLETEVERSION
    OLDFILENAMES
    OPTFLAGS
    ORDERFLAGS
    ORDERNAME
    ORDERVERSION
    ORIGBASENAMES
    ORIGDIRINDEXES
    ORIGDIRNAMES
    ORIGFILENAMES
    OS
    P
    PACKAGER
    PATCH
    PATCHESFLAGS
    PATCHESNAME
    PATCHESVERSION
    PAYLOADCOMPRESSOR
    PAYLOADFLAGS
    PAYLOADFORMAT
    PKGID
    PLATFORM
    POLICIES
    POLICYFLAGS
    POLICYNAMES
    POLICYTYPES
    POLICYTYPESINDEXES
    POSTIN
    POSTINFLAGS
    POSTINPROG
    POSTTRANS
    POSTTRANSFLAGS
    POSTTRANSPROG
    POSTUN
    POSTUNFLAGS
    POSTUNPROG
    PREFIXES
    PREIN
    PREINFLAGS
    PREINPROG
    PRETRANS
    PRETRANSFLAGS
    PRETRANSPROG
    PREUN
    PREUNFLAGS
    PREUNPROG
    PROVIDEFLAGS
    PROVIDENAME
    PROVIDENEVRS
    PROVIDES
    PROVIDEVERSION
    PUBKEYS
    R
    RECONTEXTS
    RELEASE
    REMOVETID
    REQUIREFLAGS
    REQUIRENAME
    REQUIRENEVRS
    REQUIRES
    REQUIREVERSION
    RPMVERSION
    RSAHEADER
    SHA1HEADER
    SIGGPG
    SIGMD5
    SIGPGP
    SIGSIZE
    SIZE
    SOURCE
    SOURCEPACKAGE
    SOURCEPKGID
    SOURCERPM
    SUMMARY
    TRIGGERCONDS
    TRIGGERFLAGS
    TRIGGERINDEX
    TRIGGERNAME
    TRIGGERSCRIPTFLAGS
    TRIGGERSCRIPTPROG
    TRIGGERSCRIPTS
    TRIGGERTYPE
    TRIGGERVERSION
    URL
    V
    VCS
    VENDOR
    VERBOSE
    VERIFYSCRIPT
    VERIFYSCRIPTFLAGS
    VERIFYSCRIPTPROG
    VERSION
    XPM
    


2015-04-13