乐闻世界logo
搜索文章和话题

How do I mirror a directory with wget without creating parent directories?

1个答案

1

When using wget to mirror a directory, by default, wget creates a complete directory structure locally to replicate the directory structure of the remote server. If you do not want to create parent directories, you can use the -nH (--no-host-directories) option, which prevents wget from creating top-level host directories. Additionally, if you want to further avoid creating any directories, you can add the --cut-dirs=X option, where X is the number of directory levels you wish to skip.

For example, if you want to mirror the data directory from http://example.com/files/data/ without creating any parent directories, you can use the following command:

bash
wget -r -nH --cut-dirs=2 --no-parent http://example.com/files/data/

Here is the explanation of the parameters:

  • -r : Recursively download.
  • -nH : Do not create host directories.
  • --cut-dirs=2 : Ignore the first two directory levels in the URL (the directories before files and data).
  • --no-parent : Prevent wget from accessing parent directories.

Using this approach, you can start mirroring the contents of the data directory directly in the current directory without creating any other parent or host directories. This helps maintain a clean local directory structure and makes managing downloaded files more convenient.

2024年7月30日 00:23 回复

你的答案