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

前端 未结 14 2104
再見小時候
再見小時候 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/"

提交回复
热议问题