I may not fully understand the question, but a simple fix is to use the -r
flag. So:
wget -r www.site.com
will recursively grab the items up to a depth of 5 levels (you can change that too with -l N
where N is the max depth) and will store them in ./www.site.com/, basically recreating the folder structure of the URL you grabbed inside that folder. So you would end up with:
.
├── www.site.com /
└─────── pics
| └─── image1.jpg
| └─── image2.jpg
└─────── index.html
└─────── links.html
This will not, however, leave the index.html file in your current folder, it will put it in the folder for the site.
If you want to play around with the directory structure, here's some info from the man page on how to cut down the path:
Directory Options
-nd
--no-directories
Do not create a hierarchy of directories when retrieving recursively. With this option turned on, all files will get saved to the current directory, without clobbering (if a name shows up more than once, the filenames
will get extensions .n).
-x
--force-directories
The opposite of -nd---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.
-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.
--cut-dirs=number
Ignore number directory components. This is useful for getting a fine-grained control over the directory where recursive retrieval will be saved.
Take, for example, the directory at ftp://ftp.xemacs.org/pub/xemacs/. If you retrieve it with -r, it will be saved locally under ftp.xemacs.org/pub/xemacs/. While the -nH option can remove the ftp.xemacs.org/ part,
you are still stuck with pub/xemacs. This is where --cut-dirs comes in handy; it makes Wget not "see" number remote directory components. Here are several examples of how --cut-dirs option works.
No options -> ftp.xemacs.org/pub/xemacs/
-nH -> pub/xemacs/
-nH --cut-dirs=1 -> xemacs/
-nH --cut-dirs=2 -> .
--cut-dirs=1 -> ftp.xemacs.org/xemacs/
...
If you just want to get rid of the directory structure, this option is similar to a combination of -nd and -P. However, unlike -nd, --cut-dirs does not lose with subdirectories---for instance, with -nH --cut-dirs=1, a
beta/ subdirectory will be placed to xemacs/beta, as one would expect.