using wget utility to download files while keeping path structure

发布时间 2023-09-26 09:23:27作者: profesor

From man wget:

-x, --force-directories:

[...]

create a hierarchy of directories, even if one would not have been created otherwise. E.g. wget -x http://fly.srk.fer.hr/robots.txt will save the downloaded file to fly.srk.fer.hr/robots.txt.

 

 

To get the structure you are asking for, I would suggest using -nH as well as -x.

This will remove the hostname as well as create the expected directory structure.

e.g.

wget -x -nH http://xyz.abc.com/Dir1/Dir3/sds.exe

- 'Dir1/Dir3/sds.exe' saved [1234]
-nH
--no-host-directories
   Disable generation of host-prefixed directories.  By default, invoking Wget with -r http://fly.srk.fer.hr/ will create a structure of directories beginning with fly.srk.fer.hr/.  This option disables such behavior.

-x
--force-directories
   ...create a hierarchy of directories, even if one would not have been created otherwise...

来源:https://unix.stackexchange.com/questions/72240/download-files-and-create-same-file-structure-as-the-source