当前位置: 首页>>技术教程>>正文


apt – 如何在 ubuntu 上列出已安装的软件包及其详细信息?

,

问题描述

我是 ubuntu 新手,试图找出列出所有已安装软件包及其详细信息(如 Ubuntu 上的版本、发行版、安装时间、类别)的方法。发现以下命令将帮助我获取其中一些信息:

1)dpkg -l

2)dpkg-query -W -f='${PackageSpec}\\t${version}\\t${Description}\\n'

与 Redhat 不同的是,其中缺少安装时间和类别信息。谁能知道检索这些详细信息的方法吗?

提前致谢。

最佳思路

简洁优雅:

sudo dpkg -l | more

或者

sudo dpkg -l | less

如果你想获取某些特定包的描述,请说 firefox

sudo dpkg -l | grep firefox

这是我的输出:

$ sudo dpkg -l | more
 Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                        Version                                 Description
+++-===========================================-=======================================-==============================================================
================
ii  accountsservice                             0.6.15-2ubuntu9.4                       query and manipulate user account information
ii  acl                                         2.2.51-5ubuntu1                         Access control list utilities
ii  acpi-support                                0.140                                   scripts for handling many ACPI events
ii  acpid                                       1:2.0.10-1ubuntu3                       Advanced Configuration and Power Interface event daemon
ii  activity-log-manager-common                 0.9.4-0ubuntu3.2                        blacklist configuration for Zeitgeist (assets)
ii  activity-log-manager-control-center         0.9.4-0ubuntu3.2                        blacklist configuration for Zeitgeist (control center integrat
ion)
ii  adduser                                     3.113ubuntu2                            add and remove users and groups
ii  adium-theme-ubuntu                          0.3.2-0ubuntu1                          Adium message style for Ubuntu
ii  aisleriot                                   1:3.2.3.2-0ubuntu1                      Solitaire card games
ii  akonadi-backend-mysql                       1.7.2-0ubuntu1                          MySQL storage backend for Akonadi
ii  akonadi-server                              1.7.2-0ubuntu1                          Akonadi PIM storage service
ii  alacarte                                    0.13.2-2ubuntu4                         easy GNOME menu editing tool
ii  alsa-base                                   1.0.25+dfsg-0ubuntu1                    ALSA driver configuration files
ii  alsa-utils                                  1.0.25-1ubuntu5                         Utilities for configuring and using ALSA
ii  anacron                                     2.3-14ubuntu1                           cron-like program that doesn't go by time
ii  apg                                         2.2.3.dfsg.1-2                          Automated Password Generator - Standalone version
ii  app-install-data                            0.12.04.4                               Ubuntu applications (data files)
ii  app-install-data-partner                    12.12.04.1                              Application Installer (data files for partner applications/rep
ositories)
ii  apparmor                                    2.7.102-0ubuntu3.7                      User-space parser utility for AppArmor
ii  appmenu-gtk                                 0.3.92-0ubuntu1.1                       Export GTK menus over DBus
ii  appmenu-gtk3                                0.3.92-0ubuntu1.1                       Export GTK menus over DBus
ii  appmenu-qt                                  0.2.6-0ubuntu1                          appmenu support for Qt
ii  apport                                      2.0.1-0ubuntu17.1                       automatically generate crash reports for debugging
ii  apport-gtk                                  2.0.1-0ubuntu17.1                       GTK+ frontend for the apport crash report system
ii  apport-symptoms                             0.16.1                                  symptom scripts for apport
ii  apt                                         0.8.16~exp12ubuntu10.7                  commandline package manager
ii  apt-transport-https                         0.8.16~exp12ubuntu10.7                  https download transport for APT
ii  apt-utils                                   0.8.16~exp12ubuntu10.7                  package managment related utility programs
--More--

获取正在安装的软件包的日期和时间

cat /var/log/dpkg.log | grep " install "

获取特定套餐:

$cat /var/log/dpkg.log | grep " install " | grep banshee
2013-12-12 12:51:48 install banshee <none> 2.4.1-3ubuntu1~precise2
2013-12-12 12:51:51 install banshee-extensions-common <none> 2.4.0-1ubuntu1
2013-12-12 12:51:51 install banshee-extension-radiostationfetcher <none> 2.4.0-    1ubuntu1
2013-12-12 12:51:51 install banshee-extension-soundmenu <none> 2.4.1-3ubuntu1~precise2

获取该部分

$apt-cache show firefox | grep Section
Section: web

See Also: ListInstalledPackagesByDate

次佳思路

apt-cache showpkg <package> 将为您提供有关可用软件包版本、正向和反向依赖关系等的详细信息。

apt-cache show <package>将提供描述、类别(Section)等。

我不知道有什么方法可以查看软件包的安装时间。

第三种思路

使用apt

列出已安装软件包的另一种方法是:

apt list --installed

所有软件包安装手册都可以通过以下方式打印

apt list --manual-installed

而所有版本均按以下方式列出:

apt list --all-versions

这些是非常有用的命令。例如,如果您想将本地安装的软件包安装到另一台计算机上,则只需执行以下命令

apt list --installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > apt_packages.txt

如果您只想手动安装软件包,请尝试以下操作:

 apt list --manual-installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > apt_packages.txt   

现在您的所有 apt-packages 都已准备好安装在另一个或新安装的 Ubuntu 系统上。

sudo apt-get install < apt_packages.txt

详细说明

如果您想确切地知道何时、删除了什么以及哪些软件包被删除,请查看您的

/var/log/apt

目录。例如。在 history.log 文件中搜索或使用 sed、awk、grep 或您最喜欢的 text-editor 来搜索历史文件。

第四种思路

\\n

Now it is far easier to get the installation details of packages.

\\n

以下是简单的步骤:

  1. 将以下脚本复制并粘贴到文件中,并使用任意名称(如 pkgdetails )保存。

    \n

    #!/bin/bash\n\n#Get the details and section of installed packages\n# usage:\n# pkgdetails <pkgname1> <pkgname2>\n\n#first append all info from archived logs\n\ni=2\nmycount=$(ls -l /var/log/dpkg.log.*.gz | wc -l)\nnlogs=$(( $mycount + 1 ))\n\nwhile [ $i -le $nlogs ]\ndo\nif [ -e /var/log/dpkg.log.$i.gz ]; then\nzcat /var/log/dpkg.log.$i.gz | grep "\\ install\\ " >> $HOME/pkgtmp.txt\nfi\ni=$(( $i+1 ))\n\ndone\n\n#next append all info from unarchived logs\n\ni=1\nnulogs=$(ls -l /var/log/dpkg.log.* | wc -l)\nnulogs=$(( $nulogs - $nlogs + 1 ))\nwhile [ $i -le $nulogs ]\ndo\nif [ -e /var/log/dpkg.log.$i ]; then\ncat /var/log/dpkg.log.$i | grep "\\ install\\ " >> $HOME/pkgtmp.txt\nfi\ni=$(( $i+1 ))\n\ndone\n\n#next append current log\n\ncat /var/log/dpkg.log | grep "\\ install\\ " >> $HOME/pkgtmp.txt\n\n#sort text file by date\n\nsort -n $HOME/pkgtmp.txt > $HOME/pkginstalls.txt\n\nrm $HOME/pkgtmp.txt\n\n# Now displaying the installation details of packages passed as arguments\n\nfor pkg in $@\ndo\necho "--------------------- Installation Details of $pkg ----------------------"\necho \ncat $HOME/pkginstalls.txt | grep -i $pkg\necho\napt-cache show $pkg | grep "Section" | sort -u\necho\ndone\n\nexit 0\n
  2. 使文件可执行并复制到 /bin 以将其用作命令。

    \n

    chmod a+x pkgdetails && sudo cp pkgdetails /bin/\n
  3. 现在使用 pkgdetails 命令获取安装详细信息和软件包部分:

    \n

    pkgdetails qbittorrent artha\n

这是我的输出:

--------------------- Installation Details of qbittorrent ----------------------

2013-07-24 07:52:27 install qbittorrent <none> 2.9.7-1
2013-07-24 09:11:32 install qbittorrent <none> 3.0.x-0~4366-20130722~precise1
2013-10-19 05:32:27 install qbittorrent <none> 3.0.x-0~4389-20130802~precise1

Section: net
Section: universe/net

--------------------- Installation Details of artha ----------------------

2013-07-11 23:50:16 install artha <none> 1.0.2-1ubuntu1

Section: universe/utils

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/14085.html,未经允许,请勿转载。