我需要将文件下载到 /tmp/cron_test/ 下。我的wget代码如下:
wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/
那么有没有某个参数可以指定目录呢?
我需要将文件下载到 /tmp/cron_test/ 下。我的wget代码如下:
wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/
那么有没有某个参数可以指定目录呢?
从手册页面获取:
-P prefix
--directory-prefix=prefix
Set directory prefix to prefix. The directory prefix is the
directory where all other files and sub-directories will be
saved to, i.e. the top of the retrieval tree. The default
is . (the current directory).
因此,您需要向您的命令添加-P /tmp/cron_test/
(缩写形式)或--directory-prefix=/tmp/cron_test/
(长格式)。还要注意,如果该目录不存在,则会创建该目录。
-O
是指定要下载到的文件路径的选项:
wget <uri> -O /path/to/file.ext
-P
是一个前缀,它将把文件下载到该目录中:
wget <uri> -P /path/to/folder
/path/to/folder/
。 - Louis Maddox-O
选项,虽然我不需要它,但这让我更加自信地知道 -P
才是我需要的。 - WORMSSdirname
和仅输出文件名(请考虑basename
)。对于此操作,请只使用“-O”并指定完整的文件路径。 - murla确保您下载的内容的URL是正确的。首先,包含像?
等字符的URL无法被解析和解决。这会使cmd命令行混淆,并接受任何未解决为源URL名称的字符作为您要下载到的文件名。
例如:
wget "sourceforge.net/projects/ebosse/files/latest/download?source=typ_redirect"
将下载的文件命名为 ?source=typ_redirect
。
如你所见,了解 URL 对于理解 wget
有所帮助。
我正在使用 hirens 光盘引导计算机,并且只能使用 Linux 2.6.1 作为资源(无法使用 import os)。解决我的问题并将 ISO 下载到物理硬盘上的正确语法是:
wget "(source url)" -O (directory where HD was mounted)/isofile.iso"
通过查找 wget
下载到名为 index.html
(默认文件)的文件的位置,并使用以下命令显示所需文件的正确大小/其他属性,可以确定正确的 URL:
wget "(source url)"
当URL和源文件正确,并下载到index.html
时,您可以停止下载 (ctrl+z) 并使用以下命令更改输出文件:
-O "<specified download directory>/filename.extension"
在源URL之后。
在我的情况下,这将导致下载一个ISO文件并将其存储为二进制文件,命名为isofile.iso
,希望它能够挂载。
-P prefix
--directory-prefix=prefix
Set directory prefix to prefix. The directory prefix is the directory where all other files and subdirectories will be saved to, i.e. the top of the retrieval tree. The default is . (the current directory).
-nd
--no-directories
Do not create a hierarchy of directories when retrieving recursively. With this option turned on, all files will get saved to the current directory, without clobbering (if a name shows up more than once, the
filenames will get extensions .n).
-np
--no-parent
Do not ever ascend to the parent directory when retrieving recursively. This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.
man wget: -O 文件名 --output-document=文件名
wget "url" -O /tmp/cron_test/<file>