Download files via the command line in Linux

There are man times when you will have to download files from the command line. In most distributions, you have two tools – wget and curl.

wget

This a very powerful command to simply download a file. Just use wget URL to download the file to the current location:

root@web [/]# wget  https://ip.plothost.com/test
--2020-01-19 06:11:50--  https://ip.plothost.com/test
Resolving ip.plothost.com (ip.plothost.com)... 104.10.10.155
Connecting to ip.plothost.com (ip.plothost.com)|104.10.10.155|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 94371840 (90M)
Saving to: 'test'

100%[==============================================================================================================================>] 94,371,840  11.2MB/s   in 8.3s

2020-01-19 06:11:58 (10.9 MB/s) - 'test' saved [94371840/94371840]

root@web [/]#

To use a custom filename, the command is wget URL -O filename.

curl

With the curl command, you can get the file content or download a file. To get file content, use curl URL:

root@web [~]# curl https://ip.plothost.com/testfile.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>Test file PlotHost.com</TITLE>
</HEAD>


<BODY bgcolor="#EFEFEF">
Testing ...
</BODY></HTML>
root@web [~]#

To download a file, curl URL -o filename

root@web [/]# curl https://ip.plothost.com/test -o test_file
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 90.0M  100 90.0M    0     0  10.5M      0  0:00:08  0:00:08 --:--:-- 11.1M
root@web [/]#
wget download
Linux wget command

Resources:
wget man page
curl man page

Leave a Reply