我想将已安装程序的依赖项列表保存到文本文件中。我想要这样做的原因是,例如,如果我要安装一个元包,而该元包又依赖于其他几个包,而这些包不会因单独删除元包而被删除。
我知道我可以用以下方法做到:
sudo apt-get install kubuntu-desktop | tee log_file.txt
但这会保存命令的整个输出。我只想有一个包含已安装包和依赖项的列表,以便我可以使用此命令删除包和依赖项:
sudo apt remove $(cat log_file.txt)
我想这应该是可能的,只是超出了我对 Bash 和 shell 脚本的了解。所以如果能提供一些建议就好了。
答案1
使用apt-cache
和awk
apt-cache showpkg kubuntu-desktop | awk '/Dependencies:/,/Provides:/ {for(i=1;i<NF;i++) {if(i%3==0) {print $i}}}' | tee log_file.txt
示例(带有ubuntu-desktop
,抱歉)
% apt-cache showpkg ubuntu-desktop | awk '/Dependencies:/,/Provides:/ {for(i=1;i<NF;i++) {if(i%3==0) {print $i}}}' > out
% cat out
alsa-base
alsa-utils
anacron
at-spi2-core
baobab
bc
ca-certificates
checkbox-gui
dmz-cursor-theme
doc-base
eog
evince
file-roller
fonts-dejavu-core
fonts-freefont-ttf
foomatic-db-compressed-ppds
gedit
genisoimage
ghostscript-x
gnome-calculator
gnome-font-viewer
gnome-menus
gnome-power-manager
gnome-screenshot
gnome-session-canberra
gnome-system-log
gnome-system-monitor
gstreamer1.0-alsa
gstreamer1.0-plugins-base-apps
gstreamer1.0-pulseaudio
gucharmap
gvfs-bin
inputattach
language-selector-gnome
libatk-adaptor
libnotify-bin
libpam-systemd
libsasl2-modules
lightdm
memtest86+
nautilus
nautilus-sendto
notify-osd
openprinting-ppds
printer-driver-pnm2ppa
pulseaudio
rfkill
seahorse
software-center
software-properties-gtk
ssh-askpass-gnome
system-config-printer-gnome
ubuntu-artwork
ubuntu-drivers-common
ubuntu-release-upgrader-gtk
ubuntu-session
ubuntu-settings
ubuntu-sounds
ubuntu-sso-client-qt
unity
unity-control-center
unity-greeter
unity-settings-daemon
unzip
update-manager
update-notifier
wireless-tools
wpasupplicant
xdg-user-dirs
xdg-user-dirs-gtk
xdiagnose
xkb-data
xorg
yelp
zenity
zip
acpi-support
activity-log-manager
aisleriot
app-install-data-partner
apport-gtk
avahi-autoipd
avahi-daemon
bluez
bluez-cups
branding-ubuntu
brasero
brltty
cheese
cups
cups-bsd
cups-client
cups-filters
deja-dup
empathy
example-content
firefox
fonts-droid
fonts-guru
fonts-kacst-one
fonts-khmeros-core
fonts-lao
fonts-liberation
fonts-lklug-sinhala
fonts-nanum
fonts-sil-abyssinica
fonts-sil-padauk
fonts-takao-pgothic
fonts-thai-tlwg
fonts-tibetan-machine
gcc
gnome-accessibility-themes
gnome-bluetooth
gnome-disk-utility
gnome-keyring
gnome-mahjongg
gnome-mines
gnome-orca
gnome-screensaver
gnome-sudoku
gnome-terminal
gnupg-agent
gvfs-fuse
hplip
ibus
ibus-gtk
ibus-gtk3
ibus-table
im-config
kerneloops-daemon
landscape-client-ui-install
laptop-detect
libgail-common
libnss-mdns
libpam-gnome-keyring
libproxy1-plugin-gsettings
libproxy1-plugin-networkmanager
libqt4-sql-sqlite
libreoffice-calc
libreoffice-gnome
libreoffice-impress
libreoffice-math
libreoffice-ogltrans
libreoffice-pdfimport
libreoffice-style-human
libreoffice-writer
libwmf0.2-7-gtk
make
mousetweaks
nautilus-share
network-manager-gnome
network-manager-pptp
network-manager-pptp-gnome
onboard
overlay-scrollbar
pcmciautils
plymouth-theme-ubuntu-logo
policykit-desktop-privileges
printer-driver-brlaser
printer-driver-c2esp
printer-driver-foo2zjs
printer-driver-min12xxw
printer-driver-ptouch
printer-driver-pxljr
printer-driver-sag-gdi
printer-driver-splix
pulseaudio-module-bluetooth
pulseaudio-module-x11
python3-aptdaemon.pkcompat
qt-at-spi
remmina
rhythmbox
rhythmbox-plugin-magnatune
shotwell
simple-scan
sni-qt
speech-dispatcher
telepathy-idle
thunderbird
thunderbird-gnome-support
totem
transmission-gtk
ttf-ancient-fonts-symbola
ttf-indic-fonts-core
ttf-ubuntu-font-family
ubuntu-docs
unity-webapps-common
usb-creator-gtk
vino
whoopsie
xcursor-themes
xdg-utils
xterm
xul-ext-ubufox
zeitgeist-core
zeitgeist-datahub