Shell-Script
如何列出 APT 命令已安裝的所有文件
我試過如何列出 APT 包安裝的所有文件?. 但問題是,例如:
當我執行
sudo apt install libvirt-daemon-system
它時,它不僅安裝一個包(在這種情況下libvirt-daemon-system
)。它還安裝將安裝以下新軟體包中提到的軟體包:$ sudo apt install libvirt-daemon-system Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: cpu-checker ibverbs-providers ipxe-qemu ipxe-qemu-256k-compat-efi-roms libcacard0 libfdt1 libibverbs1 libiscsi7 libpmem1 librados2 librbd1 librdmacm1 libslirp0 libspice-server1 libusbredirparser1 libvirglrenderer1 libvirt-clients libvirt-daemon libvirt-daemon-driver-qemu libvirt-daemon-driver-storage-rbd libvirt-daemon-system-systemd libvirt0 msr-tools ovmf qemu-block-extra qemu-kvm qemu-system-common qemu-system-data qemu-system-gui qemu-system-x86 qemu-utils seabios Suggested packages: libvirt-daemon-driver-lxc libvirt-daemon-driver-vbox libvirt-daemon-driver-xen libvirt-daemon-driver-storage-gluster libvirt-daemon-driver-storage-zfs numad auditd nfs-common open-iscsi radvd systemtap zfsutils samba vde2 debootstrap The following NEW packages will be installed: cpu-checker ibverbs-providers ipxe-qemu ipxe-qemu-256k-compat-efi-roms libcacard0 libfdt1 libibverbs1 libiscsi7 libpmem1 librados2 librbd1 librdmacm1 libslirp0 libspice-server1 libusbredirparser1 libvirglrenderer1 libvirt-clients libvirt-daemon libvirt-daemon-driver-qemu libvirt-daemon-driver-storage-rbd libvirt-daemon-system libvirt-daemon-system-systemd libvirt0 msr-tools ovmf qemu-block-extra qemu-kvm qemu-system-common qemu-system-data qemu-system-gui qemu-system-x86 qemu-utils seabios 0 upgraded, 33 newly installed, 0 to remove and 1 not upgraded. Need to get 22.4 MB of archives. After this operation, 93.9 MB of additional disk space will be used. Do you want to continue? [Y/n]
所以,我沒有通過執行得到完整的畫面
dpkg -L libvirt-daemon-system
獲取命令後創建的所有文件列表的一種選擇
apt install
是執行dpkg -L libvirt-daemon-system dpkg -L cpu-checker dpkg -L ibverbs-providers dpkg -L ipxe-qemu ....
但我認為這將是一個漫長的過程。
另一種選擇是在安裝軟體包後執行以下命令:
sudo find / -xdev -mtime -5 -type f ! -path '/home/blueray/*' ! -path '/timeshift/*'
有沒有更好的解決方案來獲取
apt install
命令後創建的所有文件的列表。
事後,您可以將已安裝軟體包的列表提供給
dpkg -L
:dpkg -L libvirt-daemon-system cpu-checker ibverbs-providers ipxe-qemu \ ipxe-qemu-256k-compat-efi-roms libcacard0 libfdt1 libibverbs1 \ libiscsi7 libpmem1 librados2 librbd1 librdmacm1 libslirp0 \ libspice-server1 libusbredirparser1 libvirglrenderer1 \ libvirt-clients libvirt-daemon libvirt-daemon-driver-qemu \ libvirt-daemon-driver-storage-rbd libvirt-daemon-system \ libvirt-daemon-system-systemd libvirt0 msr-tools ovmf \ qemu-block-extra qemu-kvm qemu-system-common qemu-system-data \ qemu-system-gui qemu-system-x86 qemu-utils seabios
在大多數情況下,這不會很長(儘管結果可能是,並且在這種情況下是)。
通過一些準備,您可以列出軟體包安裝的所有文件(不包括維護者腳本所做的更改)。在執行之前
apt
,儲存打包系統知道的所有文件的列表:sort -u /var/lib/dpkg/info/*.list > files-before
執行後
apt
,將其再次儲存在不同的文件中:sort -u /var/lib/dpkg/info/*.list > files-after
然後,您可以比較這兩個文件以查看發生了什麼變化,例如
comm files-{before,after}
或者
meld files-{before,after}
這也適用於軟體包刪除和軟體包升級期間的文件刪除;您的
find
方法將無法確定刪除了什麼。在您只對新(或升級)軟體包安裝的文件感興趣的情況下,您可以查看最近x分鐘內修改的文件列表,例如10:
find /var/lib/dpkg/info -name \*.list -mmin -10 -exec sort -u {} +
或者,如果您使用的是 Zsh:
sort -u /var/lib/dpkg/info/*.list(mm-10)