How to specify the location with wget?

后端 未结 5 1484
梦毁少年i
梦毁少年i 2020-12-04 04:27

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/u         


        
相关标签:
5条回答
  • 2020-12-04 04:56

    "-P" is the right option, please read on for more related information:

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

    Relevant snippets from man pages for convenience:

       -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.
    
    0 讨论(0)
  • 2020-12-04 04:59

    -O is the option to specify the path of the file you want to download to:

    wget <uri> -O /path/to/file.ext
    

    -P is prefix where it will download the file in the directory:

    wget <uri> -P /path/to/folder
    
    0 讨论(0)
  • 2020-12-04 05:08

    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 aren't resolved into the source URL name as the file name you are downloading into.

    For example:

    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.

    0 讨论(0)
  • 2020-12-04 05:10

    man wget: -O file --output-document=file

    wget "url" -O /tmp/cron_test/<file>
    
    0 讨论(0)
  • 2020-12-04 05:14

    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.

    0 讨论(0)
提交回复
热议问题