How to Download Files to Specific Directory Using Wget

Wget is a popular, non-interactive and widely used network downloader which supports protocols such as HTTP, HTTPS, and FTP, and retrieval via HTTP proxies. By default, wget downloads files in the current working directory where it is run.

Read Also: How to Rename File While Downloading with Wget in Linux

In this article, we will show how to download files to a specific directory without moving into that directory. This guide is useful, if, for example, you are using wget in a script, and want to automate downloads which should be stored in different directories.

In addition, wget being non-interactive (can work in the background) by design makes it easy to use for automating downloads via shell scripts. You can actually initiate a download and disconnect from the system, letting wget complete the job.

Wget’s -P or --directory-prefix option is used to set the directory prefix where all retrieved files and subdirectories will be saved to.

In this example, we will demonstrate how to download the glances config template and store it under /etc/glances/ directory.

$ sudo mkdir /etc/glances
$ ls /etc/glances/
$ sudo wget -P /etc/glances/
$ ls /etc/glances/
Wget Download Files to Specific Directory

Wget Download Files to Specific Directory

If you are downloading a heavy file, you may want to add the -c or --continue flag, which means continue getting a partially-downloaded file. With it, you don’t have to start the download afresh.

This option helps you to resume downloading a file started by a previous instance of wget, or by another program or one that you had paused. It is also useful in case of any network failure. For example,

$ wget -c

For more information, see the wget man page.

$ man wget 

You might also like to read these following related articles.

  1. How to Download and Extract Tar Files with One Command
  2. 5 Linux Command Line Based Tools for Downloading Files and Browsing Websites
  3. 15 Tips On How to Use ‘Curl’ Command in Linux

That’s all! In this short article, we have explained how to download files to a specific directory without moving into that directory, using wget. You can share your thoughts with us in the comments.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.