Using wget to recursively fetch a directory with arbitrary files in it

前端 未结 14 2097
再見小時候
再見小時候 2020-11-27 08:31

I have a web directory where I store some config files. I\'d like to use wget to pull those files down and maintain their current structure. For instance, the remote directo

14条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 09:17

    All you need is two flags, one is "-r" for recursion and "--no-parent" (or -np) in order not to go in the '.' and ".." . Like this:

    wget -r --no-parent http://example.com/configs/.vim/

    That's it. It will download into the following local tree: ./example.com/configs/.vim . However if you do not want the first two directories, then use the additional flag --cut-dirs=2 as suggested in earlier replies:

    wget -r --no-parent --cut-dirs=2 http://example.com/configs/.vim/

    And it will download your file tree only into ./.vim/

    In fact, I got the first line from this answer precisely from the wget manual, they have a very clean example towards the end of section 4.3.

提交回复
热议问题