How to use the Linux wget command to download files from the internet
By using the Linux command wget you can start the program of the same name and download files from the internet. This command gives you plenty of options to optimize the process as well.
What is the Linux wget command?
wget is an important tool on Linux systems if you want to download files from the internet. The program allows you to download content directly from your terminal. First released in 1996 and managed by the GNU project wget is a free tool that comes as standard on most Linux distributions such as Debian or Ubuntu. You can initiate downloads by using the wget command. Downloads are supported by FTP-, HTTP and HTTPS servers.
If you don’t have wget on your Linux system, you can install it by using the following command:
$ sudo apt-get install wget
shellHow does the wget command work?
You can use the wget command to download a file from the internet. Files are automatically saved in your current work folder. The download won’t take place interactively. This means that processes can be carried out even when you’re not logged in. This option is also used to restart a download that was previously stopped.
What does the wget syntax look like?
Once you’ve installed Linux wget, you can use the command to download content. This is what the syntax looks like:
$ wget [Option] [URL]
shellYou can also modify wget through different options. If you want to download multiple files you can list the corresponding URLs and simply separate them with a space.
What options does the wget command have?
There are numerous options for wget. These are the most common:
- -c or –continue: Continues a previously interrupted download.
- -N: Will only download a file if it’s newer than a file of the same name on your computer.
- -t [amount]: Sets how many times Linux wget will try to download a file.
- -w [time]: Sets how many seconds wget will wait between multiple downloads.
Examples of a wget command
Finally we will show you how you can use wget. Here are a few examples:
$ wget http://example.com/folder/file
shellThis is how you can download a file.
$ wget -c http://example.com/folder/file
shellAnd with this command you can restart a download.
$ wget -t 5 http://example.com/folder/file
shellIn this example wget will attempt to download the file five times. If these five attempts aren’t successful, the download will fail.