![使用 apt](https://linux22.com/image/1044148/%E4%BD%BF%E7%94%A8%20apt.png)
我是 Ubuntu 新手,正在尝试找到列出所有已安装软件包及其详细信息(如版本、发布、安装时间、Ubuntu 上的类别)的方法。发现以下命令可以帮助我获取其中一些信息:
1)dpkg -l
2)dpkg-query -W -f='${PackageSpec}\t${version}\t${Description}\n'
与 Redhat 不同,这里缺少安装时间和类别信息。有人知道检索这些详细信息的方法吗?
提前致谢。
答案1
简洁优雅:
sudo dpkg -l | more
或者
sudo dpkg -l | less
如果你想获得某些特定包的描述,请说firefox
:
sudo dpkg -l | grep firefox
这是我的输出:
$ sudo dpkg -l | more
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
+++-===========================================-=======================================-==============================================================
================
ii accountsservice 0.6.15-2ubuntu9.4 query and manipulate user account information
ii acl 2.2.51-5ubuntu1 Access control list utilities
ii acpi-support 0.140 scripts for handling many ACPI events
ii acpid 1:2.0.10-1ubuntu3 Advanced Configuration and Power Interface event daemon
ii activity-log-manager-common 0.9.4-0ubuntu3.2 blacklist configuration for Zeitgeist (assets)
ii activity-log-manager-control-center 0.9.4-0ubuntu3.2 blacklist configuration for Zeitgeist (control center integrat
ion)
ii adduser 3.113ubuntu2 add and remove users and groups
ii adium-theme-ubuntu 0.3.2-0ubuntu1 Adium message style for Ubuntu
ii aisleriot 1:3.2.3.2-0ubuntu1 Solitaire card games
ii akonadi-backend-mysql 1.7.2-0ubuntu1 MySQL storage backend for Akonadi
ii akonadi-server 1.7.2-0ubuntu1 Akonadi PIM storage service
ii alacarte 0.13.2-2ubuntu4 easy GNOME menu editing tool
ii alsa-base 1.0.25+dfsg-0ubuntu1 ALSA driver configuration files
ii alsa-utils 1.0.25-1ubuntu5 Utilities for configuring and using ALSA
ii anacron 2.3-14ubuntu1 cron-like program that doesn't go by time
ii apg 2.2.3.dfsg.1-2 Automated Password Generator - Standalone version
ii app-install-data 0.12.04.4 Ubuntu applications (data files)
ii app-install-data-partner 12.12.04.1 Application Installer (data files for partner applications/rep
ositories)
ii apparmor 2.7.102-0ubuntu3.7 User-space parser utility for AppArmor
ii appmenu-gtk 0.3.92-0ubuntu1.1 Export GTK menus over DBus
ii appmenu-gtk3 0.3.92-0ubuntu1.1 Export GTK menus over DBus
ii appmenu-qt 0.2.6-0ubuntu1 appmenu support for Qt
ii apport 2.0.1-0ubuntu17.1 automatically generate crash reports for debugging
ii apport-gtk 2.0.1-0ubuntu17.1 GTK+ frontend for the apport crash report system
ii apport-symptoms 0.16.1 symptom scripts for apport
ii apt 0.8.16~exp12ubuntu10.7 commandline package manager
ii apt-transport-https 0.8.16~exp12ubuntu10.7 https download transport for APT
ii apt-utils 0.8.16~exp12ubuntu10.7 package managment related utility programs
--More--
获取软件包安装的日期和时间
cat /var/log/dpkg.log | grep " install "
获取特定包:
$cat /var/log/dpkg.log | grep " install " | grep banshee
2013-12-12 12:51:48 install banshee <none> 2.4.1-3ubuntu1~precise2
2013-12-12 12:51:51 install banshee-extensions-common <none> 2.4.0-1ubuntu1
2013-12-12 12:51:51 install banshee-extension-radiostationfetcher <none> 2.4.0- 1ubuntu1
2013-12-12 12:51:51 install banshee-extension-soundmenu <none> 2.4.1-3ubuntu1~precise2
获取部分
$apt-cache show firefox | grep Section
Section: web
答案2
apt-cache showpkg <package>
将为您提供有关可用软件包版本、正向和反向依赖关系等的详细信息。
apt-cache show <package>
将提供描述,类别(部分)等。
我不知道如何查看软件包的安装时间。
答案3
使用 apt
列出已安装软件包的另一种方法是:
apt list --installed
所有已安装的软件包手动的可以通过以下方式打印
apt list --manual-installed
然而所有版本列出方式:
apt list --all-versions
这些命令非常有用。例如,如果你想将本地安装的软件包安装到另一台计算机上,你只需要执行以下命令
apt list --installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > apt_packages.txt
如果您只想手动安装软件包,请尝试以下操作:
apt list --manual-installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > apt_packages.txt
现在,您的所有 apt-packages 都已准备好安装到另一个或新安装的 Ubuntu 系统上。
sudo apt-get install < apt_packages.txt
详细说明
如果你想确切地知道什么时候,什么和哪个软件包已被删除,请查看你的
/var/log/apt
目录。例如在history.log
文件中搜索或使用sed,awk,grep或您最喜欢的文本编辑器来搜索您的历史文件。
答案4
打开文本编辑器并将以下内容粘贴到 anyname.sh 中,然后使其可执行
chmod +x anyname.sh
代码 :
#!/bin/bash
#pkginstalls.sh
#creates text file with a list of all packages installed by date
#first append all info from archived logs
i=2
mycount=$(ls -l /var/log/dpkg.log.*.gz | wc -l)
nlogs=$(( $mycount + 1 ))
while [ $i -le $nlogs ]
do
if [ -e /var/log/dpkg.log.$i.gz ]; then
zcat /var/log/dpkg.log.$i.gz | grep "\ install\ " >> $HOME/pkgtmp.txt
fi
i=$(( $i+1 ))
done
#next append all info from unarchived logs
i=1
nulogs=$(ls -l /var/log/dpkg.log.* | wc -l)
nulogs=$(( $nulogs - $nlogs + 1 ))
while [ $i -le $nulogs ]
do
if [ -e /var/log/dpkg.log.$i ]; then
cat /var/log/dpkg.log.$i | grep "\ install\ " >> $HOME/pkgtmp.txt
fi
i=$(( $i+1 ))
done
#next append current log
cat /var/log/dpkg.log | grep "\ install\ " >> $HOME/pkgtmp.txt
#sort text file by date
sort -n $HOME/pkgtmp.txt > $HOME/pkginstalls.txt
rm $HOME/pkgtmp.txt
exit 0