如何使用wget重命名下载的文件? [英] How to rename the downloaded file with wget?
问题描述
要从服务器下载SOFA统计信息,请使用wget命令:
To download the SOFA Statistics from the server I use the wget command:
wget -c http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp
在这种情况下,下载文件的文件名是download?source=files
.如果我在命令中添加--output-document
选项,以将输出文件重命名为sofastatistics-latest.deb
,则dpkg软件包无法识别下载文件的格式.
The filename of downloaded file in this case is download?source=files
. If I add the --output-document
option to the command, to rename the output file to sofastatistics-latest.deb
, the format of downloaded file is not recognized by dpkg package.
dpkg-deb: error: `sofastatistics-latest.deb' is not a debian format archive
如何使用wget正确重命名下载的文件?
How to rename correctly the downloaded file with wget?
更新-15年1月8日
UPDATE - Jan 08 '15
使用提供的链接,下载的文件将始终是* .tar.gz.要使用真实名称获取它,只需添加--content-disposition
选项(感谢@ 6EQUJ5!):
With the provided link the downloaded file always will be a *.tar.gz one. To get it with the real name just add the --content-disposition
option as this (thanks to @6EQUJ5!):
wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp
但是我需要一个* .deb文件,所以这里是@creaktive,我不得不搜索* .deb文件链接.
But I needed a *.deb file, so here was right the @creaktive, I had to search for a *.deb file link.
感谢大家的回答!
推荐答案
将标准输出重定向到任意文件名始终有效.您按照 man wget 所说使用-O
A redirect of standard output into arbitrary file name always works. You are doing it correctly as man wget says, using -O
wget http://www.kernel.org/pub/linux/kernel/README -O foo
--2013-01-13 18:59:44-- http://www.kernel.org/pub/linux/kernel/README
Resolving www.kernel.org... 149.20.4.69, 149.20.20.133
Connecting to www.kernel.org|149.20.4.69|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12056 (12K) [text/plain]
Saving to: `foo'
100%[======================================================================================================================================>] 12,056 --.-K/s in 0.003s
2013-01-13 18:59:45 (4.39 MB/s) - `foo' saved [12056/12056]
实际上,您必须在文件中获取HTML(通常可以通过 man文件进行检查).
Indeed, you must be getting an HTML in your file (usually can be checked with man file).
在您的情况下,客户端收到的是 302找到的(您可以使用 curl -v URL 进行检查).
In your case client is receiving 302 Found (you can check it with curl -v URL).
以下curl通过遵守3xx来达到目的:
The following curl does the trick by respecting the 3xx:
$ curl -L http://sourceforge.net/projects/sofastatistics/files/latest/download?source=files -o foo.deb
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 463 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
100 2035k 100 2035k 0 0 390k 0 0:00:05 0:00:05 --:--:-- 1541k
$ file foo.deb
foo.deb: gzip compressed data, was "sofastats-1.3.1.tar", last modified: Thu Jan 10 00:30:44 2013, max compression
wget 应该有类似的选项来容忍HTTP重定向.
There should be similar option for wget to tolerate HTTP redirects.
这篇关于如何使用wget重命名下载的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!