Linux wget -O 用于不存在的保存路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11258271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wget -O for non-existing save path?
提问by u775856
I can't wget
while there is no path already to save. I mean, wget
doens't work for the non-existing save paths. For e.g:
我不能wget
,因为已经没有路径可以保存。我的意思是,wget
不适用于不存在的保存路径。例如:
wget -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
If /path/to/image/
is not previously existed, it always returns:
如果/path/to/image/
之前不存在,它总是返回:
No such file or directory
How can i make it work to automatically create the path and save?
我怎样才能让它自动创建路径并保存?
采纳答案by kev
Try curl
尝试 curl
curl http://www.site.org/image.jpg --create-dirs -o /path/to/save/images.jpg
回答by Ash
mkdir -p /path/i/want && wget -O /path/i/want/image.jpg http://www.com/image.jpg
回答by K1773R
wget is only getting a file NOT creating the directory structure for you (mkdir -p /path/to/image/), you have to do this by urself:
wget 只是获取一个文件,而不是为您创建目录结构(mkdir -p /path/to/image/),您必须自己执行此操作:
mkdir -p /path/to/image/ && wget -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
You can tell wget to create the directory (so you dont have to use mkdir) with the parameter --force-directories
您可以使用参数告诉 wget 创建目录(因此您不必使用 mkdir) --force-directories
alltogether this would be
总之这将是
wget --force-directories -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
回答by Toan Nguyen
After searching a lot, I finally found a way to use wget
to download for non-existing path.
找了好久,终于找到了wget
下载不存在路径的方法。
wget -q --show-progress -c -nc -r -nH -i ""
=====
Clarification
-q
--quiet --show-progress
Kill annoying output but keep the progress-bar
-c
--continue
Resume download if the connection lost
-nc
--no-clobber
Overwriting file if exists
-r
--recursive
Download in recursive mode (What topic creator asked for!)
-nH
--no-host-directories
Tell wget do not use the domain as a directory (for e.g: https://example.com/what/you/need
- without this option, it will download to "example.com/what/you/need")
-i
--input-file
File with URLs need to be download (in case you want to download a lot of URLs,
otherwise just remove this option)
Happy wget-ing!
祝您工作愉快!
回答by Noam Manos
To download a file with wget, into a new directory, use --directory-prefix
without-O
:
要使用 wget 将文件下载到新目录中,请使用--directory-prefix
不带-O
:
wget --directory-prefix=/new/directory/ http://www.example.com/old_image.jpg
Using -O new_file
in conjunction with --directory-prefix
, will not create the new directorystructure, and will save the new file in the current directory.
It may even fail with "No such file or directory" error, if you specify -O /new/directory/new_file
使用-O new_file
结合--directory-prefix
,将无法创建新的目录结构,将新文件保存在当前目录中。如果您指定,它甚至可能因“没有这样的文件或目录”错误而失败-O /new/directory/new_file