Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to recursively download the contents of a particular directory (via http from a web server) using wget. The command I am using is:

wget -r -l 0 --user=josh --ask-password http://morris.cs.example.com/files/Software/MySoftware/V2012_Linux

wget then appears to download the contents of the parent directories rather than just the intended child directory (V2012_Linux).

How do I modify my command to download only the contents of the child directory and also place it in a directory of my choosing?

share|improve this question
up vote 3 down vote accepted

I think you're looking for

-np, --no-parent                 don't ascend to the parent directory.


wget -r -l 0 -np --user=josh --ask-password http://morris.cs.example.com/files/Software/MySoftware/V2012_Linux/

Wget doesn't give much flexibility with output file names. If you want recursive downloading, you have to let the structure of the downloaded tree match the structure as served. Move V2012_Linux where you want it once the download is finished, or create a symbolic link.

share|improve this answer
Thanks Gilles, your answer was helpful, however in my particular case, I needed to ensure that the trailing slash / was present. From wget's manual: "Note that, for HTTP (and HTTPS), the trailing slash is very important to ‘--no-parent’. HTTP has no concept of a “directory”—Wget relies on you to indicate what's a directory and what isn't. In ‘foo/bar’, Wget will consider ‘bar’ to be a directory, while in ‘foo/bar’ (no trailing slash), ‘bar’ will be considered a filename (so ‘--no-parent’ would be meaningless, as its parent is ‘/’)." – Josh Feb 13 '13 at 0:00
@Josh Right, thank you, I'd forgotten about that. – Gilles Feb 13 '13 at 0:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.