
我有一個設定文件,其中包含我要下載的 URI 清單。例如,
http://xyz.abc.com/Dir1/Dir3/sds.exe
http://xyz.abc.com/Dir2/Dir4/jhjs.exe
http://xyz.abc.com/Dir1/itr.exe
我想讀取設定檔並複製每個 URL,但同時建立與主機上相同的目錄結構。例如,對於設定檔中的第一行,我想在本機上建立目錄結構 Dir1/Dir3(如果不存在),然後將 sds.exe 複製到 .../Dir1/Dir3/
我發現我可以使用“wget -i”下載文件中的所有 URL,但如何使用它來創建相應的目錄結構
答案1
從man wget
:
-x,--force-目錄:
[...]
建立目錄層次結構,即使不會以其他方式建立目錄層次結構。例如 wget -xhttp://fly.srk.fer.hr/robots.txt將把下載的檔案儲存到fly.srk.fer.hr/robots.txt。
答案2
為了獲得您所要求的結構,我建議使用 -nH 以及 -x。
這將刪除主機名稱並建立預期的目錄結構。
例如
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...