我想列出某个来源的所有文件,比如extras.ubuntu.com从命令行。该命令是什么?
dpkg --list
列出所有文件或仅列出文件名。
答案1
/var/lib/apt/lists/
找到以结尾的相关文件Packages
,并执行以下命令:
# example for deb http://security.ubuntu.com/ubuntu natty-security multiverse
awk '$1 == "Package:" { print $2 }' /var/lib/apt/lists/security*multiverse*Packages
顺便说一句,我的extras.ubuntu.com_ubuntu_dists_natty_main_binary-i386_Packages
是空的。
编辑
您还可以解析apt-cache
输出。此脚本列出了所有带有服务器和存储库信息的软件包:
#!/bin/bash
apt-cache policy $(dpkg -l | awk 'NR >= 6 { print $2 }') |
awk '/^[^ ]/ { split($1, a, ":"); pkg = a[1] }
nextline == 1 { nextline = 0; printf("%-40s %-50s %s\n", pkg, $2, $3) }
/\*\*\*/ { nextline = 1 }'
方便地对输出进行排序,您可以获得所需的信息。
答案2
我只需直接在服务器端检查,如下所示:
$ curl -s http://extras.ubuntu.com/ubuntu/dists/maverick/main/binary-i386/Packages.gz |
gzip -d | grep Package
Package: news
Package: suspended-sentence
答案3
我为此写了一个糟糕的脚本:
#!/bin/bash
clear
##array aufbauen
declare -a repoList=()
for i in $(ls /var/lib/apt/lists/ | grep _Packages)
do
#echo $i
repoList=("${repoList[@]}" "$i")
done
repoAnzahl=${#repoList[@]}
echo "Anzahl der Repos: " $repoAnzahl
for ((i=0;$i<$repoAnzahl;i++))
do
if [[ "${repoList[$i]}" =~ "archive.ubuntu" ]]
then
rname=${repoList[$i]##*archive.ubuntu}
echo "$i RepoName: " "${rname%%_binary*}"
elif [[ "${repoList[$i]}" =~ "ubuntu" ]]
then
echo "$i RepoName: " "${repoList[$i]%%_ubuntu*}"
else
echo "$i RepoName: " "${repoList[$i]%%_dist*}"
fi
done
read -p "Gib die RepoNummer ein: " repoNummer
packages=()
for i in $(cat /var/lib/apt/lists/${repoList[$repoNummer]} | grep Package)
do
if ! [[ "$i" =~ "Package" ]]
then
packages=("${packages[@]}" "$i")
fi
done
paketAnzahl=${#packages[@]}
echo "Anzahl der pakete: " $paketAnzahl
function listPackages () {
for ((i=0;$i<$paketAnzahl;i++))
do
echo ${packages[$i]}
done
}
if test $paketAnzahl -gt 20
then
listPackages | less
else
listPackages
fi
echo "Anzahl der Pakete: " $paketAnzahl
答案4
类似这个 Python 脚本的东西应该能从该站点找到你机器上安装的所有包(参见这个答案对于显示所有非 Ubuntu 软件包的脚本):
#!/usr/bin/env python3
#
# This lists all packages from extras.ubuntu.com
#
# If you receive an import error, you may need to install python-apt first with e.g.
# sudo apt install python-apt
# but this is often not necessary
import apt
cache = apt.Cache()
package_count = 0
for package in cache:
if (
cache[package.name].is_installed
and package.candidate.origins[0].site == "extras.ubuntu.com"
):
package_origin = package.candidate.origins[0]
print(
package.name,
# See https://apt-team.pages.debian.net/python-apt/library/apt.package.html#apt.package.Origin
# for further details on the meanings of the below
package_origin.origin, # The Origin, as set in the Release file
package_origin.archive, # The archive (eg. Ubuntu release name)
package_origin.component, # The component (eg. main/universe)
package_origin.site, # The hostname of the site.
# package_origin.label, # The Label, as set in the Release file
# package_origin.trusted, # Origin trusted (Release file signed by key in apt keyring)
)
package_count += 1
print(package_count, "packages total")