当前位置: 首页>>技术问答>>正文


是否有可能获得最近安装的软件包列表?

, ,

问题描述

是否有可能通过apt-get获取最近安装的软件包列表?

最佳解决思路

命令列出最近安装的软件包,通过任何方法安装(apt-get,软件中心等):

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

示例输出:

2010-12-08 15:48:14 install python-testtools <none> 0.9.2-1
2010-12-08 15:48:16 install quickly-widgets <none> 10.09
2010-12-08 22:21:31 install libobasis3.3-sdk <none> 3.3.0-17
2010-12-09 12:00:24 install mc <none> 3:4.7.0.6-1
2010-12-09 23:32:06 install oggconvert <none> 0.3.3-1ubuntu1
2010-12-09 23:34:50 install mpg123 <none> 1.12.1-3ubuntu1
2010-12-09 23:34:52 install dir2ogg <none> 0.11.8-1
2010-12-09 23:34:53 install faad <none> 2.7-4
2010-12-09 23:34:54 install wavpack <none> 4.60.1-1
2010-12-10 11:53:00 install playonlinux <none> 3.8.6

您可以运行此命令以仅列出最近安装的软件包名称,

awk '$3~/^install$/ {print $4;}' /var/log/dpkg.log

列出apt-get历史记录的命令(注意:这里没有列出安装的依赖关系,只是列出了之前运行的apt-get命令):

grep " install " /var/log/apt/history.log

示例输出:

Commandline: apt-get install libindicate-doc
Commandline: apt-get install googlecl
Commandline: apt-get --reinstall install ttf-mscorefonts-installer
Commandline: apt-get install valac libvala-0.10-dev
Commandline: apt-get install libgtksourceview-dev
Commandline: apt-get install python-sphinx
Commandline: apt-get install python-epydoc
Commandline: apt-get install quickly-widgets
Commandline: apt-get install libreoffice3* libobasis3.3*
Commandline: apt-get install mc

次佳解决思路

Ubuntu的软件中心显示已安装/升级/删除的所有软件包的全部历史记录。只需点击左侧列表底部的”History”即可。

第三种解决思路

要查看按安装时间排序的旧软件包:

grep " install " /var/log/dpkg.log.1 /var/log/dpkg.log

对于很久以前安装的软件包:

gunzip -c `ls -tr /var/log/dpkg.log.*.gz` | grep " install "

第四种思路

全部在一条线上;供命令使用

只选择并打印最近安装的package-names,全部在一行上。

为此,请将most-voted答案更改为:

cat /var/log/dpkg.log |awk '/ install / {printf "%s ",$4}'

这导致一行包名称。这样一行可以很容易地添加到sudo apt-get purge命令中。

示例输出

libgnome-media-profiles-3.0-0 gstreamer0.10-gconf gnome-media gnome-menus librest-0.7-0 libgoa-1.0-common libgoa-1.0-0 libwacom-common libwacom2 ubuntu-docs apg libgnome-control-center1 libgnomekbd-common libgnomekbd7 gnome-control-center-data gnome-icon-theme-symbolic gnome-settings-daemon ubuntu-system-service gnome-control-center gnome-online-accounts gnome-session-bin indicator-power mousetweaks

将软件包列在另一个下面

根据大众的需求,这里有一些略微改变的版本,用于将软件包列在下面:

cat /var/log/dpkg.log |awk '/ install / {printf "%s\n",$4}'

第五种思路

有一个名为wajig的包检查它的命令行,这是我现在安装的第一件事。像aptitude一样,只是它的工作方式与您期望的命令调度程序一样。所以真的,它不像aptitude。下面的命令只是一小部分。

wajig help
Common JIG commands:

 update         Update the list of downloadable packages

 new            List packages that became available since last update
 newupgrades    List packages newly available for upgrading

 install        Install (or upgrade) one or more packages or .deb files
 remove         Remove one or more packages (see also purge)

 toupgrade      List packages with newer versions available for upgrading
 upgrade        Upgrade all of the installed packages or just those listed

 listfiles      List the files that are supplied by the named package
 listnames      List all known packages or those containing supplied string
 whatis         For each package named obtain a one line description
 whichpkg       Find the package that supplies the given command or file

Run 'wajig -v commands' for a complete list of commands.

第六种思路

以下技巧回答了Aleksandr Dubinsky的请求,将其限制为manually-installed包:

comm -12 <(apt-mark showmanual | sort) <(grep " install " /var/log/dpkg.log | cut -d " " -sf4 | grep -o "^[^:]*" | sort)
  • comm -12列出两个排序文件共有的行。

  • <(command)展开为包含command输出的文件的名称。

  • apt-mark showmanual列出手动安装的软件包;即。那些不应该是auto-removed。

  • grep " install " /var/log/dpkg.log取自公认的答案。

另一种方法是,按时间顺序显示更多信息,并访问所有可用日志,方法是:

zcat -f /var/log/dpkg.log* | grep " install " | sort > /tmp/dpkg.log
grep -F "`comm -12 <(apt-mark showmanual | sort) <(cat /tmp/dpkg.log | cut -d " " -sf4 | grep -o "^[^:]*" | sort)`" /tmp/dpkg.log | grep \<none\>

grep \<none\>将结果限制为新安装。例如,您可以使用grep通过将grep 2016-0[567]添加到第一个管道来将搜索限制到three-month时间段;它非常灵活。

参考资料

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