我使用--print-uris
来apt-get
获取我想要下载并安装在我的 Debian 上的 debs 的 url(下载链接)(特里克尔)GNU/Linux。
--print-uris
Instead of fetching the files to install their URIs are printed. Each URI will have the path, the
destination file name, the size and the expected MD5 hash. Note that the file name to write to will not
always match the file name on the remote site! This also works with the source and update commands. When
used with the update command the MD5 and size are not included, and it is up to the user to decompress any
compressed files. Configuration Item: APT::Get::Print-URIs.
示例输出wesnoth
:-
$ apt_uris wesnoth
http://mirror.fsf.org/trisquel/pool/main/s/sdl-net1.2/libsdl-net1.2_1.2.8-4_i386.deb
http://mirror.fsf.org/trisquel/pool/main/s/sdl-ttf2.0/libsdl-ttf2.0-0_2.0.11-3_i386.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-data_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-core_1.10.7-1ubuntu0.14.04.1_i386.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-httt_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-tsg_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-trow_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-ttb_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-ei_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-utbs_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-did_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-nr_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-sof_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-sotbe_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-l_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-aoi_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-thot_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-low_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-dm_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-dw_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-music_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth_1.10.7-1ubuntu0.14.04.1_all.deb
笔记:
$ type apt_uris
apt_uris is a function
apt_uris ()
{
sudo apt-get install "$@" --print-uris -qq | grep http:// | cut -d "'" -f 2;
}
现在进入正题:-我想从 URL 获取/打印每个 deb 文件的大小(无需下载)。
我该如何通过使用wget
或其他方式做到这一点?
答案1
在不下载的情况下获取文件大小的典型方法是发出 HTTP HEAD 请求,并希望服务器将大小发送回Content-Length
标头中。对于通常的静态文件(例如deb
文件),服务器可能会发回该信息,但不能保证。
有多种工具可以发送这些 HTTP HEAD 请求。以下是使用该实用程序执行此操作的函数示例curl
:
get_size() { # arg: URI
curl -sI "$1" | sed -n 's/^Content-Length: \([0-9]\{1,\}\).*/\1/p'
}
Content-Length
请注意,无论查询成功还是返回错误(例如,404 Not found
是Content-Length
错误消息的大小),它都会返回。
替代方案包括curl
:
- GNU
wget
:。wget -qSO- --max-redirect=0 --method=HEAD "$1"
如果查询不成功(例如与set -o pipefail
实例结合使用),该查询将返回一个不成功的退出状态。 - Perl LWP
HEAD
命令:HEAD "$1"
.该命令也会报告查询失败,但会遵循 HTTP 重定向,并且您似乎无法禁用它。
如果您追求的是一种人性化的方法,您也可以使用lftp
:
$ lftp -c 'du -h http://mirror.fsf.org/trisquel/pool/main/s/sdl-net1.2/libsdl-net1.2_1.2.8-4_i386.deb'
12K /trisquel/pool/main/s/sdl-net1.2/libsdl-net1.2_1.2.8-4_i386.deb
答案2
在 Debian 衍生版本中,每个文件的大小.deb
都存储在软件包列表中,因此您无需下载任何内容即可检索它。
其实直接apt-get --print-uris
给你信息:
$ apt-get install nginx --print-uris -qq
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
'http://ftp.fr.debian.org/debian/pool/main/n/nginx/nginx-common_1.9.1-1_all.deb' nginx-common_1.9.1-1_all.deb 96110 MD5Sum:fc64530dcd5a4d50a36b9f2423fcf6c2
'http://ftp.fr.debian.org/debian/pool/main/n/nginx/nginx-full_1.9.1-1_amd64.deb' nginx-full_1.9.1-1_amd64.deb 471998 MD5Sum:6392f45e4e376ea3be2e60949dd80fe0
'http://ftp.fr.debian.org/debian/pool/main/n/nginx/nginx_1.9.1-1_all.deb' nginx_1.9.1-1_all.deb 75882 MD5Sum:ab5fa732657fba06544b353572967383
第三个字段是.deb
文件的大小。
当我这样做时,您不需要运行apt-get
asroot
来确定要下载的包列表!