介紹如何查詢 Debian/Ubuntu Linux 與 RHCE/CentOS Linux 系統套件的更新記錄。
Ubuntu/Debian Linux
若在 Ubuntu 或 Debian Linux 系統下,所有 deb 格式的系統套件更新記錄都放在 /var/log/dpkg.log
中,我們可以用 grep
等工具從中篩選出需要的資訊,例如查詢套件安裝記錄:
# 查詢套件安裝記錄(Ubuntu/Debian Linux) grep "install " /var/log/dpkg.log
2021-04-17 06:01:07 install linux-headers-4.15.0-142:all <無> 4.15.0-142.146 2021-04-17 06:01:09 install linux-headers-4.15.0-142-generic:amd64 <無> 4.15.0-142.146 2021-04-17 06:01:11 install linux-modules-4.15.0-142-generic:amd64 <無> 4.15.0-142.146 2021-04-17 06:01:12 install linux-image-4.15.0-142-generic:amd64 <無> 4.15.0-142.146 2021-04-17 10:46:52 install socat:amd64 <無> 1.7.3.2-2ubuntu2 2021-04-25 19:42:31 install whois:amd64 <無> 5.3.0
查詢套件升級記錄:
# 查詢套件升級記錄(Ubuntu/Debian Linux) grep "upgrade " /var/log/dpkg.log
2021-04-24 14:53:09 upgrade ubuntu-release-upgrader-gtk:all 1:18.04.42 1:18.04.44 2021-04-24 14:53:09 upgrade ubuntu-release-upgrader-core:all 1:18.04.42 1:18.04.44 2021-04-24 14:53:09 upgrade python3-distupgrade:all 1:18.04.42 1:18.04.44 2021-04-28 06:19:17 upgrade file-roller:amd64 3.28.0-1ubuntu1.2 3.28.0-1ubuntu1.3 2021-04-28 06:19:20 upgrade firefox:amd64 87.0+build3-0ubuntu0.18.04.2 88.0+build2-0ubuntu0.18.04.2 2021-04-28 06:19:28 upgrade firefox-locale-en:amd64 87.0+build3-0ubuntu0.18.04.2 88.0+build2-0ubuntu0.18.04.2
查詢套件移除記錄:
# 查詢套件移除記錄(Ubuntu/Debian Linux) grep "remove " /var/log/dpkg.log
2021-04-15 06:18:02 remove linux-modules-4.15.0-140-generic:amd64 4.15.0-140.144 <無> 2021-04-15 06:18:05 remove linux-headers-5.4.0-66-generic:amd64 5.4.0-66.74~18.04.2 <無> 2021-04-15 06:18:10 remove linux-headers-5.4.0-67-generic:amd64 5.4.0-67.75~18.04.1 <無> 2021-04-18 06:07:11 remove linux-headers-4.15.0-141-generic:amd64 4.15.0-141.145 <無> 2021-04-18 06:07:12 remove linux-headers-4.15.0-141:all 4.15.0-141.145 <無> 2021-04-18 06:07:17 remove linux-image-4.15.0-141-generic:amd64 4.15.0-141.145 <無> 2021-04-18 06:07:21 remove linux-modules-4.15.0-141-generic:amd64 4.15.0-141.145 <無>
比較舊的記錄檔通常會以 gzip 的方式壓縮起來,這時候可以改用 zgrep
來篩選資料:
# 查詢套件安裝記錄(Ubuntu/Debian Linux) zgrep "install " /var/log/dpkg.log.2.gz
2021-02-26 06:19:21 install linux-headers-4.15.0-136-generic:amd64 <none> 4.15.0-136.140 2021-02-26 06:19:22 install linux-modules-4.15.0-136-generic:amd64 <none> 4.15.0-136.140 2021-02-26 06:19:23 install linux-image-4.15.0-136-generic:amd64 <none> 4.15.0-136.140
如果想要查詢 apt
與 apt-get
等指令的操作記錄,可以查閱 /var/log/apt/history.log
這個記錄檔。
RHCE/CentOS Linux
在 RHCE/CentOS Linux 中,所有透過 yum
套件管理系統所進行的套件安裝、更新或移除動作,都會記錄在 /var/log/yum.log
這個記錄檔中,使用 grep
就可以篩選出需要的資訊。
查詢套件安裝記錄:
# 查詢套件安裝記錄(RHCE/CentOS Linux) grep "Installed:" /var/log/yum.log
Oct 21 17:15:51 Installed: php-imap-5.4.16-9.el7.x86_64 Oct 21 17:15:51 Installed: php-intl-5.4.16-48.el7.x86_64 Oct 21 17:15:51 Installed: php-PHPMailer-5.2.27-1.el7.noarch Nov 19 15:41:32 Installed: kernel-3.10.0-1160.6.1.el7.x86_64 Nov 19 15:42:26 Installed: kernel-devel-3.10.0-1160.6.1.el7.x86_64
查詢套件升級記錄:
# 查詢套件升級記錄(RHCE/CentOS Linux) grep "Updated:" /var/log/yum.log
Nov 19 15:42:30 Updated: iwl6050-firmware-41.28.5.1-79.el7.noarch Nov 19 15:42:30 Updated: iwl3945-firmware-15.32.2.9-79.el7.noarch Nov 19 15:42:30 Updated: iwl6000-firmware-9.221.4.1-79.el7.noarch Nov 19 15:42:30 Updated: iwl100-firmware-39.31.5.1-79.el7.noarch Nov 19 15:42:30 Updated: iwl6000g2a-firmware-18.168.6.1-79.el7.noarch
查詢套件移除記錄:
# 查詢套件移除記錄(RHCE/CentOS Linux) grep "Erased:" /var/log/yum.log
Jun 19 13:27:51 Erased: rh-postgresql10-postgresql-10.12-2.el7.x86_64 Jun 19 13:28:10 Erased: rh-php73-php-pgsql-7.3.11-1.el7.x86_64 Jun 19 13:28:10 Erased: rh-postgresql10-postgresql-libs-10.12-2.el7.x86_64 Jun 19 13:28:11 Erased: rh-postgresql10-runtime-3.1-1.el7.x86_64 Jun 19 13:28:11 Erased: postgresql-libs-9.2.24-4.el7_8.x86_64