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

前端 未结 14 2041
再見小時候
再見小時候 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:29

    This version downloads recursively and doesn't create parent directories.

    wgetod() {
        NSLASH="$(echo "$1" | perl -pe 's|.*://[^/]+(.*?)/?$|\1|' | grep -o / | wc -l)"
        NCUT=$((NSLASH > 0 ? NSLASH-1 : 0))
        wget -r -nH --user-agent=Mozilla/5.0 --cut-dirs=$NCUT --no-parent --reject="index.html*" "$1"
    }
    

    Usage:

    1. Add to ~/.bashrc or paste into terminal
    2. wgetod "http://example.com/x/"
    0 讨论(0)
  • 2020-11-27 09:34

    You should be able to do it simply by adding a -r

    wget -r http://stackoverflow.com/
    
    0 讨论(0)
提交回复
热议问题