如何用wget指定位置?

Léo*_* 준영 643 wget

我需要将文件下载到/ tmp/cron_test /.我的wget代码是

wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/
Run Code Online (Sandbox Code Playgroud)

那么是否有一些参数来指定目录?

Ric*_*dle 883

从手册页:

-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).
Run Code Online (Sandbox Code Playgroud)

所以你需要为你的命令添加-P /tmp/cron_test/(简短形式)或--directory-prefix=/tmp/cron_test/(长形式).另请注意,如果目录不存在,则会创建该目录.

  • 手册的说明使此选项难以搜索.我不认为我想将某些东西保存为"目录前缀"的位置.感谢分享! (32认同)
  • 袋鼠它可能不起作用,因为你的系统上没有/ tmp/cron_test /:P (6认同)
  • 此外,您可以根据http://serverfault.com/questions/354792/downloading-from-wget-folder-issue通过`--no-host-directories`或`-nH`删除根文件夹. (6认同)
  • -P/tmp/cron_test /不起作用,但删除/喜欢-P tmp/cron_test /工作,甚至创建不存在的目录. (3认同)
  • 好吧,“-P”选项对我不起作用(在 18.04 上),至少对“-O”选项不起作用。还有其他细节需要注意吗? (3认同)
  • @artu-hnrq `-P` 不能与 `-O` 一起使用,因为 `-O` 保存到文件(请参阅 `wget --help` ,它概述了这一点。您不能将 `wget` URI 保存为目录* *和**同时创建一个文件。 (2认同)

小智 362

-O是指定要下载的文件的路径的选项.

wget <file.ext> -O /path/to/folder/file.ext
Run Code Online (Sandbox Code Playgroud)

-P是将在目录中下载文件的前缀

wget <file.ext> -P /path/to/folder
Run Code Online (Sandbox Code Playgroud)

  • 投票赞成也指定了我不需要的"-O",但让我更有信心`-P`是我所需要的. (27认同)
  • 我将添加一个尾部斜杠,使其成为`/ path/to/folder /` (7认同)
  • 注意:“-O”覆盖“-P”,因此您不能仅指定输出目录(认为“dirname”**和**仅指定输出文件名(认为“basename”)。为此,只需使用“-O”指定完整文件路径。 (5认同)
  • @ TimothyL.J.Stewart没有双斜杠错误. (2认同)

小智 7

确保您所下载的内容的URL正确无误.首先,?无法解析和解析具有类似字符等的URL .这将混淆cmd行并接受未解析为源URL名称的任何字符作为要下载的文件名.

例如:

wget "sourceforge.net/projects/ebosse/files/latest/download?source=typ_redirect"
Run Code Online (Sandbox Code Playgroud)

将下载到名为的文件中?source=typ_redirect.

正如您所看到的,了解有关URL的一两件事有助于理解wget.

我从一个hirens磁盘启动,只有Linux 2.6.1作为资源(导入操作系统不可用).解决了将ISO下载到物理硬盘驱动器上的问题的正确语法是:

wget "(source url)" -O (directory where HD was mounted)/isofile.iso" 
Run Code Online (Sandbox Code Playgroud)

可以通过查找wget下载到名为index.html(默认文件)的文件的哪个点来确定正确的URL ,并且具有您需要通过以下命令显示的文件的正确大小/其他属性:

wget "(source url)"
Run Code Online (Sandbox Code Playgroud)

一旦该URL和源文件正确并且正在下载index.html,您可以使用以下命令停止下载(ctrl+ z)并更改输出文件:

-O "<specified download directory>/filename.extension"
Run Code Online (Sandbox Code Playgroud)

在源网址之后.

在我的情况下,这导致下载ISO并将其存储为二进制文件isofile.iso,希望安装.


pr-*_*pal 7

“-P”是正确的选项,请继续阅读以获取更多相关信息:

wget -nd -np -P /dest/dir --recursive http://url/dir1/dir2

为了方便起见,手册页中的相关片段:

   -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.
Run Code Online (Sandbox Code Playgroud)