How to specify the location with wget?
I need files to be downloaded to /tmp/cron_test/. My wget code is
wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/
So is there some parameter to specify the directory?
From the manual page:
-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).
So you need to add -P /tmp/cron_test/
(short form) or --directory-prefix=/tmp/cron_test/
(long form) to your command. Also note that if the directory does not exist it will get created.
-O is the option to specify the path of the file you want to download to.
wget <file.ext> -O /path/to/folder/file.ext
-P is prefix where it will download the file in the directory
wget <file.ext> -P /path/to/folder
Make sure you have the url correct for whatever you are downloading first of all, urls with characters like '?'
and such cannot be parsed and resolved, this will confuse the cmd line and accept any characters that arent resolved into the source url name as the file name you are downloading into.
ie, wget "sourceforge.net/projects/ebosse/files/latest/download?source=typ_redirect"
will download into a file named ?source=typ_redirect
.
As you can see knowing a thing or two about urls helps to understand wget.
I am booting from a hirens disk and only had Linux 2.6.1 as a resource (import os is unavailable). The correct syntax that solved my problem, downloading an iso onto the physical hard drive, was:
wget "(source url)" -O (directory where HD was mounted)/isofile.iso"
one could figure the correct url by finding at what point wget downloads into a file named "index.html" (the default file) ,and has the correct size/other attributes of the file you need shown by the following command:
wget "(source url)"
once that url and source file is correct and it is downloading into index.html, you can stop the download (ctrl + z) and change the output file by using -O "<specified download directory>/filename.extension"
after the source url.
In my case this results in downloading an iso and storing it as a binary file under isofile.iso, which hopefully mounts.
链接地址: http://www.djcxy.com/p/57156.html上一篇: 递归wget与热链接的必备条件
下一篇: 如何用wget指定位置?