如何确定何时安装或更新了Debian或Ubuntu软件包

时间:2020-01-09 10:38:00  来源:igfitidea点击:

我如何找到并列出已安装的Debian或Ubuntu Linux软件包的日期?
我如何查看软件包在系统上何时更新?

Debian或Ubuntu Linux日志包状态更改以及对文件的操作。
默认值为/var/log/dpkg.log文件。
该文件具有以下格式的日志消息:

日志消息的格式为
YYYY-MM-DD HH:MM:SS status state pkg installed-version,用于状态更改更新;
YYYY-MM-DD HH:MM:SS操作pkg已安装版本可用版本,适用于其中操作是安装,升级,删除,清除的操作;
YYYY-MM-DD HH:MM:SS conffile文件名决定,用于conffile更改(决定是安装还是保留)。

按安装日期列出软件包

只需执行以下tail命令即可查看最后的软件包信息:

# tail -f /var/log/dpkg.log
$ sudo tail -f /var/log/dpkg.log

输出示例:

2019-11-13 23:11:39 purge linux-modules-extra-5.3.0-18-generic:amd64 5.3.0-18.19 
2019-11-13 23:11:39 status config-files linux-modules-extra-5.3.0-18-generic:amd64 5.3.0-18.19
2019-11-13 23:11:39 status not-installed linux-modules-extra-5.3.0-18-generic:amd64 
2019-11-13 23:11:39 purge linux-modules-5.3.0-18-generic:amd64 5.3.0-18.19 
2019-11-13 23:11:39 status config-files linux-modules-5.3.0-18-generic:amd64 5.3.0-18.19
2019-11-13 23:11:39 status not-installed linux-modules-5.3.0-18-generic:amd64 
2019-11-13 23:11:39 purge linux-image-5.3.0-18-generic:amd64 5.3.0-18.19+1 
2019-11-13 23:11:39 status config-files linux-image-5.3.0-18-generic:amd64 5.3.0-18.19+1
2019-11-13 23:11:39 status not-installed linux-image-5.3.0-18-generic:amd64 
2019-11-13 23:11:39 startup packages configure

要查看所有信息,请输入:

# less /var/log/dpkg.log
# more /var/log/dpkg.log

Ubuntu Linux列表软件包安装升级日期和时间

/var/log/dpkg.log可以使用logrotate工具旋转或压缩。
要查看所有文件的列表,请输入:

# ls -l /var/log/dpkg.log*

输出示例:

-rw-r--r-- 1 root root  9252 Jan 14 13:27 /var/log/dpkg.log
-rw-r--r-- 1 root root 11658 Dec 16 03:53 /var/log/dpkg.log.1
-rw-r--r-- 1 root root  1563 Mar 22  2015 /var/log/dpkg.log.10.gz
-rw-r--r-- 1 root root 14218 Feb 17  2015 /var/log/dpkg.log.11.gz
-rw-r--r-- 1 root root   962 Nov 27 18:14 /var/log/dpkg.log.2.gz
-rw-r--r-- 1 root root  2008 Oct 30 14:09 /var/log/dpkg.log.3.gz
-rw-r--r-- 1 root root  2490 Sep 30 14:01 /var/log/dpkg.log.4.gz
-rw-r--r-- 1 root root  1875 Aug 17 05:09 /var/log/dpkg.log.5.gz
-rw-r--r-- 1 root root   847 Jul 22 12:31 /var/log/dpkg.log.6.gz
-rw-r--r-- 1 root root  1367 Jun 25  2015 /var/log/dpkg.log.7.gz
-rw-r--r-- 1 root root  1460 May 31  2015 /var/log/dpkg.log.8.gz
-rw-r--r-- 1 root root  5504 Apr 29  2015 /var/log/dpkg.log.9.gz

使用zgrep或zmore命令(zcommands)搜索或查看gzip压缩的日志文件:

# zmore /var/log/dpkg.log.5.gz
# zless /var/log/dpkg.log.5.gz
# zgrep 'remove' /var/log/dpkg.log.5.gz

查看套件安装日期和时间

运行以下grep命令:

# grep installed /var/log/dpkg.log

输出示例:

2019-11-02 15:09:43 status half-installed libmagickcore-6.q16-6-extra:amd64 8:6.9.10.23+dfsg-2.1ubuntu3
2019-11-02 15:09:43 status half-installed libnetpbm10:amd64 2:10.0-15.3build1
2019-11-02 15:09:43 status half-installed netpbm:amd64 2:10.0-15.3build1
2019-11-02 15:09:44 status installed libmagickcore-6.q16-6-extra:amd64 8:6.9.10.23+dfsg-2.1ubuntu3
2019-11-02 15:09:44 status installed libnetpbm10:amd64 2:10.0-15.3build1

要查看gzipd日志文件,请输入:

# zgrep installed /var/log/dpkg.log.3.gz

列出软件包升级日期和时间

# grep upgrade /var/log/dpkg.log
# grep upgrade /var/log/dpkg.log.1
#***[ Look into gzipd dpkg.log.2.gz file using zgrep ]***#
# zgrep upgrade /var/log/dpkg.log.2.gz

显示包删除(删除)的日期和时间

# grep remove /var/log/dpkg.log
# grep remove /var/log/dpkg.log.1
#***[ Look into gzipd dpkg.log.2.gz file using zgrep ]***#
# zgrep remove /var/log/dpkg.log.2.gz

/var/log/apt/history.log文件

/var/log/apt/history.log文件也具有相同的信息。
要查看,请输入:

# tail -f /var/log/apt/history.log
# more /var/log/apt/history.log
# less /var/log/apt/history.log
# grep -A4 -B4 'yyyy-mm-dd' /var/log/apt/history.log
# grep -A4 '2016-01-14' /var/log/apt/history.log
Start-Date: 2016-01-14  13:18:16
Commandline: apt-get upgrade
Upgrade: isc-dhcp-common:amd64 (4.2.4-7ubuntu12.3, 4.2.4-7ubuntu12.4), isc-dhcp-client:amd64 (4.2.4-7ubuntu12.3, 4.2.4-7ubuntu12.4)
End-Date: 2016-01-14  13:18:24
grep -A4 '2019-11-05 11:18:36' /var/log/apt/history.log

输出示例:

Start-Date: 2019-11-05  11:18:36
Commandline: apt install lolcat
Requested-By: Hyman (1000)
Install: lolcat:amd64 (42.0.99-1), ruby2.5:amd64 (2.5.5-4ubuntu2, automatic), rake:amd64 (12.3.1-3, automatic), ruby-net-telnet:amd64 (0.1.1-2, automatic), ruby-trollop:amd64 (2.0-2, automatic), ruby-minitest:amd64 (5.11.3-1, automatic), ruby-paint:amd64 (0.8.6-2, automatic), ruby-xmlrpc:amd64 (0.3.0-2, automatic), libruby2.5:amd64 (2.5.5-4ubuntu2, automatic), ruby:amd64 (1:2.5.1, automatic), ruby-power-assert:amd64 (1.1.1-1, automatic), rubygems-integration:amd64 (1.11, automatic), fonts-lato:amd64 (2.0-2, automatic), ruby-test-unit:amd64 (3.2.8-1, automatic), ruby-did-you-mean:amd64 (1.2.1-1, automatic)
End-Date: 2019-11-05  11:18:40

dpkg查询

dpkg-query是一个工具,用于显示有关Debian或Ubuntu Linux下dpkg数据库中列出的软件包的信息。
但是,它不显示安装或更新日期:

dpkg-query -l

输出示例:

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                       Version                              Architecture Description
+++-==========================================-====================================-============-===============================================================================
ii  accountsservice                            0.6.55-0ubuntu10                     amd64        query and manipulate user account information
rc  apache2                                    2.4.41-1ubuntu1                      amd64        Apache HTTP Server
ii  apg                                        2.2.3.dfsg.1-5                       amd64        Automated Password Generator - Standalone version
ii  app-install-data-partner                   19.04                                all          Application Installer (data files for partner applications/repositories)
ii  apparmor                                   2.13.3-5ubuntu1                      amd64        user-space parser utility for AppArmor
ii  apport                                     2.20.11-0ubuntu8.2                   all          automatically generate crash reports for debugging

有关更多信息,请参见dpkg-query手册页。