Wget(Website get) is a Linux command line tool to download any file which is available through a network which has a hostname or IP address. With wget command we can download from an FTP or HTTP site as this supports many protocols like FTP, HTTP, https, ftps etc. By default wget command downloads files to the present working directory where you execute the command. This is a bit annoying as we have to move the downloaded file to a specific folder or we have to go the directory where you want that file downloaded and use wget command. In this post, we will see how to download to a specific location in the system.
Saving a file downloaded with wget with a different name Posted in Linux/Unix/BSD - Last updated Feb. Wget is a command line utility for downloading files from FTP and HTTP web servers. By default when you download a file with wget, the file will be written to the current directory, with the same name as the filename in the URL. WGet and Downloading an entire remote directory. When I need to download an ISO or a single file, using wget with recurse on an. Need to download a specific.
wget command syntax:
Wget Download File To Directory Free
To get downloaded file to a specific directory we should use -P or –directory-prefix=prefix. From wget man pages.
The syntax for downloading to a specific directory.
Example:
Output:
How about if you want to download a file to a specific directory with a specific name. Downloading as a specific file is required when the downloaded file does not have a specific name. Sometimes the files which we download will not have a specific name. For example, when we try to download firefox browser we will get the file name as “index.html?product=firefox-latest-ssl ”
This is a bit annoying as we have to figure out what is the file name. With wget’s -O or –output-document option we can specify the filename we are going to save the file.
Example:
In our next post, we will see some other exiting command example.
The following two tabs change content below.- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018
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.
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,
For more information, see the wget man page.
Find Download File
You might also like to read these following related articles.
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.